Anthony Wilson | 79f697e | 2018-09-13 13:48:52 -0500 | [diff] [blame] | 1 | #!/bin/sh -e |
| 2 | |
| 3 | set -euo pipefail |
| 4 | |
Anthony Wilson | 0f35983 | 2018-09-13 14:28:07 -0500 | [diff] [blame^] | 5 | OPTS="bmcstate,bootprogress,chassisstate,hoststate,power,state,status" |
| 6 | |
Anthony Wilson | f3f16fa | 2018-09-13 14:10:52 -0500 | [diff] [blame] | 7 | USAGE="Usage: obmcutil [-h] |
Anthony Wilson | 0f35983 | 2018-09-13 14:28:07 -0500 | [diff] [blame^] | 8 | {$OPTS}" |
Anthony Wilson | 79f697e | 2018-09-13 13:48:52 -0500 | [diff] [blame] | 9 | |
| 10 | INTERFACE_ROOT=xyz.openbmc_project |
| 11 | STATE_INTERFACE=$INTERFACE_ROOT.State |
| 12 | |
| 13 | OBJECT_ROOT=/xyz/openbmc_project |
| 14 | STATE_OBJECT=$OBJECT_ROOT/state |
| 15 | |
Anthony Wilson | f3f16fa | 2018-09-13 14:10:52 -0500 | [diff] [blame] | 16 | print_help () |
| 17 | { |
| 18 | echo "$USAGE" |
| 19 | echo "" |
| 20 | echo "positional arguments:" |
Anthony Wilson | 0f35983 | 2018-09-13 14:28:07 -0500 | [diff] [blame^] | 21 | echo " {$OPTS}" |
Anthony Wilson | f3f16fa | 2018-09-13 14:10:52 -0500 | [diff] [blame] | 22 | echo "" |
| 23 | echo "optional arguments:" |
| 24 | echo " -h, --help show this help message and exit" |
| 25 | exit 0 |
| 26 | } |
| 27 | |
Anthony Wilson | 79f697e | 2018-09-13 13:48:52 -0500 | [diff] [blame] | 28 | get_property () |
| 29 | { |
| 30 | busctl get-property "$@" |
| 31 | } |
| 32 | |
| 33 | state_query () |
| 34 | { |
| 35 | local state=$(get_property "$@" | cut -d '"' -f2) |
| 36 | printf "%-20s: %s\n" $4 $state |
| 37 | } |
| 38 | |
| 39 | handle_cmd () |
| 40 | { |
| 41 | case "$1" in |
| 42 | bmcstate) |
| 43 | OBJECT=$STATE_OBJECT/bmc0 |
| 44 | SERVICE=$(mapper get-service $OBJECT) |
| 45 | INTERFACE=$STATE_INTERFACE.BMC |
| 46 | PROPERTY=CurrentBMCState |
| 47 | state_query $SERVICE $OBJECT $INTERFACE $PROPERTY |
| 48 | ;; |
| 49 | chassisstate) |
| 50 | OBJECT=$STATE_OBJECT/chassis0 |
| 51 | SERVICE=$(mapper get-service $OBJECT) |
| 52 | INTERFACE=$STATE_INTERFACE.Chassis |
| 53 | PROPERTY=CurrentPowerState |
| 54 | state_query $SERVICE $OBJECT $INTERFACE $PROPERTY |
| 55 | ;; |
| 56 | hoststate) |
| 57 | OBJECT=$STATE_OBJECT/host0 |
| 58 | SERVICE=$(mapper get-service $OBJECT) |
| 59 | INTERFACE=$STATE_INTERFACE.Host |
| 60 | PROPERTY=CurrentHostState |
| 61 | state_query $SERVICE $OBJECT $INTERFACE $PROPERTY |
| 62 | ;; |
| 63 | state|status) |
| 64 | for query in bmcstate chassisstate hoststate |
| 65 | do |
| 66 | handle_cmd $query |
| 67 | done |
| 68 | ;; |
Anthony Wilson | 50c5f88 | 2018-09-13 14:19:37 -0500 | [diff] [blame] | 69 | bootprogress) |
| 70 | OBJECT=$STATE_OBJECT/host0 |
| 71 | SERVICE=$(mapper get-service $OBJECT) |
| 72 | INTERFACE=$STATE_INTERFACE.Boot.Progress |
| 73 | PROPERTY=BootProgress |
| 74 | state_query $SERVICE $OBJECT $INTERFACE $PROPERTY |
| 75 | ;; |
Anthony Wilson | 0f35983 | 2018-09-13 14:28:07 -0500 | [diff] [blame^] | 76 | power) |
| 77 | OBJECT=/org/openbmc/control/power0 |
| 78 | SERVICE=$(mapper get-service $OBJECT) |
| 79 | INTERFACE=org.openbmc.control.Power |
| 80 | for property in pgood state pgood_timeout |
| 81 | do |
| 82 | # get_property can potentially return several |
| 83 | # different formats of values, so we do the parsing outside |
| 84 | # of get_property depending on the query. These queries |
| 85 | # return 'i VALUE' formatted strings. |
| 86 | STATE=$(get_property $SERVICE $OBJECT $INTERFACE $property \ |
| 87 | | sed 's/i[ ^I]*//') |
| 88 | printf "%s = %s\n" $property $STATE |
| 89 | done |
| 90 | ;; |
Anthony Wilson | f3f16fa | 2018-09-13 14:10:52 -0500 | [diff] [blame] | 91 | -h|--help) |
| 92 | print_help |
| 93 | ;; |
Anthony Wilson | 79f697e | 2018-09-13 13:48:52 -0500 | [diff] [blame] | 94 | *) |
| 95 | echo "ERROR: Invalid Choice: '$1'" |
| 96 | echo "$USAGE" |
| 97 | ;; |
| 98 | esac |
| 99 | } |
| 100 | |
| 101 | handle_cmd $1 |