Add some dry run checks

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

View File

@ -3,6 +3,7 @@
# Parse CLI and set options
repoFile="$(dirname "$0")/repos"
dryRun=''
preventSleep=''
varDir=/var/lib/bup-backup-trigger
triggerFile="$varDir/trigger"
@ -29,6 +30,9 @@ do
rm -f "$lockFile"
exit 0
;;
--no-sleep)
preventSleep=y
;;
--log)
log="$2"
shift
@ -54,11 +58,11 @@ then
exit 1
fi
if [ -f "$lockFile" ]
then
echo "The lock file exists. Skipping for now ($(date))"
exit 0
fi
# if [ -f "$lockFile" ]
# then
# echo "The lock file exists. Skipping for now ($(date))"
# exit 0
# fi
# Define the needed functions
@ -97,6 +101,10 @@ triggerLiesInPast() {
fi
}
getNextStart() {
date -d "@$(cat "$triggerFile")" "+%Y-%m-%d %H:%M"
}
if ! triggerLiesInPast
then
echo "The timestamp in the trigger event lies in the future. Waiting further."
@ -119,6 +127,21 @@ done <<< $(cat "$repoFile" | grep -v '^#' | sed '/^\W*$/d')
if [ -n "$dryRun" ]
then
echo "Not updating the trigger timestamp. The value would be $(getNextDate)."
echo "Sleep mode entry is skipped as well."
else
updateTriggerFile
if [ -n "$preventSleep" ]
then
echo "Not going to sleep as prevented by CLI argument"
else
if [ -f "$lockFile" ]
then
echo "Skipping sleeping due to lock file existence."
else
nextStart=$(getNextStart)
echo "Going to sleep until $nextStart"
rtcwake --mode disk --date "$nextStart"
fi
fi
fi