aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorJacob Appelbaum <jacob@appelbaum.net>2011-04-30 15:00:57 -0700
committerJacob Appelbaum <jacob@appelbaum.net>2011-04-30 15:00:57 -0700
commit088ebff68273c4cd2cc7d17eab74c7e0432105cc (patch)
treecd327a81c005450ab0a31a6f276b58cbe5f391a5 /src
parenta9b1d9db56f46dda0fee6bb89fae3304c96c8cab (diff)
downloadsmartmonster-088ebff68273c4cd2cc7d17eab74c7e0432105cc.tar.gz
smartmonster-088ebff68273c4cd2cc7d17eab74c7e0432105cc.tar.bz2
initial hook for sleep, hibernate, wake, and thaw events
Diffstat (limited to 'src')
-rwxr-xr-xsrc/99_smartmonster_sleep.d.sh60
1 files changed, 60 insertions, 0 deletions
diff --git a/src/99_smartmonster_sleep.d.sh b/src/99_smartmonster_sleep.d.sh
new file mode 100755
index 0000000..2977bdb
--- /dev/null
+++ b/src/99_smartmonster_sleep.d.sh
@@ -0,0 +1,60 @@
+#!/bin/bash
+#
+# smartmonster_sleep.d.sh - hook sleep, hibernate and shutdown events
+#
+#
+
+if [ "$USER" != "root" ];
+then
+ echo "You must be root!";
+ exit 1;
+fi
+
+STATE_DIR="/var/lib/smartmonster";
+HOOK_DIR="/etc/pm/sleep.d/";
+HIBERNATE_DATE_STAMP="$STATE_DIR/hibernate.stamp";
+SUSPEND_DATE_STAMP="$STATE_DIR/suspend.stamp";
+THAW_DATE_STAMP="$STATE_DIR/thaw.stamp";
+RESUME_DATE_STAMP="$STATE_DIR/resume.stamp";
+UNHANDLED_STAMP="$STATE_DIR/unhandled.stamp";
+
+# XXX: Hello TOCTOU!
+if [ ! -d "$STATE_DIR" ];
+then
+ echo "You have no $STATE_DIR; creating it!";
+ mkdir -p $STATE_DIR;
+
+ if [ $? != 0 ];
+ then
+ echo "Unable to create $STATE_DIR!";
+ exit 1;
+ fi
+
+fi
+
+# Load the common power related functions
+. /usr/lib/pm-utils/functions
+
+case "$1" in
+ hibernate)
+ update_power_counter.sh;
+ date -R > $HIBERNATE_DATE_STAMP;
+ ;;
+ suspend)
+ update_power_counter.sh;
+ date -R > $SUSPEND_DATE_STAMP;
+ ;;
+ thaw)
+ date -R > $THAW_DATE_STAMP;
+ ;;
+ resume)
+ update_power_counter.sh;
+ date -R > $RESUME_DATE_STAMP;
+ ;;
+
+ *)
+ echo "Unhandled case: $1" > $UNHANDLED_STAMP;
+ ;;
+esac
+
+exit $?