Skip to content

Commit f5e6dc2

Browse files
Merge pull request #341 from dappnode/pablo/commands-refactor
commands refactor && update debian ISO image
2 parents 71d69fb + d98f7df commit f5e6dc2

3 files changed

Lines changed: 43 additions & 30 deletions

File tree

.dappnode_profile

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,13 +24,19 @@ alias dappnode_stop='docker-compose $DNCORE_YMLS stop && docker stop $(docker co
2424
# Start docker core containers
2525
alias dappnode_start='docker-compose $DNCORE_YMLS up -d && docker start $(docker container ls -a -q -f name=DAppNode*)'
2626
# Return open-vpn credentials from a specific user. e.g: dappnode_get dappnode_admin
27-
alias dappnode_get='docker exec -i DAppNodeCore-vpn.dnp.dappnode.eth vpncli get'
27+
alias dappnode_openvpn_get='docker exec -i DAppNodeCore-vpn.dnp.dappnode.eth vpncli get'
2828
# Return open-vpn admin credentials
29-
alias dappnode_connect='docker exec -i DAppNodeCore-vpn.dnp.dappnode.eth getAdminCredentials'
29+
alias dappnode_openvpn='docker exec -i DAppNodeCore-vpn.dnp.dappnode.eth getAdminCredentials || echo -e "Open VPN may not be installed. Try with wireguard \e[32mdappnode_wireguard\e[0m"'
3030
# Return wifi credentials (ssid and password)
3131
alias dappnode_wifi='cat /usr/src/dappnode/DNCORE/docker-compose-wifi.yml | grep "SSID\|WPA_PASSPHRASE"'
3232
# Return remote credentials in plain text. OPTIONS:
3333
# --qr (QR format). --local (local creds for NAT loopback issues)
34-
alias dappnode_wireguard='docker exec -i DAppNodeCore-api.wireguard.dnp.dappnode.eth getWireguardCredentials'
34+
alias dappnode_wireguard='docker exec -i DAppNodeCore-api.wireguard.dnp.dappnode.eth getWireguardCredentials || echo -e "Wireguard may not be installed. Try with Open VPN \e[32mdappnode_openvpn\e[0m" '
35+
# Execute access_credentials.sh script to check for connectivity methods
36+
alias dappnode_connect='/usr/bin/bash /usr/src/dappnode/scripts/dappnode_access_credentials.sh'
37+
# Return all available commands
38+
HELP_MESSAGE="\n\tDAppNode commands available:\n\n\tdappnode_help\t\tprints out this message\n\n\tdappnode_wifi\t\tget wifi credentials (SSID and password)\n\n\tdappnode_openvpn\treturn Open VPN credentials\n\n\tdappnode_wireguard\treturn Wireguard VPN credentials (dappnode_wireguard --help for more info)\n\n\tdappnode_connect\tcheck connectivity methods available in DAppNode\n\n\tdappnode_status\t\treturn status of dappnode containers\n\n\tdappnode_start\t\tstart dappnode containers\n\n\tdappnode_stop\t\tstop dappnode containers\n"
39+
alias dappnode_help='echo -e ${HELP_MESSAGE}'
3540

3641
return
42+
Lines changed: 24 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
#!/bin/bash
22

33
# This script will iterate over the access methods in dappnode
4-
# and display its credentials based on priority.
5-
# PRIORITY: Wi-Wi > Avahi > VPN (Wireguard > OpenVpn)
4+
# and return the credentials for each service available
65

