#!/bin/bash

STATE_DIR="/var/lib/kuroevtd"
debug=true

current=$(date +%s)

if [ -f "${STATE_DIR}/last" ] ; then
	read last <<<$(cat "${STATE_DIR}/last")
	rm -f ${STATE_DIR}/last
	if (( current <= (last+3) )) ; then
		${debug} && echo "[kuroevtd] powerdown: will reset soon..."
		touch ${STATE_DIR}/reset
		exit 0
	fi
fi

${debug} && echo "[kuroevtd] powerdown: saving push date"
echo ${current} > "${STATE_DIR}/last"
