#!/bin/sh -e

##########################################################################
#   Title:
#       Optional, defaults to the name of the script sans extention
#
#   Section:
#       8
#
#   Synopsis:
#       
#   Description:
#       Issue IPMI power control over a node
#       
#   Arguments:
#       
#   Returns:
#
#   Examples:
#
#   Files:
#
#   Environment:
#
#   See also:
#       
#   History:
#   Date        Name        Modification
#   2020-02-02  Jason Bacon Begin
#   2024-11-12  Jason Bacon Add man page template and usage
##########################################################################

usage()
{
    printf "Usage: $0 host-bmc-address on|off\n"
    exit 1
}


##########################################################################
#   Main
##########################################################################

if [ $# != 2 ]; then
    usage
fi

auto-group-check operator $0

host=$1
state=$2
case $state in
on|off)
    ;;
*)
    usage
    ;;
esac

if [ -r /root/.ipmipw ]; then
    pw_flags="-f /root/.ipmipw"
fi

# FIXME: Don't hard-code lanplus, maybe just default to it?
ipmitool -v -I lanplus -H $host -U root $pw_flags chassis power $state
