179f697e0SAnthony Wilson#!/bin/sh -e 279f697e0SAnthony Wilson 379f697e0SAnthony Wilsonset -euo pipefail 479f697e0SAnthony Wilson 5f3f16fa9SAnthony WilsonUSAGE="Usage: obmcutil [-h] 6*50c5f88dSAnthony Wilson {bmcstate,bootprogress,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 14f3f16fa9SAnthony Wilsonprint_help () 15f3f16fa9SAnthony Wilson{ 16f3f16fa9SAnthony Wilson echo "$USAGE" 17f3f16fa9SAnthony Wilson echo "" 18f3f16fa9SAnthony Wilson echo "positional arguments:" 19*50c5f88dSAnthony Wilson echo " {bmcstate,bootprogress,chassisstate,hoststate,state,status}" 20f3f16fa9SAnthony Wilson echo "" 21f3f16fa9SAnthony Wilson echo "optional arguments:" 22f3f16fa9SAnthony Wilson echo " -h, --help show this help message and exit" 23f3f16fa9SAnthony Wilson exit 0 24f3f16fa9SAnthony Wilson} 25f3f16fa9SAnthony 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*50c5f88dSAnthony Wilson bootprogress) 68*50c5f88dSAnthony Wilson OBJECT=$STATE_OBJECT/host0 69*50c5f88dSAnthony Wilson SERVICE=$(mapper get-service $OBJECT) 70*50c5f88dSAnthony Wilson INTERFACE=$STATE_INTERFACE.Boot.Progress 71*50c5f88dSAnthony Wilson PROPERTY=BootProgress 72*50c5f88dSAnthony Wilson state_query $SERVICE $OBJECT $INTERFACE $PROPERTY 73*50c5f88dSAnthony Wilson ;; 74f3f16fa9SAnthony Wilson -h|--help) 75f3f16fa9SAnthony Wilson print_help 76f3f16fa9SAnthony Wilson ;; 7779f697e0SAnthony Wilson *) 7879f697e0SAnthony Wilson echo "ERROR: Invalid Choice: '$1'" 7979f697e0SAnthony Wilson echo "$USAGE" 8079f697e0SAnthony Wilson ;; 8179f697e0SAnthony Wilson esac 8279f697e0SAnthony Wilson} 8379f697e0SAnthony Wilson 8479f697e0SAnthony Wilsonhandle_cmd $1 85