-
Notifications
You must be signed in to change notification settings - Fork 167
/
install.sh
executable file
·76 lines (66 loc) · 2.17 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
#!/bin/sh
LEGACY_INSTALL_DIR="/opt/lenovo_fix"
INSTALL_DIR="/opt/throttled"
INIT="$(ps --no-headers -o comm 1)"
if [ "$INIT" = "systemd" ]; then
systemctl stop lenovo_fix.service >/dev/null 2>&1
systemctl stop throttled.service >/dev/null 2>&1
elif [ "$INIT" = "runit" ]; then
sv down lenovo_fix >/dev/null 2>&1
sv down throttled >/dev/null 2>&1
elif [ "$INIT" = "init" ]; then
rc-service lenovo_fix stop >/dev/null 2>&1
rc-service throttled stop >/dev/null 2>&1
fi
mv "$LEGACY_INSTALL_DIR" "$INSTALL_DIR" >/dev/null 2>&1
rm -f "$INSTALL_DIR/lenovo_fix.py" >/dev/null 2>&1
mkdir -p "$INSTALL_DIR" >/dev/null 2>&1
set -e
cd "$(dirname "$0")"
if [ -f /etc/lenovo_fix.conf ]; then
echo "Updating config filename"
mv /etc/lenovo_fix.conf /etc/throttled.conf
fi
echo "Copying config file"
if [ ! -f /etc/throttled.conf ]; then
cp etc/throttled.conf /etc
else
echo "Config file already exists, skipping"
fi
if [ "$INIT" = "systemd" ]; then
echo "Copying systemd service file"
cp systemd/throttled.service /etc/systemd/system
rm -f /etc/systemd/system/lenovo_fix.service >/dev/null 2>&1
elif [ "$INIT" = "runit" ]; then
echo "Copying runit service file"
cp -R runit/throttled /etc/sv/
rm -r /etc/sv/lenovo_fix >/dev/null 2>&1
elif [ "$INIT" = "init" ]; then
echo "Copying OpenRC service file"
cp -R openrc/throttled /etc/init.d/throttled
rm -f /etc/init.d/lenovo_fix >/dev/null 2>&1
chmod 755 /etc/init.d/throttled
fi
echo "Copying core files"
cp requirements.txt throttled.py mmio.py "$INSTALL_DIR"
echo "Building virtualenv"
cd "$INSTALL_DIR"
/usr/bin/python3 -m venv venv
. venv/bin/activate
pip install wheel
pip install -r requirements.txt
if [ "$INIT" = "systemd" ]; then
echo "Enabling and starting systemd service"
systemctl daemon-reload
systemctl enable throttled.service
systemctl restart throttled.service
elif [ "$INIT" = "runit" ]; then
echo "Enabling and starting runit service"
ln -sv /etc/sv/throttled /var/service/
sv up throttled
elif [ "$INIT" = "init" ]; then
echo "Enabling and starting OpenRC service"
rc-update add throttled default
rc-service throttled start
fi
echo "All done."