diff options
Diffstat (limited to 'delayed_hibernation.sh')
-rwxr-xr-x | delayed_hibernation.sh | 32 |
1 files changed, 20 insertions, 12 deletions
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 |