179f697e0SAnthony Wilson#!/bin/sh -e 279f697e0SAnthony Wilson 379f697e0SAnthony Wilsonset -euo pipefail 479f697e0SAnthony Wilson 5*f3f16fa9SAnthony WilsonUSAGE="Usage: obmcutil [-h] 6*f3f16fa9SAnthony Wilson {bmcstate,chassisstate,hoststate,state,status}" 779f697e0SAnthony Wilson 879f697e0SAnthony WilsonINTERFACE_ROOT=xyz.openbmc_project 979f697e0SAnthony WilsonSTATE_INTERFACE=$INTERFACE_ROOT.State 1079f697e0SAnthony Wilson 1179f697e0SAnthony WilsonOBJECT_ROOT=/xyz/openbmc_project 1279f697e0SAnthony WilsonSTATE_OBJECT=$OBJECT_ROOT/state 1379f697e0SAnthony Wilson 14*f3f16fa9SAnthony Wilsonprint_help () 15*f3f16fa9SAnthony Wilson{ 16*f3f16fa9SAnthony Wilson echo "$USAGE" 17*f3f16fa9SAnthony Wilson echo "" 18*f3f16fa9SAnthony Wilson echo "positional arguments:" 19*f3f16fa9SAnthony Wilson echo " {bmcstate,chassisstate,hoststate,state,status}" 20*f3f16fa9SAnthony Wilson echo "" 21*f3f16fa9SAnthony Wilson echo "optional arguments:" 22*f3f16fa9SAnthony Wilson echo " -h, --help show this help message and exit" 23*f3f16fa9SAnthony Wilson exit 0 24*f3f16fa9SAnthony Wilson} 25*f3f16fa9SAnthony Wilson 2679f697e0SAnthony Wilsonget_property () 2779f697e0SAnthony Wilson{ 2879f697e0SAnthony Wilson busctl get-property "$@" 2979f697e0SAnthony Wilson} 3079f697e0SAnthony Wilson 3179f697e0SAnthony Wilsonstate_query () 3279f697e0SAnthony Wilson{ 3379f697e0SAnthony Wilson local state=$(get_property "$@" | cut -d '"' -f2) 3479f697e0SAnthony Wilson printf "%-20s: %s\n" $4 $state 3579f697e0SAnthony Wilson} 3679f697e0SAnthony Wilson 3779f697e0SAnthony Wilsonhandle_cmd () 3879f697e0SAnthony Wilson{ 3979f697e0SAnthony Wilson case "$1" in 4079f697e0SAnthony Wilson bmcstate) 4179f697e0SAnthony Wilson OBJECT=$STATE_OBJECT/bmc0 4279f697e0SAnthony Wilson SERVICE=$(mapper get-service $OBJECT) 4379f697e0SAnthony Wilson INTERFACE=$STATE_INTERFACE.BMC 4479f697e0SAnthony Wilson PROPERTY=CurrentBMCState 4579f697e0SAnthony Wilson state_query $SERVICE $OBJECT $INTERFACE $PROPERTY 4679f697e0SAnthony Wilson ;; 4779f697e0SAnthony Wilson chassisstate) 4879f697e0SAnthony Wilson OBJECT=$STATE_OBJECT/chassis0 4979f697e0SAnthony Wilson SERVICE=$(mapper get-service $OBJECT) 5079f697e0SAnthony Wilson INTERFACE=$STATE_INTERFACE.Chassis 5179f697e0SAnthony Wilson PROPERTY=CurrentPowerState 5279f697e0SAnthony Wilson state_query $SERVICE $OBJECT $INTERFACE $PROPERTY 5379f697e0SAnthony Wilson ;; 5479f697e0SAnthony Wilson hoststate) 5579f697e0SAnthony Wilson OBJECT=$STATE_OBJECT/host0 5679f697e0SAnthony Wilson SERVICE=$(mapper get-service $OBJECT) 5779f697e0SAnthony Wilson INTERFACE=$STATE_INTERFACE.Host 5879f697e0SAnthony Wilson PROPERTY=CurrentHostState 5979f697e0SAnthony Wilson state_query $SERVICE $OBJECT $INTERFACE $PROPERTY 6079f697e0SAnthony Wilson ;; 6179f697e0SAnthony Wilson state|status) 6279f697e0SAnthony Wilson for query in bmcstate chassisstate hoststate 6379f697e0SAnthony Wilson do 6479f697e0SAnthony Wilson handle_cmd $query 6579f697e0SAnthony Wilson done 6679f697e0SAnthony Wilson ;; 67*f3f16fa9SAnthony Wilson -h|--help) 68*f3f16fa9SAnthony Wilson print_help 69*f3f16fa9SAnthony Wilson ;; 7079f697e0SAnthony Wilson *) 7179f697e0SAnthony Wilson echo "ERROR: Invalid Choice: '$1'" 7279f697e0SAnthony Wilson echo "$USAGE" 7379f697e0SAnthony Wilson ;; 7479f697e0SAnthony Wilson esac 7579f697e0SAnthony Wilson} 7679f697e0SAnthony Wilson 7779f697e0SAnthony Wilsonhandle_cmd $1 78