2020-02-09 14:44:06 +01:00
|
|
|
#!/bin/bash
|
|
|
|
#
|
2020-03-06 10:38:12 +01:00
|
|
|
# auto-cpufreq-installer:
|
|
|
|
# auto-cpufreq source code based installer
|
2020-02-09 14:44:06 +01:00
|
|
|
|
2020-08-05 18:06:28 +02:00
|
|
|
SCRIPT_PATH=$(readlink -f "$0")
|
|
|
|
SCRIPT_DIR=$(dirname "${SCRIPT_PATH}")
|
|
|
|
cd "${SCRIPT_DIR}"
|
|
|
|
|
2020-02-09 14:44:06 +01:00
|
|
|
distro="$(lsb_release -is)"
|
|
|
|
release="$(lsb_release -rs)"
|
|
|
|
codename="$(lsb_release -cs)"
|
|
|
|
|
|
|
|
separator(){
|
2020-02-16 13:15:15 +01:00
|
|
|
sep="\n-------------------------------------------------------------------------------"
|
2020-02-09 14:44:06 +01:00
|
|
|
echo -e $sep
|
|
|
|
}
|
|
|
|
|
|
|
|
# root check
|
|
|
|
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
|
|
|
|
pip_pkg_install(){
|
2020-08-14 08:38:44 +02:00
|
|
|
python3 -m pip install -r requirements.txt
|
2020-02-09 14:44:06 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
complete_msg(){
|
|
|
|
echo -e "\nauto-cpufreq tool successfully installed.\n"
|
|
|
|
echo -e "For list of options, run:\nauto-cpufreq"
|
|
|
|
}
|
|
|
|
|
|
|
|
# tool install
|
|
|
|
install(){
|
|
|
|
python3 setup.py install --record files.txt
|
|
|
|
mkdir -p /usr/local/share/auto-cpufreq/
|
|
|
|
cp -r scripts/ /usr/local/share/auto-cpufreq/
|
|
|
|
}
|
|
|
|
|
|
|
|
tool_install(){
|
|
|
|
# Debian
|
|
|
|
if [ -f /etc/debian_version ];
|
|
|
|
then
|
|
|
|
separator
|
|
|
|
echo -e "\nDetected Debian based distribution"
|
|
|
|
separator
|
|
|
|
echo -e "\nSetting up Python environment\n"
|
2021-02-03 09:18:03 +01:00
|
|
|
apt install python3-dev python3-pip python3-setuptools dmidecode -y
|
2020-02-09 14:44:06 +01:00
|
|
|
separator
|
|
|
|
echo -e "\nInstalling necessary Python packages\n"
|
|
|
|
pip_pkg_install
|
|
|
|
separator
|
2020-02-16 13:15:15 +01:00
|
|
|
echo -e "\ninstalling auto-cpufreq tool\n"
|
2020-02-09 14:44:06 +01:00
|
|
|
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
|
2021-02-03 09:18:03 +01:00
|
|
|
yum install platform-python-devel dmidecode
|
2020-02-09 14:44:06 +01:00
|
|
|
else
|
2021-02-03 09:18:03 +01:00
|
|
|
yum install python-devel dmidecode
|
2020-02-09 14:44:06 +01:00
|
|
|
fi
|
|
|
|
echo -e "\nInstalling necessary Python packages\n"
|
|
|
|
pip_pkg_install
|
|
|
|
separator
|
2020-02-16 13:15:15 +01:00
|
|
|
echo -e "\ninstalling auto-cpufreq tool\n"
|
2020-02-09 14:44:06 +01:00
|
|
|
install
|
|
|
|
separator
|
|
|
|
complete_msg
|
|
|
|
separator
|
2020-09-24 07:51:46 +02:00
|
|
|
# Solus
|
|
|
|
elif [ -f /etc/solus-release ];
|
|
|
|
then
|
|
|
|
separator
|
|
|
|
echo -e "\nDetected Solus distribution\n"
|
|
|
|
echo -e "\nSetting up Python environment\n"
|
2021-02-03 09:18:03 +01:00
|
|
|
eopkg install pip python3 python3-devel dmidecode
|
2020-09-24 09:19:42 +02:00
|
|
|
eopkg install -c system.devel
|
2020-09-24 07:51:46 +02:00
|
|
|
echo -e "\nInstalling necessary Python packages\n"
|
|
|
|
pip_pkg_install
|
|
|
|
separator
|
|
|
|
echo -e "\ninstalling auto-cpufreq tool\n"
|
|
|
|
install
|
|
|
|
sed -i 's/ExecStart=\/usr\/local\/bin\/auto-cpufreq/ExecStart=\/usr\/bin\/auto-cpufreq/' /usr/local/share/auto-cpufreq/scripts/auto-cpufreq.service
|
|
|
|
separator
|
|
|
|
complete_msg
|
|
|
|
separator
|
2020-12-07 20:27:34 +01:00
|
|
|
# OpenSUSE
|
|
|
|
elif [ -f /etc/os-release ] && eval "$(cat /etc/os-release)" && [[ $ID == "opensuse"* ]];
|
2020-12-06 18:21:50 +01:00
|
|
|
then
|
|
|
|
separator
|
2020-12-07 20:27:34 +01:00
|
|
|
echo -e "\nDetected an OpenSUSE distribution\n"
|
2020-12-06 18:21:50 +01:00
|
|
|
echo -e "\nSetting up Python environment\n"
|
2020-12-07 20:27:34 +01:00
|
|
|
if [[ $ID == "opensuse-leap" ]];
|
|
|
|
then
|
2021-02-03 09:18:03 +01:00
|
|
|
zypper install -y python3 python3-pip python3-setuptools python3-devel gcc dmidecode
|
2020-12-07 20:27:34 +01:00
|
|
|
else
|
2021-02-03 09:18:03 +01:00
|
|
|
zypper install -y python38 python3-pip python3-setuptools python3-devel gcc dmidecode
|
2020-12-07 20:27:34 +01:00
|
|
|
fi
|
2020-12-06 18:21:50 +01:00
|
|
|
echo -e "\nInstalling necessary Python packages\n"
|
|
|
|
pip_pkg_install
|
|
|
|
separator
|
|
|
|
echo -e "\ninstalling auto-cpufreq tool\n"
|
|
|
|
install
|
|
|
|
separator
|
|
|
|
complete_msg
|
|
|
|
separator
|
2021-01-20 21:32:12 +01:00
|
|
|
# Manjaro/Arch
|
2021-02-03 09:18:03 +01:00
|
|
|
elif [ -f /etc/os-release ] && eval "$(cat /etc/os-release)" && [[ $ID == "manjaro" || $ID == "arch" || $ID == "garuda" ]];
|
2021-01-20 21:32:12 +01:00
|
|
|
then
|
|
|
|
separator
|
|
|
|
echo -e "\nDetected an Arch Linux based distribution\n"
|
|
|
|
echo -e "\nSetting up Python environment\n"
|
2021-02-03 09:18:03 +01:00
|
|
|
pacman -S --noconfirm python python-pip python-setuptools gcc dmidecode
|
2021-01-20 21:32:12 +01:00
|
|
|
echo -e "\nInstalling necessary Python packages\n"
|
|
|
|
pip_pkg_install
|
|
|
|
separator
|
|
|
|
echo -e "\ninstalling auto-cpufreq tool\n"
|
|
|
|
install
|
|
|
|
separator
|
|
|
|
complete_msg
|
|
|
|
separator
|
2020-02-09 14:44:06 +01:00
|
|
|
# Other
|
|
|
|
else
|
|
|
|
separator
|
|
|
|
echo -e "\nDidn't detect Debian or RedHat based distro.\n"
|
|
|
|
echo -e "To complete installation, you need to:"
|
2020-09-20 22:32:05 +02:00
|
|
|
echo -e "Install: python3, pip3, python3-setuptools\n"
|
2020-02-09 14:44:06 +01:00
|
|
|
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:"
|
2020-03-06 10:38:12 +01:00
|
|
|
echo -e "auto-cpufreq"
|
2020-02-09 14:44:06 +01:00
|
|
|
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
|
|
|
|
}
|
|
|
|
|
|
|
|
tool_remove(){
|
2020-02-16 13:15:15 +01:00
|
|
|
|
2020-02-17 10:06:58 +01:00
|
|
|
files="files.txt"
|
|
|
|
share_dir="/usr/local/share/auto-cpufreq/"
|
|
|
|
srv_install="/usr/bin/auto-cpufreq-install"
|
|
|
|
srv_remove="/usr/bin/auto-cpufreq-remove"
|
2021-02-02 21:40:55 +01:00
|
|
|
stats_file="/var/run/auto-cpufreq.stats"
|
2020-02-16 13:15:15 +01:00
|
|
|
tool_proc_rm="auto-cpufreq --remove"
|
|
|
|
|
2020-02-17 10:06:58 +01:00
|
|
|
# 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 ]
|
2020-02-16 13:15:15 +01:00
|
|
|
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
|
2021-02-02 21:40:55 +01:00
|
|
|
[ -f $stats_file ] && rm $stats_file
|
2020-02-09 14:44:06 +01:00
|
|
|
|
|
|
|
separator
|
2020-09-13 20:28:34 +02:00
|
|
|
echo -e "\nauto-cpufreq tool and all its supporting files successfully removed."
|
|
|
|
separator
|
2020-02-09 14:44:06 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
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
|
2020-04-21 22:33:14 +02:00
|
|
|
fi
|