Showing 1 changed files with 36 additions and 0 deletions
+36
rtcwake
... ...
@@ -0,0 +1,36 @@
1
+#!/bin/bash
2
+# /lib/systemd/system-sleep/rtcwake
3
+# chmod a+rx
4
+
5
+set -e
6
+
7
+AWAKE_TIME="01:23:45" # hour:minute:second
8
+GAP="10 seconds"      # precision of awake time in date(1) format
9
+WAIT_TRIGGER='true'   # test to go back to sleep when action is finished 
10
+                      # typically pgrep on user or for specific process
11
+WAIT_TRIGGER_DELAY=60 # sleep duration in seconds between two tests with WAIT_TRIGGER
12
+MAX_TRIGGER=60        # don't go back to sleep if WAIT_TRIGGER isn't true
13
+                      # after WAIT_TRIGGER_DELAY * MAX_TRIGGER seconds
14
+
15
+test -r $0.conf && source $0.conf # all previous variables can be set here
16
+
17
+NOW=$(date +%_H%M%S)
18
+RTCWAKE_TIME=$([ $NOW -lt ${AWAKE_TIME//:} ] && date +%s -d $AWAKE_TIME || date +%s -d "tomorrow $AWAKE_TIME")
19
+
20
+case "$1/$2" in
21
+    pre/suspend)
22
+        rtcwake -m no -t $RTCWAKE_TIME
23
+        echo $1 $RTCWAKE_TIME > $LOG_FILE
24
+        ;;
25
+    post/suspend)
26
+        if test $NOW -ge ${AWAKE_TIME//:} -a $NOW -le $(date +%_H%M%S -d "$AWAKE_TIME $GAP"); then
27
+            COUNT=1
28
+            while sleep $WAIT_TRIGGER_DELAY && eval $WAIT_TRIGGER; do
29
+                let COUNT++ && [ $COUNT -lt $MAX_TRIGGER ] || exit 0
30
+            done
31
+            rtcwake -m mem -t $RTCWAKE_TIME
32
+        else
33
+            rtcwake -m disable
34
+        fi
35
+        ;;
36
+esac