Add a utility script to turn off/on all the indicator LEDs

the script will set Asserted property of all the D-Bus objects
under /xyz/openbmc_project/led/groups/ to true or false

One usecase: IBM has a requirement to clean start each power-on
operation by clearing all indicator LEDs. This script will be
used in the power-on sequence.

Change-Id: I8e14d78f15f97094054a9864d5c4291b6814238b
Signed-off-by: Vishwanatha Subbanna <vishwa@linux.vnet.ibm.com>
diff --git a/scripts/led-set-all-groups-asserted.sh b/scripts/led-set-all-groups-asserted.sh
new file mode 100755
index 0000000..1375b11
--- /dev/null
+++ b/scripts/led-set-all-groups-asserted.sh
@@ -0,0 +1,67 @@
+#!/bin/bash
+
+# This shell script sets all the group D-Bus objects
+# in /xyz/openbmc_project/led/groups/ to true or false.
+# If the group is in excluded list, then, they are not
+# altered
+
+function usage()
+{
+    echo "led-set-all-groups-asserted.sh [true/false] [optional groups to be excluded]"
+    echo "Example: led-set-all-groups-asserted.sh true"
+    echo "Example: led-set-all-groups-asserted.sh false bmc_booted power_on"
+    return 0;
+}
+
+# We need at least 1 argument
+if [ $# -lt 1 ]; then
+    echo "At least ONE argument needed";
+    usage;
+    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
+    echo "Bad argument $action passed";
+    usage;
+    exit -1;
+fi
+
+# Get the excluded groups, where $@ is all the agruments passed
+index=2;
+excluded_groups=""
+
+for arg in "$@"
+do
+   if [ $arg == $action ]
+   then
+       # Must be true/false
+       continue
+   elif [ $index -eq $# ]
+   then
+       excluded_groups="${excluded_groups}$arg"
+   else
+       excluded_groups="${excluded_groups}$arg|"
+   fi
+   let "index+=1"
+done
+
+# Now, set the LED group to what has been requested
+if [ ${#excluded_groups} -eq 0 ]
+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;
+    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}');
+    do
+        busctl set-property xyz.openbmc_project.LED.GroupManager $line xyz.openbmc_project.Led.Group Asserted b $action;
+    done
+fi
+
+# Return Success
+exit 0