blob: 35a175294e72f934bd2633769c6c63936dbb63ad [file] [log] [blame]
Anthony Wilson79f697e2018-09-13 13:48:52 -05001#!/bin/sh -e
2
3set -euo pipefail
4
Anthony Wilsonf3f16fa2018-09-13 14:10:52 -05005USAGE="Usage: obmcutil [-h]
Anthony Wilson50c5f882018-09-13 14:19:37 -05006 {bmcstate,bootprogress,chassisstate,hoststate,state,status}"
Anthony Wilson79f697e2018-09-13 13:48:52 -05007
8INTERFACE_ROOT=xyz.openbmc_project
9STATE_INTERFACE=$INTERFACE_ROOT.State
10
11OBJECT_ROOT=/xyz/openbmc_project
12STATE_OBJECT=$OBJECT_ROOT/state
13
Anthony Wilsonf3f16fa2018-09-13 14:10:52 -050014print_help ()
15{
16 echo "$USAGE"
17 echo ""
18 echo "positional arguments:"
Anthony Wilson50c5f882018-09-13 14:19:37 -050019 echo " {bmcstate,bootprogress,chassisstate,hoststate,state,status}"
Anthony Wilsonf3f16fa2018-09-13 14:10:52 -050020 echo ""
21 echo "optional arguments:"
22 echo " -h, --help show this help message and exit"
23 exit 0
24}
25
Anthony Wilson79f697e2018-09-13 13:48:52 -050026get_property ()
27{
28 busctl get-property "$@"
29}
30
31state_query ()
32{
33 local state=$(get_property "$@" | cut -d '"' -f2)
34 printf "%-20s: %s\n" $4 $state
35}
36
37handle_cmd ()
38{
39 case "$1" in
40 bmcstate)
41 OBJECT=$STATE_OBJECT/bmc0
42 SERVICE=$(mapper get-service $OBJECT)
43 INTERFACE=$STATE_INTERFACE.BMC
44 PROPERTY=CurrentBMCState
45 state_query $SERVICE $OBJECT $INTERFACE $PROPERTY
46 ;;
47 chassisstate)
48 OBJECT=$STATE_OBJECT/chassis0
49 SERVICE=$(mapper get-service $OBJECT)
50 INTERFACE=$STATE_INTERFACE.Chassis
51 PROPERTY=CurrentPowerState
52 state_query $SERVICE $OBJECT $INTERFACE $PROPERTY
53 ;;
54 hoststate)
55 OBJECT=$STATE_OBJECT/host0
56 SERVICE=$(mapper get-service $OBJECT)
57 INTERFACE=$STATE_INTERFACE.Host
58 PROPERTY=CurrentHostState
59 state_query $SERVICE $OBJECT $INTERFACE $PROPERTY
60 ;;
61 state|status)
62 for query in bmcstate chassisstate hoststate
63 do
64 handle_cmd $query
65 done
66 ;;
Anthony Wilson50c5f882018-09-13 14:19:37 -050067 bootprogress)
68 OBJECT=$STATE_OBJECT/host0
69 SERVICE=$(mapper get-service $OBJECT)
70 INTERFACE=$STATE_INTERFACE.Boot.Progress
71 PROPERTY=BootProgress
72 state_query $SERVICE $OBJECT $INTERFACE $PROPERTY
73 ;;
Anthony Wilsonf3f16fa2018-09-13 14:10:52 -050074 -h|--help)
75 print_help
76 ;;
Anthony Wilson79f697e2018-09-13 13:48:52 -050077 *)
78 echo "ERROR: Invalid Choice: '$1'"
79 echo "$USAGE"
80 ;;
81 esac
82}
83
84handle_cmd $1