-
Notifications
You must be signed in to change notification settings - Fork 0
/
install.sh
82 lines (65 loc) · 2.51 KB
/
install.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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
#!/bin/bash
# Checking if the script is runned as root (via sudo or other)
if [[ $(id -u) != 0 ]]; then
echo "Please run the installation script as root (using sudo for example)"
exit 1
fi
cp power_supply_mode_switcher.service /etc/systemd/system/
mkdir -p /var/log/power_supply_mode_switcher-driver
mkdir -p /usr/share/power_supply_mode_switcher-driver/conf
install enable_bat_or_ac_mode.sh /usr/share/power_supply_mode_switcher-driver/
AC_MODE_FILE='/usr/share/power_supply_mode_switcher-driver/conf/ac_mode.sh'
BAT_MODE_FILE='/usr/share/power_supply_mode_switcher-driver/conf/bat_mode.sh'
AC_MODE_CONFIG_DIFF=""
if test -f "$AC_MODE_FILE"; then
AC_MODE_CONFIG_DIFF=$(diff <(grep -v '^#' conf/ac_mode.sh) <(grep -v '^#' $AC_MODE_FILE))
fi
BAT_MODE_CONFIG_DIFF=""
if test -f "$BAT_MODE_FILE"; then
BAT_MODE_CONFIG_DIFF=$(diff <(grep -v '^#' conf/bat_mode.sh) <(grep -v '^#' $BAT_MODE_FILE))
fi
if [ "$AC_MODE_CONFIG_DIFF" != "" ] || [ "$BAT_MODE_CONFIG_DIFF" != "" ]
then
read -r -p "Overwrite existing config scripts for each mode [y/N]" response
case "$response" in [yY][eE][sS]|[yY])
echo "Used default config files. Config may be edited here /usr/share/power_supply_mode_switcher-driver/conf"
cp -r conf /usr/share/power_supply_mode_switcher-driver
;;
*)
echo "Used last config files."
;;
esac
else
echo "Used default config files. Config may be edited here /usr/share/power_supply_mode_switcher-driver/conf"
cp -r conf /usr/share/power_supply_mode_switcher-driver
fi
chmod +x /usr/share/power_supply_mode_switcher-driver/conf/ac_mode.sh
chmod +x /usr/share/power_supply_mode_switcher-driver/conf/bat_mode.sh
echo "Installing udev rules to /usr/lib/udev/rules.d/"
cp udev/80-power-supply-mode-switcher.rules /usr/lib/udev/rules.d/
echo "Added 80-power-supply-mode-switcher.rules"
udevadm control --reload-rules
echo "Reloaded udev rules"
systemctl enable power_supply_mode_switcher
if [[ $? != 0 ]]; then
echo "Something went wrong when enabling the power_supply_mode_switcher.service"
exit 1
else
echo "Power supply mode switcher driver service enabled"
fi
systemctl restart power_supply_mode_switcher
if [[ $? != 0 ]]; then
echo "Something went wrong when enabling the power_supply_mode_switcher.service"
exit 1
else
echo "Power supply mode switcher driver service started"
fi
read -r -p "Is required reboot. Reboot now? [y/N]" response
case "$response" in [yY][eE][sS]|[yY])
reboot
;;
*)
;;
esac
echo "Install finished"
exit 0