Skip to content

Commit

Permalink
Improve auto-cpufreq installer (#459)
Browse files Browse the repository at this point in the history
* Fixed seperator so that it prints to the lenght of the terminal and uses box lines instead of hyphens

* Replaced multiple echo calls with either a single echo call or a here
doc.
Here docs are more efficient as they only call once, and formatting
doesn't need to be done with escape characters, thus making code more
readable

* Moved header to the center

* Fixed _EOF_ error

* Fixed Indentation problem.
Moved $COLOUMN into seperator function, so if the terminal is resized
while the script is running, a new seperator should be resized as well.

* Added a header function as the "auto-cpufreq installer" heading comes up
multiple times.

Made local variables to allow for neat drawing when resizing the
terminal.

* Fixed spacing issue

* Replaced "=" with seperators and added blank lines

* Added a check for wrapper script. This allows uninstallation without the daemon needing to be installed
  • Loading branch information
abvee committed Dec 5, 2022
1 parent 13edca0 commit 9a1c0ad
Showing 1 changed file with 61 additions and 27 deletions.
88 changes: 61 additions & 27 deletions auto-cpufreq-installer
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,17 @@ then
codename="$(lsb_release -cs)"
fi

sep="\n-------------------------------------------------------------------------------"

# functions

#separator
function separator {
echo -e $sep
local COLOUMNS="`tput cols`"
echo -e "\n"
printf "%0.s─" $(seq $COLOUMNS)
echo -e "\n"
}

# root check
function root_check {
if ((EUID != 0)); then
Expand All @@ -33,6 +36,17 @@ function root_check {
fi
}

function header {
local COLOUMNS="`tput cols`"
MID="$((COLOUMNS / 2))"
HEADER="$1"
printf "%0.s─" $(seq $((MID-(${#HEADER}/2)- 1)))
echo -n " $HEADER "
printf "%0.s─" $(seq $((MID-(${#HEADER}/2)- 1)))
echo -e "\n"
return
}

# python packages install
function setup_venv {
venv_dir=/opt/auto-cpufreq/venv
Expand Down Expand Up @@ -73,32 +87,52 @@ function completed () {

function complete_msg() {
separator
echo -e "\nauto-cpufreq tool successfully installed.\n"
echo -e "For list of options, run:\nauto-cpufreq --help"
cat <<- _EOF_
auto-cpufreq tool successfully installed.
For list of options, run:
auto-cpufreq --help"
_EOF_
separator
}

function manual_install {
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"
cat <<- _EOF_
Didn't detect Debian or RedHat based distro.
To complete installation, you need to:
Install: python3, pip3, python3-setuptools
Install necessary Python packages:
pip3 install psutil click distro power
Run following sequence of lines:
-----
python3 setup.py install --record files.txt
mkdir -p /usr/local/share/auto-cpufreq/
cp -r scripts/ /usr/local/share/auto-cpufreq/
-----
After which tool is installed, for full list of options run:
auto-cpufreq
_EOF_
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"
cat <<- _EOF_
Consider creating a feature request to add support for your distro:
https://github.com/AdnanHodzic/auto-cpufreq/issues/new
Make sure to include following information:
Distribution: $distro
Release: $release
Codename: $codename
_EOF_
separator
}

Expand Down Expand Up @@ -189,7 +223,7 @@ function tool_remove {
done

# run uninstall in case of installed daemon
if [ -f $srv_remove -o -f $srv_remove_old ]; then
if [ -f $srv_remove -o -f $srv_remove_old -o $wrapper_script ]; then
eval $tool_proc_rm
else
separator
Expand Down Expand Up @@ -225,9 +259,9 @@ function tool_remove {
}

function ask_operation {
echo -e "\n-------------------------- auto-cpufreq installer -----------------------------"
echo -e "\nWelcome to auto-cpufreq tool installer."
echo -e "\nOptions:\n"
header "auto-cpufreq installer"
echo -e "Welcome to auto-cpufreq tool installer.
\nOptions:\n"
read -p \
"[I]nstall
[R]emove
Expand Down

0 comments on commit 9a1c0ad

Please sign in to comment.