led-set-all-groups-asserted: fix shellcheck issues
Fix various issues reported by shellcheck:
- Negative numbers are not valid shell return codes.
- Numorous variables needing quotes to prevent wordsplits.
- Prefer (( expr )) over let syntax.
Signed-off-by: Patrick Williams <patrick@stwcx.xyz>
Change-Id: I8f23138e969a49ee4951aedee5fda22cb19ce217
diff --git a/scripts/led-set-all-groups-asserted.sh b/scripts/led-set-all-groups-asserted.sh
index 1375b11..4e8bf91 100755
--- a/scripts/led-set-all-groups-asserted.sh
+++ b/scripts/led-set-all-groups-asserted.sh
@@ -17,17 +17,17 @@
if [ $# -lt 1 ]; then
echo "At least ONE argument needed";
usage;
- exit -1;
+ exit 1;
fi
# User passed in argument [true/false]
action=$1
# If it is not "true" or "false", exit
-if [ $action != "true" ] && [ $action != "false" ]; then
+if [ "$action" != "true" ] && [ "$action" != "false" ]; then
echo "Bad argument $action passed";
usage;
- exit -1;
+ exit 1;
fi
# Get the excluded groups, where $@ is all the agruments passed
@@ -36,7 +36,7 @@
for arg in "$@"
do
- if [ $arg == $action ]
+ if [ "$arg" == "$action" ]
then
# Must be true/false
continue
@@ -46,7 +46,7 @@
else
excluded_groups="${excluded_groups}$arg|"
fi
- let "index+=1"
+ ((index+=1))
done
# Now, set the LED group to what has been requested
@@ -54,12 +54,12 @@
then
for line in $(busctl tree xyz.openbmc_project.LED.GroupManager | grep -e groups/ | awk -F 'xyz' '{print "/xyz" $2}');
do
- busctl set-property xyz.openbmc_project.LED.GroupManager $line xyz.openbmc_project.Led.Group Asserted b $action;
+ busctl set-property xyz.openbmc_project.LED.GroupManager "$line" xyz.openbmc_project.Led.Group Asserted b "$action";
done
else
- for line in $(busctl tree xyz.openbmc_project.LED.GroupManager | grep -e groups/ | grep -Ev $excluded_groups | awk -F 'xyz' '{print "/xyz" $2}');
+ for line in $(busctl tree xyz.openbmc_project.LED.GroupManager | grep -e groups/ | grep -Ev "$excluded_groups" | awk -F 'xyz' '{print "/xyz" $2}');
do
- busctl set-property xyz.openbmc_project.LED.GroupManager $line xyz.openbmc_project.Led.Group Asserted b $action;
+ busctl set-property xyz.openbmc_project.LED.GroupManager "$line" xyz.openbmc_project.Led.Group Asserted b "$action";
done
fi