forked from TamtamHero/fw-fanctrl
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinstall.sh
executable file
·64 lines (55 loc) · 1.92 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
#!/usr/bin/bash
# Copy fanctrl.py to /usr/local/bin and creates a service to run it
# Adapted from https://gist.github.com/ahmedsadman/2c1f118a02190c868b33c9c71835d706
if [ "$EUID" -ne 0 ]
then echo "Please run as root"
exit
fi
SERVICE_NAME="fw-fanctrl"
if [ "$1" = "remove" ]; then
sudo systemctl stop ${SERVICE_NAME//'.service'/} # remove the extension
sudo systemctl disable ${SERVICE_NAME//'.service'/}
rm /usr/local/bin/fanctrl.py
ectool --interface=lpc autofanctrl # restore default fan manager
rm /usr/local/bin/ectool
rm -rf /home/$(logname)/.config/fw-fanctrl
echo "fw-fanctrl has been removed successfully from system"
elif [ -z $1 ]; then
cp ./bin/ectool /usr/local/bin
cp ./fanctrl.py /usr/local/bin
mkdir -p /home/$(logname)/.config/fw-fanctrl
cp config.json /home/$(logname)/.config/fw-fanctrl/
# check if service is active
IS_ACTIVE=$(sudo systemctl is-active $SERVICE_NAME)
if [ "$IS_ACTIVE" == "active" ]; then
# restart the service
echo "Service is running"
echo "Restarting service"
sudo systemctl restart $SERVICE_NAME
echo "Service restarted"
else
# create service file
echo "Creating service file"
sudo cat > /etc/systemd/system/${SERVICE_NAME//'"'/}.service << EOF
[Unit]
Description=FrameWork Fan Controller
After=multi-user.target
[Service]
Type=simple
Restart=always
ExecStart=/usr/bin/python3 /usr/local/bin/fanctrl.py --config /home/$(logname)/.config/fw-fanctrl/config.json --no-log
[Install]
WantedBy=multi-user.target
EOF
# restart daemon, enable and start service
echo "Reloading daemon and enabling service"
sudo systemctl daemon-reload
sudo systemctl enable ${SERVICE_NAME//'.service'/} # remove the extension
sudo systemctl start ${SERVICE_NAME//'.service'/}
echo "Service Started"
fi
else
echo "Unknown command $1"
exit
fi
exit 0