about summary refs log tree commit diff
path: root/bundles/hdidle/files
diff options
context:
space:
mode:
Diffstat (limited to 'bundles/hdidle/files')
-rwxr-xr-xbundles/hdidle/files/cron_job5
-rwxr-xr-xbundles/hdidle/files/hdidle17
2 files changed, 22 insertions, 0 deletions
diff --git a/bundles/hdidle/files/cron_job b/bundles/hdidle/files/cron_job
new file mode 100755
index 0000000..c4d8209
--- /dev/null
+++ b/bundles/hdidle/files/cron_job
@@ -0,0 +1,5 @@
+#!/bin/sh
+set -eu
+/usr/bin/hdidle >/dev/null 2>&1 &&
+	tgnotify '💤*shimakaze/hdidle*\nput drives to sleep' >/dev/null 2>&1
+exit 0
diff --git a/bundles/hdidle/files/hdidle b/bundles/hdidle/files/hdidle
new file mode 100755
index 0000000..d88c992
--- /dev/null
+++ b/bundles/hdidle/files/hdidle
@@ -0,0 +1,17 @@
+#!/bin/sh
+set -ex
+
+main() {
+	disks_were_put_to_sleep=0
+
+	for drv in /dev/sd*; do
+		if hdparm -C $drv | grep -vq 'standby'; then
+			hdparm -y $drv
+			disks_were_put_to_sleep=1
+		fi
+	done
+
+	test -z "$disks_were_put_to_sleep" && exit 1 || exit 0
+}
+
+main