forked from TamtamHero/fw-fanctrl
-
Notifications
You must be signed in to change notification settings - Fork 0
/
install.sh
executable file
·89 lines (71 loc) · 2.53 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
83
84
85
86
87
88
89
#!/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/fw-fanctrl
ectool --interface=lpc autofanctrl # restore default fan manager
rm /usr/local/bin/ectool
rm -rf /home/$(logname)/.config/fw-fanctrl
rm /usr/lib/systemd/system-sleep/fw-fanctrl-suspend
echo "fw-fanctrl has been removed successfully from system"
elif [ -z $1 ]; then
pip3 install -r requirements.txt
cp ./bin/ectool /usr/local/bin
cp ./fanctrl.py /usr/local/bin/fw-fanctrl
chmod +x /usr/local/bin/fw-fanctrl
chown $(logname):$(logname) /usr/local/bin/fw-fanctrl
mkdir -p /home/$(logname)/.config/fw-fanctrl
cp config.json /home/$(logname)/.config/fw-fanctrl/
# cleaning legacy file
rm /usr/local/bin/fanctrl.py 2> /dev/null || true
# 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 "Stoping service"
sudo systemctl stop $SERVICE_NAME
echo "Service stoped"
fi
# 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/fw-fanctrl --config /home/$(logname)/.config/fw-fanctrl/config.json --no-log
[Install]
WantedBy=multi-user.target
EOF
# create suspend hooks
echo "Creating suspend hooks"
sudo cat > /lib/systemd/system-sleep/fw-fanctrl-suspend << EOF
#!/bin/sh
case \$1 in
pre) runuser -l $(logname) -c "fw-fanctrl sleep" ;;
post) runuser -l $(logname) -c "fw-fanctrl defaultStrategy" ;;
esac
EOF
# make the suspend hook executable
sudo chmod +x /lib/systemd/system-sleep/fw-fanctrl-suspend
# 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"
else
echo "Unknown command $1"
exit
fi
exit 0