You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

132 lines
2.5 KiB

#!/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"
daemon_start() {
case "$OS" in
"Alpine Linux"|postmarketOS)
sudo rc-service "$1" start
;;
"Arch Linux ARM"|alarm)
[ "$1" = "modemmanager" ] && set -- ModemManager
sudo systemctl start "$1"
;;
esac
}
daemon_stop() {
case "$OS" in
"Alpine Linux"|postmarketOS)
sudo rc-service "$1" stop
;;
"Arch Linux ARM"|alarm)
[ "$1" = "modemmanager" ] && set -- ModemManager
sudo systemctl stop "$1"
;;
esac
}
daemon_isrunning() {
daemon_exists "$1" || return 0
case "$OS" in
"Alpine Linux"|postmarketOS)
rc-service "$1" status | grep -q started
;;
"Arch Linux ARM"|alarm)
[ "$1" = "modemmanager" ] && set -- ModemManager
systemctl status "$1" | grep -q running
;;
esac
}
daemon_exists() {
case "$OS" in
"Alpine Linux"|postmarketOS)
[ -f /etc/init.d/"$1" ]
;;
"Arch Linux ARM"|alarm)
systemctl status "$1" >/dev/null
;;
esac
}
ensure_daemon() {
TRIES=0
while ! daemon_isrunning "$1"; do
if [ "$TRIES" -eq 10 ]; then
return 1
fi
TRIES=$((TRIES+1))
daemon_start "$1"
sleep 5
done
return 0
}
ensure_daemons() {
if (daemon_isrunning eg25-manager) && \
(daemon_isrunning modemmanager); then
return
fi
echo "sxmo_modemmonitortoggle: forcing modem restart" >&2
notify-send "Resetting modem daemons, this may take a minute..."
daemon_stop modemmanager
daemon_stop eg25-manager
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
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
Rework the status bar Goals of this patch : - display the signal quality I used a thermometer icon cause there is no available icon with a filleable bar o_O - display the currently used network technology (4g, 3g, etc...) I used the mapping from: https://gitlab.freedesktop.org/mobile-broadband/ModemManager/-/blob/master/include/ModemManager-enums.h#L220 Dylan also said: Anything from POTS to GPRS = 2G UMTS to EVDOB = 3G LTE = 4G 5GNR = 5G - display the modem infos when modemmonitor is disabled We want to decorelate the modem monitor from the icon. We still want to know easily if modem monitor is runing but we also want those modem infos if not. - simplify the modem state determination (no state file anymore) The statusbar probe mmcli itself. - fix the leading timer without call issue This was caused by the "pgrep -f" command that was matching itself. Using a simple "pgrep" looks good enough anyway. - fix some sxmo_statusbar update spaming issues (vol control) This one point took me a lot of time to findout a good solution. We want the USR1 kill to be spamable without causing issue to the displayed bar. We dont want mid rendered bar (half the icons). We dont want empty bars (empty stdout line). I use some variable to store pid, smart waits and a better trap function to make it to works cleanly. Now we can spam statusbarupdate. Only the last one will actually redraw the bar. Signed-off-by: Stacy Harper <contact@stacyharper.net> Signed-off-by: Maarten van Gompel <proycon@anaproy.nl>
3 years ago
sleep 1
sxmo_statusbarupdate.sh