Last active
October 4, 2023 20:46
-
-
Save nexus166/21c71d7b9da6b0ab1c835b7f5ae40dfa to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash -x | |
sleep 15 | |
_uqmi="/sbin/uqmi" | |
ifdown WWAN || true | |
_cleanup() { | |
/usr/bin/killall "${_uqmi}" 2>/dev/null || true | |
for i in $(/bin/ps www | /usr/bin/awk '/uqmi/ && /cdc-wdm0/ && !/awk/ {print $1}'); do | |
/bin/kill -9 "$i" 2>/dev/null || true | |
done | |
} | |
_timeout_() { | |
local _pid="" | |
${*} & | |
_pid=$! | |
sleep 5 | |
_still_running=$(ps w | awk -v p="${_pid}" '$1 == p {print $1}') | |
if [[ -n ${_still_running} ]]; then | |
killall "${_uqmi}" 2>/dev/null || true | |
kill -9 "${_still_running}" 2>/dev/null || true | |
return 2 | |
fi | |
return 0 | |
} | |
_timeout=0 | |
while :; do | |
if [[ ${_timeout} -gt 60 ]]; then | |
printf '%s bailing out...\n' "$0" | |
exit 2 | |
fi | |
if _timeout_ "${_uqmi}" -d /dev/cdc-wdm0 --set-device-operating-mode=online; then | |
sleep 1 | |
_timeout_ "${_uqmi}" -d /dev/cdc-wdm0 --set-network-roaming=any | |
break | |
fi | |
sleep 3 | |
_timeout=$((_timeout + 3)) | |
_cleanup | |
done | |
_timeout=0 | |
while :; do | |
if [[ ${_timeout} -gt 60 ]]; then | |
printf '%s bailing out...\n' "$0" | |
exit 2 | |
fi | |
if _timeout_ /sbin/ifup WWAN; then | |
sleep 3 | |
"${_uqmi}" -d /dev/cdc-wdm0 --get-signal-info | |
/bin/sleep 1 | |
"${_uqmi}" -d /dev/cdc-wdm0 --get-data-status | |
/bin/sleep 1 | |
"${_uqmi}" -d /dev/cdc-wdm0 --get-current-settings | |
break | |
fi | |
sleep 3 | |
_timeout=$((_timeout + 3)) | |
_cleanup | |
done | |
exit 0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment