#!/usr/bin/sh
# Copyright (c) 2019-2021 Eric Vidal <eric@obarun.org>
# All rights reserved.
#
# This file is part of Obarun. It is subject to the license terms in
# the LICENSE file found in the top-level directory of this
# distribution.
# This file may not be copied, modified, propagated, or distributed
# except according to the terms contained in the LICENSE file.

PROG="shutdown"

usage () {
cat <<EOF

$PROG [ -h | -p | -r ] time

$PROG <options> time

options :
    -h: halt the machine
    -p: poweroff the machine
    -r: reboot the machine

Time must be one of these formats: [ now | [+]mins | hh:mm ] where:

    now : triggers the shutdown sequence immediately.
    mins or +mins : relative time; triggers the shutdown sequence after mins minutes.
    hh:mm : absolute time; triggers the shutdown sequence when the time hh:mm occurs.

See also 66-shutdown program to more features.
EOF
exit 111
}

die() {
    printf "${PROG}:fatal: options must be set first\n" >&1
    usage
}

[ -z ${1} ] && die

[ ${1:0:1} != '-' ] && die

66-shutdown "${@}"
