auto-cpufreq/auto-cpufreq-installer

164 lines
3.5 KiB
Plaintext
Raw Normal View History

2020-02-09 14:44:06 +01:00
#!/bin/bash
#
# auto-cpufreq install tool
distro="$(lsb_release -is)"
release="$(lsb_release -rs)"
codename="$(lsb_release -cs)"
separator(){
sep="\n-------------------------------------------------------------------"
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(){
pip3 install psutil click distro power
}
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"
apt install python3-dev python3-pip -y
separator
echo -e "\nInstalling necessary Python packages\n"
pip_pkg_install
separator
echo -e "\ninstalling auto-cpufreq\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
else
yum install python-devel
fi
echo -e "\nInstalling necessary Python packages\n"
pip_pkg_install
separator
echo -e "\ninstalling auto-cpufreq\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 and pip3\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
}
tool_remove(){
cat files.txt | xargs sudo rm -rf && rm -f files.txt
sudo rm -rf /usr/local/share/auto-cpufreq/
separator
echo -e "\nauto-cpufreq successfully removed.\n"
}
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