Skip to content

Commit

Permalink
[energizta.sh] Test for commands and display error if they are not av…
Browse files Browse the repository at this point in the history
…ailable
  • Loading branch information
Guillaume Subiron committed Mar 3, 2023
1 parent 78a2b6b commit 8546c52
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions energizta/energizta.sh
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,9 @@ if [ -n "$USER" ] && [ "$USER" != "root" ] && ! $FORCE_WITHOUT_ROOT; then
fi

# This command can hangs indefinitely so we have to test it with timeout
if ! command -v ipmi-dcmi > /dev/null; then
>&2 echo "You should try to install ipmi-dcmi (package freeipmi-tools)"
fi
dcmi=$(timeout 1 /usr/sbin/ipmi-dcmi --get-system-power-statistics 2>/dev/null)
DCMI=false
if echo "$dcmi" | grep -q 'Active$'; then
Expand All @@ -122,6 +125,9 @@ fi

if ! $DCMI && [ -z "$IPMI_SENSOR_ID" ]; then
debug "ipmi-dcmi does not work, trying ipmitool sensor"
if ! command -v ipmitool > /dev/null; then
>&2 echo "You should try to install ipmitool"
fi
IPMI_SENSOR_ID=$(timeout 10 ipmitool sensor 2>/dev/null | grep Watt | tail -n 1 | sed 's/ .*//g')
if [ -n "$IPMI_SENSOR_ID" ]; then
debug "Found IPMI sensor id $IPMI_SENSOR_ID"
Expand Down

0 comments on commit 8546c52

Please sign in to comment.