76
#############
87
#0.VARIABLES#
@@ -21,28 +20,27 @@ WIFI_GET_CREDS=$(grep 'SSID\|WPA_PASSPHRASE' /usr/src/dappnode/DNCORE/docker-com
2120
AVAHI_ENDPOINT="dappnode.local"
2221
DAPPNODE_ADMINUI_URL="http://my.dappnode"
2322
DAPPNODE_ADMINUI_LOCAL_URL="http://${AVAHI_ENDPOINT}"
24-
DAPPNODE_WELCOME_URL="http://welcome.dappnode"
23+
DAPPNODE_WELCOME_URL="http://welcome.dappnode.io"
2524

2625
#############
2726
#1.FUNCTIONS#
2827
#############
2928

3029
function dappnode_startup_check () {
31-
echo -n "Wait until DAppNode initializes (press ctrl+c to stop) "
32-
sleep 5
30+
echo -ne "Checking DAppNode connectivity methods (press ctrl+c to stop)...\n"
3331
n=0
3432
until [ "$n" -ge 8 ]
3533
do
3634
[ "$(docker inspect -f '{{.State.Running}}' ${DAPPMANAGER_CONTAINER} 2> /dev/null)" = "true" ] && break
3735
n=$((n+1))
3836
echo -n "."
39-
sleep 8
37+
sleep 4
4038
done
4139
}
4240

4341
# $1 Connection method $2 Credentials
4442
function create_connection_message () {
45-
echo -e "\n\e[32mConnect to DAppNode through $1 using the following credentials:\e[0m\n$2\n\nAccess your DAppNode at \e[4m$DAPPNODE_ADMINUI_URL\e\n\n[0mDiscover more ways to connect to your DAppNode at \e[4m$DAPPNODE_WELCOME_URL\e[0m\n"
43+
echo -e "\e[32mConnect to DAppNode through $1 using the following credentials:\e[0m\n$2\n\nAccess your DAppNode at \e[4m$DAPPNODE_ADMINUI_URL\e\n\n[0mDiscover more ways to connect to your DAppNode at \e[4m$DAPPNODE_WELCOME_URL\e[0m"
4644
}
4745

4846
function wifi_connection () {
@@ -52,24 +50,23 @@ function wifi_connection () {
5250
[ "$(docker inspect -f '{{.State.Running}}' ${WIFI_CONTAINER} 2> /dev/null)" = "true" ] && \
5351
# Check interface variable is set
5452
[ -n "$(docker exec -it $WIFI_CONTAINER iw dev | grep 'Interface' | awk 'NR==1{print $2}')" ] && \
55-
create_connection_message "Wi-Fi" "$WIFI_GET_CREDS" && \
56-
exit 0 || echo -e "\nWifi not detected"
53+
create_connection_message "Wi-Fi" "$WIFI_GET_CREDS" || \
54+
echo -e "\e[33mWifi not detected\e[0m"
5755
}
5856

5957
function avahi_connection () {
60-
# Ping to avahi endpoint: -c: number of pings. -w: timeout
61-
avahi-resolve -n $AVAHI_ENDPOINT > /dev/null 2>&1 || { echo "Avahi-daemon not detected" ; return ; }
62-
# Https container exists
6358
# shellcheck disable=SC2143
59+
avahi-resolve -n $AVAHI_ENDPOINT > /dev/null 2>&1 && \
60+
# Https container exists
6461
[ "$(docker ps -a | grep ${HTTPS_CONTAINER})" ] && \
6562
# Https container running
6663
[ "$(docker inspect -f '{{.State.Running}}' ${HTTPS_CONTAINER})" = "true" ] && \
6764
# Https env variable LOCAL_PROXYING="true"
6865
[ "$(docker exec -i ${HTTPS_CONTAINER} sh -c 'echo "$LOCAL_PROXYING"')" = "true" ] && \
6966
# avahi-daemon running => systemctl is-active avahi-daemon RETURNS "active" or "inactive"
7067
[ "$(systemctl is-active avahi-daemon)" = "active" ] && \
71-
echo -e "\n\e[32mConnect to DAppNode through Local Proxying.\e[0m\n\nVisit \e[4m$DAPPNODE_ADMINUI_LOCAL_URL\e\n\n[0mCheck out all the access methods available to connect to your DAppNode at \e[4m$DAPPNODE_WELCOME_URL\e[0m\n" && \
72-
exit 0 || echo "Avahi-daemon not detected"
68+
echo -e "\n\e[32mConnect to DAppNode through Local Proxying.\e[0m\n\nVisit \e[4m$DAPPNODE_ADMINUI_LOCAL_URL\e\n\n[0mCheck out all the access methods available to connect to your DAppNode at \e[4m$DAPPNODE_WELCOME_URL\e[0m\n" || \
69+
echo -e "\e[33mLocal Proxy not detected\e[0m"
7370
}
7471

7572
function wireguard_connection () {
@@ -78,8 +75,8 @@ function wireguard_connection () {
7875
[ "$(docker ps -a | grep ${WIREGUARD_CONTAINER})" ] && \
7976
# wireguard container running
8077
[ "$(docker inspect -f '{{.State.Running}}' ${WIREGUARD_CONTAINER})" = "true" ] && \
81-
create_connection_message "Wireguard" "$($WIREGUARD_GET_CREDS)" && \
82-
exit 0 || echo "Wireguard not detected"
78+
create_connection_message "Wireguard" "$($WIREGUARD_GET_CREDS)" || \
79+
echo -e "\e[33mWireguard not detected\e[0m"
8380
}
8481

8582
function openvpn_connection () {
@@ -88,19 +85,26 @@ function openvpn_connection () {
8885
[ "$(docker ps -a | grep ${OPENVPN_CONTAINER})" ] && \
8986
# openvpn container running
9087
[ "$(docker inspect -f '{{.State.Running}}' ${OPENVPN_CONTAINER})" = "true" ] && \
91-
create_connection_message "Open-VPN" "$($OPENVPN_GET_CREDS)" && \
92-
exit 0 || echo "Open-VPN not detected"
88+
create_connection_message "Open-VPN" "$($OPENVPN_GET_CREDS)" || \
89+
echo -e "\e[33mOpen VPN not detected\e[0m"
90+
}
91+
92+
function line_separator () {
93+
echo "====================="
9394
}
9495

9596
########
9697
#2.MAIN#
9798
########
9899

99100
dappnode_startup_check
101+
line_separator
100102
wifi_connection
103+
line_separator
101104
avahi_connection
105+
line_separator
102106
wireguard_connection
107+
line_separator
103108
openvpn_connection
104109

105-
echo -e "\e[33mWARNING: no connection services detected\e[0m Check out all the access methods available to connect to your DAppNode at \e[4m$DAPPNODE_WELCOME_URL\e[0m\n"
106-
exit 0
110+
exit 0

scripts/dappnode_install.sh

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ SWGET="wget -q -O-"
2323
# Other
2424
CONTENT_HASH_PKGS=(geth openethereum nethermind)
2525
ARCH=$(dpkg --print-architecture)
26+
WELCOME_MESSAGE="echo -e '\nChoose a way to connect to your DAppNode, then go to \e[1mhttp://my.dappnode\e[0m\n\n\e[1m- Wifi\e[0m\t\tScan and connect to DAppNodeWIFI. Get wifi credentials with \e[32mdappnode_wifi\e[0m\n\n\e[1m- Local Proxy\e[0m\tConnect to the same router as your DAppNode. Then go to \e[1mhttp://dappnode.local\e[0m\n\n\e[1m- Wireguard\e[0m\tDownload Wireguard app on your device. Get your dappnode wireguard credentials with \e[32mdappnode_wireguard\e[0m\n\n\e[1m- Open VPN\e[0m\tDownload OPen VPN app on your device. Get your openVPN creds with \e[32mdappnode_openvpn\e[0m\n\n\nTo see a full list of commands available execute \e[32mdappnode_help\e[0m\n'"
2627

2728
# Clean if update
2829
if [ "$UPDATE" = true ]; then
@@ -231,21 +232,23 @@ dappnode_start() {
231232
echo -e "source ${DAPPNODE_PROFILE}\n" >>$PROFILE
232233
fi
233234

235+
# Remove return from profile
234236
sed -i '/return/d' $DAPPNODE_PROFILE | tee -a $LOGFILE
235237

236-
if ! grep -q "$DAPPNODE_ACCESS_CREDENTIALS" "$DAPPNODE_PROFILE"; then
237-
[ -f $DAPPNODE_ACCESS_CREDENTIALS ] || ${WGET} -O ${DAPPNODE_ACCESS_CREDENTIALS} ${DAPPNODE_ACCESS_CREDENTIALS_URL}
238-
# shellcheck disable=SC2216
239-
sed -i "/return/i /bin/bash $DAPPNODE_ACCESS_CREDENTIALS" $DAPPNODE_PROFILE | echo "/bin/bash $DAPPNODE_ACCESS_CREDENTIALS" >>$DAPPNODE_PROFILE
240-
fi
238+
# Append welcome message execution at end of profile
239+
# shellcheck disable=SC1003
240+
sed -i '$a\'"${WELCOME_MESSAGE}"'' $DAPPNODE_PROFILE
241+
242+
# Download access_credentials script
243+
[ -f $DAPPNODE_ACCESS_CREDENTIALS ] || ${WGET} -O ${DAPPNODE_ACCESS_CREDENTIALS} ${DAPPNODE_ACCESS_CREDENTIALS_URL}
241244

242245
# Delete dappnode_install.sh execution from rc.local if exists, and is not the unattended firstboot
243246
if [ -f "/etc/rc.local" ] && [ ! -f "/usr/src/dappnode/.firstboot" ]; then
244247
sed -i '/\/usr\/src\/dappnode\/scripts\/dappnode_install.sh/d' /etc/rc.local 2>&1 | tee -a $LOGFILE
245248
fi
246249

247-
# Display credentials to the user
248-
[ -f $DAPPNODE_ACCESS_CREDENTIALS ] && /bin/bash $DAPPNODE_ACCESS_CREDENTIALS
250+
# Display help message to the user
251+
echo -e "Execute \e[32mdappnode_help\e[0m to see a full list with commands available"
249252
}
250253

251254
installExtraDpkg() {

0 commit comments

Comments
 (0)