diff options
author | Niccolò Maggioni | 2015-12-27 01:11:12 +0100 |
---|---|---|
committer | Niccolò Maggioni | 2015-12-27 01:11:12 +0100 |
commit | bfd470ae099fabc3c0a8558d4ab07c49b045c386 (patch) | |
tree | 5393e29e11511347a74002582ea5693d774f668a | |
parent | a18a8fa9c38d5b23931433550b2bab9a37fd55eb (diff) | |
download | aur-delayed_hibernation.tar.gz |
Suspension loop fix
-rw-r--r-- | .SRCINFO | 10 | ||||
-rw-r--r-- | PKGBUILD | 8 | ||||
-rwxr-xr-x | delayed_hibernation.sh | 32 |
3 files changed, 30 insertions, 20 deletions
@@ -1,7 +1,9 @@ +# Generated by mksrcinfo v8 +# Sun Dec 27 00:10:38 UTC 2015 pkgbase = delayed_hibernation - pkgdesc = Script to hibernate the computer after having spent some time in suspension - pkgver = 1.0 - pkgrel = 1 + pkgdesc = Script to hibernate the computer after suspension. Fallbacks to suspension if hibernation does not work. + pkgver = 1.1 + pkgrel = 2 url = https://bbs.archlinux.org/viewtopic.php?pid=1554259 install = delayed_hibernation.install arch = any @@ -10,7 +12,7 @@ pkgbase = delayed_hibernation depends = bash source = delayed_hibernation.sh source = delayed_hibernation.conf - md5sums = 36867d9b80ab9c94f5cbecae85e32dda + md5sums = 89423caf82c10bf126cee821bb20b693 md5sums = 0fe21901bbc6f9ce9e8a85e5ec7a3eaf pkgname = delayed_hibernation @@ -2,16 +2,16 @@ # Credits to Derek Pressnall (http://askubuntu.com/a/33192/440625) pkgname=delayed_hibernation -pkgver=1.0 -pkgrel=1 -pkgdesc="Script to hibernate the computer after having spent some time in suspension" +pkgver=1.1 +pkgrel=2 +pkgdesc="Script to hibernate the computer after suspension. Fallbacks to suspension if hibernation does not work." arch=('any') url="https://bbs.archlinux.org/viewtopic.php?pid=1554259" license=('MIT') depends=('systemd' 'bash') install=delayed_hibernation.install source=(delayed_hibernation.sh delayed_hibernation.conf) -md5sums=('36867d9b80ab9c94f5cbecae85e32dda' '0fe21901bbc6f9ce9e8a85e5ec7a3eaf') +md5sums=('89423caf82c10bf126cee821bb20b693' '0fe21901bbc6f9ce9e8a85e5ec7a3eaf') package() { install -Dm 755 $srcdir/delayed_hibernation.sh ${pkgdir}/usr/lib/systemd/system-sleep/delayed_hibernation.sh diff --git a/delayed_hibernation.sh b/delayed_hibernation.sh index 49080ab298f3..7e644d705337 100755 --- a/delayed_hibernation.sh +++ b/delayed_hibernation.sh @@ -6,36 +6,44 @@ if [ ! -f /etc/delayed_hibernation.conf ]; then exit 1 fi -ENABLE=$(cat /etc/delayed_hibernation.conf | grep "^[^#]" | grep "ENABLE=" | awk -F'=' '{ print $2 }') -if [ $ENABLE = "" ]; then +ENABLE=$(grep "^[^#]" /etc/delayed_hibernation.conf | grep "ENABLE=" | awk -F'=' '{ print $2 }') +if [ "$ENABLE" = "" ]; then echo "${logtag}Missing enable parameter, aborting." exit 1 -elif [ $ENABLE != "0" ] && [ $ENABLE != "1" ]; then +elif [ "$ENABLE" != "0" ] && [ "$ENABLE" != "1" ]; then echo "${logtag}Bad enable parameter, aborting." exit 1 fi -TIMEOUT=$(cat /etc/delayed_hibernation.conf | grep "^[^#]" | grep "TIMEOUT=" | awk -F'=' '{ print $2 }') -if [ $TIMEOUT = "" ]; then +TIMEOUT=$(grep "^[^#]" /etc/delayed_hibernation.conf | grep "TIMEOUT=" | awk -F'=' '{ print $2 }') +if [ "$TIMEOUT" = "" ]; then echo "${logtag}Missing timeout parameter, aborting." exit 1 -elif [[ ! $TIMEOUT =~ ^[0-9]+$ ]]; then +elif [[ ! "$TIMEOUT" =~ ^[0-9]+$ ]]; then echo "${logtag}Bad timeout parameter, aborting." exit 1 fi -if [ $ENABLE = "1" ]; then +if [ "$ENABLE" = "1" ]; then if [ "$2" = "suspend" ]; then curtime=$(date +%s) if [ "$1" = "pre" ]; then - echo "${logtag}Setting RTC wakeup..." - echo "$curtime" > /var/run/delayed_hibernation.lock - rtcwake -m no -s $TIMEOUT + if [ -f /var/run/delayed_hibernation.fail ]; then + echo "${logtag}Failed hibernation detected, skipping setting RTC wakeup." + else + echo "${logtag}Setting RTC wakeup..." + echo "$curtime" > /var/run/delayed_hibernation.lock + rtcwake -m no -s "$TIMEOUT" + fi elif [ "$1" = "post" ]; then + if [ -f /var/run/delayed_hibernation.fail ]; then + rm /var/run/delayed_hibernation.fail + fi sustime=$(cat /var/run/delayed_hibernation.lock) - if [ $(($curtime - $sustime)) -ge $TIMEOUT ]; then + if [ $((curtime - sustime)) -ge "$TIMEOUT" ]; then echo "${logtag}Automatic resume detected, hibernating." - systemctl hibernate || echo "${logtag}There has been an error during hibernation, suspending!" && systemctl suspend + systemctl hibernate || echo "${logtag}There has been an error during hibernation, suspending!" && touch /var/run/delayed_hibernation.fail && +systemctl suspend else echo "${logtag}Manual resume detected, disabling RTC wakeup." rtcwake -m disable |