From 18c88e071755f6c0502ae6f5526c498c6a95f3cd Mon Sep 17 00:00:00 2001 From: fbt Date: Fri, 10 Oct 2014 18:06:14 +0400 Subject: [PATCH] init --- README.md | 9 +++++++++ shutdown | 30 ++++++++++++++++++++++++++++++ 2 files changed, 39 insertions(+) create mode 100644 README.md create mode 100755 shutdown diff --git a/README.md b/README.md new file mode 100644 index 0000000..a4386b8 --- /dev/null +++ b/README.md @@ -0,0 +1,9 @@ +sinit-tools +=========== + +shutdown +-------- + +A script that provides a familiar command to poweroff or reboot your system. + +It checks the exe name, so you can just make poweroff and reboot links in your $PATH. diff --git a/shutdown b/shutdown new file mode 100755 index 0000000..6d52caf --- /dev/null +++ b/shutdown @@ -0,0 +1,30 @@ +#!/bin/sh + +usage() { echo "Usage: shutdown <-p|-r>"; } + +main() { + while [ "$1" ]; do + case "$1" in + -p|--poweroff) init_signal='10';; + -r|--reboot) init_signal='2';; + + -h|--help|--usage) usage; return;; + *) usage; return 1 + esac + shift + done + + exe_name="${0##*/}" + + [ "$init_signal" ] || { + case "$exe_name" in + poweroff) init_signal='USR1';; + reboot) init_signal='INT';; + *) usage; return 1;; + esac + } + + kill -s "$init_signal" 1 +} + +main "$@"