2023-10-16 06:14:00 -04:00
#!/bin/sh
2023-10-17 07:02:40 -04:00
action = $1
logger -p notice -t blue-merle-toggle " Called... ${ action } "
2023-10-16 06:14:00 -04:00
2023-10-16 10:10:17 -04:00
. /lib/functions/gl_util.sh
2023-10-16 06:14:00 -04:00
2023-10-16 10:03:11 -04:00
2023-10-16 06:14:00 -04:00
if [ " $action " = "on" ] ; then
2023-10-16 10:10:17 -04:00
mcu_send_message " Blue Merle ${ action } "
2023-10-16 06:14:00 -04:00
echo "on" > /tmp/sim_change_switch
2023-10-17 09:49:25 -04:00
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"
2023-10-17 08:48:47 -04:00
flock -n /tmp/blue-merle-switch.lock timeout 90 /usr/bin/blue-merle-switch-stage1
2023-10-16 06:14:00 -04:00
elif [ " $action " = "off" ] ; then
2023-10-17 08:48:47 -04:00
# 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
2023-10-16 06:14:00 -04:00
echo "off" > /tmp/sim_change_switch
2023-10-16 10:10:17 -04:00
2023-10-16 06:14:00 -04:00
else
echo "off" > /tmp/sim_change_switch
fi
2023-10-17 08:48:47 -04:00
logger -p notice -t blue-merle-toggle " Finished Switch $action "
2023-10-16 06:14:00 -04:00
sleep 1