Fix service unit file on Arch Linux (#190)

* Fix service unit file on arch.

* Remove duplication in installer script.

* Improve formatting of installer script bash code.
This commit is contained in:
Marco Vermeulen 2021-03-14 18:23:06 +00:00 committed by GitHub
parent f870049d91
commit e87a32f6c9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 106 additions and 114 deletions

View File

@ -11,15 +11,14 @@ distro="$(lsb_release -is)"
release="$(lsb_release -rs)" release="$(lsb_release -rs)"
codename="$(lsb_release -cs)" codename="$(lsb_release -cs)"
separator(){ function separator {
sep="\n-------------------------------------------------------------------------------" sep="\n-------------------------------------------------------------------------------"
echo -e $sep echo -e $sep
} }
# root check # root check
root_check(){ function root_check {
if (( $EUID != 0 )); if (($EUID != 0)); then
then
separator separator
echo -e "\nMust be run as root (i.e: 'sudo $0')." echo -e "\nMust be run as root (i.e: 'sudo $0')."
separator separator
@ -28,26 +27,29 @@ fi
} }
# python packages install # python packages install
pip_pkg_install(){ function pip_pkg_install {
python3 -m pip install -r requirements.txt python3 -m pip install -r requirements.txt
} }
complete_msg(){ function complete_msg {
echo -e "\nauto-cpufreq tool successfully installed.\n" echo -e "\nauto-cpufreq tool successfully installed.\n"
echo -e "For list of options, run:\nauto-cpufreq" echo -e "For list of options, run:\nauto-cpufreq"
} }
# tool install # tool install
install(){ function install {
python3 setup.py install --record files.txt python3 setup.py install --record files.txt
mkdir -p /usr/local/share/auto-cpufreq/ mkdir -p /usr/local/share/auto-cpufreq/
cp -r scripts/ /usr/local/share/auto-cpufreq/ cp -r scripts/ /usr/local/share/auto-cpufreq/
} }
tool_install(){ 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 # Debian
if [ -f /etc/debian_version ]; if [ -f /etc/debian_version ]; then
then
separator separator
echo -e "\nDetected Debian based distribution" echo -e "\nDetected Debian based distribution"
separator separator
@ -63,14 +65,12 @@ then
complete_msg complete_msg
separator separator
# RedHat # RedHat
elif [ -f /etc/redhat-release ]; elif [ -f /etc/redhat-release ]; then
then
separator separator
echo -e "\nDetected RedHat based distribution\n" echo -e "\nDetected RedHat based distribution\n"
echo -e "\nSetting up Python environment\n" echo -e "\nSetting up Python environment\n"
# CentOS exception # CentOS exception
if [ -f /etc/centos-release ]; if [ -f /etc/centos-release ]; then
then
yum install platform-python-devel dmidecode yum install platform-python-devel dmidecode
else else
yum install python-devel dmidecode yum install python-devel dmidecode
@ -84,8 +84,7 @@ then
complete_msg complete_msg
separator separator
# Solus # Solus
elif [ -f /etc/solus-release ]; elif [ -f /etc/solus-release ]; then
then
separator separator
echo -e "\nDetected Solus distribution\n" echo -e "\nDetected Solus distribution\n"
echo -e "\nSetting up Python environment\n" echo -e "\nSetting up Python environment\n"
@ -96,18 +95,16 @@ then
separator separator
echo -e "\ninstalling auto-cpufreq tool\n" echo -e "\ninstalling auto-cpufreq tool\n"
install install
sed -i 's/ExecStart=\/usr\/local\/bin\/auto-cpufreq/ExecStart=\/usr\/bin\/auto-cpufreq/' /usr/local/share/auto-cpufreq/scripts/auto-cpufreq.service update_service_file
separator separator
complete_msg complete_msg
separator separator
# OpenSUSE # OpenSUSE
elif [ -f /etc/os-release ] && eval "$(cat /etc/os-release)" && [[ $ID == "opensuse"* ]]; elif [ -f /etc/os-release ] && eval "$(cat /etc/os-release)" && [[ $ID == "opensuse"* ]]; then
then
separator separator
echo -e "\nDetected an OpenSUSE distribution\n" echo -e "\nDetected an OpenSUSE distribution\n"
echo -e "\nSetting up Python environment\n" echo -e "\nSetting up Python environment\n"
if [[ $ID == "opensuse-leap" ]]; if [[ $ID == "opensuse-leap" ]]; then
then
zypper install -y python3 python3-pip python3-setuptools python3-devel gcc dmidecode zypper install -y python3 python3-pip python3-setuptools python3-devel gcc dmidecode
else else
zypper install -y python38 python3-pip python3-setuptools python3-devel gcc dmidecode zypper install -y python38 python3-pip python3-setuptools python3-devel gcc dmidecode
@ -121,8 +118,7 @@ then
complete_msg complete_msg
separator separator
# Manjaro/Arch # Manjaro/Arch
elif [ -f /etc/os-release ] && eval "$(cat /etc/os-release)" && [[ $ID == "manjaro" || $ID == "arch" || $ID == "garuda" ]]; elif [ -f /etc/os-release ] && eval "$(cat /etc/os-release)" && [[ $ID == "manjaro" || $ID == "arch" || $ID == "garuda" ]]; then
then
separator separator
echo -e "\nDetected an Arch Linux based distribution\n" echo -e "\nDetected an Arch Linux based distribution\n"
echo -e "\nSetting up Python environment\n" echo -e "\nSetting up Python environment\n"
@ -132,6 +128,7 @@ then
separator separator
echo -e "\ninstalling auto-cpufreq tool\n" echo -e "\ninstalling auto-cpufreq tool\n"
install install
update_service_file
separator separator
complete_msg complete_msg
separator separator
@ -162,7 +159,7 @@ else
fi fi
} }
tool_remove(){ function tool_remove {
files="files.txt" files="files.txt"
share_dir="/usr/local/share/auto-cpufreq/" share_dir="/usr/local/share/auto-cpufreq/"
@ -180,8 +177,7 @@ for pid in "${tool_arg_pids[@]}"; do
done done
# run uninstall in case of installed daemon # run uninstall in case of installed daemon
if [ -f $srv_remove ] if [ -f $srv_remove ]; then
then
eval $tool_proc_rm eval $tool_proc_rm
fi fi
@ -199,7 +195,7 @@ echo -e "\nauto-cpufreq tool and all its supporting files successfully removed."
separator separator
} }
ask_operation(){ function ask_operation {
echo -e "\n-------------------------- auto-cpufreq installer -----------------------------" echo -e "\n-------------------------- auto-cpufreq installer -----------------------------"
echo -e "\nWelcome to auto-cpufreq tool installer." echo -e "\nWelcome to auto-cpufreq tool installer."
echo -e "\nOptions:\n" echo -e "\nOptions:\n"
@ -212,8 +208,7 @@ Select a key: [i/r/q]: " answer
root_check root_check
if [[ -z "${1}" ]]; if [[ -z "${1}" ]]; then
then
ask_operation ask_operation
else else
case "${1}" in case "${1}" in
@ -229,16 +224,13 @@ else
esac esac
fi fi
if [[ $answer == [Ii] ]]; if [[ $answer == [Ii] ]]; then
then
root_check root_check
tool_install tool_install
elif [[ $answer == [Rr] ]]; elif [[ $answer == [Rr] ]]; then
then
root_check root_check
tool_remove tool_remove
elif [[ $answer == [Qq] ]]; elif [[ $answer == [Qq] ]]; then
then
separator separator
echo "" echo ""
exit 0 exit 0

View File

@ -5,6 +5,6 @@ After=network.target network-online.target
[Service] [Service]
Type=simple Type=simple
User=root User=root
ExecStart=/usr/bin/auto-cpufreq --daemon ExecStart=/usr/local/bin/auto-cpufreq --daemon
[Install] [Install]
WantedBy=multi-user.target WantedBy=multi-user.target