xref: /openbmc/phosphor-state-manager/obmcutil (revision 79f697e02c64c5a4ce17af36d7d251cd99d7b274)
1*79f697e0SAnthony Wilson#!/bin/sh -e
2*79f697e0SAnthony Wilson
3*79f697e0SAnthony Wilsonset -euo pipefail
4*79f697e0SAnthony Wilson
5*79f697e0SAnthony WilsonUSAGE="Usage: obmcutil {bmcstate,chassisstate,hoststate,state,status}"
6*79f697e0SAnthony Wilson
7*79f697e0SAnthony WilsonINTERFACE_ROOT=xyz.openbmc_project
8*79f697e0SAnthony WilsonSTATE_INTERFACE=$INTERFACE_ROOT.State
9*79f697e0SAnthony Wilson
10*79f697e0SAnthony WilsonOBJECT_ROOT=/xyz/openbmc_project
11*79f697e0SAnthony WilsonSTATE_OBJECT=$OBJECT_ROOT/state
12*79f697e0SAnthony Wilson
13*79f697e0SAnthony Wilsonget_property ()
14*79f697e0SAnthony Wilson{
15*79f697e0SAnthony Wilson    busctl get-property "$@"
16*79f697e0SAnthony Wilson}
17*79f697e0SAnthony Wilson
18*79f697e0SAnthony Wilsonstate_query ()
19*79f697e0SAnthony Wilson{
20*79f697e0SAnthony Wilson    local state=$(get_property "$@" | cut -d '"' -f2)
21*79f697e0SAnthony Wilson    printf "%-20s: %s\n" $4 $state
22*79f697e0SAnthony Wilson}
23*79f697e0SAnthony Wilson
24*79f697e0SAnthony Wilsonhandle_cmd ()
25*79f697e0SAnthony Wilson{
26*79f697e0SAnthony Wilson    case "$1" in
27*79f697e0SAnthony Wilson        bmcstate)
28*79f697e0SAnthony Wilson            OBJECT=$STATE_OBJECT/bmc0
29*79f697e0SAnthony Wilson            SERVICE=$(mapper get-service $OBJECT)
30*79f697e0SAnthony Wilson            INTERFACE=$STATE_INTERFACE.BMC
31*79f697e0SAnthony Wilson            PROPERTY=CurrentBMCState
32*79f697e0SAnthony Wilson            state_query $SERVICE $OBJECT $INTERFACE $PROPERTY
33*79f697e0SAnthony Wilson            ;;
34*79f697e0SAnthony Wilson        chassisstate)
35*79f697e0SAnthony Wilson            OBJECT=$STATE_OBJECT/chassis0
36*79f697e0SAnthony Wilson            SERVICE=$(mapper get-service $OBJECT)
37*79f697e0SAnthony Wilson            INTERFACE=$STATE_INTERFACE.Chassis
38*79f697e0SAnthony Wilson            PROPERTY=CurrentPowerState
39*79f697e0SAnthony Wilson            state_query $SERVICE $OBJECT $INTERFACE $PROPERTY
40*79f697e0SAnthony Wilson            ;;
41*79f697e0SAnthony Wilson        hoststate)
42*79f697e0SAnthony Wilson            OBJECT=$STATE_OBJECT/host0
43*79f697e0SAnthony Wilson            SERVICE=$(mapper get-service $OBJECT)
44*79f697e0SAnthony Wilson            INTERFACE=$STATE_INTERFACE.Host
45*79f697e0SAnthony Wilson            PROPERTY=CurrentHostState
46*79f697e0SAnthony Wilson            state_query $SERVICE $OBJECT $INTERFACE $PROPERTY
47*79f697e0SAnthony Wilson            ;;
48*79f697e0SAnthony Wilson        state|status)
49*79f697e0SAnthony Wilson            for query in bmcstate chassisstate hoststate
50*79f697e0SAnthony Wilson            do
51*79f697e0SAnthony Wilson                handle_cmd $query
52*79f697e0SAnthony Wilson            done
53*79f697e0SAnthony Wilson            ;;
54*79f697e0SAnthony Wilson        *)
55*79f697e0SAnthony Wilson            echo "ERROR: Invalid Choice: '$1'"
56*79f697e0SAnthony Wilson            echo "$USAGE"
57*79f697e0SAnthony Wilson            ;;
58*79f697e0SAnthony Wilson    esac
59*79f697e0SAnthony Wilson}
60*79f697e0SAnthony Wilson
61*79f697e0SAnthony Wilsonhandle_cmd $1
62