Welcome to little lamb

Code » anopa » master » tree

[master] / src / scripts / aa-shutdown

#!/bin/sh
#
# anopa - Copyright (C) 2015-2017 Olivier Brunel
#
# aa-shutdown
# Copyright (C) 2015 Olivier Brunel <jjk@jjacky.com>
#
# This file is part of anopa.
#
# anopa is free software: you can redistribute it and/or modify it under the
# terms of the GNU General Public License as published by the Free Software
# Foundation, either version 3 of the License, or (at your option) any later
# version.
#
# anopa is distributed in the hope that it will be useful, but WITHOUT ANY
# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
# FOR A PARTICULAR PURPOSE.
# See the GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License along with
# anopa. If not, see http://www.gnu.org/licenses/
#

dieusage() {
    cat << EOF
Usage: aa-shutdown [OPTION]
 -r, --reboot                  Reboot the machine
 -H, --halt                    Halt the machine
 -p, --poweroff                Power off the machine
 -h, --help                    Show this help screen and exit
 -V, --version                 Show version information and exit
EOF
    exit $1
}

dieversion() {
    cat << EOF
aa-shutdown v@VERSION@
Copyright (C) 2015 Olivier Brunel - https://jjacky.com/anopa
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.
EOF
    exit 0
}

cmd=
case "${0##*/}" in
    halt)
        cmd=s
        ;;
    reboot)
        cmd=r
        ;;
    poweroff)
        cmd=p
        ;;
esac

if [ $# -ne 1 ] && [ -z $cmd ]; then
    dieusage 1
fi

case "$1" in
    -H|--halt)
        cmd=s
        ;;
    -h|--help)
        dieusage 0
        ;;
    -p|--poweroff)
        cmd=p
        ;;
    -r|--reboot)
        cmd=r
        ;;
    -V|--version)
        dieversion
        ;;
    *)
        [ -z cmd ] && dieusage 1
esac

exec s6-svscanctl -${cmd}b /run/services/.scandir