blob: 35a175294e72f934bd2633769c6c63936dbb63ad [file] [log] [blame]
#!/bin/sh -e
set -euo pipefail
USAGE="Usage: obmcutil [-h]
{bmcstate,bootprogress,chassisstate,hoststate,state,status}"
INTERFACE_ROOT=xyz.openbmc_project
STATE_INTERFACE=$INTERFACE_ROOT.State
OBJECT_ROOT=/xyz/openbmc_project
STATE_OBJECT=$OBJECT_ROOT/state
print_help ()
{
echo "$USAGE"
echo ""
echo "positional arguments:"
echo " {bmcstate,bootprogress,chassisstate,hoststate,state,status}"
echo ""
echo "optional arguments:"
echo " -h, --help show this help message and exit"
exit 0
}
get_property ()
{
busctl get-property "$@"
}
state_query ()
{
local state=$(get_property "$@" | cut -d '"' -f2)
printf "%-20s: %s\n" $4 $state
}
handle_cmd ()
{
case "$1" in
bmcstate)
OBJECT=$STATE_OBJECT/bmc0
SERVICE=$(mapper get-service $OBJECT)
INTERFACE=$STATE_INTERFACE.BMC
PROPERTY=CurrentBMCState
state_query $SERVICE $OBJECT $INTERFACE $PROPERTY
;;
chassisstate)
OBJECT=$STATE_OBJECT/chassis0
SERVICE=$(mapper get-service $OBJECT)
INTERFACE=$STATE_INTERFACE.Chassis
PROPERTY=CurrentPowerState
state_query $SERVICE $OBJECT $INTERFACE $PROPERTY
;;
hoststate)
OBJECT=$STATE_OBJECT/host0
SERVICE=$(mapper get-service $OBJECT)
INTERFACE=$STATE_INTERFACE.Host
PROPERTY=CurrentHostState
state_query $SERVICE $OBJECT $INTERFACE $PROPERTY
;;
state|status)
for query in bmcstate chassisstate hoststate
do
handle_cmd $query
done
;;
bootprogress)
OBJECT=$STATE_OBJECT/host0
SERVICE=$(mapper get-service $OBJECT)
INTERFACE=$STATE_INTERFACE.Boot.Progress
PROPERTY=BootProgress
state_query $SERVICE $OBJECT $INTERFACE $PROPERTY
;;
-h|--help)
print_help
;;
*)
echo "ERROR: Invalid Choice: '$1'"
echo "$USAGE"
;;
esac
}
handle_cmd $1