Skip to content

Commit

Permalink
Clean code
Browse files Browse the repository at this point in the history
  • Loading branch information
Angel-Karasu committed May 9, 2024
1 parent 7642802 commit 7f3ee74
Showing 1 changed file with 24 additions and 36 deletions.
60 changes: 24 additions & 36 deletions auto-cpufreq-installer
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,7 @@
# auto-cpufreq-installer:
# auto-cpufreq source code based installer

SCRIPT_PATH=$(readlink -f "$0")
SCRIPT_DIR=$(dirname "${SCRIPT_PATH}")
cd "${SCRIPT_DIR}" || exit 1
cd "$(dirname "$(readlink -f "$0")")" || exit 1

# check if lsb_release exists on the system before using it
if command -v lsb_release > /dev/null
Expand Down Expand Up @@ -47,16 +45,6 @@ function header {
return
}

# python packages install
function setup_venv {
venv_dir=/opt/auto-cpufreq/venv
mkdir -p "${venv_dir}"
python3 -m venv "${venv_dir}"

source "${venv_dir}/bin/activate"
python3 -m pip install --upgrade pip wheel
}

# tool install
function install {
git config --global --add safe.directory $(pwd)
Expand All @@ -78,33 +66,12 @@ function install {
}

# First argument is the distro
function detected_distro() {
function detected_distro {
echo -e "\nDetected $1 distribution"
separator
echo -e "\nSetting up Python environment\n"
}

# merged functions pip - install - complete_msg, since it repeats
function completed () {
echo -e "\nInstalling necessary Python packages\n"
setup_venv
separator
echo -e "\ninstalling auto-cpufreq tool\n"
install
}

function complete_msg() {
completed
separator
echo -e "
auto-cpufreq tool successfully installed.
For list of options, run:
auto-cpufreq --help"
separator
}

function manual_install {
echo -e "
Didn't detect Debian or RedHat or Arch based distro.
Expand Down Expand Up @@ -190,7 +157,28 @@ function tool_install {
manual_install
exit 1
fi
complete_msg

echo -e "\nInstalling necessary Python packages\n"

venv_dir=/opt/auto-cpufreq/venv
mkdir -p "${venv_dir}"
python3 -m venv "${venv_dir}"

source "${venv_dir}/bin/activate"
python3 -m pip install --upgrade pip wheel

separator
echo -e "\ninstalling auto-cpufreq tool\n"
install

separator
echo -e "
auto-cpufreq tool successfully installed.
For list of options, run:
auto-cpufreq --help"
separator
}

function tool_remove {
Expand Down

0 comments on commit 7f3ee74

Please sign in to comment.