pidor/scripts/lockbutton.sh.d/changestatus

24 lines
1.0 KiB
Plaintext
Raw Normal View History

#!/bin/bash
# changes level2 state by the state of the main door
# i.e. people have to leave it open to keep status open
sleep 1 # silly way to debounce
if [ ! -f /run/spacestatus ] # needed to init after boot
then
cp -p /root/var/spacestatus /run/spacestatus
fi
if [ "$1" = "pushed" ] &&
[ "$(cat /run/spacestatus)" = "open" ]
then
FORM_action="close" /root/pidor/webserver/cgi-bin/pidor.sh
/root/pidor/scripts/upd_status.sh
fi
if [ "$1" = "released" ] && # if switch was released (the door opened, or someone is playing with the switch)
[ "$(cat /run/spacestatus)" = "closed" ] # the status was closed
# [ $(stat -c "%Y" /run/spacestatus) -lt $(date --date "1 hour ago" +%s) ] # since at least one hour
then
FORM_action="open" /root/pidor/webserver/cgi-bin/pidor.sh
/root/pidor/scripts/upd_status.sh
# echo "intrusion detected: space was closed since some time and locked, but now is still closed but unlocked" | wall
# logger -t $(basename $0) "INTRUSION ALARM. door was opened while status is closed"
fi