Skip to content

Instantly share code, notes, and snippets.

@sisimomo
Last active April 30, 2022 16:24
Show Gist options
  • Save sisimomo/f469328cf9d611086530858a75a8d4d9 to your computer and use it in GitHub Desktop.
Save sisimomo/f469328cf9d611086530858a75a8d4d9 to your computer and use it in GitHub Desktop.
#!/usr/bin/env bash
# https://stackoverflow.com/a/53628882
reboot_countdown () {
local counter=$1
while [ 1 ]
do
if [ ${counter} -eq 0 ]
then
break
fi
echo "Rebooting in ${counter} second(s)."
sleep 1
counter=$( echo "${counter}-1" | bc )
done
reboot
}
# inspired from: https://gist.githubusercontent.com/libbymiller/e8fe6821e122e0a0ac921c8e557320a9/raw/46138fb4d28b494728e66515e46bd7d736b19132/start.sh
# export DBUS_SYSTEM_BUS_ADDRESS=unix:path=/host/run/dbus/system_bus_socket
# ^^^ this can cause barfing and isn't needed
# Choose a condition for running WiFi Connect according to your use case:
# 1. Is there a default gateway?
# ip route | grep default
# 2. Is there Internet connectivity?
# nmcli -t g | grep full
# 3. Is there Internet connectivity via a google ping?
# wget --spider http://google.com 2>&1
# 4. Is there an active WiFi connection?
iwgetid -r
if [ $? -eq 0 ]; then
printf 'Skipping WiFi Connect\n'
else
printf 'Starting WiFi Connect\n'
# Start Wifi Setup wizard. If no response after 30 min, restart.
wifi-connect -s "MagicMirror WiFi Connect" -a 1800 && reboot_countdown 15
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment