diff --git a/scripts/modem/sxmo_modemmonitor.sh b/scripts/modem/sxmo_modemmonitor.sh index 4ade1dc..6a8a330 100755 --- a/scripts/modem/sxmo_modemmonitor.sh +++ b/scripts/modem/sxmo_modemmonitor.sh @@ -191,6 +191,7 @@ initialmodemstatus() { touch /tmp/modem.registered.state elif echo "$state" | grep -q -E "^.*state:.*locked.*$"; then touch /tmp/modem.locked.state + pidof sxmo_unlocksim.sh || sxmo_unlocksim.sh & fi } @@ -232,6 +233,7 @@ mainloop() { read -r newstate if echo "$newstate" | grep "int32 2"; then touch /tmp/modem.locked.state + pidof sxmo_unlocksim.sh || sxmo_unlocksim.sh & elif echo "$newstate" | grep "int32 8"; then touch /tmp/modem.registered.state checkforfinishedcalls diff --git a/scripts/modem/sxmo_unlocksim.sh b/scripts/modem/sxmo_unlocksim.sh new file mode 100755 index 0000000..12eaa5a --- /dev/null +++ b/scripts/modem/sxmo_unlocksim.sh @@ -0,0 +1,39 @@ +#!/usr/bin/env sh + +# include common definitions +# shellcheck source=scripts/core/sxmo_common.sh +. "$(dirname "$0")/sxmo_common.sh" + +modem_n() { + MODEMS="$(mmcli -L)" + echo "$MODEMS" | grep -oE 'Modem\/([0-9]+)' | cut -d'/' -f2 + return +} + +sim_n() { + SIMS="$(mmcli -m $(modem_n) | grep SIM)" + echo "$SIMS" | grep -oE 'SIM\/([0-9]+)' | cut -d'/' -f2 + return +} + +if [ -x "$XDG_CONFIG_HOME/sxmo/hooks/unlocksim" ]; then + "$XDG_CONFIG_HOME/sxmo/hooks/unlocksim" "$(sim_n)" +else + retry=1 + while [ $retry -eq 1 ]; do + PICKED="$( + echo -e "Cancel\n0000\n1234" | sxmo_dmenu_with_kb.sh -l 3 -c -p "PIN:" | tr -d "\n\r " + )" + if [ -n "$PICKED" ] && [ "$PICKED" != "Cancel" ]; then + retry=0 + mmcli -i $(sim_n) --pin "$PICKED" > /tmp/unlockmsg 2>&1 || retry=1 + MSG=$(cat /tmp/unlockmsg) + [ -n "$MSG" ] && notify-send "$MSG" + if echo "$MSG" | grep -q "not SIM-PIN locked"; then + retry=0 + fi + else + retry=0 + fi + done +fi