summaryrefslogtreecommitdiff
path: root/shutdownasap.in
diff options
context:
space:
mode:
Diffstat (limited to 'shutdownasap.in')
-rwxr-xr-xshutdownasap.in45
1 files changed, 34 insertions, 11 deletions
diff --git a/shutdownasap.in b/shutdownasap.in
index a32f92d..d2d471f 100755
--- a/shutdownasap.in
+++ b/shutdownasap.in
@@ -6,28 +6,39 @@ set -e
. #ETCDIR#/shutdownasap.conf
-[ -r "${pidFile}" ] && ps aux | grep -q "^\S\+\s\+$(cat "${pidFile}") " && exit
-
-echo $$ > "${pidFile}"
+mkdir -p "${tmpDir}"
quiet=false
-reboot=false
+intentionSet=false
while [ $# -gt 0 ]; do
case "$1" in
+ '-a')
+ echo 'none' >"${tmpDir}/intention"
+ exit
+ ;;
'-q')
quiet=true
;;
'-r')
- reboot=true
+ echo 'reboot' >"${tmpDir}/intention"
+ intentionSet=true
;;
*)
- >&2 echo 'usage: shutdownasap [-q] [-r]'
+ >&2 echo 'usage: shutdownasap [-q] [-a|-r]'
exit 1
;;
esac
shift
done
+if ! ${intentionSet}; then
+ echo 'shutdown' >"${tmpDir}/intention"
+fi
+
+[ -r "${tmpDir}/pid" ] && kill -0 "$(cat "${tmpDir}/pid")" && exit
+
+echo $$ > "${tmpDir}/pid"
+
beforeWatchHook
i=1
@@ -130,8 +141,20 @@ else
pre=''
fi
-if ${reboot}; then
- ${pre} /sbin/reboot
-else
- ${pre} /sbin/poweroff
-fi
+case "$(head -n1 "${tmpDir}/intention")" in
+ 'reboot')
+ ${pre} /sbin/reboot
+ ;;
+ 'shutdown')
+ ${pre} /sbin/poweroff
+ ;;
+ 'none')
+ echo 'shutdown was aborted'
+ ;;
+ *)
+ printf 'intention "%s" not implemented\n' "$(head -n1 "${tmpDir}/intention")"
+ exit 1
+ ;;
+esac
+
+rm -rf --one-file-system "${tmpDir}"