From e6ea6576344b52652745576989f048c5b0c88856 Mon Sep 17 00:00:00 2001 From: Stacy Harper Date: Tue, 29 Jun 2021 19:21:00 +0200 Subject: [PATCH] Cleanup hooks This add a script to use either the user hook or the default one. Sometime we checked the user hook or a default code. We move this default code in a defaut hook. Signed-off-by: Stacy Harper Signed-off-by: Maarten van Gompel --- Makefile | 1 + configs/default_hooks/lisgdstart | 55 +++++++++++++++++ configs/default_hooks/lock | 3 + configs/default_hooks/notification | 9 +++ configs/default_hooks/presuspend | 11 ++++ configs/default_hooks/unlock | 4 ++ configs/default_hooks/unlocksim | 37 ++++++++++++ scripts/core/sxmo_common.sh | 4 +- scripts/core/sxmo_hooks.sh | 10 ++++ scripts/core/sxmo_lisgdstart.sh | 59 ------------------- scripts/core/sxmo_lock.sh | 23 -------- scripts/core/sxmo_migrate.sh | 16 +---- scripts/core/sxmo_networkmonitor.sh | 12 +--- scripts/core/sxmo_postwake.sh | 16 ----- scripts/core/sxmo_presuspend.sh | 18 ------ scripts/core/sxmo_rotate.sh | 6 +- scripts/core/sxmo_screenlock.sh | 22 +++---- scripts/core/sxmo_xinit.sh | 11 +--- scripts/modem/sxmo_modemcall.sh | 18 ++---- scripts/modem/sxmo_modemmonitor.sh | 22 +++---- scripts/modem/sxmo_unlocksim.sh | 41 ------------- .../notifications/sxmo_notificationmonitor.sh | 16 +---- 22 files changed, 160 insertions(+), 254 deletions(-) create mode 100644 configs/default_hooks/lisgdstart create mode 100644 configs/default_hooks/lock create mode 100644 configs/default_hooks/notification create mode 100644 configs/default_hooks/presuspend create mode 100644 configs/default_hooks/unlock create mode 100644 configs/default_hooks/unlocksim create mode 100644 scripts/core/sxmo_hooks.sh delete mode 100755 scripts/core/sxmo_lisgdstart.sh delete mode 100755 scripts/core/sxmo_lock.sh delete mode 100755 scripts/core/sxmo_postwake.sh delete mode 100755 scripts/core/sxmo_presuspend.sh delete mode 100755 scripts/modem/sxmo_unlocksim.sh diff --git a/Makefile b/Makefile index c5f717d..b55ddad 100644 --- a/Makefile +++ b/Makefile @@ -32,6 +32,7 @@ clean: install: $(PROGRAMS) cd configs && find . -type f -exec install -D -m 0644 "{}" "$(DESTDIR)$(PREFIX)/share/sxmo/{}" \; && cd .. + cd configs && find default_hooks -type f -exec install -D -m 0655 "{}" "$(DESTDIR)$(PREFIX)/share/sxmo/{}" \; && cd .. cd resources && find . -type f -exec install -D -m 0644 "{}" "$(DESTDIR)$(PREFIX)/share/sxmo/{}" \; && cd .. diff --git a/configs/default_hooks/lisgdstart b/configs/default_hooks/lisgdstart new file mode 100644 index 0000000..4fab073 --- /dev/null +++ b/configs/default_hooks/lisgdstart @@ -0,0 +1,55 @@ +#!/usr/bin/env sh + +# include common definitions +# shellcheck source=scripts/core/sxmo_common.sh +. "$(which sxmo_common.sh)" + +pkill -9 lisgd + +if [ -z "$LISGD_THRESHOLD" ]; then + LISGD_THRESHOLD=125 +fi +if [ -z "$LISGD_THRESHOLD_PRESSED" ]; then + LISGD_THRESHOLD_PRESSED=60 +fi + +#-g format: +# fingers,swipe,edge,distance,command +#order matters, only the first match gets executed +lisgd "$@" -t "$LISGD_THRESHOLD" -T "$LISGD_THRESHOLD_PRESSED" \ + -g '1,DRUL,BR,*,sxmo_inputhandler.sh bottomrightcorner' \ + -g '1,DLUR,BL,*,sxmo_inputhandler.sh bottomleftcorner' \ + -g '1,ULDR,TL,*,sxmo_inputhandler.sh topleftcorner' \ + -g '1,URDL,TR,*,sxmo_inputhandler.sh toprightcorner' \ + -g '1,LR,B,L,sxmo_inputhandler.sh rightbottomcorner' \ + -g '1,RL,B,L,sxmo_inputhandler.sh leftbottomcorner' \ + -g '1,LR,L,*,sxmo_inputhandler.sh rightleftcorner' \ + -g '1,RL,R,*,sxmo_inputhandler.sh leftrightcorner' \ + -g '1,DU,L,*,P,sxmo_inputhandler.sh upleftcorner' \ + -g '1,UD,L,*,P,sxmo_inputhandler.sh downleftcorner' \ + -g '1,LR,T,*,P,sxmo_inputhandler.sh righttopcorner' \ + -g '1,RL,T,*,P,sxmo_inputhandler.sh lefttopcorner' \ + -g "1,DU,B,*,sxmo_inputhandler.sh upbottomcorner" \ + -g "1,UD,B,*,sxmo_inputhandler.sh downbottomcorner" \ + -g "1,UD,T,*,sxmo_inputhandler.sh downtopcorner" \ + -g "1,DU,T,*,sxmo_inputhandler.sh uptopcorner" \ + -g "2,UD,T,*,sxmo_inputhandler.sh twodowntopcorner" \ + -g "2,UD,B,*,sxmo_inputhandler.sh twodownbottomcorner" \ + -g "r,UD,B,*,sxmo_inputhandler.sh threedownbottomcorner" \ + -g '1,DU,R,*,P,sxmo_inputhandler.sh uprightcorner' \ + -g '1,UD,R,*,P,sxmo_inputhandler.sh downrightcorner' \ + -g '1,LR,R,S,sxmo_inputhandler.sh rightrightcorner_short' \ + -g '1,RL,L,S,sxmo_inputhandler.sh leftrightcorner_short' \ + -g '1,RL,*,*,sxmo_inputhandler.sh left' \ + -g '1,LR,*,*,sxmo_inputhandler.sh right' \ + -g '1,DU,*,*,sxmo_inputhandler.sh up' \ + -g '1,UD,*,*,sxmo_inputhandler.sh down' \ + -g '1,DRUL,*,*,sxmo_inputhandler.sh upleft' \ + -g '1,URDL,*,*,sxmo_inputhandler.sh downleft' \ + -g '1,DLUR,*,*,sxmo_inputhandler.sh upright' \ + -g '1,ULDR,*,*,sxmo_inputhandler.sh downright' \ + -g '2,RL,*,*,sxmo_inputhandler.sh twoleft' \ + -g '2,LR,*,*,sxmo_inputhandler.sh tworight' \ + -g '2,DU,*,*,sxmo_inputhandler.sh twoup' \ + -g '2,UD,*,*,sxmo_inputhandler.sh twodown' \ + >"$CACHEDIR/lisgd.log" 2>&1 diff --git a/configs/default_hooks/lock b/configs/default_hooks/lock new file mode 100644 index 0000000..ed69ecc --- /dev/null +++ b/configs/default_hooks/lock @@ -0,0 +1,3 @@ +#!/usr/bin/env sh + +pkill -9 lisgd diff --git a/configs/default_hooks/notification b/configs/default_hooks/notification new file mode 100644 index 0000000..bba9b1c --- /dev/null +++ b/configs/default_hooks/notification @@ -0,0 +1,9 @@ +#!/usr/bin/env sh + +VIBS=5 +VIBI=0 +while [ $VIBI -lt $VIBS ]; do + sxmo_vibratepine 400 & + sleep 0.5 + VIBI=$(echo $VIBI+1 | bc) +done diff --git a/configs/default_hooks/presuspend b/configs/default_hooks/presuspend new file mode 100644 index 0000000..ff85020 --- /dev/null +++ b/configs/default_hooks/presuspend @@ -0,0 +1,11 @@ +#!/usr/bin/env sh + +# This script is called prior to suspending + +# include common definitions +# shellcheck source=scripts/core/sxmo_common.sh +. "$(which sxmo_common.sh)" + +pkill -STOP conky +pkill clickclack +pkill -f "$KEYBOARD" diff --git a/configs/default_hooks/unlock b/configs/default_hooks/unlock new file mode 100644 index 0000000..558e2a2 --- /dev/null +++ b/configs/default_hooks/unlock @@ -0,0 +1,4 @@ +#!/usr/bin/env sh + +[ "$(xrandr | grep DSI-1 | cut -d ' ' -f 5)" = "right" ] && ORIENTATION=1 || ORIENTATION=0 +sxmo_hooks.sh lisgdstart -o $ORIENTATION & diff --git a/configs/default_hooks/unlocksim b/configs/default_hooks/unlocksim new file mode 100644 index 0000000..3bb8465 --- /dev/null +++ b/configs/default_hooks/unlocksim @@ -0,0 +1,37 @@ +#!/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 +} + +retry=1 +pkill dmenu #kill existing dmenu +while [ $retry -eq 1 ]; do + PICKED="$( + # shellcheck disable=SC2039,SC3037 + 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 diff --git a/scripts/core/sxmo_common.sh b/scripts/core/sxmo_common.sh index 2b16b04..0a07e90 100644 --- a/scripts/core/sxmo_common.sh +++ b/scripts/core/sxmo_common.sh @@ -255,6 +255,4 @@ icon_bok="" icon_map="" #allow the user to override icons -if [ -x "$XDG_CONFIG_HOME/sxmo/hooks/icons" ]; then - "$XDG_CONFIG_HOME/sxmo/hooks/icons" -fi +sxmo_hooks.sh icons diff --git a/scripts/core/sxmo_hooks.sh b/scripts/core/sxmo_hooks.sh new file mode 100644 index 0000000..d25200a --- /dev/null +++ b/scripts/core/sxmo_hooks.sh @@ -0,0 +1,10 @@ +#!/usr/bin/env sh + +hook="$1" +shift + +if [ -x "$XDG_CONFIG_HOME/sxmo/hooks/$hook" ]; then + exec "$XDG_CONFIG_HOME/sxmo/hooks/$hook" "$@" +elif [ -x "/usr/share/sxmo/default_hooks/$hook" ]; then + exec "/usr/share/sxmo/default_hooks/$hook" "$@" +fi diff --git a/scripts/core/sxmo_lisgdstart.sh b/scripts/core/sxmo_lisgdstart.sh deleted file mode 100755 index cad6c95..0000000 --- a/scripts/core/sxmo_lisgdstart.sh +++ /dev/null @@ -1,59 +0,0 @@ -#!/usr/bin/env sh - -# include common definitions -# shellcheck source=scripts/core/sxmo_common.sh -. "$(dirname "$0")/sxmo_common.sh" - -pkill -9 lisgd - -if [ -z "$LISGD_THRESHOLD" ]; then - LISGD_THRESHOLD=125 -fi -if [ -z "$LISGD_THRESHOLD_PRESSED" ]; then - LISGD_THRESHOLD_PRESSED=60 -fi - -if [ -x "$XDG_CONFIG_HOME"/sxmo/hooks/lisgdstart ]; then - "$XDG_CONFIG_HOME"/sxmo/hooks/lisgdstart "$@" & -else - #-g format: - # fingers,swipe,edge,distance,command - #order matters, only the first match gets executed - lisgd "$@" -t "$LISGD_THRESHOLD" -T "$LISGD_THRESHOLD_PRESSED" \ - -g '1,DRUL,BR,*,sxmo_inputhandler.sh bottomrightcorner' \ - -g '1,DLUR,BL,*,sxmo_inputhandler.sh bottomleftcorner' \ - -g '1,ULDR,TL,*,sxmo_inputhandler.sh topleftcorner' \ - -g '1,URDL,TR,*,sxmo_inputhandler.sh toprightcorner' \ - -g '1,LR,B,L,sxmo_inputhandler.sh rightbottomcorner' \ - -g '1,RL,B,L,sxmo_inputhandler.sh leftbottomcorner' \ - -g '1,LR,L,*,sxmo_inputhandler.sh rightleftcorner' \ - -g '1,RL,R,*,sxmo_inputhandler.sh leftrightcorner' \ - -g '1,DU,L,*,P,sxmo_inputhandler.sh upleftcorner' \ - -g '1,UD,L,*,P,sxmo_inputhandler.sh downleftcorner' \ - -g '1,LR,T,*,P,sxmo_inputhandler.sh righttopcorner' \ - -g '1,RL,T,*,P,sxmo_inputhandler.sh lefttopcorner' \ - -g "1,DU,B,*,sxmo_inputhandler.sh upbottomcorner" \ - -g "1,UD,B,*,sxmo_inputhandler.sh downbottomcorner" \ - -g "1,UD,T,*,sxmo_inputhandler.sh downtopcorner" \ - -g "1,DU,T,*,sxmo_inputhandler.sh uptopcorner" \ - -g "2,UD,T,*,sxmo_inputhandler.sh twodowntopcorner" \ - -g "2,UD,B,*,sxmo_inputhandler.sh twodownbottomcorner" \ - -g "r,UD,B,*,sxmo_inputhandler.sh threedownbottomcorner" \ - -g '1,DU,R,*,P,sxmo_inputhandler.sh uprightcorner' \ - -g '1,UD,R,*,P,sxmo_inputhandler.sh downrightcorner' \ - -g '1,LR,R,S,sxmo_inputhandler.sh rightrightcorner_short' \ - -g '1,RL,L,S,sxmo_inputhandler.sh leftrightcorner_short' \ - -g '1,RL,*,*,sxmo_inputhandler.sh left' \ - -g '1,LR,*,*,sxmo_inputhandler.sh right' \ - -g '1,DU,*,*,sxmo_inputhandler.sh up' \ - -g '1,UD,*,*,sxmo_inputhandler.sh down' \ - -g '1,DRUL,*,*,sxmo_inputhandler.sh upleft' \ - -g '1,URDL,*,*,sxmo_inputhandler.sh downleft' \ - -g '1,DLUR,*,*,sxmo_inputhandler.sh upright' \ - -g '1,ULDR,*,*,sxmo_inputhandler.sh downright' \ - -g '2,RL,*,*,sxmo_inputhandler.sh twoleft' \ - -g '2,LR,*,*,sxmo_inputhandler.sh tworight' \ - -g '2,DU,*,*,sxmo_inputhandler.sh twoup' \ - -g '2,UD,*,*,sxmo_inputhandler.sh twodown' \ - >"$CACHEDIR/lisgd.log" 2>&1 & -fi diff --git a/scripts/core/sxmo_lock.sh b/scripts/core/sxmo_lock.sh deleted file mode 100755 index b64c6e9..0000000 --- a/scripts/core/sxmo_lock.sh +++ /dev/null @@ -1,23 +0,0 @@ -#!/usr/bin/env sh - -# include common definitions -# shellcheck source=scripts/core/sxmo_common.sh -. "$(dirname "$0")/sxmo_common.sh" - -finish() { - kill "$LOCKPID" -} -trap 'finish' TERM INT - -if [ -x "$XDG_CONFIG_HOME/sxmo/hooks/lock" ]; then - "$XDG_CONFIG_HOME/sxmo/hooks/lock" -fi -pkill -9 lisgd -sxmo_screenlock "$@" & -LOCKPID="$!" -wait $LOCKPID -[ "$(xrandr | grep DSI-1 | cut -d ' ' -f 5)" = "right" ] && ORIENTATION=1 || ORIENTATION=0 -sxmo_lisgdstart.sh -o $ORIENTATION & -if [ -x "$XDG_CONFIG_HOME/sxmo/hooks/unlock" ]; then - "$XDG_CONFIG_HOME/sxmo/hooks/unlock" -fi diff --git a/scripts/core/sxmo_migrate.sh b/scripts/core/sxmo_migrate.sh index 1f4d464..1706a9c 100644 --- a/scripts/core/sxmo_migrate.sh +++ b/scripts/core/sxmo_migrate.sh @@ -28,18 +28,4 @@ defaultconfig() { fi } -defaultconfigs() { - defaultconfig /usr/share/sxmo/appcfg/xinit_template "$XDG_CONFIG_HOME/sxmo/xinit" 744 - defaultconfig /usr/share/sxmo/default_hooks/discard "$XDG_CONFIG_HOME/sxmo/hooks/discard" 744 - defaultconfig /usr/share/sxmo/default_hooks/missed_call "$XDG_CONFIG_HOME/sxmo/hooks/missed_call" 744 - defaultconfig /usr/share/sxmo/default_hooks/mute_ring "$XDG_CONFIG_HOME/sxmo/hooks/mute_ring" 744 - defaultconfig /usr/share/sxmo/default_hooks/pickup "$XDG_CONFIG_HOME/sxmo/hooks/pickup" 744 - defaultconfig /usr/share/sxmo/default_hooks/postwake "$XDG_CONFIG_HOME/sxmo/hooks/postwake" 744 - defaultconfig /usr/share/sxmo/default_hooks/ring "$XDG_CONFIG_HOME/sxmo/hooks/ring" 744 - defaultconfig /usr/share/sxmo/default_hooks/rtcwake "$XDG_CONFIG_HOME/sxmo/hooks/rtcwake" 744 - defaultconfig /usr/share/sxmo/default_hooks/sms "$XDG_CONFIG_HOME/sxmo/hooks/sms" 744 - defaultconfig /usr/share/sxmo/default_hooks/battery "$XDG_CONFIG_HOME/sxmo/hooks/battery" 744 - defaultconfig /usr/share/sxmo/default_hooks/battery_crit "$XDG_CONFIG_HOME/sxmo/hooks/battery_crit" 744 -} - -defaultconfigs +defaultconfig /usr/share/sxmo/appcfg/xinit_template "$XDG_CONFIG_HOME/sxmo/xinit" 744 diff --git a/scripts/core/sxmo_networkmonitor.sh b/scripts/core/sxmo_networkmonitor.sh index 66f8a43..4599f17 100755 --- a/scripts/core/sxmo_networkmonitor.sh +++ b/scripts/core/sxmo_networkmonitor.sh @@ -21,22 +21,16 @@ dbus-monitor --system "interface='org.freedesktop.NetworkManager',type='signal', if echo "$newstate" | grep "int32 70"; then #network just connected (70=NM_STATE_CONNECTED_GLOBAL) echo "network up">&2 - if [ -x "$XDG_CONFIG_HOME/sxmo/hooks/network-up" ]; then - "$XDG_CONFIG_HOME/sxmo/hooks/network-up" & - fi + sxmo_hooks.sh network-up & sxmo_statusbarupdate.sh elif echo "$newstate" | grep "int32 20"; then #network just disconnected (20=NM_STATE_DISCONNECTED) echo "network down">&2 - if [ -x "$XDG_CONFIG_HOME/sxmo/hooks/network-down" ]; then - "$XDG_CONFIG_HOME/sxmo/hooks/network-down" & - fi + sxmo_hooks.sh network-down & sxmo_statusbarupdate.sh elif echo "$newstate" | grep "int32 30"; then #network is going down (30=NM_STATE_DISCONNECTING) - if [ -x "$XDG_CONFIG_HOME/sxmo/hooks/network-pre-down" ]; then - "$XDG_CONFIG_HOME/sxmo/hooks/network-pre-down" & - fi + sxmo_hooks.sh network-pre-down & fi fi done & diff --git a/scripts/core/sxmo_postwake.sh b/scripts/core/sxmo_postwake.sh deleted file mode 100755 index 18e3488..0000000 --- a/scripts/core/sxmo_postwake.sh +++ /dev/null @@ -1,16 +0,0 @@ -#!/usr/bin/env sh - -# This script is called when the system has successfully woken up after sleep - -# include common definitions -# shellcheck source=scripts/core/sxmo_common.sh -. "$(dirname "$0")/sxmo_common.sh" - -sxmo_statusbarupdate.sh -pkill -CONT conky - -(sleep 15 && sxmo_resetscaninterval.sh) & - -if [ -x "$XDG_CONFIG_HOME/sxmo/hooks/postwake" ]; then - "$XDG_CONFIG_HOME/sxmo/hooks/postwake" -fi diff --git a/scripts/core/sxmo_presuspend.sh b/scripts/core/sxmo_presuspend.sh deleted file mode 100755 index e6a9712..0000000 --- a/scripts/core/sxmo_presuspend.sh +++ /dev/null @@ -1,18 +0,0 @@ -#!/usr/bin/env sh - -# This script is called prior to suspending - -# include common definitions -# shellcheck source=scripts/core/sxmo_common.sh -. "$(dirname "$0")/sxmo_common.sh" - -pkill -STOP conky -pkill clickclack -pkill -f "$KEYBOARD" - -# If this script returns a non-zero exit code, suspension will be cancelled - -if [ -x "$XDG_CONFIG_HOME/sxmo/hooks/presuspend" ]; then - "$XDG_CONFIG_HOME/sxmo/hooks/presuspend" - exit $? -fi diff --git a/scripts/core/sxmo_rotate.sh b/scripts/core/sxmo_rotate.sh index 96e41cf..04542f7 100755 --- a/scripts/core/sxmo_rotate.sh +++ b/scripts/core/sxmo_rotate.sh @@ -19,7 +19,7 @@ rotnormal() { sxmo_keyboard.sh close xrandr -o normal applyptrmatrix 0 0 0 0 0 0 0 0 0 - pidof lisgd && pkill lisgd | sxmo_lisgdstart.sh -o 0 & + pidof lisgd && pkill lisgd | sxmo_hooks.sh lisgdstart -o 0 & exit 0 } @@ -27,7 +27,7 @@ rotright() { sxmo_keyboard.sh close xrandr -o right applyptrmatrix 0 1 0 -1 0 1 0 0 1 - pidof lisgd && pkill lisgd | sxmo_lisgdstart.sh -o 1 & + pidof lisgd && pkill lisgd | sxmo_hooks.sh lisgdstart -o 1 & exit 0 } @@ -35,7 +35,7 @@ rotleft() { sxmo_keyboard.sh close xrandr -o left applyptrmatrix 0 -1 1 1 0 0 0 0 1 - pidof lisgd && pkill lisgd | sxmo_lisgdstart.sh -o 3 & + pidof lisgd && pkill lisgd | sxmo_hooks.sh lisgdstart -o 3 & exit 0 } diff --git a/scripts/core/sxmo_screenlock.sh b/scripts/core/sxmo_screenlock.sh index 90f60dc..7437e94 100755 --- a/scripts/core/sxmo_screenlock.sh +++ b/scripts/core/sxmo_screenlock.sh @@ -73,9 +73,7 @@ if [ "$1" = "lock" ] ; then # TODO: Document LASTSTATE getCurState > "$LASTSTATE" # Do we want this hook after disabling all the input devices so users can enable certain devices? - if [ -x "$XDG_CONFIG_HOME/sxmo/hooks/lock" ]; then - "$XDG_CONFIG_HOME/sxmo/hooks/lock" - fi + sxmo_hooks.sh lock xset dpms 0 0 0 xset dpms force on @@ -92,14 +90,12 @@ if [ "$1" = "lock" ] ; then exit 0 elif [ "$1" = "unlock" ] ; then getCurState > "$LASTSTATE" - if [ -x "$XDG_CONFIG_HOME/sxmo/hooks/unlock" ]; then - "$XDG_CONFIG_HOME/sxmo/hooks/unlock" - fi + sxmo_hooks.sh unlock xset dpms 0 0 0 xset dpms force on xinput enable "$TOUCH_POINTER_ID" - sxmo_lisgdstart.sh + sxmo_hooks.sh lisgdstart & echo 16000 > "$NETWORKRTCSCAN" updateLed @@ -107,9 +103,7 @@ elif [ "$1" = "unlock" ] ; then elif [ "$1" = "off" ] ; then getCurState > "$LASTSTATE" # TODO: document this hook - if [ -x "$XDG_CONFIG_HOME/sxmo/hooks/screenoff" ]; then - "$XDG_CONFIG_HOME/sxmo/hooks/screenoff" - fi + sxmo_hooks.sh screenoff xset dpms 0 0 3 xset dpms force off @@ -128,9 +122,7 @@ elif [ "$1" = "crust" ] ; then saveAllEventCounts - if [ -x "$XDG_CONFIG_HOME/sxmo/hooks/presuspend" ]; then - "$XDG_CONFIG_HOME/sxmo/hooks/presuspend" - fi + sxmo_hooks.sh presuspend xset dpms force off suspend_time="$(($(mnc)-10))" @@ -153,9 +145,9 @@ elif [ "$1" = "crust" ] ; then xset dpms force on fi - if [ "$UNSUSPENDREASON" = "button" ] && [ -x "$XDG_CONFIG_HOME/sxmo/hooks/postwake" ]; then + if [ "$UNSUSPENDREASON" = "button" ]; then echo 1200 > "$NETWORKRTCSCAN" - "$XDG_CONFIG_HOME/sxmo/hooks/postwake" + sxmo_hooks.sh postwake fi exit 0 elif [ "$1" = "getCurState" ] ; then diff --git a/scripts/core/sxmo_xinit.sh b/scripts/core/sxmo_xinit.sh index 25fa47f..bbd0869 100755 --- a/scripts/core/sxmo_xinit.sh +++ b/scripts/core/sxmo_xinit.sh @@ -70,7 +70,7 @@ daemonsneedingdbus() { dunst -conf /usr/share/sxmo/appcfg/dunst.conf & sxmo_notificationmonitor.sh & sxmo_networkmonitor.sh & - sxmo_lisgdstart.sh & + sxmo_hooks.sh lisgdstart & } defaultconfig() { @@ -85,15 +85,6 @@ defaultconfigs() { [ -r "$XDG_CONFIG_HOME/sxmo/xinit" ] && return defaultconfig /usr/share/sxmo/appcfg/xinit_template "$XDG_CONFIG_HOME/sxmo/xinit" 744 - - defaultconfig /usr/share/sxmo/default_hooks/discard "$XDG_CONFIG_HOME/sxmo/hooks/discard" 744 - defaultconfig /usr/share/sxmo/default_hooks/missed_call "$XDG_CONFIG_HOME/sxmo/hooks/missed_call" 744 - defaultconfig /usr/share/sxmo/default_hooks/mute_ring "$XDG_CONFIG_HOME/sxmo/hooks/mute_ring" 744 - defaultconfig /usr/share/sxmo/default_hooks/pickup "$XDG_CONFIG_HOME/sxmo/hooks/pickup" 744 - defaultconfig /usr/share/sxmo/default_hooks/postwake "$XDG_CONFIG_HOME/sxmo/hooks/postwake" 744 - defaultconfig /usr/share/sxmo/default_hooks/ring "$XDG_CONFIG_HOME/sxmo/hooks/ring" 744 - defaultconfig /usr/share/sxmo/default_hooks/rtcwake "$XDG_CONFIG_HOME/sxmo/hooks/rtcwake" 744 - defaultconfig /usr/share/sxmo/default_hooks/sms "$XDG_CONFIG_HOME/sxmo/hooks/sms" 744 } customxinit() { diff --git a/scripts/modem/sxmo_modemcall.sh b/scripts/modem/sxmo_modemcall.sh index 5ed0833..fb43b01 100755 --- a/scripts/modem/sxmo_modemcall.sh +++ b/scripts/modem/sxmo_modemcall.sh @@ -110,10 +110,8 @@ acceptcall() { log_event "call_start" "$CALLID" echo "sxmo_modemcall: Started call $CALLID">&2 elif [ "$DIRECTION" = "incoming" ]; then - if [ -x "$XDG_CONFIG_HOME/sxmo/hooks/pickup" ]; then - echo "sxmo_modemcall: Invoking pickup hook (async)">&2 - "$XDG_CONFIG_HOME/sxmo/hooks/pickup" & - fi + echo "sxmo_modemcall: Invoking pickup hook (async)">&2 + sxmo_hooks.sh pickup & touch "$CACHEDIR/${CALLID}.pickedupcall" #this signals that we picked this call up #to other asynchronously running processes modem_cmd_errcheck -m "$(modem_n)" -o "$CALLID" --accept @@ -134,10 +132,8 @@ hangup() { else #this call was never picked up and hung up immediately, so it is a discarded call touch "$CACHEDIR/${CALLID}.discardedcall" #this signals that we discarded this call to other asynchronously running processes - if [ -x "$XDG_CONFIG_HOME/sxmo/hooks/discard" ]; then - echo "sxmo_modemcall: Invoking discard hook (async)">&2 - "$XDG_CONFIG_HOME/sxmo/hooks/discard" & - fi + echo "sxmo_modemcall: Invoking discard hook (async)">&2 + sxmo_hooks.sh discard & log_event "call_discard" "$CALLID" fi modem_cmd_errcheck -m "$(modem_n)" -o "$CALLID" --hangup @@ -228,10 +224,8 @@ pickup() { mute() { touch "$CACHEDIR/$1.mutedring" #this signals that we muted this ring - if [ -x "$XDG_CONFIG_HOME/sxmo/hooks/mute_ring" ]; then - echo "sxmo_modemmonitor: Invoking mute_ring hook (async)">&2 - "$XDG_CONFIG_HOME/sxmo/hooks/mute_ring" "$CONTACTNAME" & - fi + echo "sxmo_modemmonitor: Invoking mute_ring hook (async)">&2 + sxmo_hooks.sh mute_ring "$CONTACTNAME" & log_event "ring_mute" "$1" finish "Ringing with $NUMBER muted" } diff --git a/scripts/modem/sxmo_modemmonitor.sh b/scripts/modem/sxmo_modemmonitor.sh index cde591d..7345e93 100755 --- a/scripts/modem/sxmo_modemmonitor.sh +++ b/scripts/modem/sxmo_modemmonitor.sh @@ -125,10 +125,8 @@ checkforfinishedcalls() { echo "sxmo_modemmonitor: Missed call from $FINISHEDNUMBER">&2 printf %b "$TIME\tcall_missed\t$FINISHEDNUMBER\n" >> "$LOGDIR/modemlog.tsv" - if [ -x "$XDG_CONFIG_HOME/sxmo/hooks/missed_call" ]; then - echo "sxmo_modemmonitor: Invoking missed call hook (async)">&2 - "$XDG_CONFIG_HOME/sxmo/hooks/missed_call" "$CONTACTNAME" & - fi + echo "sxmo_modemmonitor: Invoking missed call hook (async)">&2 + sxmo_hooks.sh missed_call "$CONTACTNAME" & CONTACT="$(lookupcontactname "$FINISHEDNUMBER")" sxmo_notificationwrite.sh \ @@ -168,12 +166,8 @@ checkforincomingcalls() { xset dpms force on - if [ -x "$XDG_CONFIG_HOME/sxmo/hooks/ring" ]; then - echo "sxmo_modemmonitor: Invoking ring hook (async)">&2 - "$XDG_CONFIG_HOME/sxmo/hooks/ring" "$CONTACTNAME" & - else - sxmo_vibratepine 2500 & - fi + echo "sxmo_modemmonitor: Invoking ring hook (async)">&2 + sxmo_hooks.sh ring "$CONTACTNAME" & TIME="$(date --iso-8601=seconds)" mkdir -p "$LOGDIR" @@ -224,9 +218,7 @@ checkfornewtexts() { "$LOGDIR/$NUM/sms.txt" \ "Message - $CONTACTNAME: $TEXT" - if [ -x "$XDG_CONFIG_HOME/sxmo/hooks/sms" ]; then - "$XDG_CONFIG_HOME/sxmo/hooks/sms" "$CONTACTNAME" "$TEXT" - fi + sxmo_hooks.sh sms "$CONTACTNAME" "$TEXT" done if grep -q modem "$UNSUSPENDREASONFILE" && grep -q crust "$LASTSTATE"; then @@ -246,7 +238,7 @@ initialmodemstatus() { echo registered > "$MODEMSTATEFILE" elif echo "$state" | grep -q -E "^.*state:.*locked.*$"; then echo locked > "$MODEMSTATEFILE" - pidof sxmo_unlocksim.sh || sxmo_unlocksim.sh & + pidof unlocksim || sxmo_hooks.sh unlocksim & else echo unknown > "$MODEMSTATEFILE" fi @@ -290,7 +282,7 @@ mainloop() { read -r newstate if echo "$newstate" | grep "int32 2"; then echo locked > "$MODEMSTATEFILE" - pidof sxmo_unlocksim.sh || sxmo_unlocksim.sh & + pidof unlocksim || sxmo_hooks.sh unlocksim & elif echo "$newstate" | grep "int32 8"; then echo registered > "$MODEMSTATEFILE" checkforfinishedcalls diff --git a/scripts/modem/sxmo_unlocksim.sh b/scripts/modem/sxmo_unlocksim.sh deleted file mode 100755 index 64fe998..0000000 --- a/scripts/modem/sxmo_unlocksim.sh +++ /dev/null @@ -1,41 +0,0 @@ -#!/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 - pkill dmenu #kill existing dmenu - while [ $retry -eq 1 ]; do - PICKED="$( - # shellcheck disable=SC2039,SC3037 - 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 diff --git a/scripts/notifications/sxmo_notificationmonitor.sh b/scripts/notifications/sxmo_notificationmonitor.sh index 53dbed1..96be1f7 100755 --- a/scripts/notifications/sxmo_notificationmonitor.sh +++ b/scripts/notifications/sxmo_notificationmonitor.sh @@ -10,20 +10,6 @@ gracefulexit() { kill -9 0 } -notificationhook() { - if [ -x "$XDG_CONFIG_HOME"/sxmo/hooks/notification ]; then - "$XDG_CONFIG_HOME"/sxmo/hooks/notification "$@" - else - VIBS=5 - VIBI=0 - while [ $VIBI -lt $VIBS ]; do - sxmo_vibratepine 400 & - sleep 0.5 - VIBI=$(echo $VIBI+1 | bc) - done - fi -} - handlenewnotiffile(){ NOTIFFILE="$1" @@ -31,7 +17,7 @@ handlenewnotiffile(){ echo "Invalid notification file $NOTIFFILE found (<3 lines -- see notif spec in sxmo_notifwrite.sh), deleting!" >&2 rm -f "$NOTIFFILE" else - notificationhook "$NOTIFFILE" & + sxmo_hooks.sh notification "$NOTIFFILE" & NOTIFACTION="$(awk NR==1 "$NOTIFFILE")" NOTIFWATCHFILE="$(awk NR==2 "$NOTIFFILE")" NOTIFMSG="$(tail -n+3 "$NOTIFFILE" | cut -c1-70)"