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 # Parse CLI and set options
repoFile="$(dirname "$0")/repos" repoFile="$(dirname "$0")/repos"
dryRun='' dryRun=''
preventSleep=''
varDir=/var/lib/bup-backup-trigger varDir=/var/lib/bup-backup-trigger
triggerFile="$varDir/trigger" triggerFile="$varDir/trigger"
@ -29,6 +30,9 @@ do
rm -f "$lockFile" rm -f "$lockFile"
exit 0 exit 0
;; ;;
--no-sleep)
preventSleep=y
;;
--log) --log)
log="$2" log="$2"
shift shift
@ -54,11 +58,11 @@ then
exit 1 exit 1
fi fi
if [ -f "$lockFile" ] # if [ -f "$lockFile" ]
then # then
echo "The lock file exists. Skipping for now ($(date))" # echo "The lock file exists. Skipping for now ($(date))"
exit 0 # exit 0
fi # fi
# Define the needed functions # Define the needed functions
@ -97,6 +101,10 @@ triggerLiesInPast() {
fi fi
} }
getNextStart() {
date -d "@$(cat "$triggerFile")" "+%Y-%m-%d %H:%M"
}
if ! triggerLiesInPast if ! triggerLiesInPast
then then
echo "The timestamp in the trigger event lies in the future. Waiting further." 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" ] if [ -n "$dryRun" ]
then then
echo "Not updating the trigger timestamp. The value would be $(getNextDate)." echo "Not updating the trigger timestamp. The value would be $(getNextDate)."
echo "Sleep mode entry is skipped as well."
else else
updateTriggerFile 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 fi