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] |
| 6 | {bmcstate,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:" |
| 19 | echo " {bmcstate,chassisstate,hoststate,state,status}" |
| 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 | f3f16fa | 2018-09-13 14:10:52 -0500 | [diff] [blame^] | 67 | -h|--help) |
| 68 | print_help |
| 69 | ;; |
Anthony Wilson | 79f697e | 2018-09-13 13:48:52 -0500 | [diff] [blame] | 70 | *) |
| 71 | echo "ERROR: Invalid Choice: '$1'" |
| 72 | echo "$USAGE" |
| 73 | ;; |
| 74 | esac |
| 75 | } |
| 76 | |
| 77 | handle_cmd $1 |