Enable active suspension

This commit is contained in:
Christian Wolf 2024-05-09 13:50:34 +02:00
parent 37c6675a4f
commit 42b0b57742

View File

@ -4,6 +4,7 @@
repoFile="$(dirname "$0")/repos"
dryRun=''
preventSleep=''
suspend=''
varDir=/var/lib/bup-backup-trigger
triggerFile="$varDir/trigger"
@ -33,6 +34,9 @@ do
--no-sleep)
preventSleep=y
;;
--suspend)
suspend=y
;;
--log)
log="$2"
shift
@ -105,12 +109,30 @@ getNextStart() {
date -d "@$(cat "$triggerFile")" "+%Y-%m-%d %H:%M"
}
goToSleep() {
nextStart=$(getNextStart)
echo "Going to sleep until $nextStart"
rtcwake --mode disk --date "$nextStart"
}
if ! triggerLiesInPast
then
echo "The timestamp in the trigger event lies in the future. Waiting further."
exit 0
fi
if [ -n "$suspend"]
then
if [ -f "$lockFile" -o -n "$preventSleep" ]
then
echo "Failed to go to sleep while lock file is present or sleep prevention given."
exit 1
else
goToSleep
exit 0
fi
fi
echo "The backup script is triggered."
while read line
@ -139,9 +161,7 @@ else
then
echo "Skipping sleeping due to lock file existence."
else
nextStart=$(getNextStart)
echo "Going to sleep until $nextStart"
rtcwake --mode disk --date "$nextStart"
goToSleep
fi
fi
fi