2024-07-11 22:39:14 +00:00
|
|
|
#!/bin/env fish
|
|
|
|
function waitNetwork -a witness
|
|
|
|
set -l timeout (math 10 \* 60)
|
|
|
|
set -l codeFile (mktemp)
|
|
|
|
|
|
|
|
if [ -z "$witness" ]
|
|
|
|
if not systemctl --quiet is-active network-online.target
|
2024-07-11 22:40:48 +00:00
|
|
|
tmux new-session -d 'cat /etc/motd; echo "$(tput bold)Please establish an internet connection…$(tput sgr0)"; $SHELL'
|
2024-07-11 22:39:14 +00:00
|
|
|
fish (status filename) true &
|
|
|
|
set -l pid "$last_pid"
|
|
|
|
|
|
|
|
function witnessHandler -V codeFile --on-process-exit "$pid" -a event pid code
|
|
|
|
echo "$code" > "$codeFile"
|
|
|
|
|
|
|
|
if [ "$code" -gt 0 ]
|
|
|
|
echo "Unable to connect to the internet!"
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
tmux attach
|
|
|
|
wait "$pid"
|
|
|
|
return "$(cat "$codeFile")"
|
|
|
|
end
|
|
|
|
else
|
|
|
|
set -l x 0
|
|
|
|
|
|
|
|
while true
|
|
|
|
set x (math $x + 1)
|
|
|
|
|
|
|
|
if systemctl --quiet is-active network-online.target
|
|
|
|
tmux kill-session &> /dev/null
|
|
|
|
break
|
|
|
|
else
|
|
|
|
not tmux list-sessions &> /dev/null
|
|
|
|
or test "$x" -gt 10
|
|
|
|
and begin
|
|
|
|
tmux kill-session &> /dev/null
|
|
|
|
exit 1
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
sleep 1
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
if [ -n "$argv" ]
|
|
|
|
waitNetwork $argv
|
|
|
|
end
|