From f488132f1ef0c469a734578c87648c8cf643e1f7 Mon Sep 17 00:00:00 2001 From: abvee Date: Thu, 24 Nov 2022 13:31:37 +0530 Subject: [PATCH 1/9] Fixed seperator so that it prints to the lenght of the terminal and uses box lines instead of hyphens --- auto-cpufreq-installer | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/auto-cpufreq-installer b/auto-cpufreq-installer index 6fc9d5bc..fd2a4090 100755 --- a/auto-cpufreq-installer +++ b/auto-cpufreq-installer @@ -15,14 +15,18 @@ then codename="$(lsb_release -cs)" fi -sep="\n-------------------------------------------------------------------------------" # functions #separator +COLOUMNS="`tput cols`" function separator { - echo -e $sep + + echo -e "\n" + printf "%0.s─" $(seq $COLOUMNS) + echo -e "\n" } + # root check function root_check { if ((EUID != 0)); then From 384c153e0272dbf4a78b76e349cf15577a145398 Mon Sep 17 00:00:00 2001 From: abvee Date: Thu, 24 Nov 2022 14:44:02 +0530 Subject: [PATCH 2/9] 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 --- auto-cpufreq-installer | 61 ++++++++++++++++++++++++++---------------- 1 file changed, 38 insertions(+), 23 deletions(-) diff --git a/auto-cpufreq-installer b/auto-cpufreq-installer index fd2a4090..c0850f6c 100755 --- a/auto-cpufreq-installer +++ b/auto-cpufreq-installer @@ -77,32 +77,47 @@ function completed () { function complete_msg() { separator - echo -e "\nauto-cpufreq tool successfully installed.\n" - echo -e "For list of options, run:\nauto-cpufreq --help" + echo -e "\nauto-cpufreq tool successfully installed.\n + For list of options, run:\nauto-cpufreq --help" 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 } @@ -211,8 +226,8 @@ function tool_remove { function ask_operation { echo -e "\n-------------------------- auto-cpufreq installer -----------------------------" - echo -e "\nWelcome to auto-cpufreq tool installer." - echo -e "\nOptions:\n" + echo -e "\nWelcome to auto-cpufreq tool installer. + \nOptions:\n" read -p \ "[I]nstall [R]emove From fbacd71768ad9177a240e8f87a28f9b05572c2a8 Mon Sep 17 00:00:00 2001 From: abvee Date: Thu, 24 Nov 2022 15:06:46 +0530 Subject: [PATCH 3/9] Moved header to the center --- auto-cpufreq-installer | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/auto-cpufreq-installer b/auto-cpufreq-installer index c0850f6c..bd5696fe 100755 --- a/auto-cpufreq-installer +++ b/auto-cpufreq-installer @@ -225,7 +225,11 @@ function tool_remove { } function ask_operation { - echo -e "\n-------------------------- auto-cpufreq installer -----------------------------" + MID="$((COLOUMNS / 2))" + HEADER=" auto-cpufreq installer " + printf "%0.s-" $(seq $((MID-(${#HEADER}/2)))) + echo -n $HEADER + printf "%0.s-" $(seq $((MID-(${#HEADER}/2)))) echo -e "\nWelcome to auto-cpufreq tool installer. \nOptions:\n" read -p \ From 66080dace8b264e738e10e63ac1292abf9894b10 Mon Sep 17 00:00:00 2001 From: abvee Date: Thu, 24 Nov 2022 15:12:28 +0530 Subject: [PATCH 4/9] Fixed _EOF_ error --- auto-cpufreq-installer | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/auto-cpufreq-installer b/auto-cpufreq-installer index bd5696fe..d85aad5e 100755 --- a/auto-cpufreq-installer +++ b/auto-cpufreq-installer @@ -105,7 +105,7 @@ function manual_install { After which tool is installed, for full list of options run: auto-cpufreq - _EOF_ +_EOF_ separator cat <<- _EOF_ @@ -117,7 +117,7 @@ function manual_install { Distribution: $distro Release: $release Codename: $codename - _EOF_ +_EOF_ separator } From fd0f2b7fdfab4d3c12344e286cb8a770801d4cba Mon Sep 17 00:00:00 2001 From: abvee Date: Fri, 25 Nov 2022 12:47:04 +0530 Subject: [PATCH 5/9] 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. --- auto-cpufreq-installer | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/auto-cpufreq-installer b/auto-cpufreq-installer index d85aad5e..599d5eb1 100755 --- a/auto-cpufreq-installer +++ b/auto-cpufreq-installer @@ -19,9 +19,8 @@ fi # functions #separator -COLOUMNS="`tput cols`" function separator { - + COLOUMNS="`tput cols`" echo -e "\n" printf "%0.s─" $(seq $COLOUMNS) echo -e "\n" @@ -77,8 +76,13 @@ function completed () { function complete_msg() { separator - echo -e "\nauto-cpufreq tool successfully installed.\n - 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 } From add60e5bb4c997421024309bc63b52375d3a278e Mon Sep 17 00:00:00 2001 From: abvee Date: Fri, 25 Nov 2022 14:08:10 +0530 Subject: [PATCH 6/9] 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. --- auto-cpufreq-installer | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/auto-cpufreq-installer b/auto-cpufreq-installer index 599d5eb1..3ad4a4a0 100755 --- a/auto-cpufreq-installer +++ b/auto-cpufreq-installer @@ -20,7 +20,7 @@ fi #separator function separator { - COLOUMNS="`tput cols`" + local COLOUMNS="`tput cols`" echo -e "\n" printf "%0.s─" $(seq $COLOUMNS) echo -e "\n" @@ -36,6 +36,16 @@ function root_check { fi } +function header { + local COLOUMNS="`tput cols`" + MID="$((COLOUMNS / 2))" + HEADER="$1" + printf "%0.s=" $(seq $((MID-(${#HEADER}/2)))) + echo -n $HEADER + printf "%0.s=" $(seq $((MID-(${#HEADER}/2)))) + return +} + # python packages install function setup_venv { venv_dir=/opt/auto-cpufreq/venv @@ -229,11 +239,7 @@ function tool_remove { } function ask_operation { - MID="$((COLOUMNS / 2))" - HEADER=" auto-cpufreq installer " - printf "%0.s-" $(seq $((MID-(${#HEADER}/2)))) - echo -n $HEADER - printf "%0.s-" $(seq $((MID-(${#HEADER}/2)))) + header " auto-cpufreq installer " echo -e "\nWelcome to auto-cpufreq tool installer. \nOptions:\n" read -p \ From 2fa0e99410001d58eb0693b8cbd6f275bf851f5f Mon Sep 17 00:00:00 2001 From: abvee Date: Fri, 25 Nov 2022 17:50:32 +0530 Subject: [PATCH 7/9] Fixed spacing issue --- auto-cpufreq-installer | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/auto-cpufreq-installer b/auto-cpufreq-installer index 3ad4a4a0..022c41e0 100755 --- a/auto-cpufreq-installer +++ b/auto-cpufreq-installer @@ -40,9 +40,9 @@ function header { local COLOUMNS="`tput cols`" MID="$((COLOUMNS / 2))" HEADER="$1" - printf "%0.s=" $(seq $((MID-(${#HEADER}/2)))) - echo -n $HEADER - printf "%0.s=" $(seq $((MID-(${#HEADER}/2)))) + printf "%0.s=" $(seq $((MID-(${#HEADER}/2)- 1))) + echo -n " $HEADER " + printf "%0.s=" $(seq $((MID-(${#HEADER}/2)- 1))) return } @@ -239,7 +239,7 @@ function tool_remove { } function ask_operation { - header " auto-cpufreq installer " + header "auto-cpufreq installer" echo -e "\nWelcome to auto-cpufreq tool installer. \nOptions:\n" read -p \ From 316eefa71a8a21956700d76e1d9c2cbd75617e3a Mon Sep 17 00:00:00 2001 From: abvee Date: Sat, 26 Nov 2022 08:44:37 +0530 Subject: [PATCH 8/9] Replaced "=" with seperators and added blank lines --- auto-cpufreq-installer | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/auto-cpufreq-installer b/auto-cpufreq-installer index 022c41e0..96d926de 100755 --- a/auto-cpufreq-installer +++ b/auto-cpufreq-installer @@ -40,9 +40,10 @@ function header { local COLOUMNS="`tput cols`" MID="$((COLOUMNS / 2))" HEADER="$1" - printf "%0.s=" $(seq $((MID-(${#HEADER}/2)- 1))) + printf "%0.s─" $(seq $((MID-(${#HEADER}/2)- 1))) echo -n " $HEADER " - printf "%0.s=" $(seq $((MID-(${#HEADER}/2)- 1))) + printf "%0.s─" $(seq $((MID-(${#HEADER}/2)- 1))) + echo -e "\n" return } @@ -240,7 +241,7 @@ function tool_remove { function ask_operation { header "auto-cpufreq installer" - echo -e "\nWelcome to auto-cpufreq tool installer. + echo -e "Welcome to auto-cpufreq tool installer. \nOptions:\n" read -p \ "[I]nstall From 0fe8638295658c4dae08b97775e6f720ad271bcb Mon Sep 17 00:00:00 2001 From: abvee Date: Thu, 1 Dec 2022 19:51:39 +0530 Subject: [PATCH 9/9] Added a check for wrapper script. This allows uninstallation without the daemon needing to be installed --- auto-cpufreq-installer | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/auto-cpufreq-installer b/auto-cpufreq-installer index 0691b963..f7bf8555 100755 --- a/auto-cpufreq-installer +++ b/auto-cpufreq-installer @@ -223,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