Anthony Wilson | 79f697e | 2018-09-13 13:48:52 -0500 | [diff] [blame] | 1 | #!/bin/sh -e |
| 2 | |
| 3 | set -euo pipefail |
| 4 | |
Anthony Wilson | f3f16fa | 2018-09-13 14:10:52 -0500 | [diff] [blame] | 5 | USAGE="Usage: obmcutil [-h] |
Anthony Wilson | 50c5f88 | 2018-09-13 14:19:37 -0500 | [diff] [blame^] | 6 | {bmcstate,bootprogress,chassisstate,hoststate,state,status}" |
Anthony Wilson | 79f697e | 2018-09-13 13:48:52 -0500 | [diff] [blame] | 7 | |
| 8 | INTERFACE_ROOT=xyz.openbmc_project |
| 9 | STATE_INTERFACE=$INTERFACE_ROOT.State |
| 10 | |
| 11 | OBJECT_ROOT=/xyz/openbmc_project |
| 12 | STATE_OBJECT=$OBJECT_ROOT/state |
| 13 | |
Anthony Wilson | f3f16fa | 2018-09-13 14:10:52 -0500 | [diff] [blame] | 14 | print_help () |
| 15 | { |
| 16 | echo "$USAGE" |
| 17 | echo "" |
| 18 | echo "positional arguments:" |
Anthony Wilson | 50c5f88 | 2018-09-13 14:19:37 -0500 | [diff] [blame^] | 19 | echo " {bmcstate,bootprogress,chassisstate,hoststate,state,status}" |
Anthony Wilson | f3f16fa | 2018-09-13 14:10:52 -0500 | [diff] [blame] | 20 | echo "" |
| 21 | echo "optional arguments:" |
| 22 | echo " -h, --help show this help message and exit" |
| 23 | exit 0 |
| 24 | } |
| 25 | |
Anthony Wilson | 79f697e | 2018-09-13 13:48:52 -0500 | [diff] [blame] | 26 | get_property () |
| 27 | { |
| 28 | busctl get-property "$@" |
| 29 | } |
| 30 | |
| 31 | state_query () |
| 32 | { |
| 33 | local state=$(get_property "$@" | cut -d '"' -f2) |
| 34 | printf "%-20s: %s\n" $4 $state |
| 35 | } |
| 36 | |
| 37 | handle_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 Wilson | 50c5f88 | 2018-09-13 14:19:37 -0500 | [diff] [blame^] | 67 | 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 Wilson | f3f16fa | 2018-09-13 14:10:52 -0500 | [diff] [blame] | 74 | -h|--help) |
| 75 | print_help |
| 76 | ;; |
Anthony Wilson | 79f697e | 2018-09-13 13:48:52 -0500 | [diff] [blame] | 77 | *) |
| 78 | echo "ERROR: Invalid Choice: '$1'" |
| 79 | echo "$USAGE" |
| 80 | ;; |
| 81 | esac |
| 82 | } |
| 83 | |
| 84 | handle_cmd $1 |