forked from Gibtnix/MSIKLM
-
Notifications
You must be signed in to change notification settings - Fork 1
/
autostart.sh
executable file
·57 lines (44 loc) · 1.73 KB
/
autostart.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
#!/bin/sh
# to enable the autostart, execute this script with your configuration of choice (same arguments as used for 'msiklm')
# this script will create a file '/etc/udev/rules.d/99-msiklm.rules' to activate the respective configuration at startup or wakeup
# further, this script can also undo this by calling it with the '--disable' argument
if [ $# -eq 0 ]; then
echo "At least one argument is required"
exit 1
fi
# the rules file
file='/etc/udev/rules.d/99-msiklm.rules'
if [ "$1" != "--disable" ]; then
# activate the autostart
# autostart requires 'msiklm' to be installed
if [ ! -f '/usr/local/bin/msiklm' ]; then
echo "MSI Keyboard Light Manager is not installed, hence no autostart possible"
exit 1
fi
if (sudo /usr/local/bin/msiklm $@); then
echo "Activating MSIKLM autostart..."
sleep 1
#redirection with '>' or '>>' takes place before 'sudo' is applied, hence not directly usable here
run="ACTION==\"add\", ATTRS{idVendor}==\"1770\", ATTRS{idProduct}==\"ff00\", RUN+=\"/usr/local/bin/msiklm "
for arg in "$@"; do
run="$run '$arg'"
done
run="$run\"";
sudo sh -c "echo '# run MSIKLM to configure the keyboard illumination' > $file"
echo $run | sudo tee -a $file > /dev/null
sudo chmod 755 $file
echo "Autostart rules file '$file' created"
else
echo "Input arguments are not valid for 'msiklm', use 'msiklm help' to get an overview of valid arguments"
exit 1
fi
else
# deactivate the autostart
echo "Deactivating MSIKLM autostart..."
sleep 1
if [ -f $file ]; then
echo "Removing autostart rules file..."
sleep 1
sudo rm -v $file
fi
fi