aboutsummaryrefslogtreecommitdiff
path: root/scripts
diff options
context:
space:
mode:
authorWilliam Hubbs <w.d.hubbs@gmail.com>2017-06-12 17:58:18 -0500
committerWilliam Hubbs <w.d.hubbs@gmail.com>2017-06-12 17:58:18 -0500
commit1e837d596e483ceb5cec177a6c7faff24a42384b (patch)
tree21f47f8451904ac5f8553157afc17e50ace854ea /scripts
parentdcc686e42b406d63d52ef75de9a326f67d0a06c9 (diff)
fix argument parsing for the sysvinit shutdown wrapper
This fixes #140.
Diffstat (limited to 'scripts')
-rw-r--r--scripts/shutdown.in26
1 files changed, 15 insertions, 11 deletions
diff --git a/scripts/shutdown.in b/scripts/shutdown.in
index 4a3d9fd1..69a4a12a 100644
--- a/scripts/shutdown.in
+++ b/scripts/shutdown.in
@@ -1,17 +1,21 @@
#!@SHELL@
-args=
-for x; do
- case "$x" in
- -h) args=" ${args} --halt" ;;
- *) args=" ${args} ${x} " ;;
+poweroff_arg=
+while getopts :HhPr opt; do
+ case "$opt" in
+ h|P) poweroff_arg=--poweroff ;;
+ H) poweroff_arg=--halt ;;
+ r) poweroff_arg=--reboot ;;
+ \?) printf "${0##*/}: invalid option ${optarg}\n" >&2
+ exit 1
+ ;;
esac
done
+shift $((OPTIND-1))
-case "$args" in
- *-h|--halt*) ;;
- *-s|--single*) ;;
- *) args=" --single ${args}" ;;
-esac
+if [ -z "${poweroff_arg}" ]; then
+ poweroff_arg=--single
+fi
-exec @SBINDIR@/openrc-shutdown "$args"
+echo @SBINDIR@/openrc-shutdown ${poweroff_arg} ${@}
+exec @SBINDIR@/openrc-shutdown ${poweroff_arg} ${@}