Vishwanatha Subbanna | a4a4f2d | 2020-10-08 07:14:15 -0500 | [diff] [blame] | 1 | #!/bin/bash |
| 2 | |
| 3 | # This shell script sets all the group D-Bus objects |
| 4 | # in /xyz/openbmc_project/led/groups/ to true or false. |
| 5 | # If the group is in excluded list, then, they are not |
| 6 | # altered |
| 7 | |
| 8 | function usage() |
| 9 | { |
| 10 | echo "led-set-all-groups-asserted.sh [true/false] [optional groups to be excluded]" |
| 11 | echo "Example: led-set-all-groups-asserted.sh true" |
| 12 | echo "Example: led-set-all-groups-asserted.sh false bmc_booted power_on" |
| 13 | return 0; |
| 14 | } |
| 15 | |
| 16 | # We need at least 1 argument |
| 17 | if [ $# -lt 1 ]; then |
| 18 | echo "At least ONE argument needed"; |
| 19 | usage; |
Patrick Williams | 9976a4d | 2021-04-14 10:09:06 -0500 | [diff] [blame] | 20 | exit 1; |
Vishwanatha Subbanna | a4a4f2d | 2020-10-08 07:14:15 -0500 | [diff] [blame] | 21 | fi |
| 22 | |
| 23 | # User passed in argument [true/false] |
| 24 | action=$1 |
| 25 | |
| 26 | # If it is not "true" or "false", exit |
Patrick Williams | 9976a4d | 2021-04-14 10:09:06 -0500 | [diff] [blame] | 27 | if [ "$action" != "true" ] && [ "$action" != "false" ]; then |
Vishwanatha Subbanna | a4a4f2d | 2020-10-08 07:14:15 -0500 | [diff] [blame] | 28 | echo "Bad argument $action passed"; |
| 29 | usage; |
Patrick Williams | 9976a4d | 2021-04-14 10:09:06 -0500 | [diff] [blame] | 30 | exit 1; |
Vishwanatha Subbanna | a4a4f2d | 2020-10-08 07:14:15 -0500 | [diff] [blame] | 31 | fi |
| 32 | |
| 33 | # Get the excluded groups, where $@ is all the agruments passed |
| 34 | index=2; |
| 35 | excluded_groups="" |
| 36 | |
| 37 | for arg in "$@" |
| 38 | do |
Patrick Williams | 6d254ee | 2022-12-06 10:52:53 -0600 | [diff] [blame] | 39 | if [ "$arg" == "$action" ] |
| 40 | then |
| 41 | # Must be true/false |
| 42 | continue |
| 43 | elif [ $index -eq $# ] |
| 44 | then |
| 45 | excluded_groups="${excluded_groups}$arg" |
| 46 | else |
| 47 | excluded_groups="${excluded_groups}$arg|" |
| 48 | fi |
| 49 | ((index+=1)) |
Vishwanatha Subbanna | a4a4f2d | 2020-10-08 07:14:15 -0500 | [diff] [blame] | 50 | done |
| 51 | |
| 52 | # Now, set the LED group to what has been requested |
| 53 | if [ ${#excluded_groups} -eq 0 ] |
| 54 | then |
| 55 | for line in $(busctl tree xyz.openbmc_project.LED.GroupManager | grep -e groups/ | awk -F 'xyz' '{print "/xyz" $2}'); |
| 56 | do |
Patrick Williams | 9976a4d | 2021-04-14 10:09:06 -0500 | [diff] [blame] | 57 | busctl set-property xyz.openbmc_project.LED.GroupManager "$line" xyz.openbmc_project.Led.Group Asserted b "$action"; |
Vishwanatha Subbanna | a4a4f2d | 2020-10-08 07:14:15 -0500 | [diff] [blame] | 58 | done |
| 59 | else |
Patrick Williams | 9976a4d | 2021-04-14 10:09:06 -0500 | [diff] [blame] | 60 | for line in $(busctl tree xyz.openbmc_project.LED.GroupManager | grep -e groups/ | grep -Ev "$excluded_groups" | awk -F 'xyz' '{print "/xyz" $2}'); |
Vishwanatha Subbanna | a4a4f2d | 2020-10-08 07:14:15 -0500 | [diff] [blame] | 61 | do |
Patrick Williams | 9976a4d | 2021-04-14 10:09:06 -0500 | [diff] [blame] | 62 | busctl set-property xyz.openbmc_project.LED.GroupManager "$line" xyz.openbmc_project.Led.Group Asserted b "$action"; |
Vishwanatha Subbanna | a4a4f2d | 2020-10-08 07:14:15 -0500 | [diff] [blame] | 63 | done |
| 64 | fi |
| 65 | |
| 66 | # Return Success |
| 67 | exit 0 |