obmcutil: Rewrite in sh and move to phosphor-state-manager
Due to space, security, and performance concerns obmcutil is
being converted to shell script. Have implemented the basic
state interface queries (bmc, chassis, and host).
Moved to phosphor-state-manager repo as this tool mostly deals
with setting and querying state interfaces.
Change-Id: Ib42da06a45e386dd1cc150ac85b638bdf87bdb9d
Signed-off-by: Anthony Wilson <wilsonan@us.ibm.com>
diff --git a/obmcutil b/obmcutil
new file mode 100644
index 0000000..65ca763
--- /dev/null
+++ b/obmcutil
@@ -0,0 +1,61 @@
+#!/bin/sh -e
+
+set -euo pipefail
+
+USAGE="Usage: obmcutil {bmcstate,chassisstate,hoststate,state,status}"
+
+INTERFACE_ROOT=xyz.openbmc_project
+STATE_INTERFACE=$INTERFACE_ROOT.State
+
+OBJECT_ROOT=/xyz/openbmc_project
+STATE_OBJECT=$OBJECT_ROOT/state
+
+get_property ()
+{
+ busctl get-property "$@"
+}
+
+state_query ()
+{
+ local state=$(get_property "$@" | cut -d '"' -f2)
+ printf "%-20s: %s\n" $4 $state
+}
+
+handle_cmd ()
+{
+ case "$1" in
+ bmcstate)
+ OBJECT=$STATE_OBJECT/bmc0
+ SERVICE=$(mapper get-service $OBJECT)
+ INTERFACE=$STATE_INTERFACE.BMC
+ PROPERTY=CurrentBMCState
+ state_query $SERVICE $OBJECT $INTERFACE $PROPERTY
+ ;;
+ chassisstate)
+ OBJECT=$STATE_OBJECT/chassis0
+ SERVICE=$(mapper get-service $OBJECT)
+ INTERFACE=$STATE_INTERFACE.Chassis
+ PROPERTY=CurrentPowerState
+ state_query $SERVICE $OBJECT $INTERFACE $PROPERTY
+ ;;
+ hoststate)
+ OBJECT=$STATE_OBJECT/host0
+ SERVICE=$(mapper get-service $OBJECT)
+ INTERFACE=$STATE_INTERFACE.Host
+ PROPERTY=CurrentHostState
+ state_query $SERVICE $OBJECT $INTERFACE $PROPERTY
+ ;;
+ state|status)
+ for query in bmcstate chassisstate hoststate
+ do
+ handle_cmd $query
+ done
+ ;;
+ *)
+ echo "ERROR: Invalid Choice: '$1'"
+ echo "$USAGE"
+ ;;
+ esac
+}
+
+handle_cmd $1