summarylogtreecommitdiffstats
diff options
context:
space:
mode:
authorNiccolò Maggioni2015-08-18 22:34:48 +0200
committerNiccolò Maggioni2015-08-18 22:34:48 +0200
commita18a8fa9c38d5b23931433550b2bab9a37fd55eb (patch)
tree56b1159471f23b500b34b53a29dde061ed023a2f
downloadaur-a18a8fa9c38d5b23931433550b2bab9a37fd55eb.tar.gz
Initial commit
-rw-r--r--.SRCINFO17
-rw-r--r--PKGBUILD19
-rw-r--r--delayed_hibernation.conf7
-rw-r--r--delayed_hibernation.install14
-rwxr-xr-xdelayed_hibernation.sh46
5 files changed, 103 insertions, 0 deletions
diff --git a/.SRCINFO b/.SRCINFO
new file mode 100644
index 000000000000..ecd0f1f4caee
--- /dev/null
+++ b/.SRCINFO
@@ -0,0 +1,17 @@
+pkgbase = delayed_hibernation
+ pkgdesc = Script to hibernate the computer after having spent some time in suspension
+ pkgver = 1.0
+ pkgrel = 1
+ url = https://bbs.archlinux.org/viewtopic.php?pid=1554259
+ install = delayed_hibernation.install
+ arch = any
+ license = MIT
+ depends = systemd
+ depends = bash
+ source = delayed_hibernation.sh
+ source = delayed_hibernation.conf
+ md5sums = 36867d9b80ab9c94f5cbecae85e32dda
+ md5sums = 0fe21901bbc6f9ce9e8a85e5ec7a3eaf
+
+pkgname = delayed_hibernation
+
diff --git a/PKGBUILD b/PKGBUILD
new file mode 100644
index 000000000000..491d6a9376a6
--- /dev/null
+++ b/PKGBUILD
@@ -0,0 +1,19 @@
+# Maintainer: Niccolò Maggioni <nicco.maggioni@gmail.com>
+# 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"
+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')
+
+package() {
+ install -Dm 755 $srcdir/delayed_hibernation.sh ${pkgdir}/usr/lib/systemd/system-sleep/delayed_hibernation.sh
+ install -Dm 644 $srcdir/delayed_hibernation.conf ${pkgdir}/etc/delayed_hibernation.conf
+}
diff --git a/delayed_hibernation.conf b/delayed_hibernation.conf
new file mode 100644
index 000000000000..73e71aa13bdf
--- /dev/null
+++ b/delayed_hibernation.conf
@@ -0,0 +1,7 @@
+## Enable or disable delayed hibernation.
+## Possible values: 1 (enabled), 0 (disabled)
+ENABLE=1
+
+## Set the time to spend in suspension before the computer hibernates.
+## (The value is in seconds)
+TIMEOUT=1800
diff --git a/delayed_hibernation.install b/delayed_hibernation.install
new file mode 100644
index 000000000000..63bcae9c83dc
--- /dev/null
+++ b/delayed_hibernation.install
@@ -0,0 +1,14 @@
+post_install() {
+cat << EOF
+
+ Be sure to have configured hibernation first! Read the wiki for more info:
+ https://wiki.archlinux.org/index.php/Power_management/Suspend_and_hibernate#Hibernation
+
+ Check '/etc/delayed_hibernation.conf' for further configuration.
+
+EOF
+}
+
+post_upgrade() {
+ post_install
+}
diff --git a/delayed_hibernation.sh b/delayed_hibernation.sh
new file mode 100755
index 000000000000..49080ab298f3
--- /dev/null
+++ b/delayed_hibernation.sh
@@ -0,0 +1,46 @@
+#!/bin/bash
+logtag="delayed_hibernation: "
+
+if [ ! -f /etc/delayed_hibernation.conf ]; then
+ echo "${logtag}Missing configuration file, aborting."
+ exit 1
+fi
+
+ENABLE=$(cat /etc/delayed_hibernation.conf | grep "^[^#]" | grep "ENABLE=" | awk -F'=' '{ print $2 }')
+if [ $ENABLE = "" ]; then
+ echo "${logtag}Missing enable parameter, aborting."
+ exit 1
+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
+ echo "${logtag}Missing timeout parameter, aborting."
+ exit 1
+elif [[ ! $TIMEOUT =~ ^[0-9]+$ ]]; then
+ echo "${logtag}Bad timeout parameter, aborting."
+ exit 1
+fi
+
+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
+ elif [ "$1" = "post" ]; then
+ sustime=$(cat /var/run/delayed_hibernation.lock)
+ 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
+ else
+ echo "${logtag}Manual resume detected, disabling RTC wakeup."
+ rtcwake -m disable
+ fi
+ rm /var/run/delayed_hibernation.lock
+ fi
+ fi
+fi