sxmo-utils/scripts/modem/sxmo_modemmonitortoggle.sh
Stacy Harper 8a27933c47 SWMO - SXMO over Wayland
This is a huge patch for Swmo, Sxmo over Sway.

It is Dwm backward compatible so dwm users should not expect regressions.

If you install all dependencies, you then can toggle between Sway and Dwm using a new config entry. It will reboot the phone.

This commit also contains:
    * Make the modemmonitor bullet proof
    * various other smaller fixes

Signed-off-by: Stacy Harper <contact@stacyharper.net>
Signed-off-by: Maarten van Gompel <proycon@anaproy.nl>
2021-08-22 13:23:22 +02:00

83 lines
1.8 KiB
Bash
Executable file

#!/usr/bin/env sh
# This script toggles the modem monitor
# It optionally takes a parameter "on" or "off"
# forcing it to toggle only to that desired state if applicable.
# It may also take a "reset" parameter that forces the
# entire modem subsystem to reload
# include common definitions
# shellcheck source=scripts/core/sxmo_common.sh
. "$(dirname "$0")/sxmo_common.sh"
ensure_daemon() {
TRIES=0
while ! rc-service "$1" status | grep -q started; do
if [ "$TRIES" -eq 10 ]; then
return 1
fi
TRIES=$((TRIES+1))
sudo rc-service "$1" start
sleep 5
done
return 0
}
ensure_daemons() {
if (rc-service eg25-manager status | grep -q started) &&
(rc-service modemmanager status | grep -q started); then
return
fi
echo "sxmo_modemmonitortoggle: forcing modem restart" >&2
notify-send "Resetting modem daemons, this may take a minute..."
sudo rc-service modemmanager stop
sudo rc-service eg25-manager stop
sleep 2
if ! (ensure_daemon eg25-manager && ensure_daemon modemmanager); then
printf "failed\n" > "$MODEMSTATEFILE"
notify-send --urgency=critical "We failed to start the modem daemons. We may need hard reboot."
return 1
fi
}
on() {
rm "$NOTIFDIR"/incomingcall*
TRIES=0
while ! printf %s "$(mmcli -L)" 2> /dev/null | grep -qoE 'Modem\/([0-9]+)'; do
TRIES=$((TRIES+1))
if [ "$TRIES" -eq 10 ]; then
printf "failed\n" > "$MODEMSTATEFILE"
notify-send --urgency=critical "We failed to start the modem monitor. We may need hard reboot."
fi
sleep 5
done
setsid -f sxmo_modemmonitor.sh &
sleep 1
}
off() {
pkill -TERM -f sxmo_modemmonitor.sh
}
if [ -z "$1" ]; then
if pgrep -f sxmo_modemmonitor.sh; then
set -- off
else
set -- on
fi
fi
case "$1" in
restart) off; ensure_daemons && on;;
on) ensure_daemons && on;;
off) off;;
esac
sxmo_statusbarupdate.sh