Advertisement
dimon2242

Untitled

Nov 14th, 2015
184
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 0.99 KB | None | 0 0
  1. #Place to /lib/systemd/system-sleep/
  2. #!/bin/bash
  3.  
  4. hibernation_timeout=10800  #3 hours
  5.  
  6. if [ "$2" = "suspend" ]; then
  7.     curtime=$(date +%s)
  8.     if [ "$1" = "pre" ]; then
  9.         echo -e "[($curtime) $@]nExecuting pre-suspend hook..." >> /tmp/delayed_hibernation.log
  10.         echo "$curtime" > /var/run/delayed_hibernation.lock
  11.         rtcwake -m no -s $hibernation_timeout
  12.     elif [ "$1" = "post" ]; then
  13.         echo -e "[($curtime) $@]nExecuting post-suspend hook..." >> /tmp/delayed_hibernation.log
  14.         sustime=$(cat /var/run/delayed_hibernation.lock)
  15.         if [ $(($curtime - $sustime)) -ge $hibernation_timeout ]; then
  16.             echo -e "Automatic resume detected, hibernating.n" >> /tmp/delayed_hibernation.log
  17.             systemctl hibernate || systemctl suspend
  18.         else
  19.             echo -e "Manual resume detected, clearing RTC alarm.n" >> /tmp/delayed_hibernation.log
  20.             rtcwake -m no -s 1
  21.         fi
  22.         rm /var/run/delayed_hibernation.lock
  23.     fi
  24. fi
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement