Improve v4 heartbeat script
This commit is contained in:
parent
a4e223f311
commit
120933aa33
1 changed files with 36 additions and 28 deletions
|
@ -41,9 +41,6 @@ led5g(){
|
|||
|
||||
. /etc/vpnsecret # Source the server authentication secret
|
||||
|
||||
# Retrieve hosts file from server
|
||||
/usr/bin/wget -O/etc/hosts https://admin360.kumi.host/hosts --post-data "secret=$SECRET" --no-check-certificate >/var/log/wget 2>&1
|
||||
|
||||
# Prepare for default VPN-WiFi bridge
|
||||
/sbin/uci set wireless.@wifi-iface[0].network="VPN360"
|
||||
/sbin/uci commit
|
||||
|
@ -64,34 +61,45 @@ counter=0
|
|||
|
||||
while [ $counter -lt 60 ]
|
||||
do
|
||||
powerled $(( counter % 2 )) # Make power LED flash
|
||||
if [ $(ipaddr) ] # = If connection to the server is working
|
||||
then
|
||||
# Turn on LEDs indicating boot completion and connection success
|
||||
powerled 1
|
||||
led5g 1
|
||||
# Retrieve hosts file from server
|
||||
if /usr/bin/wget -O/etc/hosts https://admin360.kumi.host/hosts --post-data "secret=$SECRET" --no-check-certificate >/var/log/wget 2>&1
|
||||
then
|
||||
|
||||
# Enable WiFi as the VPN bridge is now functional
|
||||
startwifi
|
||||
if pgrep "openvpn" >/dev/null
|
||||
then
|
||||
if [ $(ipaddr) ] # = If connection to the server is working
|
||||
then
|
||||
# Turn on LEDs indicating boot completion and connection success
|
||||
powerled 1
|
||||
led5g 1
|
||||
|
||||
# Send a heartbeat to the server every 10 seconds
|
||||
# This is also used to transfer commands from the server to the device
|
||||
while [ True ]
|
||||
do
|
||||
/bin/sleep 10
|
||||
# Enable WiFi as the VPN bridge is now functional
|
||||
startwifi
|
||||
|
||||
# Let's hope there is an IP address on the VPN interface
|
||||
# If not, this might be a temporary issue (lost network connection or lease expiration)
|
||||
# We assume that users will reboot the device if it doesn't work for extended periods of time
|
||||
if [ $(ipaddr) ]
|
||||
then
|
||||
/usr/bin/wget -O- https://admin360.kumi.host/heartbeat --post-data "secret=$SECRET&ip=$(ipaddr)" --no-check-certificate 2>/var/log/wget | /bin/ash
|
||||
fi
|
||||
done
|
||||
fi
|
||||
counter=$(( counter + 1 ))
|
||||
/bin/sleep 1 # Wait for a second before re-trying
|
||||
done
|
||||
# Send a heartbeat to the server every 10 seconds
|
||||
# This is also used to transfer commands from the server to the device
|
||||
while [ True ]
|
||||
do
|
||||
/bin/sleep 10
|
||||
|
||||
# Let's hope there is an IP address on the VPN interface
|
||||
# If not, this might be a temporary issue (lost network connection or lease expiration)
|
||||
# We assume that users will reboot the device if it doesn't work for extended periods of time
|
||||
if [ $(ipaddr) ]
|
||||
then
|
||||
/usr/bin/wget -O- https://admin360.kumi.host/heartbeat --post-data "secret=$SECRET&ip=$(ipaddr)" --no-check-certificate 2>/var/log/wget | /bin/ash
|
||||
fi
|
||||
done
|
||||
|
||||
fi
|
||||
else
|
||||
# Launch VPN client if not running
|
||||
/usr/sbin/openvpn /etc/openvpn/client.conf >/var/log/openvpn &
|
||||
fi
|
||||
fi
|
||||
counter=$(( counter + 1 ))
|
||||
/bin/sleep 1 # Wait for a second before re-trying
|
||||
done
|
||||
|
||||
# We should only ever get to this point if no VPN connection was established within a minute
|
||||
|
||||
|
|
Loading…
Reference in a new issue