From b2f70e12826d44b9f9e010f52804befe8727b1e1 Mon Sep 17 00:00:00 2001 From: pablo Date: Wed, 25 Aug 2021 13:12:05 +0200 Subject: [PATCH 01/11] commands refactor --- .dappnode_profile | 10 +++++++-- scripts/dappnode_access_credentials.sh | 30 ++++++++++++-------------- 2 files changed, 22 insertions(+), 18 deletions(-) diff --git a/.dappnode_profile b/.dappnode_profile index 6ee882d..5870096 100755 --- a/.dappnode_profile +++ b/.dappnode_profile @@ -24,13 +24,19 @@ alias dappnode_stop='docker-compose $DNCORE_YMLS stop && docker stop $(docker co # Start docker core containers alias dappnode_start='docker-compose $DNCORE_YMLS up -d && docker start $(docker container ls -a -q -f name=DAppNode*)' # Return open-vpn credentials from a specific user. e.g: dappnode_get dappnode_admin -alias dappnode_get='docker exec -i DAppNodeCore-vpn.dnp.dappnode.eth vpncli get' +alias dappnode_openvpn_get='docker exec -i DAppNodeCore-vpn.dnp.dappnode.eth vpncli get' # Return open-vpn admin credentials -alias dappnode_connect='docker exec -i DAppNodeCore-vpn.dnp.dappnode.eth getAdminCredentials' +alias dappnode_openvpn='docker exec -i DAppNodeCore-vpn.dnp.dappnode.eth getAdminCredentials' # Return wifi credentials (ssid and password) alias dappnode_wifi='cat /usr/src/dappnode/DNCORE/docker-compose-wifi.yml | grep "SSID\|WPA_PASSPHRASE"' # Return remote credentials in plain text. OPTIONS: # --qr (QR format). --local (local creds for NAT loopback issues) alias dappnode_wireguard='docker exec -i DAppNodeCore-api.wireguard.dnp.dappnode.eth getWireguardCredentials' +# Execute access_credentials.sh script to check for connectivity methods +alias dappnode_connect='/usr/bin/bash /usr/src/dappnode/scripts/dappnode_access_credentials.sh' +# Return all available commands +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" +alias dappnode_help='echo -e ${HELP_MESSAGE}' return + diff --git a/scripts/dappnode_access_credentials.sh b/scripts/dappnode_access_credentials.sh index 3349927..7badf37 100755 --- a/scripts/dappnode_access_credentials.sh +++ b/scripts/dappnode_access_credentials.sh @@ -1,8 +1,7 @@ #!/bin/bash # This script will iterate over the access methods in dappnode -# and display its credentials based on priority. -# PRIORITY: Wi-Wi > Avahi > VPN (Wireguard > OpenVpn) +# and return the credentials for each service available ############# #0.VARIABLES# @@ -28,21 +27,20 @@ DAPPNODE_WELCOME_URL="http://welcome.dappnode" ############# function dappnode_startup_check () { - echo -n "Wait until DAppNode initializes (press ctrl+c to stop) " - sleep 5 + echo -n "\nChecking DAppNode connectivity methods (press ctrl+c to stop)...\n" n=0 until [ "$n" -ge 8 ] do [ "$(docker inspect -f '{{.State.Running}}' ${DAPPMANAGER_CONTAINER} 2> /dev/null)" = "true" ] && break n=$((n+1)) echo -n "." - sleep 8 + sleep 4 done } # $1 Connection method $2 Credentials function create_connection_message () { - 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" + echo -e "\n\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\n" } function wifi_connection () { @@ -52,8 +50,8 @@ function wifi_connection () { [ "$(docker inspect -f '{{.State.Running}}' ${WIFI_CONTAINER} 2> /dev/null)" = "true" ] && \ # Check interface variable is set [ -n "$(docker exec -it $WIFI_CONTAINER iw dev | grep 'Interface' | awk 'NR==1{print $2}')" ] && \ - create_connection_message "Wi-Fi" "$WIFI_GET_CREDS" && \ - exit 0 || echo -e "\nWifi not detected" + create_connection_message "Wi-Fi" "$WIFI_GET_CREDS" || \ + echo -e "\nWifi not detected\n" } function avahi_connection () { @@ -68,8 +66,8 @@ function avahi_connection () { [ "$(docker exec -i ${HTTPS_CONTAINER} sh -c 'echo "$LOCAL_PROXYING"')" = "true" ] && \ # avahi-daemon running => systemctl is-active avahi-daemon RETURNS "active" or "inactive" [ "$(systemctl is-active avahi-daemon)" = "active" ] && \ - 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" && \ - exit 0 || echo "Avahi-daemon not detected" + 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" || \ + echo "\nAvahi-daemon not detected\n" } function wireguard_connection () { @@ -78,8 +76,8 @@ function wireguard_connection () { [ "$(docker ps -a | grep ${WIREGUARD_CONTAINER})" ] && \ # wireguard container running [ "$(docker inspect -f '{{.State.Running}}' ${WIREGUARD_CONTAINER})" = "true" ] && \ - create_connection_message "Wireguard" "$($WIREGUARD_GET_CREDS)" && \ - exit 0 || echo "Wireguard not detected" + create_connection_message "Wireguard" "$($WIREGUARD_GET_CREDS)" || \ + echo "\nWireguard not detected\n" } function openvpn_connection () { @@ -88,8 +86,8 @@ function openvpn_connection () { [ "$(docker ps -a | grep ${OPENVPN_CONTAINER})" ] && \ # openvpn container running [ "$(docker inspect -f '{{.State.Running}}' ${OPENVPN_CONTAINER})" = "true" ] && \ - create_connection_message "Open-VPN" "$($OPENVPN_GET_CREDS)" && \ - exit 0 || echo "Open-VPN not detected" + create_connection_message "Open-VPN" "$($OPENVPN_GET_CREDS)" || \ + echo "\nOpen-VPN not detected\n" } ######## @@ -102,5 +100,5 @@ avahi_connection wireguard_connection openvpn_connection -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" -exit 0 \ No newline at end of file +echo -e "\n\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" +exit 0 From 458d8cd74df7c55b35c8f35763d7940819a45a84 Mon Sep 17 00:00:00 2001 From: pablo Date: Wed, 25 Aug 2021 13:30:06 +0200 Subject: [PATCH 02/11] fix lint issues --- scripts/dappnode_access_credentials.sh | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/scripts/dappnode_access_credentials.sh b/scripts/dappnode_access_credentials.sh index 7badf37..c5f7467 100755 --- a/scripts/dappnode_access_credentials.sh +++ b/scripts/dappnode_access_credentials.sh @@ -27,7 +27,7 @@ DAPPNODE_WELCOME_URL="http://welcome.dappnode" ############# function dappnode_startup_check () { - echo -n "\nChecking DAppNode connectivity methods (press ctrl+c to stop)...\n" + echo -ne "\nChecking DAppNode connectivity methods (press ctrl+c to stop)...\n" n=0 until [ "$n" -ge 8 ] do @@ -67,7 +67,7 @@ function avahi_connection () { # avahi-daemon running => systemctl is-active avahi-daemon RETURNS "active" or "inactive" [ "$(systemctl is-active avahi-daemon)" = "active" ] && \ 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" || \ - echo "\nAvahi-daemon not detected\n" + echo -e "\nAvahi-daemon not detected\n" } function wireguard_connection () { @@ -77,7 +77,7 @@ function wireguard_connection () { # wireguard container running [ "$(docker inspect -f '{{.State.Running}}' ${WIREGUARD_CONTAINER})" = "true" ] && \ create_connection_message "Wireguard" "$($WIREGUARD_GET_CREDS)" || \ - echo "\nWireguard not detected\n" + echo -e "\nWireguard not detected\n" } function openvpn_connection () { @@ -87,7 +87,7 @@ function openvpn_connection () { # openvpn container running [ "$(docker inspect -f '{{.State.Running}}' ${OPENVPN_CONTAINER})" = "true" ] && \ create_connection_message "Open-VPN" "$($OPENVPN_GET_CREDS)" || \ - echo "\nOpen-VPN not detected\n" + echo -e "\nOpen-VPN not detected\n" } ######## From 257a795ba0fe6c865c08e916724a14f56aace7f7 Mon Sep 17 00:00:00 2001 From: pablo Date: Wed, 25 Aug 2021 13:12:05 +0200 Subject: [PATCH 03/11] commands refactor --- .dappnode_profile | 10 +++++++-- scripts/dappnode_access_credentials.sh | 30 ++++++++++++-------------- 2 files changed, 22 insertions(+), 18 deletions(-) diff --git a/.dappnode_profile b/.dappnode_profile index 6ee882d..5870096 100755 --- a/.dappnode_profile +++ b/.dappnode_profile @@ -24,13 +24,19 @@ alias dappnode_stop='docker-compose $DNCORE_YMLS stop && docker stop $(docker co # Start docker core containers alias dappnode_start='docker-compose $DNCORE_YMLS up -d && docker start $(docker container ls -a -q -f name=DAppNode*)' # Return open-vpn credentials from a specific user. e.g: dappnode_get dappnode_admin -alias dappnode_get='docker exec -i DAppNodeCore-vpn.dnp.dappnode.eth vpncli get' +alias dappnode_openvpn_get='docker exec -i DAppNodeCore-vpn.dnp.dappnode.eth vpncli get' # Return open-vpn admin credentials -alias dappnode_connect='docker exec -i DAppNodeCore-vpn.dnp.dappnode.eth getAdminCredentials' +alias dappnode_openvpn='docker exec -i DAppNodeCore-vpn.dnp.dappnode.eth getAdminCredentials' # Return wifi credentials (ssid and password) alias dappnode_wifi='cat /usr/src/dappnode/DNCORE/docker-compose-wifi.yml | grep "SSID\|WPA_PASSPHRASE"' # Return remote credentials in plain text. OPTIONS: # --qr (QR format). --local (local creds for NAT loopback issues) alias dappnode_wireguard='docker exec -i DAppNodeCore-api.wireguard.dnp.dappnode.eth getWireguardCredentials' +# Execute access_credentials.sh script to check for connectivity methods +alias dappnode_connect='/usr/bin/bash /usr/src/dappnode/scripts/dappnode_access_credentials.sh' +# Return all available commands +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" +alias dappnode_help='echo -e ${HELP_MESSAGE}' return + diff --git a/scripts/dappnode_access_credentials.sh b/scripts/dappnode_access_credentials.sh index 3349927..7badf37 100755 --- a/scripts/dappnode_access_credentials.sh +++ b/scripts/dappnode_access_credentials.sh @@ -1,8 +1,7 @@ #!/bin/bash # This script will iterate over the access methods in dappnode -# and display its credentials based on priority. -# PRIORITY: Wi-Wi > Avahi > VPN (Wireguard > OpenVpn) +# and return the credentials for each service available ############# #0.VARIABLES# @@ -28,21 +27,20 @@ DAPPNODE_WELCOME_URL="http://welcome.dappnode" ############# function dappnode_startup_check () { - echo -n "Wait until DAppNode initializes (press ctrl+c to stop) " - sleep 5 + echo -n "\nChecking DAppNode connectivity methods (press ctrl+c to stop)...\n" n=0 until [ "$n" -ge 8 ] do [ "$(docker inspect -f '{{.State.Running}}' ${DAPPMANAGER_CONTAINER} 2> /dev/null)" = "true" ] && break n=$((n+1)) echo -n "." - sleep 8 + sleep 4 done } # $1 Connection method $2 Credentials function create_connection_message () { - 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" + echo -e "\n\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\n" } function wifi_connection () { @@ -52,8 +50,8 @@ function wifi_connection () { [ "$(docker inspect -f '{{.State.Running}}' ${WIFI_CONTAINER} 2> /dev/null)" = "true" ] && \ # Check interface variable is set [ -n "$(docker exec -it $WIFI_CONTAINER iw dev | grep 'Interface' | awk 'NR==1{print $2}')" ] && \ - create_connection_message "Wi-Fi" "$WIFI_GET_CREDS" && \ - exit 0 || echo -e "\nWifi not detected" + create_connection_message "Wi-Fi" "$WIFI_GET_CREDS" || \ + echo -e "\nWifi not detected\n" } function avahi_connection () { @@ -68,8 +66,8 @@ function avahi_connection () { [ "$(docker exec -i ${HTTPS_CONTAINER} sh -c 'echo "$LOCAL_PROXYING"')" = "true" ] && \ # avahi-daemon running => systemctl is-active avahi-daemon RETURNS "active" or "inactive" [ "$(systemctl is-active avahi-daemon)" = "active" ] && \ - 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" && \ - exit 0 || echo "Avahi-daemon not detected" + 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" || \ + echo "\nAvahi-daemon not detected\n" } function wireguard_connection () { @@ -78,8 +76,8 @@ function wireguard_connection () { [ "$(docker ps -a | grep ${WIREGUARD_CONTAINER})" ] && \ # wireguard container running [ "$(docker inspect -f '{{.State.Running}}' ${WIREGUARD_CONTAINER})" = "true" ] && \ - create_connection_message "Wireguard" "$($WIREGUARD_GET_CREDS)" && \ - exit 0 || echo "Wireguard not detected" + create_connection_message "Wireguard" "$($WIREGUARD_GET_CREDS)" || \ + echo "\nWireguard not detected\n" } function openvpn_connection () { @@ -88,8 +86,8 @@ function openvpn_connection () { [ "$(docker ps -a | grep ${OPENVPN_CONTAINER})" ] && \ # openvpn container running [ "$(docker inspect -f '{{.State.Running}}' ${OPENVPN_CONTAINER})" = "true" ] && \ - create_connection_message "Open-VPN" "$($OPENVPN_GET_CREDS)" && \ - exit 0 || echo "Open-VPN not detected" + create_connection_message "Open-VPN" "$($OPENVPN_GET_CREDS)" || \ + echo "\nOpen-VPN not detected\n" } ######## @@ -102,5 +100,5 @@ avahi_connection wireguard_connection openvpn_connection -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" -exit 0 \ No newline at end of file +echo -e "\n\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" +exit 0 From e51762c119c540ad2c7007b02d7cb56e679b00dc Mon Sep 17 00:00:00 2001 From: pablo Date: Wed, 25 Aug 2021 13:30:06 +0200 Subject: [PATCH 04/11] fix lint issues --- scripts/dappnode_access_credentials.sh | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/scripts/dappnode_access_credentials.sh b/scripts/dappnode_access_credentials.sh index 7badf37..c5f7467 100755 --- a/scripts/dappnode_access_credentials.sh +++ b/scripts/dappnode_access_credentials.sh @@ -27,7 +27,7 @@ DAPPNODE_WELCOME_URL="http://welcome.dappnode" ############# function dappnode_startup_check () { - echo -n "\nChecking DAppNode connectivity methods (press ctrl+c to stop)...\n" + echo -ne "\nChecking DAppNode connectivity methods (press ctrl+c to stop)...\n" n=0 until [ "$n" -ge 8 ] do @@ -67,7 +67,7 @@ function avahi_connection () { # avahi-daemon running => systemctl is-active avahi-daemon RETURNS "active" or "inactive" [ "$(systemctl is-active avahi-daemon)" = "active" ] && \ 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" || \ - echo "\nAvahi-daemon not detected\n" + echo -e "\nAvahi-daemon not detected\n" } function wireguard_connection () { @@ -77,7 +77,7 @@ function wireguard_connection () { # wireguard container running [ "$(docker inspect -f '{{.State.Running}}' ${WIREGUARD_CONTAINER})" = "true" ] && \ create_connection_message "Wireguard" "$($WIREGUARD_GET_CREDS)" || \ - echo "\nWireguard not detected\n" + echo -e "\nWireguard not detected\n" } function openvpn_connection () { @@ -87,7 +87,7 @@ function openvpn_connection () { # openvpn container running [ "$(docker inspect -f '{{.State.Running}}' ${OPENVPN_CONTAINER})" = "true" ] && \ create_connection_message "Open-VPN" "$($OPENVPN_GET_CREDS)" || \ - echo "\nOpen-VPN not detected\n" + echo -e "\nOpen-VPN not detected\n" } ######## From d3f4145c6914ed0317bc603afe3b338b20493e2f Mon Sep 17 00:00:00 2001 From: pablo Date: Wed, 25 Aug 2021 17:46:31 +0200 Subject: [PATCH 05/11] remove default execution of dappnode_Access_credentials script --- scripts/dappnode_install.sh | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) diff --git a/scripts/dappnode_install.sh b/scripts/dappnode_install.sh index ddc6b0d..9e20c7d 100755 --- a/scripts/dappnode_install.sh +++ b/scripts/dappnode_install.sh @@ -233,19 +233,13 @@ dappnode_start() { sed -i '/return/d' $DAPPNODE_PROFILE | tee -a $LOGFILE - if ! grep -q "$DAPPNODE_ACCESS_CREDENTIALS" "$DAPPNODE_PROFILE"; then - [ -f $DAPPNODE_ACCESS_CREDENTIALS ] || ${WGET} -O ${DAPPNODE_ACCESS_CREDENTIALS} ${DAPPNODE_ACCESS_CREDENTIALS_URL} - # shellcheck disable=SC2216 - sed -i "/return/i /bin/bash $DAPPNODE_ACCESS_CREDENTIALS" $DAPPNODE_PROFILE | echo "/bin/bash $DAPPNODE_ACCESS_CREDENTIALS" >>$DAPPNODE_PROFILE - fi - # Delete dappnode_install.sh execution from rc.local if exists, and is not the unattended firstboot if [ -f "/etc/rc.local" ] && [ ! -f "/usr/src/dappnode/.firstboot" ]; then sed -i '/\/usr\/src\/dappnode\/scripts\/dappnode_install.sh/d' /etc/rc.local 2>&1 | tee -a $LOGFILE fi - # Display credentials to the user - [ -f $DAPPNODE_ACCESS_CREDENTIALS ] && /bin/bash $DAPPNODE_ACCESS_CREDENTIALS + # Display help message to the user + echo -e "Execute \e[32mdappnode_help\e[0m to see a full list with commands vailable" } installExtraDpkg() { From 3fa88f6ca93b7ce1c7e924f299a86abb24db6bc7 Mon Sep 17 00:00:00 2001 From: pablo Date: Wed, 25 Aug 2021 17:51:45 +0200 Subject: [PATCH 06/11] download access_credentials script and dont execute it --- scripts/dappnode_install.sh | 2 ++ 1 file changed, 2 insertions(+) diff --git a/scripts/dappnode_install.sh b/scripts/dappnode_install.sh index 9e20c7d..81ff98b 100755 --- a/scripts/dappnode_install.sh +++ b/scripts/dappnode_install.sh @@ -233,6 +233,8 @@ dappnode_start() { sed -i '/return/d' $DAPPNODE_PROFILE | tee -a $LOGFILE + [ -f $DAPPNODE_ACCESS_CREDENTIALS ] || ${WGET} -O ${DAPPNODE_ACCESS_CREDENTIALS} ${DAPPNODE_ACCESS_CREDENTIALS_URL} + # Delete dappnode_install.sh execution from rc.local if exists, and is not the unattended firstboot if [ -f "/etc/rc.local" ] && [ ! -f "/usr/src/dappnode/.firstboot" ]; then sed -i '/\/usr\/src\/dappnode\/scripts\/dappnode_install.sh/d' /etc/rc.local 2>&1 | tee -a $LOGFILE From 55a58ad8642b68975e1897d1a0747d437464df29 Mon Sep 17 00:00:00 2001 From: pablo Date: Thu, 26 Aug 2021 13:27:47 +0200 Subject: [PATCH 07/11] Type wireguard and openvpn errors. Improve access_cred script. Add welcome message --- .dappnode_profile | 4 ++-- scripts/dappnode_access_credentials.sh | 25 ++++++++++++++++--------- scripts/dappnode_install.sh | 6 ++++++ 3 files changed, 24 insertions(+), 11 deletions(-) diff --git a/.dappnode_profile b/.dappnode_profile index 5870096..7f6a6af 100755 --- a/.dappnode_profile +++ b/.dappnode_profile @@ -26,12 +26,12 @@ alias dappnode_start='docker-compose $DNCORE_YMLS up -d && docker start $(docker # Return open-vpn credentials from a specific user. e.g: dappnode_get dappnode_admin alias dappnode_openvpn_get='docker exec -i DAppNodeCore-vpn.dnp.dappnode.eth vpncli get' # Return open-vpn admin credentials -alias dappnode_openvpn='docker exec -i DAppNodeCore-vpn.dnp.dappnode.eth getAdminCredentials' +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"' # Return wifi credentials (ssid and password) alias dappnode_wifi='cat /usr/src/dappnode/DNCORE/docker-compose-wifi.yml | grep "SSID\|WPA_PASSPHRASE"' # Return remote credentials in plain text. OPTIONS: # --qr (QR format). --local (local creds for NAT loopback issues) -alias dappnode_wireguard='docker exec -i DAppNodeCore-api.wireguard.dnp.dappnode.eth getWireguardCredentials' +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" ' # Execute access_credentials.sh script to check for connectivity methods alias dappnode_connect='/usr/bin/bash /usr/src/dappnode/scripts/dappnode_access_credentials.sh' # Return all available commands diff --git a/scripts/dappnode_access_credentials.sh b/scripts/dappnode_access_credentials.sh index c5f7467..3886e99 100755 --- a/scripts/dappnode_access_credentials.sh +++ b/scripts/dappnode_access_credentials.sh @@ -20,14 +20,14 @@ WIFI_GET_CREDS=$(grep 'SSID\|WPA_PASSPHRASE' /usr/src/dappnode/DNCORE/docker-com AVAHI_ENDPOINT="dappnode.local" DAPPNODE_ADMINUI_URL="http://my.dappnode" DAPPNODE_ADMINUI_LOCAL_URL="http://${AVAHI_ENDPOINT}" -DAPPNODE_WELCOME_URL="http://welcome.dappnode" +DAPPNODE_WELCOME_URL="http://welcome.dappnode.io" ############# #1.FUNCTIONS# ############# function dappnode_startup_check () { - echo -ne "\nChecking DAppNode connectivity methods (press ctrl+c to stop)...\n" + echo -ne "Checking DAppNode connectivity methods (press ctrl+c to stop)...\n" n=0 until [ "$n" -ge 8 ] do @@ -40,7 +40,7 @@ function dappnode_startup_check () { # $1 Connection method $2 Credentials function create_connection_message () { - echo -e "\n\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\n" + 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" } function wifi_connection () { @@ -51,12 +51,12 @@ function wifi_connection () { # Check interface variable is set [ -n "$(docker exec -it $WIFI_CONTAINER iw dev | grep 'Interface' | awk 'NR==1{print $2}')" ] && \ create_connection_message "Wi-Fi" "$WIFI_GET_CREDS" || \ - echo -e "\nWifi not detected\n" + echo -e "\e[33mWifi not detected\e[0m" } function avahi_connection () { # Ping to avahi endpoint: -c: number of pings. -w: timeout - avahi-resolve -n $AVAHI_ENDPOINT > /dev/null 2>&1 || { echo "Avahi-daemon not detected" ; return ; } + avahi-resolve -n $AVAHI_ENDPOINT > /dev/null 2>&1 && \ # Https container exists # shellcheck disable=SC2143 [ "$(docker ps -a | grep ${HTTPS_CONTAINER})" ] && \ @@ -67,7 +67,7 @@ function avahi_connection () { # avahi-daemon running => systemctl is-active avahi-daemon RETURNS "active" or "inactive" [ "$(systemctl is-active avahi-daemon)" = "active" ] && \ 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" || \ - echo -e "\nAvahi-daemon not detected\n" + echo -e "\e[33mLocal Proxy not detected\e[0m" } function wireguard_connection () { @@ -77,7 +77,7 @@ function wireguard_connection () { # wireguard container running [ "$(docker inspect -f '{{.State.Running}}' ${WIREGUARD_CONTAINER})" = "true" ] && \ create_connection_message "Wireguard" "$($WIREGUARD_GET_CREDS)" || \ - echo -e "\nWireguard not detected\n" + echo -e "\e[33mWireguard not detected\e[0m" } function openvpn_connection () { @@ -87,7 +87,11 @@ function openvpn_connection () { # openvpn container running [ "$(docker inspect -f '{{.State.Running}}' ${OPENVPN_CONTAINER})" = "true" ] && \ create_connection_message "Open-VPN" "$($OPENVPN_GET_CREDS)" || \ - echo -e "\nOpen-VPN not detected\n" + echo -e "\e[33mOpen VPN not detected\e[0m" +} + +function line_separator () { + echo "=====================" } ######## @@ -95,10 +99,13 @@ function openvpn_connection () { ######## dappnode_startup_check +line_separator wifi_connection +line_separator avahi_connection +line_separator wireguard_connection +line_separator openvpn_connection -echo -e "\n\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" exit 0 diff --git a/scripts/dappnode_install.sh b/scripts/dappnode_install.sh index 81ff98b..b9b7e29 100755 --- a/scripts/dappnode_install.sh +++ b/scripts/dappnode_install.sh @@ -23,6 +23,7 @@ SWGET="wget -q -O-" # Other CONTENT_HASH_PKGS=(geth openethereum nethermind) ARCH=$(dpkg --print-architecture) +HELP_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'" # Clean if update if [ "$UPDATE" = true ]; then @@ -231,8 +232,13 @@ dappnode_start() { echo -e "source ${DAPPNODE_PROFILE}\n" >>$PROFILE fi + # Remove return from profile sed -i '/return/d' $DAPPNODE_PROFILE | tee -a $LOGFILE + # Append welcome message execution at end of profile + sed -i '$a\'"${WELCOME_MESSAGE}"'' $DAPPNODE_PROFILE + + # Download access_credentials script [ -f $DAPPNODE_ACCESS_CREDENTIALS ] || ${WGET} -O ${DAPPNODE_ACCESS_CREDENTIALS} ${DAPPNODE_ACCESS_CREDENTIALS_URL} # Delete dappnode_install.sh execution from rc.local if exists, and is not the unattended firstboot From 677393eb1593933a5578e672dd19f294b6295cfb Mon Sep 17 00:00:00 2001 From: pablo Date: Thu, 26 Aug 2021 13:38:35 +0200 Subject: [PATCH 08/11] fix lint issues --- scripts/dappnode_access_credentials.sh | 2 -- scripts/dappnode_install.sh | 3 ++- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/scripts/dappnode_access_credentials.sh b/scripts/dappnode_access_credentials.sh index 3886e99..7be6598 100755 --- a/scripts/dappnode_access_credentials.sh +++ b/scripts/dappnode_access_credentials.sh @@ -55,10 +55,8 @@ function wifi_connection () { } function avahi_connection () { - # Ping to avahi endpoint: -c: number of pings. -w: timeout avahi-resolve -n $AVAHI_ENDPOINT > /dev/null 2>&1 && \ # Https container exists - # shellcheck disable=SC2143 [ "$(docker ps -a | grep ${HTTPS_CONTAINER})" ] && \ # Https container running [ "$(docker inspect -f '{{.State.Running}}' ${HTTPS_CONTAINER})" = "true" ] && \ diff --git a/scripts/dappnode_install.sh b/scripts/dappnode_install.sh index b9b7e29..f9a9efb 100755 --- a/scripts/dappnode_install.sh +++ b/scripts/dappnode_install.sh @@ -23,7 +23,7 @@ SWGET="wget -q -O-" # Other CONTENT_HASH_PKGS=(geth openethereum nethermind) ARCH=$(dpkg --print-architecture) -HELP_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'" +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'" # Clean if update if [ "$UPDATE" = true ]; then @@ -236,6 +236,7 @@ dappnode_start() { sed -i '/return/d' $DAPPNODE_PROFILE | tee -a $LOGFILE # Append welcome message execution at end of profile + # shellcheck disable=SC1003 sed -i '$a\'"${WELCOME_MESSAGE}"'' $DAPPNODE_PROFILE # Download access_credentials script From 6bb50b3ca77f89cda16a5127e136e0c03484fca8 Mon Sep 17 00:00:00 2001 From: pablo Date: Thu, 26 Aug 2021 13:42:43 +0200 Subject: [PATCH 09/11] fix lint issues --- scripts/dappnode_access_credentials.sh | 1 + 1 file changed, 1 insertion(+) diff --git a/scripts/dappnode_access_credentials.sh b/scripts/dappnode_access_credentials.sh index 7be6598..2907d5e 100755 --- a/scripts/dappnode_access_credentials.sh +++ b/scripts/dappnode_access_credentials.sh @@ -57,6 +57,7 @@ function wifi_connection () { function avahi_connection () { avahi-resolve -n $AVAHI_ENDPOINT > /dev/null 2>&1 && \ # Https container exists + # shellcheck disable=SC2143 [ "$(docker ps -a | grep ${HTTPS_CONTAINER})" ] && \ # Https container running [ "$(docker inspect -f '{{.State.Running}}' ${HTTPS_CONTAINER})" = "true" ] && \ From 226b05bf26c4ec321c625698d1702a102882778c Mon Sep 17 00:00:00 2001 From: pablo Date: Thu, 26 Aug 2021 13:48:28 +0200 Subject: [PATCH 10/11] fix lint issue --- scripts/dappnode_access_credentials.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/dappnode_access_credentials.sh b/scripts/dappnode_access_credentials.sh index 2907d5e..f9c614d 100755 --- a/scripts/dappnode_access_credentials.sh +++ b/scripts/dappnode_access_credentials.sh @@ -55,9 +55,9 @@ function wifi_connection () { } function avahi_connection () { + # shellcheck disable=SC2143 avahi-resolve -n $AVAHI_ENDPOINT > /dev/null 2>&1 && \ # Https container exists - # shellcheck disable=SC2143 [ "$(docker ps -a | grep ${HTTPS_CONTAINER})" ] && \ # Https container running [ "$(docker inspect -f '{{.State.Running}}' ${HTTPS_CONTAINER})" = "true" ] && \ From d98f7dfac8dd6cde453ab88f9efe435da266e637 Mon Sep 17 00:00:00 2001 From: pablo Date: Mon, 30 Aug 2021 10:47:51 +0200 Subject: [PATCH 11/11] fix typo --- scripts/dappnode_install.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/dappnode_install.sh b/scripts/dappnode_install.sh index f9a9efb..8fdec88 100755 --- a/scripts/dappnode_install.sh +++ b/scripts/dappnode_install.sh @@ -248,7 +248,7 @@ dappnode_start() { fi # Display help message to the user - echo -e "Execute \e[32mdappnode_help\e[0m to see a full list with commands vailable" + echo -e "Execute \e[32mdappnode_help\e[0m to see a full list with commands available" } installExtraDpkg() {