blob: 4e8bf91bdb5a280fe04e873b6c1d5ac5fa5b96ad [file] [log] [blame]
Vishwanatha Subbannaa4a4f2d2020-10-08 07:14:15 -05001#!/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
8function 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
17if [ $# -lt 1 ]; then
18 echo "At least ONE argument needed";
19 usage;
Patrick Williams9976a4d2021-04-14 10:09:06 -050020 exit 1;
Vishwanatha Subbannaa4a4f2d2020-10-08 07:14:15 -050021fi
22
23# User passed in argument [true/false]
24action=$1
25
26# If it is not "true" or "false", exit
Patrick Williams9976a4d2021-04-14 10:09:06 -050027if [ "$action" != "true" ] && [ "$action" != "false" ]; then
Vishwanatha Subbannaa4a4f2d2020-10-08 07:14:15 -050028 echo "Bad argument $action passed";
29 usage;
Patrick Williams9976a4d2021-04-14 10:09:06 -050030 exit 1;
Vishwanatha Subbannaa4a4f2d2020-10-08 07:14:15 -050031fi
32
33# Get the excluded groups, where $@ is all the agruments passed
34index=2;
35excluded_groups=""
36
37for arg in "$@"
38do
Patrick Williams9976a4d2021-04-14 10:09:06 -050039 if [ "$arg" == "$action" ]
Vishwanatha Subbannaa4a4f2d2020-10-08 07:14:15 -050040 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
Patrick Williams9976a4d2021-04-14 10:09:06 -050049 ((index+=1))
Vishwanatha Subbannaa4a4f2d2020-10-08 07:14:15 -050050done
51
52# Now, set the LED group to what has been requested
53if [ ${#excluded_groups} -eq 0 ]
54then
55 for line in $(busctl tree xyz.openbmc_project.LED.GroupManager | grep -e groups/ | awk -F 'xyz' '{print "/xyz" $2}');
56 do
Patrick Williams9976a4d2021-04-14 10:09:06 -050057 busctl set-property xyz.openbmc_project.LED.GroupManager "$line" xyz.openbmc_project.Led.Group Asserted b "$action";
Vishwanatha Subbannaa4a4f2d2020-10-08 07:14:15 -050058 done
59else
Patrick Williams9976a4d2021-04-14 10:09:06 -050060 for line in $(busctl tree xyz.openbmc_project.LED.GroupManager | grep -e groups/ | grep -Ev "$excluded_groups" | awk -F 'xyz' '{print "/xyz" $2}');
Vishwanatha Subbannaa4a4f2d2020-10-08 07:14:15 -050061 do
Patrick Williams9976a4d2021-04-14 10:09:06 -050062 busctl set-property xyz.openbmc_project.LED.GroupManager "$line" xyz.openbmc_project.Led.Group Asserted b "$action";
Vishwanatha Subbannaa4a4f2d2020-10-08 07:14:15 -050063 done
64fi
65
66# Return Success
67exit 0