| Patrick Williams | b239820 | 2021-04-13 20:53:26 -0500 | [diff] [blame] | 1 | #!/bin/bash -e | 
| Anthony Wilson | 79f697e | 2018-09-13 13:48:52 -0500 | [diff] [blame] | 2 |  | 
|  | 3 | set -euo pipefail | 
|  | 4 |  | 
| Anthony Wilson | 189cf24 | 2018-10-23 01:18:21 -0500 | [diff] [blame] | 5 | OPTS="bmcstate,bootprogress,chassiskill,chassisoff,chassison,chassisstate,hoststate,\ | 
| Vishwanatha Subbanna | a65d30d | 2019-11-13 01:26:12 -0600 | [diff] [blame] | 6 | osstate,power,poweroff,poweron,state,status,hostrebootoff,hostrebooton,recoveryoff,recoveryon,\ | 
| Andrew Geissler | ad1afe5 | 2022-02-23 16:07:06 -0600 | [diff] [blame] | 7 | bmcrebootoff, bmcrebooton, listbootblock listlogs showlog deletelogs, stopofftargets" | 
| Anthony Wilson | 0f35983 | 2018-09-13 14:28:07 -0500 | [diff] [blame] | 8 |  | 
| Potin Lai | 0e044c4 | 2022-05-13 23:42:31 +0800 | [diff] [blame] | 9 | USAGE="Usage: obmcutil [-h] [--wait] [--verbose] [--id=<INSTANCE_ID>] | 
| Patrick Williams | d182bff | 2022-12-08 06:39:12 -0600 | [diff] [blame] | 10 | {$OPTS}" | 
| Anthony Wilson | 79f697e | 2018-09-13 13:48:52 -0500 | [diff] [blame] | 11 |  | 
|  | 12 | INTERFACE_ROOT=xyz.openbmc_project | 
|  | 13 | STATE_INTERFACE=$INTERFACE_ROOT.State | 
| Vishwanatha Subbanna | 6d3a2c5 | 2019-10-24 07:21:30 -0500 | [diff] [blame] | 14 | CONTROL_INTERFACE=$INTERFACE_ROOT.Control | 
| Anthony Wilson | 79f697e | 2018-09-13 13:48:52 -0500 | [diff] [blame] | 15 |  | 
|  | 16 | OBJECT_ROOT=/xyz/openbmc_project | 
|  | 17 | STATE_OBJECT=$OBJECT_ROOT/state | 
| Vishwanatha Subbanna | 6d3a2c5 | 2019-10-24 07:21:30 -0500 | [diff] [blame] | 18 | CONTROL_OBJECT=$OBJECT_ROOT/control | 
| Anthony Wilson | 79f697e | 2018-09-13 13:48:52 -0500 | [diff] [blame] | 19 |  | 
| Vishwanatha Subbanna | 7a787dd | 2019-10-31 06:02:31 -0500 | [diff] [blame] | 20 | HOST_TIMEOUT_TARGET=obmc-host-timeout@0.target | 
| Vishwanatha Subbanna | 84b3b29 | 2019-11-04 05:43:19 -0600 | [diff] [blame] | 21 | HOST_CRASH_TARGET=obmc-host-crash@0.target | 
| Vishwanatha Subbanna | 7a787dd | 2019-10-31 06:02:31 -0500 | [diff] [blame] | 22 |  | 
| Anthony Wilson | acf54d0 | 2018-09-20 15:19:28 -0500 | [diff] [blame] | 23 | ## NOTE: The following global variables are used only in the run_timeout cmd. | 
|  | 24 | ## By declaring these globally instead of passing them through the | 
|  | 25 | ## intermediary functions, which may not be "best practice", the readability | 
|  | 26 | ## and cleanliness of the code should at least be increased. | 
|  | 27 |  | 
|  | 28 | # The command passed in to be executed (e.g. poweron/off, status, etc.) | 
|  | 29 | # This will be be used in some instances of error reporting | 
|  | 30 | G_ORIG_CMD= | 
|  | 31 | # The state an interface should be in after executing the requested command. | 
|  | 32 | G_REQUESTED_STATE= | 
|  | 33 | # The query to run during a poweron/off or chassison/off to check that | 
|  | 34 | # the requested state (G_REQUESTED_STATE) of the interface has been reached. | 
|  | 35 | G_QUERY= | 
|  | 36 | # Wait the set period of time for state transitions to be successful before | 
|  | 37 | # continuing on with the program or reporting an error if timeout reached. | 
|  | 38 | G_WAIT= | 
| Andrew Jeffery | 60c3ac8 | 2019-10-02 09:29:29 +0930 | [diff] [blame] | 39 | # Print the journal to the console | 
|  | 40 | G_VERBOSE= | 
| Potin Lai | 0e044c4 | 2022-05-13 23:42:31 +0800 | [diff] [blame] | 41 | # Instance id, default 0 | 
|  | 42 | G_INSTANCE_ID="0" | 
| Anthony Wilson | acf54d0 | 2018-09-20 15:19:28 -0500 | [diff] [blame] | 43 |  | 
| Patrick Williams | d182bff | 2022-12-08 06:39:12 -0600 | [diff] [blame] | 44 | function print_help() | 
| Anthony Wilson | f3f16fa | 2018-09-13 14:10:52 -0500 | [diff] [blame] | 45 | { | 
|  | 46 | echo "$USAGE" | 
|  | 47 | echo "" | 
|  | 48 | echo "positional arguments:" | 
| Anthony Wilson | 0f35983 | 2018-09-13 14:28:07 -0500 | [diff] [blame] | 49 | echo "  {$OPTS}" | 
| Anthony Wilson | f3f16fa | 2018-09-13 14:10:52 -0500 | [diff] [blame] | 50 | echo "" | 
| Vishwanatha Subbanna | 6d3a2c5 | 2019-10-24 07:21:30 -0500 | [diff] [blame] | 51 | echo "Examples:" | 
|  | 52 | echo "" | 
| Vishwanatha Subbanna | a65d30d | 2019-11-13 01:26:12 -0600 | [diff] [blame] | 53 | echo "obmcutil hostrebootoff Disable auto reboot of Host from Quiesce state" | 
| Andrew Geissler | 3191be8 | 2020-10-23 10:45:55 -0500 | [diff] [blame] | 54 | echo "obmcutil hostrebootoffonetime Disable auto reboot of Host from" | 
|  | 55 | echo "                              Quiesce state for a single boot" | 
| Andrew Geissler | ad1afe5 | 2022-02-23 16:07:06 -0600 | [diff] [blame] | 56 | echo "obmcutil hostrebooton   Enable auto reboot of Host from Quiesce state" | 
| Vishwanatha Subbanna | 6d3a2c5 | 2019-10-24 07:21:30 -0500 | [diff] [blame] | 57 | echo "" | 
| Andrew Geissler | ad1afe5 | 2022-02-23 16:07:06 -0600 | [diff] [blame] | 58 | echo "obmcutil bmcrebootoff   Disable reboot of BMC" | 
|  | 59 | echo "obmcutil bmcrebooton    Enable reboot of BMC" | 
| Vishwanatha Subbanna | a65d30d | 2019-11-13 01:26:12 -0600 | [diff] [blame] | 60 | echo "" | 
| Andrew Geissler | ad1afe5 | 2022-02-23 16:07:06 -0600 | [diff] [blame] | 61 | echo "obmcutil recoveryoff    Disable handling boot watchdog timeout and host crash" | 
|  | 62 | echo "                        Also, disable BMC and Host auto reboots" | 
| Vishwanatha Subbanna | a65d30d | 2019-11-13 01:26:12 -0600 | [diff] [blame] | 63 | echo "" | 
| Andrew Geissler | ad1afe5 | 2022-02-23 16:07:06 -0600 | [diff] [blame] | 64 | echo "obmcutil recoveryon     Enable handling boot watchdog timeout and host crash" | 
|  | 65 | echo "                        Also, enable BMC and Host auto reboots" | 
| Vishwanatha Subbanna | 7a787dd | 2019-10-31 06:02:31 -0500 | [diff] [blame] | 66 | echo "" | 
| Andrew Geissler | ad1afe5 | 2022-02-23 16:07:06 -0600 | [diff] [blame] | 67 | echo "obmcutil listbootblock  Check for and list any errors blocking the boot" | 
|  | 68 | echo "                        of the system" | 
| Andrew Geissler | 3b7b561 | 2020-05-14 10:45:29 -0500 | [diff] [blame] | 69 | echo "" | 
| Andrew Geissler | ad1afe5 | 2022-02-23 16:07:06 -0600 | [diff] [blame] | 70 | echo "obmcutil listlogs       List all phosphor-logging entries on the" | 
|  | 71 | echo "                        system" | 
| Andrew Geissler | 295ee4f | 2020-05-14 14:14:05 -0500 | [diff] [blame] | 72 | echo "" | 
| Andrew Geissler | ad1afe5 | 2022-02-23 16:07:06 -0600 | [diff] [blame] | 73 | echo "obmcutil showlog <log>  Display details of input log. Format of <log>" | 
|  | 74 | echo "                        should match listlogs output" | 
| Andrew Geissler | d8c6320 | 2020-05-14 15:06:31 -0500 | [diff] [blame] | 75 | echo "" | 
| Andrew Geissler | ad1afe5 | 2022-02-23 16:07:06 -0600 | [diff] [blame] | 76 | echo "obmcutil deletelogs     Delete all phosphor-logging entries from" | 
|  | 77 | echo "                        system" | 
|  | 78 | echo "obmcutil stopofftargets Manually stop all obmc targets in power off" | 
|  | 79 | echo "                        path" | 
| Andrew Geissler | 42f2898 | 2020-05-14 15:12:42 -0500 | [diff] [blame] | 80 | echo "" | 
| Andrew Geissler | d8779cd | 2020-06-11 10:48:40 -0500 | [diff] [blame] | 81 | echo "optional arguments (must precede the positional options above):" | 
| Anthony Wilson | f3f16fa | 2018-09-13 14:10:52 -0500 | [diff] [blame] | 82 | echo "  -h, --help          show this help message and exit" | 
| Anthony Wilson | acf54d0 | 2018-09-20 15:19:28 -0500 | [diff] [blame] | 83 | echo "  -w, --wait          block until state transition succeeds or fails" | 
| Andrew Jeffery | 60c3ac8 | 2019-10-02 09:29:29 +0930 | [diff] [blame] | 84 | echo "  -v, --verbose       print the journal to stdout if --wait is supplied" | 
| Potin Lai | 0e044c4 | 2022-05-13 23:42:31 +0800 | [diff] [blame] | 85 | echo "  -i, -id             instance id, default 0" | 
| Anthony Wilson | f3f16fa | 2018-09-13 14:10:52 -0500 | [diff] [blame] | 86 | exit 0 | 
|  | 87 | } | 
|  | 88 |  | 
| Patrick Williams | d182bff | 2022-12-08 06:39:12 -0600 | [diff] [blame] | 89 | function run_timeout() | 
| Anthony Wilson | acf54d0 | 2018-09-20 15:19:28 -0500 | [diff] [blame] | 90 | { | 
|  | 91 | local timeout="$1"; shift | 
| Patrick Williams | b239820 | 2021-04-13 20:53:26 -0500 | [diff] [blame] | 92 | local cmd="$*" | 
| Andrew Jeffery | 60c3ac8 | 2019-10-02 09:29:29 +0930 | [diff] [blame] | 93 | local verbose_child= | 
|  | 94 |  | 
| Andrew Jeffery | 2869a92 | 2019-10-18 14:42:34 +1030 | [diff] [blame] | 95 | if [ -n "$G_VERBOSE" ]; then | 
| Andrew Jeffery | 60c3ac8 | 2019-10-02 09:29:29 +0930 | [diff] [blame] | 96 | journalctl -f & | 
|  | 97 | verbose_child=$! | 
|  | 98 | fi | 
| Anthony Wilson | acf54d0 | 2018-09-20 15:19:28 -0500 | [diff] [blame] | 99 |  | 
|  | 100 | $cmd | 
|  | 101 |  | 
|  | 102 | # Run a background query for the transition to the expected state | 
|  | 103 | # This will be killed if the transition doesn't succeed within | 
|  | 104 | # a timeout period. | 
|  | 105 | ( | 
| Patrick Williams | b239820 | 2021-04-13 20:53:26 -0500 | [diff] [blame] | 106 | while ! grep -q "$G_REQUESTED_STATE" <<< "$(handle_cmd "$G_QUERY")" ; do | 
| Anthony Wilson | acf54d0 | 2018-09-20 15:19:28 -0500 | [diff] [blame] | 107 | sleep 1 | 
|  | 108 | done | 
|  | 109 | ) & | 
| Andrew Jeffery | 60c3ac8 | 2019-10-02 09:29:29 +0930 | [diff] [blame] | 110 | wait_child=$! | 
| Anthony Wilson | acf54d0 | 2018-09-20 15:19:28 -0500 | [diff] [blame] | 111 |  | 
|  | 112 | # Could be bad if process is killed before 'timeout' occurs if | 
|  | 113 | # transition doesn't succeed. | 
|  | 114 | trap -- "" SIGTERM | 
|  | 115 |  | 
|  | 116 | # Workaround for lack of 'timeout' command. | 
|  | 117 | ( | 
| Patrick Williams | b239820 | 2021-04-13 20:53:26 -0500 | [diff] [blame] | 118 | sleep "$timeout" | 
| Andrew Jeffery | 60c3ac8 | 2019-10-02 09:29:29 +0930 | [diff] [blame] | 119 | kill $wait_child | 
| Anthony Wilson | acf54d0 | 2018-09-20 15:19:28 -0500 | [diff] [blame] | 120 | ) > /dev/null 2>&1 & | 
|  | 121 |  | 
| Andrew Jeffery | 60c3ac8 | 2019-10-02 09:29:29 +0930 | [diff] [blame] | 122 | if ! wait $wait_child; then | 
| Anthony Wilson | acf54d0 | 2018-09-20 15:19:28 -0500 | [diff] [blame] | 123 | echo "Unable to confirm '$G_ORIG_CMD' success" \ | 
| Patrick Williams | d182bff | 2022-12-08 06:39:12 -0600 | [diff] [blame] | 124 | "within timeout period (${timeout}s)" | 
| Anthony Wilson | acf54d0 | 2018-09-20 15:19:28 -0500 | [diff] [blame] | 125 | fi | 
| Andrew Jeffery | 60c3ac8 | 2019-10-02 09:29:29 +0930 | [diff] [blame] | 126 |  | 
| Andrew Jeffery | 8be7029 | 2019-11-01 08:56:49 +1030 | [diff] [blame] | 127 | if [ -n "$verbose_child" ]; then | 
| Andrew Jeffery | 60c3ac8 | 2019-10-02 09:29:29 +0930 | [diff] [blame] | 128 | kill $verbose_child | 
|  | 129 | fi | 
| Anthony Wilson | acf54d0 | 2018-09-20 15:19:28 -0500 | [diff] [blame] | 130 | } | 
|  | 131 |  | 
| Patrick Williams | d182bff | 2022-12-08 06:39:12 -0600 | [diff] [blame] | 132 | function run_cmd() | 
| Anthony Wilson | acf54d0 | 2018-09-20 15:19:28 -0500 | [diff] [blame] | 133 | { | 
| Patrick Williams | b239820 | 2021-04-13 20:53:26 -0500 | [diff] [blame] | 134 | local cmd="$*"; | 
| Anthony Wilson | acf54d0 | 2018-09-20 15:19:28 -0500 | [diff] [blame] | 135 |  | 
|  | 136 | if [ -n "$G_WAIT" ]; then | 
| Patrick Williams | b239820 | 2021-04-13 20:53:26 -0500 | [diff] [blame] | 137 | run_timeout "$G_WAIT" "$cmd" | 
| Anthony Wilson | acf54d0 | 2018-09-20 15:19:28 -0500 | [diff] [blame] | 138 | else | 
|  | 139 | $cmd | 
|  | 140 | fi | 
|  | 141 | } | 
|  | 142 |  | 
| Patrick Williams | d182bff | 2022-12-08 06:39:12 -0600 | [diff] [blame] | 143 | function set_property() | 
| Anthony Wilson | 3ae0a35 | 2018-09-13 14:47:56 -0500 | [diff] [blame] | 144 | { | 
| Anthony Wilson | acf54d0 | 2018-09-20 15:19:28 -0500 | [diff] [blame] | 145 | run_cmd busctl set-property "$@" | 
| Anthony Wilson | 3ae0a35 | 2018-09-13 14:47:56 -0500 | [diff] [blame] | 146 | } | 
|  | 147 |  | 
| Patrick Williams | d182bff | 2022-12-08 06:39:12 -0600 | [diff] [blame] | 148 | function get_property() | 
| Anthony Wilson | 79f697e | 2018-09-13 13:48:52 -0500 | [diff] [blame] | 149 | { | 
| Anthony Wilson | acf54d0 | 2018-09-20 15:19:28 -0500 | [diff] [blame] | 150 | G_WAIT="" | 
|  | 151 | run_cmd busctl get-property "$@" | 
| Anthony Wilson | 79f697e | 2018-09-13 13:48:52 -0500 | [diff] [blame] | 152 | } | 
|  | 153 |  | 
| Patrick Williams | d182bff | 2022-12-08 06:39:12 -0600 | [diff] [blame] | 154 | function state_query() | 
| Anthony Wilson | 79f697e | 2018-09-13 13:48:52 -0500 | [diff] [blame] | 155 | { | 
| Patrick Williams | b239820 | 2021-04-13 20:53:26 -0500 | [diff] [blame] | 156 | local state | 
|  | 157 | state=$(get_property "$@" | cut -d '"' -f2) | 
|  | 158 | printf "%-20s: %s\n" "$4" "$state" | 
| Anthony Wilson | 79f697e | 2018-09-13 13:48:52 -0500 | [diff] [blame] | 159 | } | 
|  | 160 |  | 
| Patrick Williams | d182bff | 2022-12-08 06:39:12 -0600 | [diff] [blame] | 161 | function print_usage_err() | 
| Anthony Wilson | ea87db4 | 2018-09-26 16:06:38 -0500 | [diff] [blame] | 162 | { | 
|  | 163 | echo "ERROR: $1" >&2 | 
|  | 164 | echo "$USAGE" | 
|  | 165 | exit 1 | 
|  | 166 | } | 
|  | 167 |  | 
| Patrick Williams | d182bff | 2022-12-08 06:39:12 -0600 | [diff] [blame] | 168 | function mask_systemd_target() | 
| Vishwanatha Subbanna | 7a787dd | 2019-10-31 06:02:31 -0500 | [diff] [blame] | 169 | { | 
| Patrick Williams | b239820 | 2021-04-13 20:53:26 -0500 | [diff] [blame] | 170 | target="$*" | 
|  | 171 | systemctl mask "$target" | 
| Vishwanatha Subbanna | 7a787dd | 2019-10-31 06:02:31 -0500 | [diff] [blame] | 172 | } | 
|  | 173 |  | 
| Patrick Williams | d182bff | 2022-12-08 06:39:12 -0600 | [diff] [blame] | 174 | function unmask_systemd_target() | 
| Vishwanatha Subbanna | 7a787dd | 2019-10-31 06:02:31 -0500 | [diff] [blame] | 175 | { | 
| Patrick Williams | b239820 | 2021-04-13 20:53:26 -0500 | [diff] [blame] | 176 | target="$*" | 
|  | 177 | systemctl unmask "$target" | 
| Vishwanatha Subbanna | 7a787dd | 2019-10-31 06:02:31 -0500 | [diff] [blame] | 178 | } | 
|  | 179 |  | 
| Patrick Williams | d182bff | 2022-12-08 06:39:12 -0600 | [diff] [blame] | 180 | function disable_bmc_reboot() | 
| Vishwanatha Subbanna | a65d30d | 2019-11-13 01:26:12 -0600 | [diff] [blame] | 181 | { | 
|  | 182 | dir="/run/systemd/system/" | 
|  | 183 | file="reboot-guard.conf" | 
|  | 184 | units=("reboot" "poweroff" "halt") | 
|  | 185 |  | 
|  | 186 | for unit in "${units[@]}"; do | 
| Patrick Williams | b239820 | 2021-04-13 20:53:26 -0500 | [diff] [blame] | 187 | mkdir -p "${dir}${unit}.target.d" | 
|  | 188 | echo -e "[Unit]\nRefuseManualStart=yes" >> "${dir}${unit}.target.d/${file}" | 
| Vishwanatha Subbanna | a65d30d | 2019-11-13 01:26:12 -0600 | [diff] [blame] | 189 | done | 
|  | 190 | } | 
|  | 191 |  | 
| Patrick Williams | d182bff | 2022-12-08 06:39:12 -0600 | [diff] [blame] | 192 | function enable_bmc_reboot() | 
| Vishwanatha Subbanna | a65d30d | 2019-11-13 01:26:12 -0600 | [diff] [blame] | 193 | { | 
|  | 194 | dir="/run/systemd/system/" | 
|  | 195 | file="reboot-guard.conf" | 
|  | 196 | units=("reboot" "poweroff" "halt") | 
|  | 197 |  | 
|  | 198 | for unit in "${units[@]}"; do | 
| Patrick Williams | b239820 | 2021-04-13 20:53:26 -0500 | [diff] [blame] | 199 | rm -rf "${dir}${unit}.target.d/${file}" | 
|  | 200 | rm -rf "${dir}${unit}.target.d" | 
| Vishwanatha Subbanna | a65d30d | 2019-11-13 01:26:12 -0600 | [diff] [blame] | 201 | done | 
|  | 202 | } | 
|  | 203 |  | 
| Andrew Geissler | 3b7b561 | 2020-05-14 10:45:29 -0500 | [diff] [blame] | 204 | # will write blocking errors to stdout | 
| Patrick Williams | d182bff | 2022-12-08 06:39:12 -0600 | [diff] [blame] | 205 | function check_boot_block_errors() | 
| Andrew Geissler | 3b7b561 | 2020-05-14 10:45:29 -0500 | [diff] [blame] | 206 | { | 
|  | 207 | # array of boot block objects | 
|  | 208 | blockArray=() | 
|  | 209 |  | 
|  | 210 | # Look for any objects under logging that implement the | 
|  | 211 | # xyz.openbmc_project.Logging.ErrorBlocksTransition | 
|  | 212 | subtree="$(busctl call xyz.openbmc_project.ObjectMapper \ | 
|  | 213 | /xyz/openbmc_project/object_mapper \ | 
|  | 214 | xyz.openbmc_project.ObjectMapper \ | 
|  | 215 | GetSubTree sias "/xyz/openbmc_project/logging/" 0 1 \ | 
|  | 216 | xyz.openbmc_project.Logging.ErrorBlocksTransition)" | 
|  | 217 |  | 
|  | 218 | # remove quotation marks | 
| Patrick Williams | b239820 | 2021-04-13 20:53:26 -0500 | [diff] [blame] | 219 | # shellcheck disable=SC2001 | 
|  | 220 | subtree="$(echo "$subtree" | sed 's/\"//g')" | 
| Andrew Geissler | 3b7b561 | 2020-05-14 10:45:29 -0500 | [diff] [blame] | 221 |  | 
|  | 222 | for entry in $subtree; do | 
|  | 223 | if [[ ${entry} =~ "xyz/openbmc_project/logging/block"* ]]; then | 
| Patrick Williams | b239820 | 2021-04-13 20:53:26 -0500 | [diff] [blame] | 224 | blockArray+=( "$entry" ) | 
| Andrew Geissler | 3b7b561 | 2020-05-14 10:45:29 -0500 | [diff] [blame] | 225 | fi | 
|  | 226 | done | 
|  | 227 |  | 
|  | 228 | # now find associated error log for each boot block error | 
|  | 229 | for berror in "${blockArray[@]}"; do | 
| Patrick Williams | b239820 | 2021-04-13 20:53:26 -0500 | [diff] [blame] | 230 | assocs="$(busctl call xyz.openbmc_project.Logging "$berror" \ | 
| Andrew Geissler | 3b7b561 | 2020-05-14 10:45:29 -0500 | [diff] [blame] | 231 | org.freedesktop.DBus.Properties Get \ | 
|  | 232 | ss xyz.openbmc_project.Association.Definitions Associations)" | 
|  | 233 |  | 
|  | 234 | # remove quotation marks | 
| Patrick Williams | b239820 | 2021-04-13 20:53:26 -0500 | [diff] [blame] | 235 | # shellcheck disable=SC2001 | 
|  | 236 | assocs="$(echo "$assocs" | sed 's/\"//g')" | 
| Andrew Geissler | 3b7b561 | 2020-05-14 10:45:29 -0500 | [diff] [blame] | 237 |  | 
|  | 238 | for entry in $assocs; do | 
|  | 239 | if [[ ${entry} =~ "xyz/openbmc_project/logging/entry"* ]]; then | 
|  | 240 | echo "Blocking Error: $entry" | 
|  | 241 | fi | 
|  | 242 | done | 
|  | 243 | done | 
|  | 244 | } | 
|  | 245 |  | 
| Andrew Geissler | deb6bb4 | 2020-05-14 13:44:57 -0500 | [diff] [blame] | 246 | # helper function to check for boot block errors and notify user | 
| Patrick Williams | d182bff | 2022-12-08 06:39:12 -0600 | [diff] [blame] | 247 | function check_and_warn_boot_block() | 
| Andrew Geissler | deb6bb4 | 2020-05-14 13:44:57 -0500 | [diff] [blame] | 248 | { | 
|  | 249 | blockingErrors=$(check_boot_block_errors) | 
| Patrick Williams | b239820 | 2021-04-13 20:53:26 -0500 | [diff] [blame] | 250 | if [ -n "$blockingErrors" ]; then | 
| Andrew Geissler | deb6bb4 | 2020-05-14 13:44:57 -0500 | [diff] [blame] | 251 | echo !!!!!!!!!! | 
|  | 252 | echo "WARNING! System has blocking errors that will prevent boot" | 
|  | 253 | echo "$blockingErrors" | 
|  | 254 | echo !!!!!!!!!! | 
|  | 255 | fi | 
|  | 256 | } | 
|  | 257 |  | 
| Andrew Geissler | 295ee4f | 2020-05-14 14:14:05 -0500 | [diff] [blame] | 258 | # list all phosphor-logging entries | 
| Patrick Williams | d182bff | 2022-12-08 06:39:12 -0600 | [diff] [blame] | 259 | function list_logs() | 
| Andrew Geissler | 295ee4f | 2020-05-14 14:14:05 -0500 | [diff] [blame] | 260 | { | 
|  | 261 | # Look for any objects under logging that implement the | 
|  | 262 | # xyz.openbmc_project.Logging.Entry | 
|  | 263 | busctl -j call xyz.openbmc_project.ObjectMapper \ | 
| Patrick Williams | d182bff | 2022-12-08 06:39:12 -0600 | [diff] [blame] | 264 | /xyz/openbmc_project/object_mapper \ | 
|  | 265 | xyz.openbmc_project.ObjectMapper \ | 
|  | 266 | GetSubTreePaths sias "/xyz/openbmc_project/logging/" 0 1 \ | 
|  | 267 | xyz.openbmc_project.Logging.Entry | 
| Andrew Geissler | 295ee4f | 2020-05-14 14:14:05 -0500 | [diff] [blame] | 268 | } | 
|  | 269 |  | 
| Andrew Geissler | d8c6320 | 2020-05-14 15:06:31 -0500 | [diff] [blame] | 270 | # display input log details | 
| Patrick Williams | d182bff | 2022-12-08 06:39:12 -0600 | [diff] [blame] | 271 | function show_log() | 
| Andrew Geissler | d8c6320 | 2020-05-14 15:06:31 -0500 | [diff] [blame] | 272 | { | 
|  | 273 | busctl -j call xyz.openbmc_project.Logging \ | 
| Patrick Williams | d182bff | 2022-12-08 06:39:12 -0600 | [diff] [blame] | 274 | "$1" \ | 
|  | 275 | org.freedesktop.DBus.Properties \ | 
|  | 276 | GetAll s xyz.openbmc_project.Logging.Entry | 
| Andrew Geissler | d8c6320 | 2020-05-14 15:06:31 -0500 | [diff] [blame] | 277 | } | 
|  | 278 |  | 
| Andrew Geissler | 42f2898 | 2020-05-14 15:12:42 -0500 | [diff] [blame] | 279 | # delete all phosphor-logging entries | 
| Patrick Williams | d182bff | 2022-12-08 06:39:12 -0600 | [diff] [blame] | 280 | function delete_logs() | 
| Andrew Geissler | 42f2898 | 2020-05-14 15:12:42 -0500 | [diff] [blame] | 281 | { | 
|  | 282 | busctl call xyz.openbmc_project.Logging \ | 
| Patrick Williams | d182bff | 2022-12-08 06:39:12 -0600 | [diff] [blame] | 283 | /xyz/openbmc_project/logging \ | 
|  | 284 | xyz.openbmc_project.Collection.DeleteAll DeleteAll | 
| Andrew Geissler | 42f2898 | 2020-05-14 15:12:42 -0500 | [diff] [blame] | 285 | } | 
|  | 286 |  | 
| Andrew Geissler | ad1afe5 | 2022-02-23 16:07:06 -0600 | [diff] [blame] | 287 | # stop all targets associated with powering off a system | 
| Patrick Williams | d182bff | 2022-12-08 06:39:12 -0600 | [diff] [blame] | 288 | function stop_off_targets() | 
| Andrew Geissler | ad1afe5 | 2022-02-23 16:07:06 -0600 | [diff] [blame] | 289 | { | 
|  | 290 | systemctl stop \ | 
|  | 291 | obmc-chassis-powered-off@0.target \ | 
|  | 292 | obmc-host-stop-pre@0.target \ | 
|  | 293 | obmc-host-stopped@0.target \ | 
|  | 294 | obmc-host-stopping@0.target \ | 
|  | 295 | obmc-power-off@0.target \ | 
|  | 296 | obmc-power-stop-pre@0.target \ | 
|  | 297 | obmc-power-stop@0.target | 
|  | 298 | } | 
|  | 299 |  | 
| Patrick Williams | d182bff | 2022-12-08 06:39:12 -0600 | [diff] [blame] | 300 | function handle_cmd() | 
| Anthony Wilson | 79f697e | 2018-09-13 13:48:52 -0500 | [diff] [blame] | 301 | { | 
|  | 302 | case "$1" in | 
| Anthony Wilson | 3ae0a35 | 2018-09-13 14:47:56 -0500 | [diff] [blame] | 303 | chassisoff) | 
| Potin Lai | 0e044c4 | 2022-05-13 23:42:31 +0800 | [diff] [blame] | 304 | OBJECT=$STATE_OBJECT/chassis$G_INSTANCE_ID | 
| Anthony Wilson | 3ae0a35 | 2018-09-13 14:47:56 -0500 | [diff] [blame] | 305 | SERVICE=$(mapper get-service $OBJECT) | 
|  | 306 | INTERFACE=$STATE_INTERFACE.Chassis | 
|  | 307 | PROPERTY=RequestedPowerTransition | 
|  | 308 | VALUE=$INTERFACE.Transition.Off | 
| Anthony Wilson | acf54d0 | 2018-09-20 15:19:28 -0500 | [diff] [blame] | 309 | G_REQUESTED_STATE=$INTERFACE.PowerState.Off | 
|  | 310 | G_QUERY="chassisstate" | 
| Patrick Williams | b239820 | 2021-04-13 20:53:26 -0500 | [diff] [blame] | 311 | set_property "$SERVICE" $OBJECT $INTERFACE $PROPERTY "s" $VALUE | 
| Anthony Wilson | 3ae0a35 | 2018-09-13 14:47:56 -0500 | [diff] [blame] | 312 | ;; | 
|  | 313 | chassison) | 
| Andrew Geissler | deb6bb4 | 2020-05-14 13:44:57 -0500 | [diff] [blame] | 314 | check_and_warn_boot_block | 
| Potin Lai | 0e044c4 | 2022-05-13 23:42:31 +0800 | [diff] [blame] | 315 | OBJECT=$STATE_OBJECT/chassis$G_INSTANCE_ID | 
| Anthony Wilson | 3ae0a35 | 2018-09-13 14:47:56 -0500 | [diff] [blame] | 316 | SERVICE=$(mapper get-service $OBJECT) | 
|  | 317 | INTERFACE=$STATE_INTERFACE.Chassis | 
|  | 318 | PROPERTY=RequestedPowerTransition | 
|  | 319 | VALUE=$INTERFACE.Transition.On | 
| Anthony Wilson | acf54d0 | 2018-09-20 15:19:28 -0500 | [diff] [blame] | 320 | G_REQUESTED_STATE=$INTERFACE.PowerState.On | 
|  | 321 | G_QUERY="chassisstate" | 
| Patrick Williams | b239820 | 2021-04-13 20:53:26 -0500 | [diff] [blame] | 322 | set_property "$SERVICE" $OBJECT $INTERFACE $PROPERTY "s" $VALUE | 
| Anthony Wilson | 3ae0a35 | 2018-09-13 14:47:56 -0500 | [diff] [blame] | 323 | ;; | 
|  | 324 | poweroff) | 
| Potin Lai | 0e044c4 | 2022-05-13 23:42:31 +0800 | [diff] [blame] | 325 | OBJECT=$STATE_OBJECT/host$G_INSTANCE_ID | 
| Anthony Wilson | 3ae0a35 | 2018-09-13 14:47:56 -0500 | [diff] [blame] | 326 | SERVICE=$(mapper get-service $OBJECT) | 
|  | 327 | INTERFACE=$STATE_INTERFACE.Host | 
|  | 328 | PROPERTY=RequestedHostTransition | 
|  | 329 | VALUE=$INTERFACE.Transition.Off | 
| Anthony Wilson | acf54d0 | 2018-09-20 15:19:28 -0500 | [diff] [blame] | 330 | G_REQUESTED_STATE=$INTERFACE.HostState.Off | 
|  | 331 | G_QUERY="hoststate" | 
| Patrick Williams | b239820 | 2021-04-13 20:53:26 -0500 | [diff] [blame] | 332 | set_property "$SERVICE" $OBJECT $INTERFACE $PROPERTY "s" $VALUE | 
| Anthony Wilson | 3ae0a35 | 2018-09-13 14:47:56 -0500 | [diff] [blame] | 333 | ;; | 
|  | 334 | poweron) | 
| Andrew Geissler | deb6bb4 | 2020-05-14 13:44:57 -0500 | [diff] [blame] | 335 | check_and_warn_boot_block | 
| Potin Lai | 0e044c4 | 2022-05-13 23:42:31 +0800 | [diff] [blame] | 336 | OBJECT=$STATE_OBJECT/host$G_INSTANCE_ID | 
| Anthony Wilson | 3ae0a35 | 2018-09-13 14:47:56 -0500 | [diff] [blame] | 337 | SERVICE=$(mapper get-service $OBJECT) | 
|  | 338 | INTERFACE=$STATE_INTERFACE.Host | 
|  | 339 | PROPERTY=RequestedHostTransition | 
|  | 340 | VALUE=$INTERFACE.Transition.On | 
| Anthony Wilson | acf54d0 | 2018-09-20 15:19:28 -0500 | [diff] [blame] | 341 | G_REQUESTED_STATE=$INTERFACE.HostState.Running | 
|  | 342 | G_QUERY="hoststate" | 
| Patrick Williams | b239820 | 2021-04-13 20:53:26 -0500 | [diff] [blame] | 343 | set_property "$SERVICE" $OBJECT $INTERFACE $PROPERTY "s" $VALUE | 
| Anthony Wilson | 3ae0a35 | 2018-09-13 14:47:56 -0500 | [diff] [blame] | 344 | ;; | 
| Anthony Wilson | 79f697e | 2018-09-13 13:48:52 -0500 | [diff] [blame] | 345 | bmcstate) | 
|  | 346 | OBJECT=$STATE_OBJECT/bmc0 | 
|  | 347 | SERVICE=$(mapper get-service $OBJECT) | 
|  | 348 | INTERFACE=$STATE_INTERFACE.BMC | 
|  | 349 | PROPERTY=CurrentBMCState | 
| Patrick Williams | b239820 | 2021-04-13 20:53:26 -0500 | [diff] [blame] | 350 | state_query "$SERVICE" $OBJECT $INTERFACE $PROPERTY | 
| Anthony Wilson | 79f697e | 2018-09-13 13:48:52 -0500 | [diff] [blame] | 351 | ;; | 
|  | 352 | chassisstate) | 
| Potin Lai | 0e044c4 | 2022-05-13 23:42:31 +0800 | [diff] [blame] | 353 | OBJECT=$STATE_OBJECT/chassis$G_INSTANCE_ID | 
| Anthony Wilson | 79f697e | 2018-09-13 13:48:52 -0500 | [diff] [blame] | 354 | SERVICE=$(mapper get-service $OBJECT) | 
|  | 355 | INTERFACE=$STATE_INTERFACE.Chassis | 
|  | 356 | PROPERTY=CurrentPowerState | 
| Patrick Williams | b239820 | 2021-04-13 20:53:26 -0500 | [diff] [blame] | 357 | state_query "$SERVICE" $OBJECT $INTERFACE $PROPERTY | 
| Anthony Wilson | 79f697e | 2018-09-13 13:48:52 -0500 | [diff] [blame] | 358 | ;; | 
|  | 359 | hoststate) | 
| Potin Lai | 0e044c4 | 2022-05-13 23:42:31 +0800 | [diff] [blame] | 360 | OBJECT=$STATE_OBJECT/host$G_INSTANCE_ID | 
| Anthony Wilson | 79f697e | 2018-09-13 13:48:52 -0500 | [diff] [blame] | 361 | SERVICE=$(mapper get-service $OBJECT) | 
|  | 362 | INTERFACE=$STATE_INTERFACE.Host | 
|  | 363 | PROPERTY=CurrentHostState | 
| Patrick Williams | b239820 | 2021-04-13 20:53:26 -0500 | [diff] [blame] | 364 | state_query "$SERVICE" $OBJECT $INTERFACE $PROPERTY | 
| Anthony Wilson | 79f697e | 2018-09-13 13:48:52 -0500 | [diff] [blame] | 365 | ;; | 
| Alexander Filippov | 86cffd9 | 2019-04-03 16:29:57 +0300 | [diff] [blame] | 366 | osstate) | 
| Potin Lai | 0e044c4 | 2022-05-13 23:42:31 +0800 | [diff] [blame] | 367 | OBJECT=$STATE_OBJECT/host$G_INSTANCE_ID | 
| Alexander Filippov | 86cffd9 | 2019-04-03 16:29:57 +0300 | [diff] [blame] | 368 | SERVICE=$(mapper get-service $OBJECT) | 
|  | 369 | INTERFACE=$STATE_INTERFACE.OperatingSystem.Status | 
|  | 370 | PROPERTY=OperatingSystemState | 
| Patrick Williams | b239820 | 2021-04-13 20:53:26 -0500 | [diff] [blame] | 371 | state_query "$SERVICE" $OBJECT $INTERFACE $PROPERTY | 
| Alexander Filippov | 86cffd9 | 2019-04-03 16:29:57 +0300 | [diff] [blame] | 372 | ;; | 
| Anthony Wilson | 79f697e | 2018-09-13 13:48:52 -0500 | [diff] [blame] | 373 | state|status) | 
| Alexander Filippov | 86cffd9 | 2019-04-03 16:29:57 +0300 | [diff] [blame] | 374 | for query in bmcstate chassisstate hoststate bootprogress osstate | 
| Anthony Wilson | 79f697e | 2018-09-13 13:48:52 -0500 | [diff] [blame] | 375 | do | 
|  | 376 | handle_cmd $query | 
|  | 377 | done | 
| Andrew Geissler | deb6bb4 | 2020-05-14 13:44:57 -0500 | [diff] [blame] | 378 | check_and_warn_boot_block | 
| Anthony Wilson | 79f697e | 2018-09-13 13:48:52 -0500 | [diff] [blame] | 379 | ;; | 
| Anthony Wilson | 50c5f88 | 2018-09-13 14:19:37 -0500 | [diff] [blame] | 380 | bootprogress) | 
| Potin Lai | 0e044c4 | 2022-05-13 23:42:31 +0800 | [diff] [blame] | 381 | OBJECT=$STATE_OBJECT/host$G_INSTANCE_ID | 
| Anthony Wilson | 50c5f88 | 2018-09-13 14:19:37 -0500 | [diff] [blame] | 382 | SERVICE=$(mapper get-service $OBJECT) | 
|  | 383 | INTERFACE=$STATE_INTERFACE.Boot.Progress | 
|  | 384 | PROPERTY=BootProgress | 
| Patrick Williams | b239820 | 2021-04-13 20:53:26 -0500 | [diff] [blame] | 385 | state_query "$SERVICE" $OBJECT $INTERFACE $PROPERTY | 
| Anthony Wilson | 50c5f88 | 2018-09-13 14:19:37 -0500 | [diff] [blame] | 386 | ;; | 
| Anthony Wilson | 0f35983 | 2018-09-13 14:28:07 -0500 | [diff] [blame] | 387 | power) | 
|  | 388 | OBJECT=/org/openbmc/control/power0 | 
|  | 389 | SERVICE=$(mapper get-service $OBJECT) | 
|  | 390 | INTERFACE=org.openbmc.control.Power | 
| Patrick Williams | d182bff | 2022-12-08 06:39:12 -0600 | [diff] [blame] | 391 | for property in pgood state pgood_timeout; do | 
| Anthony Wilson | 0f35983 | 2018-09-13 14:28:07 -0500 | [diff] [blame] | 392 | # get_property can potentially return several | 
|  | 393 | # different formats of values, so we do the parsing outside | 
|  | 394 | # of get_property depending on the query. These queries | 
|  | 395 | # return 'i VALUE' formatted strings. | 
| Patrick Williams | d182bff | 2022-12-08 06:39:12 -0600 | [diff] [blame] | 396 | STATE=$(get_property "$SERVICE" "$OBJECT" "$INTERFACE" "$property" | sed 's/i[ ^I]*//') | 
| Patrick Williams | b239820 | 2021-04-13 20:53:26 -0500 | [diff] [blame] | 397 | printf "%s = %s\n" $property "$STATE" | 
| Anthony Wilson | 0f35983 | 2018-09-13 14:28:07 -0500 | [diff] [blame] | 398 | done | 
|  | 399 | ;; | 
| Anthony Wilson | 189cf24 | 2018-10-23 01:18:21 -0500 | [diff] [blame] | 400 | chassiskill) | 
|  | 401 | /usr/libexec/chassiskill | 
|  | 402 | ;; | 
| Vishwanatha Subbanna | a65d30d | 2019-11-13 01:26:12 -0600 | [diff] [blame] | 403 | hostrebootoff) | 
| Potin Lai | 0e044c4 | 2022-05-13 23:42:31 +0800 | [diff] [blame] | 404 | OBJECT=$CONTROL_OBJECT/host$G_INSTANCE_ID/auto_reboot | 
| Vishwanatha Subbanna | 6d3a2c5 | 2019-10-24 07:21:30 -0500 | [diff] [blame] | 405 | SERVICE=$(mapper get-service $OBJECT) | 
|  | 406 | INTERFACE=$CONTROL_INTERFACE.Boot.RebootPolicy | 
|  | 407 | PROPERTY=AutoReboot | 
|  | 408 | VALUE=false | 
| Patrick Williams | b239820 | 2021-04-13 20:53:26 -0500 | [diff] [blame] | 409 | set_property "$SERVICE" $OBJECT $INTERFACE $PROPERTY "b" $VALUE | 
| Vishwanatha Subbanna | 6d3a2c5 | 2019-10-24 07:21:30 -0500 | [diff] [blame] | 410 | ;; | 
| Andrew Geissler | 3191be8 | 2020-10-23 10:45:55 -0500 | [diff] [blame] | 411 | hostrebootoffonetime) | 
| Potin Lai | 0e044c4 | 2022-05-13 23:42:31 +0800 | [diff] [blame] | 412 | OBJECT=$CONTROL_OBJECT/host$G_INSTANCE_ID/auto_reboot/one_time | 
| Andrew Geissler | 3191be8 | 2020-10-23 10:45:55 -0500 | [diff] [blame] | 413 | SERVICE=$(mapper get-service $OBJECT) | 
|  | 414 | INTERFACE=$CONTROL_INTERFACE.Boot.RebootPolicy | 
|  | 415 | PROPERTY=AutoReboot | 
|  | 416 | VALUE=false | 
| Patrick Williams | b239820 | 2021-04-13 20:53:26 -0500 | [diff] [blame] | 417 | set_property "$SERVICE" $OBJECT $INTERFACE $PROPERTY "b" $VALUE | 
| Patrick Williams | d182bff | 2022-12-08 06:39:12 -0600 | [diff] [blame] | 418 | ;; | 
| Vishwanatha Subbanna | a65d30d | 2019-11-13 01:26:12 -0600 | [diff] [blame] | 419 | hostrebooton) | 
| Potin Lai | 0e044c4 | 2022-05-13 23:42:31 +0800 | [diff] [blame] | 420 | OBJECT=$CONTROL_OBJECT/host$G_INSTANCE_ID/auto_reboot | 
| Vishwanatha Subbanna | 6d3a2c5 | 2019-10-24 07:21:30 -0500 | [diff] [blame] | 421 | SERVICE=$(mapper get-service $OBJECT) | 
|  | 422 | INTERFACE=$CONTROL_INTERFACE.Boot.RebootPolicy | 
|  | 423 | PROPERTY=AutoReboot | 
|  | 424 | VALUE=true | 
| Patrick Williams | b239820 | 2021-04-13 20:53:26 -0500 | [diff] [blame] | 425 | set_property "$SERVICE" $OBJECT $INTERFACE $PROPERTY "b" $VALUE | 
| Vishwanatha Subbanna | 6d3a2c5 | 2019-10-24 07:21:30 -0500 | [diff] [blame] | 426 | ;; | 
| Vishwanatha Subbanna | a65d30d | 2019-11-13 01:26:12 -0600 | [diff] [blame] | 427 | bmcrebootoff) | 
|  | 428 | disable_bmc_reboot | 
|  | 429 | ;; | 
|  | 430 | bmcrebooton) | 
|  | 431 | enable_bmc_reboot | 
|  | 432 | ;; | 
| Vishwanatha Subbanna | 7a787dd | 2019-10-31 06:02:31 -0500 | [diff] [blame] | 433 | recoveryoff) | 
| Vishwanatha Subbanna | a65d30d | 2019-11-13 01:26:12 -0600 | [diff] [blame] | 434 | handle_cmd hostrebootoff | 
|  | 435 | handle_cmd bmcrebootoff | 
| Vishwanatha Subbanna | 7a787dd | 2019-10-31 06:02:31 -0500 | [diff] [blame] | 436 | mask_systemd_target $HOST_TIMEOUT_TARGET | 
| Vishwanatha Subbanna | 84b3b29 | 2019-11-04 05:43:19 -0600 | [diff] [blame] | 437 | mask_systemd_target $HOST_CRASH_TARGET | 
| Vishwanatha Subbanna | 7a787dd | 2019-10-31 06:02:31 -0500 | [diff] [blame] | 438 | ;; | 
|  | 439 | recoveryon) | 
| Vishwanatha Subbanna | a65d30d | 2019-11-13 01:26:12 -0600 | [diff] [blame] | 440 | handle_cmd hostrebooton | 
|  | 441 | handle_cmd bmcrebooton | 
| Vishwanatha Subbanna | 7a787dd | 2019-10-31 06:02:31 -0500 | [diff] [blame] | 442 | unmask_systemd_target $HOST_TIMEOUT_TARGET | 
| Vishwanatha Subbanna | 84b3b29 | 2019-11-04 05:43:19 -0600 | [diff] [blame] | 443 | unmask_systemd_target $HOST_CRASH_TARGET | 
| Vishwanatha Subbanna | 7a787dd | 2019-10-31 06:02:31 -0500 | [diff] [blame] | 444 | ;; | 
| Andrew Geissler | 3b7b561 | 2020-05-14 10:45:29 -0500 | [diff] [blame] | 445 | listbootblock) | 
|  | 446 | blockingErrors=$(check_boot_block_errors) | 
|  | 447 | if [ -z "$blockingErrors" ]; then | 
|  | 448 | echo "No blocking errors present" | 
|  | 449 | else | 
|  | 450 | echo "$blockingErrors" | 
|  | 451 | fi | 
|  | 452 | ;; | 
| Andrew Geissler | 295ee4f | 2020-05-14 14:14:05 -0500 | [diff] [blame] | 453 | listlogs) | 
|  | 454 | list_logs | 
|  | 455 | ;; | 
| Andrew Geissler | d8c6320 | 2020-05-14 15:06:31 -0500 | [diff] [blame] | 456 | showlog) | 
| Patrick Williams | b239820 | 2021-04-13 20:53:26 -0500 | [diff] [blame] | 457 | show_log "$2" | 
| Andrew Geissler | d8c6320 | 2020-05-14 15:06:31 -0500 | [diff] [blame] | 458 | ;; | 
| Andrew Geissler | 42f2898 | 2020-05-14 15:12:42 -0500 | [diff] [blame] | 459 | deletelogs) | 
|  | 460 | delete_logs | 
|  | 461 | ;; | 
| Andrew Geissler | ad1afe5 | 2022-02-23 16:07:06 -0600 | [diff] [blame] | 462 | stopofftargets) | 
|  | 463 | stop_off_targets | 
|  | 464 | ;; | 
| Anthony Wilson | 79f697e | 2018-09-13 13:48:52 -0500 | [diff] [blame] | 465 | *) | 
| Anthony Wilson | ea87db4 | 2018-09-26 16:06:38 -0500 | [diff] [blame] | 466 | print_usage_err "Invalid command '$1'" | 
| Anthony Wilson | 79f697e | 2018-09-13 13:48:52 -0500 | [diff] [blame] | 467 | ;; | 
|  | 468 | esac | 
|  | 469 | } | 
|  | 470 |  | 
| Andrew Geissler | d8779cd | 2020-06-11 10:48:40 -0500 | [diff] [blame] | 471 | shiftcnt=0 | 
| Anthony Wilson | ea87db4 | 2018-09-26 16:06:38 -0500 | [diff] [blame] | 472 | for arg in "$@"; do | 
|  | 473 | case $arg in | 
| Anthony Wilson | acf54d0 | 2018-09-20 15:19:28 -0500 | [diff] [blame] | 474 | -w|--wait) | 
|  | 475 | G_WAIT=30 | 
| Andrew Geissler | d8779cd | 2020-06-11 10:48:40 -0500 | [diff] [blame] | 476 | shiftcnt=$((shiftcnt+1)) | 
| Anthony Wilson | acf54d0 | 2018-09-20 15:19:28 -0500 | [diff] [blame] | 477 | continue | 
|  | 478 | ;; | 
| Anthony Wilson | ea87db4 | 2018-09-26 16:06:38 -0500 | [diff] [blame] | 479 | -h|--help) | 
|  | 480 | print_help | 
|  | 481 | ;; | 
| Andrew Jeffery | 60c3ac8 | 2019-10-02 09:29:29 +0930 | [diff] [blame] | 482 | -v|--verbose) | 
|  | 483 | G_VERBOSE=y | 
| Andrew Geissler | d8779cd | 2020-06-11 10:48:40 -0500 | [diff] [blame] | 484 | shiftcnt=$((shiftcnt+1)) | 
| Andrew Jeffery | 60c3ac8 | 2019-10-02 09:29:29 +0930 | [diff] [blame] | 485 | ;; | 
| Potin Lai | 0e044c4 | 2022-05-13 23:42:31 +0800 | [diff] [blame] | 486 | -i=*|--id=*) | 
|  | 487 | G_INSTANCE_ID="${arg#*=}" | 
|  | 488 | shiftcnt=$((shiftcnt+1)) | 
|  | 489 | ;; | 
| Anthony Wilson | ea87db4 | 2018-09-26 16:06:38 -0500 | [diff] [blame] | 490 | -*) | 
|  | 491 | print_usage_err "Unknown option: $arg" | 
|  | 492 | ;; | 
|  | 493 | *) | 
| Anthony Wilson | acf54d0 | 2018-09-20 15:19:28 -0500 | [diff] [blame] | 494 | G_ORIG_CMD=$arg | 
| Andrew Geissler | d8779cd | 2020-06-11 10:48:40 -0500 | [diff] [blame] | 495 | # shift out the optional parameters | 
|  | 496 | shift $shiftcnt | 
| Andrew Geissler | d8c6320 | 2020-05-14 15:06:31 -0500 | [diff] [blame] | 497 | # pass all arguments to handle_cmd in case command takes additional | 
|  | 498 | # parameters | 
|  | 499 | handle_cmd "$@" | 
| Anthony Wilson | ea87db4 | 2018-09-26 16:06:38 -0500 | [diff] [blame] | 500 | break | 
|  | 501 | ;; | 
|  | 502 | esac | 
|  | 503 | done |