Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #Place to /lib/systemd/system-sleep/
- #!/bin/bash
- hibernation_timeout=10800 #3 hours
- if [ "$2" = "suspend" ]; then
- curtime=$(date +%s)
- if [ "$1" = "pre" ]; then
- echo -e "[($curtime) $@]nExecuting pre-suspend hook..." >> /tmp/delayed_hibernation.log
- echo "$curtime" > /var/run/delayed_hibernation.lock
- rtcwake -m no -s $hibernation_timeout
- elif [ "$1" = "post" ]; then
- echo -e "[($curtime) $@]nExecuting post-suspend hook..." >> /tmp/delayed_hibernation.log
- sustime=$(cat /var/run/delayed_hibernation.lock)
- if [ $(($curtime - $sustime)) -ge $hibernation_timeout ]; then
- echo -e "Automatic resume detected, hibernating.n" >> /tmp/delayed_hibernation.log
- systemctl hibernate || systemctl suspend
- else
- echo -e "Manual resume detected, clearing RTC alarm.n" >> /tmp/delayed_hibernation.log
- rtcwake -m no -s 1
- fi
- rm /var/run/delayed_hibernation.lock
- fi
- fi
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement