From 37c6675a4fed08ade39b1b17d36950eed1841c12 Mon Sep 17 00:00:00 2001 From: Christian Wolf Date: Thu, 9 May 2024 13:38:42 +0200 Subject: [PATCH] Add some dry run checks --- bup-sync-trigger.sh | 33 ++++++++++++++++++++++++++++----- 1 file changed, 28 insertions(+), 5 deletions(-) diff --git a/bup-sync-trigger.sh b/bup-sync-trigger.sh index 8730e19..f1e429b 100755 --- a/bup-sync-trigger.sh +++ b/bup-sync-trigger.sh @@ -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