179f697e0SAnthony Wilson#!/bin/sh -e 279f697e0SAnthony Wilson 379f697e0SAnthony Wilsonset -euo pipefail 479f697e0SAnthony Wilson 5*0f35983dSAnthony WilsonOPTS="bmcstate,bootprogress,chassisstate,hoststate,power,state,status" 6*0f35983dSAnthony Wilson 7f3f16fa9SAnthony WilsonUSAGE="Usage: obmcutil [-h] 8*0f35983dSAnthony Wilson {$OPTS}" 979f697e0SAnthony Wilson 1079f697e0SAnthony WilsonINTERFACE_ROOT=xyz.openbmc_project 1179f697e0SAnthony WilsonSTATE_INTERFACE=$INTERFACE_ROOT.State 1279f697e0SAnthony Wilson 1379f697e0SAnthony WilsonOBJECT_ROOT=/xyz/openbmc_project 1479f697e0SAnthony WilsonSTATE_OBJECT=$OBJECT_ROOT/state 1579f697e0SAnthony Wilson 16f3f16fa9SAnthony Wilsonprint_help () 17f3f16fa9SAnthony Wilson{ 18f3f16fa9SAnthony Wilson echo "$USAGE" 19f3f16fa9SAnthony Wilson echo "" 20f3f16fa9SAnthony Wilson echo "positional arguments:" 21*0f35983dSAnthony Wilson echo " {$OPTS}" 22f3f16fa9SAnthony Wilson echo "" 23f3f16fa9SAnthony Wilson echo "optional arguments:" 24f3f16fa9SAnthony Wilson echo " -h, --help show this help message and exit" 25f3f16fa9SAnthony Wilson exit 0 26f3f16fa9SAnthony Wilson} 27f3f16fa9SAnthony Wilson 2879f697e0SAnthony Wilsonget_property () 2979f697e0SAnthony Wilson{ 3079f697e0SAnthony Wilson busctl get-property "$@" 3179f697e0SAnthony Wilson} 3279f697e0SAnthony Wilson 3379f697e0SAnthony Wilsonstate_query () 3479f697e0SAnthony Wilson{ 3579f697e0SAnthony Wilson local state=$(get_property "$@" | cut -d '"' -f2) 3679f697e0SAnthony Wilson printf "%-20s: %s\n" $4 $state 3779f697e0SAnthony Wilson} 3879f697e0SAnthony Wilson 3979f697e0SAnthony Wilsonhandle_cmd () 4079f697e0SAnthony Wilson{ 4179f697e0SAnthony Wilson case "$1" in 4279f697e0SAnthony Wilson bmcstate) 4379f697e0SAnthony Wilson OBJECT=$STATE_OBJECT/bmc0 4479f697e0SAnthony Wilson SERVICE=$(mapper get-service $OBJECT) 4579f697e0SAnthony Wilson INTERFACE=$STATE_INTERFACE.BMC 4679f697e0SAnthony Wilson PROPERTY=CurrentBMCState 4779f697e0SAnthony Wilson state_query $SERVICE $OBJECT $INTERFACE $PROPERTY 4879f697e0SAnthony Wilson ;; 4979f697e0SAnthony Wilson chassisstate) 5079f697e0SAnthony Wilson OBJECT=$STATE_OBJECT/chassis0 5179f697e0SAnthony Wilson SERVICE=$(mapper get-service $OBJECT) 5279f697e0SAnthony Wilson INTERFACE=$STATE_INTERFACE.Chassis 5379f697e0SAnthony Wilson PROPERTY=CurrentPowerState 5479f697e0SAnthony Wilson state_query $SERVICE $OBJECT $INTERFACE $PROPERTY 5579f697e0SAnthony Wilson ;; 5679f697e0SAnthony Wilson hoststate) 5779f697e0SAnthony Wilson OBJECT=$STATE_OBJECT/host0 5879f697e0SAnthony Wilson SERVICE=$(mapper get-service $OBJECT) 5979f697e0SAnthony Wilson INTERFACE=$STATE_INTERFACE.Host 6079f697e0SAnthony Wilson PROPERTY=CurrentHostState 6179f697e0SAnthony Wilson state_query $SERVICE $OBJECT $INTERFACE $PROPERTY 6279f697e0SAnthony Wilson ;; 6379f697e0SAnthony Wilson state|status) 6479f697e0SAnthony Wilson for query in bmcstate chassisstate hoststate 6579f697e0SAnthony Wilson do 6679f697e0SAnthony Wilson handle_cmd $query 6779f697e0SAnthony Wilson done 6879f697e0SAnthony Wilson ;; 6950c5f88dSAnthony Wilson bootprogress) 7050c5f88dSAnthony Wilson OBJECT=$STATE_OBJECT/host0 7150c5f88dSAnthony Wilson SERVICE=$(mapper get-service $OBJECT) 7250c5f88dSAnthony Wilson INTERFACE=$STATE_INTERFACE.Boot.Progress 7350c5f88dSAnthony Wilson PROPERTY=BootProgress 7450c5f88dSAnthony Wilson state_query $SERVICE $OBJECT $INTERFACE $PROPERTY 7550c5f88dSAnthony Wilson ;; 76*0f35983dSAnthony Wilson power) 77*0f35983dSAnthony Wilson OBJECT=/org/openbmc/control/power0 78*0f35983dSAnthony Wilson SERVICE=$(mapper get-service $OBJECT) 79*0f35983dSAnthony Wilson INTERFACE=org.openbmc.control.Power 80*0f35983dSAnthony Wilson for property in pgood state pgood_timeout 81*0f35983dSAnthony Wilson do 82*0f35983dSAnthony Wilson # get_property can potentially return several 83*0f35983dSAnthony Wilson # different formats of values, so we do the parsing outside 84*0f35983dSAnthony Wilson # of get_property depending on the query. These queries 85*0f35983dSAnthony Wilson # return 'i VALUE' formatted strings. 86*0f35983dSAnthony Wilson STATE=$(get_property $SERVICE $OBJECT $INTERFACE $property \ 87*0f35983dSAnthony Wilson | sed 's/i[ ^I]*//') 88*0f35983dSAnthony Wilson printf "%s = %s\n" $property $STATE 89*0f35983dSAnthony Wilson done 90*0f35983dSAnthony Wilson ;; 91f3f16fa9SAnthony Wilson -h|--help) 92f3f16fa9SAnthony Wilson print_help 93f3f16fa9SAnthony Wilson ;; 9479f697e0SAnthony Wilson *) 9579f697e0SAnthony Wilson echo "ERROR: Invalid Choice: '$1'" 9679f697e0SAnthony Wilson echo "$USAGE" 9779f697e0SAnthony Wilson ;; 9879f697e0SAnthony Wilson esac 9979f697e0SAnthony Wilson} 10079f697e0SAnthony Wilson 10179f697e0SAnthony Wilsonhandle_cmd $1 102