summaryrefslogtreecommitdiff
path: root/src/helpers/commit-confirm-notify.py
diff options
context:
space:
mode:
authorkumvijaya <kuvmijaya@gmail.com>2024-09-26 11:31:07 +0530
committerkumvijaya <kuvmijaya@gmail.com>2024-09-26 11:31:07 +0530
commita950059053f7394acfb453cc0d8194aa3dc721fa (patch)
treeeb0acf278f649b5d1417e18e34d728efcd16e745 /src/helpers/commit-confirm-notify.py
parentf0815f3e9b212f424f5adb0c572a71119ad4a8a0 (diff)
downloadvyos-workflow-test-temp-a950059053f7394acfb453cc0d8194aa3dc721fa.tar.gz
vyos-workflow-test-temp-a950059053f7394acfb453cc0d8194aa3dc721fa.zip
T6732: added same as vyos 1x
Diffstat (limited to 'src/helpers/commit-confirm-notify.py')
-rw-r--r--src/helpers/commit-confirm-notify.py31
1 files changed, 31 insertions, 0 deletions
diff --git a/src/helpers/commit-confirm-notify.py b/src/helpers/commit-confirm-notify.py
new file mode 100644
index 0000000..8d7626c
--- /dev/null
+++ b/src/helpers/commit-confirm-notify.py
@@ -0,0 +1,31 @@
+#!/usr/bin/env python3
+import os
+import sys
+import time
+
+# Minutes before reboot to trigger notification.
+intervals = [1, 5, 15, 60]
+
+def notify(interval):
+ s = "" if interval == 1 else "s"
+ time.sleep((minutes - interval) * 60)
+ message = ('"[commit-confirm] System is going to reboot in '
+ f'{interval} minute{s} to rollback the last commit.\n'
+ 'Confirm your changes to cancel the reboot."')
+ os.system("wall -n " + message)
+
+if __name__ == "__main__":
+ # Must be run as root to call wall(1) without a banner.
+ if len(sys.argv) != 2 or os.getuid() != 0:
+ print('This script requires superuser privileges.', file=sys.stderr)
+ exit(1)
+ minutes = int(sys.argv[1])
+ # Drop the argument from the list so that the notification
+ # doesn't kick in immediately.
+ if minutes in intervals:
+ intervals.remove(minutes)
+ for interval in sorted(intervals, reverse=True):
+ if minutes >= interval:
+ notify(interval)
+ minutes -= (minutes - interval)
+ exit(0)