Skip to content

Commit

Permalink
Merge pull request #341 from dappnode/pablo/commands-refactor
Browse files Browse the repository at this point in the history
commands refactor && update debian ISO image
  • Loading branch information
pablomendezroyo authored Aug 30, 2021
2 parents 71d69fb + d98f7df commit f5e6dc2
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 30 deletions.
12 changes: 9 additions & 3 deletions .dappnode_profile
Original file line number Diff line number Diff line change
Expand Up @@ -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 || 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
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

44 changes: 24 additions & 20 deletions scripts/dappnode_access_credentials.sh
Original file line number Diff line number Diff line change
@@ -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#
Expand All @@ -21,28 +20,27 @@ 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 -n "Wait until DAppNode initializes (press ctrl+c to stop) "
sleep 5
echo -ne "Checking 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 "\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 () {
Expand All @@ -52,24 +50,23 @@ 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 "\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 ; }
# Https container exists
# shellcheck disable=SC2143
avahi-resolve -n $AVAHI_ENDPOINT > /dev/null 2>&1 && \
# Https container exists
[ "$(docker ps -a | grep ${HTTPS_CONTAINER})" ] && \
# Https container running
[ "$(docker inspect -f '{{.State.Running}}' ${HTTPS_CONTAINER})" = "true" ] && \
# Https env variable LOCAL_PROXYING="true"
[ "$(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 -e "\e[33mLocal Proxy not detected\e[0m"
}

function wireguard_connection () {
Expand All @@ -78,8 +75,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 -e "\e[33mWireguard not detected\e[0m"
}

function openvpn_connection () {
Expand All @@ -88,19 +85,26 @@ 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 -e "\e[33mOpen VPN not detected\e[0m"
}

function line_separator () {
echo "====================="
}

########
#2.MAIN#
########

dappnode_startup_check
line_separator
wifi_connection
line_separator
avahi_connection
line_separator
wireguard_connection
line_separator
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
exit 0
17 changes: 10 additions & 7 deletions scripts/dappnode_install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ SWGET="wget -q -O-"
# Other
CONTENT_HASH_PKGS=(geth openethereum nethermind)
ARCH=$(dpkg --print-architecture)
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
Expand Down Expand Up @@ -231,21 +232,23 @@ dappnode_start() {
echo -e "source ${DAPPNODE_PROFILE}\n" >>$PROFILE
fi

# Remove return from profile
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
# Append welcome message execution at end of profile
# shellcheck disable=SC1003
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
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 available"
}

installExtraDpkg() {
Expand Down

0 comments on commit f5e6dc2

Please sign in to comment.