forked from AdnanHodzic/auto-cpufreq
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathauto-cpufreq-installer
executable file
·257 lines (236 loc) · 7 KB
/
auto-cpufreq-installer
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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
#!/bin/bash
#
# auto-cpufreq-installer:
# auto-cpufreq source code based installer
SCRIPT_PATH=$(readlink -f "$0")
SCRIPT_DIR=$(dirname "${SCRIPT_PATH}")
cd "${SCRIPT_DIR}"
distro="$(lsb_release -is)"
release="$(lsb_release -rs)"
codename="$(lsb_release -cs)"
function separator {
sep="\n-------------------------------------------------------------------------------"
echo -e $sep
}
# root check
function root_check {
if (($EUID != 0)); then
separator
echo -e "\nMust be run as root (i.e: 'sudo $0')."
separator
exit 1
fi
}
# python packages install
function pip_pkg_install {
python3 -m pip install -r requirements.txt
}
function complete_msg {
echo -e "\nauto-cpufreq tool successfully installed.\n"
echo -e "For list of options, run:\nauto-cpufreq"
}
# tool install
function install {
python3 setup.py install --record files.txt
mkdir -p /usr/local/share/auto-cpufreq/
cp -r scripts/ /usr/local/share/auto-cpufreq/
}
function update_service_file {
sed -i 's|ExecStart=/usr/local/bin/auto-cpufreq|ExecStart=/usr/bin/auto-cpufreq|' /usr/local/share/auto-cpufreq/scripts/auto-cpufreq.service
}
function tool_install {
# Debian
if [ -f /etc/debian_version ]; then
separator
echo -e "\nDetected Debian based distribution"
separator
echo -e "\nSetting up Python environment\n"
apt install python3-dev python3-pip python3-setuptools dmidecode -y
separator
echo -e "\nInstalling necessary Python packages\n"
pip_pkg_install
separator
echo -e "\ninstalling auto-cpufreq tool\n"
install
separator
complete_msg
separator
# RedHat
elif [ -f /etc/redhat-release ]; then
separator
echo -e "\nDetected RedHat based distribution\n"
echo -e "\nSetting up Python environment\n"
# CentOS exception
if [ -f /etc/centos-release ]; then
yum install platform-python-devel dmidecode
else
yum install python-devel dmidecode
fi
echo -e "\nInstalling necessary Python packages\n"
pip_pkg_install
separator
echo -e "\ninstalling auto-cpufreq tool\n"
install
separator
complete_msg
separator
# Solus
elif [ -f /etc/solus-release ]; then
separator
echo -e "\nDetected Solus distribution\n"
echo -e "\nSetting up Python environment\n"
eopkg install pip python3 python3-devel dmidecode
eopkg install -c system.devel
echo -e "\nInstalling necessary Python packages\n"
pip_pkg_install
separator
echo -e "\ninstalling auto-cpufreq tool\n"
install
update_service_file
separator
complete_msg
separator
# OpenSUSE
elif [ -f /etc/os-release ] && eval "$(cat /etc/os-release)" && [[ $ID == "opensuse"* ]]; then
separator
echo -e "\nDetected an OpenSUSE distribution\n"
echo -e "\nSetting up Python environment\n"
if [[ $ID == "opensuse-leap" ]]; then
zypper install -y python3 python3-pip python3-setuptools python3-devel gcc dmidecode
else
zypper install -y python38 python3-pip python3-setuptools python3-devel gcc dmidecode
fi
echo -e "\nInstalling necessary Python packages\n"
pip_pkg_install
separator
echo -e "\ninstalling auto-cpufreq tool\n"
install
separator
complete_msg
separator
# Manjaro/Arch
elif [ -f /etc/os-release ] && eval "$(cat /etc/os-release)" && [[ $ID == "manjaro" || $ID == "arch" || $ID == "endeavouros" || $ID == "garuda" ]]; then
separator
echo -e "\nDetected an Arch Linux based distribution\n"
echo -e "\nSetting up Python environment\n"
pacman -S --noconfirm --needed python python-pip python-setuptools base-devel dmidecode
echo -e "\nInstalling necessary Python packages\n"
pip_pkg_install
separator
echo -e "\ninstalling auto-cpufreq tool\n"
install
update_service_file
separator
complete_msg
separator
# Void Linux
elif [ -f /etc/os-release ] && eval "$(cat /etc/os-release)" && [[ $ID == "void"* ]]; then
separator
echo -e "\nDetected Void Linux ditribution\n"
separator
echo -e "\nSetting up Python environment\n"
xbps-install -Suy python3 python3-pip python3-devel python3-setuptools base-devel dmidecode
separator
echo -e "\nInstalling necessary Python packages\n"
pip_pkg_install
separator
echo -e "\ninstalling auto-cpufreq tool\n"
install
separator
complete_msg
separator
# Other
else
separator
echo -e "\nDidn't detect Debian or RedHat based distro.\n"
echo -e "To complete installation, you need to:"
echo -e "Install: python3, pip3, python3-setuptools\n"
echo -e "Install necessary Python packages:"
echo -e "pip3 install psutil click distro power"
echo -e "\nRun following sequence of lines:"
echo -e "\n-----"
echo -e "\npython3 setup.py install --record files.txt"
echo -e "mkdir -p /usr/local/share/auto-cpufreq/"
echo -e "cp -r scripts/ /usr/local/share/auto-cpufreq/"
echo -e "\n-----"
echo -e "\nAfter which tool is installed, for full list of options run:"
echo -e "auto-cpufreq"
separator
echo -e "\nConsider creating a feature request to add support for your distro:"
echo -e "https://github.com/AdnanHodzic/auto-cpufreq/issues/new"
echo -e "\nMake sure to include following information:\n"
echo -e "Distribution: $distro"
echo -e "Release: $release"
echo -e "Codename: $codename"
separator
fi
}
function tool_remove {
files="files.txt"
share_dir="/usr/local/share/auto-cpufreq/"
srv_install="/usr/bin/auto-cpufreq-install"
srv_remove="/usr/bin/auto-cpufreq-remove"
stats_file="/var/run/auto-cpufreq.stats"
tool_proc_rm="auto-cpufreq --remove"
# stop any running auto-cpufreq argument (daemon/live/monitor)
tool_arg_pids=($(pgrep -f "auto-cpufreq --"))
for pid in "${tool_arg_pids[@]}"; do
if [[ $tool_arg_pids != $$ ]]; then
kill "$tool_arg_pids"
fi
done
# run uninstall in case of installed daemon
if [ -f $srv_remove ]; then
eval $tool_proc_rm
fi
# remove auto-cpufreq and all its supporting files
[ -f $files ] && cat $files | xargs sudo rm -rf && rm -f $files
[ -f $share_dir ] && rm -rf $share_dir
# files cleanup
[ -f $srv_install ] && rm $srv_install
[ -f $srv_remove ] && rm $srv_remove
[ -f $stats_file ] && rm $stats_file
separator
echo -e "\nauto-cpufreq tool and all its supporting files successfully removed."
separator
}
function ask_operation {
echo -e "\n-------------------------- auto-cpufreq installer -----------------------------"
echo -e "\nWelcome to auto-cpufreq tool installer."
echo -e "\nOptions:\n"
read -p "[I]nstall
[R]emove
[Q]uit
Select a key: [i/r/q]: " answer
}
root_check
if [[ -z "${1}" ]]; then
ask_operation
else
case "${1}" in
"--install")
answer="i"
;;
"--remove")
answer="r"
;;
*)
answer="n"
;;
esac
fi
if [[ $answer == [Ii] ]]; then
root_check
tool_install
elif [[ $answer == [Rr] ]]; then
root_check
tool_remove
elif [[ $answer == [Qq] ]]; then
separator
echo ""
exit 0
else
separator
echo -e "\nUnknown key, aborting ...\n"
exit 1
fi