This repository was archived by the owner on Nov 11, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 20
Expand file tree
/
Copy pathdappnode_access_credentials.sh
More file actions
executable file
·106 lines (94 loc) · 4.15 KB
/
Copy pathdappnode_access_credentials.sh
File metadata and controls
executable file
·106 lines (94 loc) · 4.15 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
#!/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)
#############
#0.VARIABLES#
#############
# Containers
DAPPMANAGER_CONTAINER="DAppNodeCore-dappmanager.dnp.dappnode.eth"
WIFI_CONTAINER="DAppNodeCore-wifi.dnp.dappnode.eth"
WIREGUARD_CONTAINER="DAppNodeCore-api.wireguard.dnp.dappnode.eth"
OPENVPN_CONTAINER="DAppNodeCore-vpn.dnp.dappnode.eth"
HTTPS_CONTAINER="DAppNodeCore-https.dnp.dappnode.eth"
# Credentials
WIREGUARD_GET_CREDS="docker exec -i $WIREGUARD_CONTAINER getWireguardCredentials"
OPENVPN_GET_CREDS="docker exec -i $OPENVPN_CONTAINER getAdminCredentials"
WIFI_GET_CREDS=$(grep 'SSID\|WPA_PASSPHRASE' /usr/src/dappnode/DNCORE/docker-compose-wifi.yml)
# Endpoints
AVAHI_ENDPOINT="dappnode.local"
DAPPNODE_ADMINUI_URL="http://my.dappnode"
DAPPNODE_ADMINUI_LOCAL_URL="http://${AVAHI_ENDPOINT}"
DAPPNODE_WELCOME_URL="http://welcome.dappnode"
#############
#1.FUNCTIONS#
#############
function dappnode_startup_check () {
echo -n "Wait until DAppNode initializes (press ctrl+c to stop) "
sleep 5
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
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"
}
function wifi_connection () {
# NOTE: network interface may be in use by host => $(cat /sys/class/net/${INTERFACE}/operstate)" !== "up")
# NOTE: wifi has a delay up to 1 min
# wifi container running
[ "$(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"
}
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
[ "$(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"
}
function wireguard_connection () {
# wireguard container exists
# shellcheck disable=SC2143
[ "$(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"
}
function openvpn_connection () {
# openvpn container exists
# shellcheck disable=SC2143
[ "$(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"
}
########
#2.MAIN#
########
dappnode_startup_check
wifi_connection
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