ajout rtcwake pour réveil de...
|
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 |
;; |
|
24 |
post/suspend) |
|
fix post sleep
|
25 |
at -M now <<< "$0 post wait-for-trigger" > /dev/null 2>&1 |
26 |
;; |
|
27 |
post/wait-for-trigger) |
|
ajout rtcwake pour réveil de...
|
28 |
if test $NOW -ge ${AWAKE_TIME//:} -a $NOW -le $(date +%_H%M%S -d "$AWAKE_TIME $GAP"); then |
29 |
COUNT=1 |
|
30 |
while sleep $WAIT_TRIGGER_DELAY && eval $WAIT_TRIGGER; do |
|
31 |
let COUNT++ && [ $COUNT -lt $MAX_TRIGGER ] || exit 0 |
|
32 |
done |
|
33 |
rtcwake -m mem -t $RTCWAKE_TIME |
|
34 |
else |
|
35 |
rtcwake -m disable |
|
36 |
fi |
|
37 |
;; |
|
38 |
esac |