blue-merle/files/etc/gl-switch.d/sim.sh
Tobias Mueller ed6856c490 switch: split the switch action into separate stages
When toggling the switch, a lock is held for a relatively long time,
preventing another toggling of the switch to be noticed. With this
change, I hope we can first shutdown the modem, wait for a toggle, and
then continue.
We're losing the abort function but I currently don't know how we would
be able to keep that functionality given that the toggle is queued and
we don't get the notification.
2023-10-17 15:15:28 +02:00

31 lines
1.2 KiB
Bash

#!/bin/sh
action=$1
logger -p notice -t blue-merle-toggle "Called... ${action}"
. /lib/functions/gl_util.sh
if [ "$action" = "on" ];then
mcu_send_message "Blue Merle ${action}"
echo "on" > /tmp/sim_change_switch
flock -n /tmp/blue-merle-switch.lock logger -p notice -t blue-merle-toggle "Running Stage 1" || logger -p notice -t blue-merle-toggle "Lockfile busy" &
flock -n /tmp/blue-merle-switch.lock timeout 90 /usr/bin/blue-merle-switch-stage1
elif [ "$action" = "off" ];then
# We check for any previous run and eventually execute the second stage. We could check for the age of this marker and only activate the second stage is the marker is young enough.
if [ -f /tmp/blue-merle-stage1 ]; then
flock -n /tmp/blue-merle-switch.lock || logger -p notice -t blue-merle-toggle "Lockfile busy" &
flock -n /tmp/blue-merle-switch.lock timeout 90 /usr/bin/blue-merle-switch-stage2
else
logger -p notice -t blue-merle-toggle "No Stage 1; Toggling Off"
fi
echo "off" > /tmp/sim_change_switch
else
echo "off" > /tmp/sim_change_switch
fi
logger -p notice -t blue-merle-toggle "Finished Switch $action"
sleep 1