]> git.scottworley.com Git - auto-upgrade-with-pinch/commitdiff
Don't upgrade during business hours
authorScott Worley <scottworley@scottworley.com>
Wed, 15 Apr 2020 20:34:31 +0000 (13:34 -0700)
committerScott Worley <scottworley@scottworley.com>
Mon, 18 May 2020 18:48:31 +0000 (11:48 -0700)
modules/auto-upgrade.nix

index 2326eccfd7c1c52bcac2e9a539fa7db0953fd160..31e2b0b1519e49cc9af098a8aa5ad284a75885fc 100644 (file)
@@ -86,6 +86,17 @@ in {
         # intervene either to fix the problem or disable automatic updates.
         sleep 2h
 
         # intervene either to fix the problem or disable automatic updates.
         sleep 2h
 
+        # Wait until outside business hours
+        now=$(date +%s)
+        day_of_week=$(date +%u)
+        business_start=$(date -d  8:00 +%s)
+        business_end=$(  date -d 17:00 +%s)
+        if (( day_of_week <= 5 && now > business_start && now < business_end ));then
+          delay=$((business_end - now))
+          echo "Waiting $delay seconds so we don't upgrade during business hours" >&2
+          sleep "$delay"
+        fi
+
         ${pkgs.auto-upgrade}/bin/auto-upgrade
       '';
 
         ${pkgs.auto-upgrade}/bin/auto-upgrade
       '';