From fb5ae8da5c0e86cc6fb5f84bd550e2dd82bb9a83 Mon Sep 17 00:00:00 2001 From: Angel <157843979+Angel-Karasu@users.noreply.github.com> Date: Thu, 9 May 2024 17:34:50 +0200 Subject: [PATCH 1/7] Add dinit --- scripts/auto-cpufreq-dinit | 3 +++ scripts/auto-cpufreq-install.sh | 10 ++++++++++ 2 files changed, 13 insertions(+) create mode 100644 scripts/auto-cpufreq-dinit diff --git a/scripts/auto-cpufreq-dinit b/scripts/auto-cpufreq-dinit new file mode 100644 index 00000000..dafbcba7 --- /dev/null +++ b/scripts/auto-cpufreq-dinit @@ -0,0 +1,3 @@ +type = scripted +command = /usr/local/bin/auto-cpufreq --daemon +run-as = root \ No newline at end of file diff --git a/scripts/auto-cpufreq-install.sh b/scripts/auto-cpufreq-install.sh index a1923208..33e90dee 100755 --- a/scripts/auto-cpufreq-install.sh +++ b/scripts/auto-cpufreq-install.sh @@ -89,6 +89,16 @@ elif [ "$(ps h -o comm 1)" = "s6-svscan" ];then s6-rc -u change auto-cpufreq default echo -e "\n* Update daemon service bundle (s6)" s6-db-reload +# Install script for dinit +elif [ "$(ps h -o comm 1)" = "dinit" ];then + echo -e "\n* Deploying auto-cpufreq dinit unit file" + cp /usr/local/share/auto-cpufreq/scripts/auto-cpufreq-dinit /etc/dinit.d/auto-cpufreq + + echo -e "Starting auto-cpufreq daemon (dinit) service" + dinitctl start auto-cpufreq + + echo -e "\n* Enabling auto-cpufreq daemon (dinit) service at boot" + dinitctl enable auto-cpufreq else echo -e "\n* Unsupported init system detected, could not install the daemon\n" echo -e "\n* Please open an issue on https://github.com/AdnanHodzic/auto-cpufreq\n" From 7d3b94371aefbc2dc94a958a83b3d82fe6a5163c Mon Sep 17 00:00:00 2001 From: Angel <157843979+Angel-Karasu@users.noreply.github.com> Date: Thu, 9 May 2024 17:43:37 +0200 Subject: [PATCH 2/7] Add dinit --- scripts/auto-cpufreq-remove.sh | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/scripts/auto-cpufreq-remove.sh b/scripts/auto-cpufreq-remove.sh index 659e7ab2..8666b096 100755 --- a/scripts/auto-cpufreq-remove.sh +++ b/scripts/auto-cpufreq-remove.sh @@ -52,6 +52,7 @@ elif [ "$(ps h -o comm 1)" = "systemd" ];then echo -e "reset failed" systemctl reset-failed +# Remove service for openrc elif [ "$(ps h -o comm 1)" = "init" ];then echo -e "\n* Stopping auto-cpufreq daemon (openrc) service" rc-service auto-cpufreq stop @@ -69,6 +70,16 @@ elif [ "$(ps h -o comm 1)" = "s6-svscan" ];then rm -rf /etc/s6/sv/auto-cpufreq echo -e "\n* Update daemon service bundle (s6)" s6-db-reload +# Remove service for dinit +elif [ "$(ps h -o comm 1)" = "init" ];then + echo -e "\n* Stopping auto-cpufreq daemon (dinit) service" + dinitctl stop auto-cpufreq + + echo -e "\n* Disabling auto-cpufreq daemon (dinit) at boot" + dinitctl disable auto-cpufreq + + echo -e "\n* Removing auto-cpufreq daemon (dinit) unit file" + rm /etc/dinit.d/auto-cpufreq else echo -e "\n* Unsupported init system detected, could not remove the daemon\n" echo -e "\n* Please open an issue on https://github.com/AdnanHodzic/auto-cpufreq\n" From d001486dcaa2a72ec07d9b32369b8072a36677b6 Mon Sep 17 00:00:00 2001 From: Angel <157843979+Angel-Karasu@users.noreply.github.com> Date: Thu, 9 May 2024 19:27:09 +0200 Subject: [PATCH 3/7] Change arch based informations --- README.md | 4 ++-- auto-cpufreq-installer | 9 ++++----- 2 files changed, 6 insertions(+), 7 deletions(-) diff --git a/README.md b/README.md index abc1fa04..928713ee 100644 --- a/README.md +++ b/README.md @@ -35,7 +35,7 @@ Example of `auto-cpufreq --stats` CLI output * [Installing auto-cpufreq](#installing-auto-cpufreq) * [auto-cpufreq-installer](#auto-cpufreq-installer) * [Snap Store](#snap-store) - * [AUR package (Arch/Manjaro Linux)](#aur-package-archmanjaro-linux) + * [AUR package (Arch based distributions)](#aur-package-arch-based-distributions) * [NixOS](#nixos) * [For developers](#installation-development-mode-only) * [Post-installation](#post-installation) @@ -128,7 +128,7 @@ sudo snap install auto-cpufreq * Fedora users will [encounter the following error](https://twitter.com/killyourfm/status/1291697985236144130) due to `cgroups v2` [being in development](https://github.com/snapcore/snapd/pull/7825). This problem can be resolved by either running `sudo snap run auto-cpufreq` after the snap installation or by using the [auto-cpufreq-installer](#auto-cpufreq-installer) which doesn't have this issue. -### AUR package (Arch/Manjaro Linux) +### AUR package (Arch based distributions) The AUR [Release Package](https://aur.archlinux.org/packages/auto-cpufreq) was last updated on version 2.2.0 and is currently being maintained by [MusicalArtist12](https://github.com/MusicalArtist12), [liljaylj](https://github.com/liljaylj), and [parmjotsinghrobot](https://github.com/Parmjot-Singh). diff --git a/auto-cpufreq-installer b/auto-cpufreq-installer index 3dc23413..3efc8f9e 100755 --- a/auto-cpufreq-installer +++ b/auto-cpufreq-installer @@ -166,6 +166,10 @@ elif [ -f /etc/solus-release ]; then eopkg install -c system.devel completed complete_msg +elif [ -f /etc/arch-release ]; then + detected_distro "Arch Linux based" + pacman -S --noconfirm --needed python python-pip python-setuptools base-devel dmidecode gobject-introspection gtk3 gcc + completed elif [ -f /etc/os-release ];then eval "$(cat /etc/os-release)" separator @@ -181,11 +185,6 @@ elif [ -f /etc/os-release ];then zypper install -y python38 python3-pip python3-setuptools python3-devel gcc dmidecode gobject-introspection-devel python3-cairo-devel gtk3 gtk3-devel completed ;; - arch|manjaro|endeavouros|garuda|artix) - detected_distro "Arch Linux based" - pacman -S --noconfirm --needed python python-pip python-setuptools base-devel dmidecode gobject-introspection gtk3 gcc - completed - ;; void) detected_distro "Void Linux" xbps-install -Sy python3 python3-pip python3-devel python3-setuptools base-devel dmidecode cairo-devel gobject-introspection gcc gtk+3 From a05a00c8cb1a670cd925d9a0aa26e6d2d071ac88 Mon Sep 17 00:00:00 2001 From: Angel <157843979+Angel-Karasu@users.noreply.github.com> Date: Thu, 9 May 2024 19:33:09 +0200 Subject: [PATCH 4/7] More compatible for Arch based distributions --- auto-cpufreq-installer | 1 + 1 file changed, 1 insertion(+) diff --git a/auto-cpufreq-installer b/auto-cpufreq-installer index 3efc8f9e..eee64d9d 100755 --- a/auto-cpufreq-installer +++ b/auto-cpufreq-installer @@ -170,6 +170,7 @@ elif [ -f /etc/arch-release ]; then detected_distro "Arch Linux based" pacman -S --noconfirm --needed python python-pip python-setuptools base-devel dmidecode gobject-introspection gtk3 gcc completed + complete_msg elif [ -f /etc/os-release ];then eval "$(cat /etc/os-release)" separator From e44cb2e77aa5c19d8ceaf06e8c53b37df361fcf7 Mon Sep 17 00:00:00 2001 From: Angel <157843979+Angel-Karasu@users.noreply.github.com> Date: Thu, 9 May 2024 19:35:56 +0200 Subject: [PATCH 5/7] More compatible for Arch based distributions --- auto-cpufreq-installer | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/auto-cpufreq-installer b/auto-cpufreq-installer index eee64d9d..43bf330c 100755 --- a/auto-cpufreq-installer +++ b/auto-cpufreq-installer @@ -170,7 +170,7 @@ elif [ -f /etc/arch-release ]; then detected_distro "Arch Linux based" pacman -S --noconfirm --needed python python-pip python-setuptools base-devel dmidecode gobject-introspection gtk3 gcc completed - complete_msg + complete_msg elif [ -f /etc/os-release ];then eval "$(cat /etc/os-release)" separator From b9f773bb294126cbddfa0c650600a0b6d4d9a2fe Mon Sep 17 00:00:00 2001 From: Angel-Karasu Date: Thu, 9 May 2024 20:46:18 +0200 Subject: [PATCH 6/7] Clean code --- README.md | 192 +++++++++++++++++++------------------- auto-cpufreq-installer | 203 ++++++++++++++++++----------------------- 2 files changed, 187 insertions(+), 208 deletions(-) diff --git a/README.md b/README.md index 928713ee..5b525484 100644 --- a/README.md +++ b/README.md @@ -24,46 +24,46 @@ Example of `auto-cpufreq --stats` CLI output ## Looking for developers and co-maintainers -* If you would like to discuss anything regarding auto-cpufreq or its development, please join the [auto-cpufreq Discord server!](https://discord.gg/Sjauxtj6kH) -* auto-cpufreq is looking for [co-maintainers & open source developers to help shape the future of the project!](https://github.com/AdnanHodzic/auto-cpufreq/discussions/312) +- If you would like to discuss anything regarding auto-cpufreq or its development, please join the [auto-cpufreq Discord server!](https://discord.gg/Sjauxtj6kH) +- auto-cpufreq is looking for [co-maintainers & open source developers to help shape the future of the project!](https://github.com/AdnanHodzic/auto-cpufreq/discussions/312) ## Index -* [Why do I need auto-cpufreq?](#why-do-i-need-auto-cpufreq) - * [Supported architectures and devices](#supported-architectures-and-devices) -* [Features](#features) -* [Installing auto-cpufreq](#installing-auto-cpufreq) - * [auto-cpufreq-installer](#auto-cpufreq-installer) - * [Snap Store](#snap-store) - * [AUR package (Arch based distributions)](#aur-package-arch-based-distributions) - * [NixOS](#nixos) - * [For developers](#installation-development-mode-only) -* [Post-installation](#post-installation) -* [Configuring auto-cpufreq](#configuring-auto-cpufreq) - * [1: power_helper.py script (Snap package install only)](#1-power_helperpy-script-snap-package-install-only) - * [2: `--force` governor override](#2---force-governor-override) - * [3: auto-cpufreq config file](#3-auto-cpufreq-config-file) - * [Example config file contents](#example-config-file-contents) -* [How to run auto-cpufreq](#how-to-run-auto-cpufreq) -* [auto-cpufreq modes and options](#auto-cpufreq-modes-and-options) - * [monitor](#monitor) - * [live](#live) - * [overriding governor](#overriding-governor) - * [Install - auto-cpufreq daemon](#install---auto-cpufreq-daemon) - * [Update - auto-cpufreq update](#update---auto-cpufreq-update) - * [Remove - auto-cpufreq daemon](#remove---auto-cpufreq-daemon) - * [stats](#stats) -* [Battery charging thresholds](#battery-charging-thresholds) - * [Supported Devices](#supported-devices) - * [Battery config](#battery-config) -* [Troubleshooting](#troubleshooting) - * [AUR](#aur) -* [Discussion](#discussion) -* [Donate](#donate) - * [Financial donation](#financial-donation) - * [Paypal](#paypal) - * [BitCoin](#bitcoin) - * [Code contribution](#code-contribution) +- [Why do I need auto-cpufreq?](#why-do-i-need-auto-cpufreq) + - [Supported architectures and devices](#supported-architectures-and-devices) +- [Features](#features) +- [Installing auto-cpufreq](#installing-auto-cpufreq) + - [auto-cpufreq-installer](#auto-cpufreq-installer) + - [Snap Store](#snap-store) + - [AUR package (Arch based distributions)](#aur-package-arch-based-distributions) + - [NixOS](#nixos) + - [For developers](#installation-development-mode-only) +- [Post-installation](#post-installation) +- [Configuring auto-cpufreq](#configuring-auto-cpufreq) + - [1: power_helper.py script (Snap package install only)](#1-power_helperpy-script-snap-package-install-only) + - [2: `--force` governor override](#2---force-governor-override) + - [3: auto-cpufreq config file](#3-auto-cpufreq-config-file) + - [Example config file contents](#example-config-file-contents) +- [How to run auto-cpufreq](#how-to-run-auto-cpufreq) +- [auto-cpufreq modes and options](#auto-cpufreq-modes-and-options) + - [monitor](#monitor) + - [live](#live) + - [overriding governor](#overriding-governor) + - [Install - auto-cpufreq daemon](#install---auto-cpufreq-daemon) + - [Update - auto-cpufreq update](#update---auto-cpufreq-update) + - [Remove - auto-cpufreq daemon](#remove---auto-cpufreq-daemon) + - [stats](#stats) +- [Battery charging thresholds](#battery-charging-thresholds) + - [Supported Devices](#supported-devices) + - [Battery config](#battery-config) +- [Troubleshooting](#troubleshooting) + - [AUR](#aur) +- [Discussion](#discussion) +- [Donate](#donate) + - [Financial donation](#financial-donation) + - [Paypal](#paypal) + - [BitCoin](#bitcoin) + - [Code contribution](#code-contribution) ## Why do I need auto-cpufreq? @@ -85,20 +85,20 @@ Only devices with an Intel, AMD, or ARM CPU are supported. This tool was develop ## Features -* Monitoring - * Basic system information - * CPU frequency (system total & per core) - * CPU usage (system total & per core) - * CPU temperature (total average & per core) - * Battery state - * System load -* CPU frequency scaling, governor, and [turbo boost](https://en.wikipedia.org/wiki/Intel_Turbo_Boost) management based on - * Battery state - * CPU usage (total & per core) - * CPU temperature in combination with CPU utilization/load (to prevent overheating) - * System load -* Automatic CPU & power optimization (temporary and persistent) -* Settings battery charging thresholds (limited support) +- Monitoring + - Basic system information + - CPU frequency (system total & per core) + - CPU usage (system total & per core) + - CPU temperature (total average & per core) + - Battery state + - System load +- CPU frequency scaling, governor, and [turbo boost](https://en.wikipedia.org/wiki/Intel_Turbo_Boost) management based on + - Battery state + - CPU usage (total & per core) + - CPU temperature in combination with CPU utilization/load (to prevent overheating) + - System load +- Automatic CPU & power optimization (temporary and persistent) +- Settings battery charging thresholds (limited support) ## Installing auto-cpufreq @@ -124,9 +124,9 @@ sudo snap install auto-cpufreq ``` **Please note:** -* Make sure [snapd](https://snapcraft.io/docs/installing-snapd) is installed and `snap version` is >= 2.44 for `auto-cpufreq` to fully work due to [recent snapd changes](https://github.com/snapcore/snapd/pull/8127). +- Make sure [snapd](https://snapcraft.io/docs/installing-snapd) is installed and `snap version` is >= 2.44 for `auto-cpufreq` to fully work due to [recent snapd changes](https://github.com/snapcore/snapd/pull/8127). -* Fedora users will [encounter the following error](https://twitter.com/killyourfm/status/1291697985236144130) due to `cgroups v2` [being in development](https://github.com/snapcore/snapd/pull/7825). This problem can be resolved by either running `sudo snap run auto-cpufreq` after the snap installation or by using the [auto-cpufreq-installer](#auto-cpufreq-installer) which doesn't have this issue. +- Fedora users will [encounter the following error](https://twitter.com/killyourfm/status/1291697985236144130) due to `cgroups v2` [being in development](https://github.com/snapcore/snapd/pull/7825). This problem can be resolved by either running `sudo snap run auto-cpufreq` after the snap installation or by using the [auto-cpufreq-installer](#auto-cpufreq-installer) which doesn't have this issue. ### AUR package (Arch based distributions) @@ -134,15 +134,15 @@ The AUR [Release Package](https://aur.archlinux.org/packages/auto-cpufreq) was l **Notices** -* The [Git Package](https://aur.archlinux.org/packages/auto-cpufreq-git) is seperately maintained and was last updated on version 1.9.6. -* The build process links to `/usr/share/` instead of `/usr/local/share/` -* The daemon installer provided does not work, instead start the daemon with +- The [Git Package](https://aur.archlinux.org/packages/auto-cpufreq-git) is seperately maintained and was last updated on version 1.9.6. +- The build process links to `/usr/share/` instead of `/usr/local/share/` +- The daemon installer provided does not work, instead start the daemon with ``` # systemctl enable --now auto-cpufreq ``` -* The GNOME Power Profiles daemon is [automatically disabled by auto-cpufreq-installer](https://github.com/AdnanHodzic/auto-cpufreq#1-power_helperpy-script-snap-package-install-only) due to it's conflict with auto-cpufreq.service. However, this doesn't happen with AUR installs, which can lead to problems (e.g., [#463](https://github.com/AdnanHodzic/auto-cpufreq/issues/463)) if not masked manually. - * Open a terminal and run `sudo systemctl mask power-profiles-daemon.service` (then `enable` and `start` the auto-cpufreq.service if you haven't already). +- The GNOME Power Profiles daemon is [automatically disabled by auto-cpufreq-installer](https://github.com/AdnanHodzic/auto-cpufreq#1-power_helperpy-script-snap-package-install-only) due to it's conflict with auto-cpufreq.service. However, this doesn't happen with AUR installs, which can lead to problems (e.g., [#463](https://github.com/AdnanHodzic/auto-cpufreq/issues/463)) if not masked manually. + - Open a terminal and run `sudo systemctl mask power-profiles-daemon.service` (then `enable` and `start` the auto-cpufreq.service if you haven't already). ### NixOS @@ -350,47 +350,47 @@ turbo = auto ## How to run auto-cpufreq auto-cpufreq should be run with with one of the following options: -* [monitor](#monitor) - - Monitor and see suggestions for CPU optimizations +- [monitor](#monitor) + - Monitor and see suggestions for CPU optimizations -* [live](#live) - - Monitor and automatically make (temporary) CPU optimizations +- [live](#live) + - Monitor and automatically make (temporary) CPU optimizations -* [install](#install---auto-cpufreq-daemon) / [remove](#remove---auto-cpufreq-daemon) - - Install/remove daemon for (permanent) automatic CPU optimizations +- [install](#install---auto-cpufreq-daemon) / [remove](#remove---auto-cpufreq-daemon) + - Install/remove daemon for (permanent) automatic CPU optimizations -* [install (GUI)](#install---auto-cpufreq-daemon) - - Install daemon via GUI for (permanent) automatic CPU optimizations +- [install (GUI)](#install---auto-cpufreq-daemon) + - Install daemon via GUI for (permanent) automatic CPU optimizations -* [update](#update---auto-cpufreq-update) - - Update auto-cpufreq to the latest release +- [update](#update---auto-cpufreq-update) + - Update auto-cpufreq to the latest release -* [install_performance](#1-power_helperpy-script) - - Install daemon in "performance" mode +- [install_performance](#1-power_helperpy-script) + - Install daemon in "performance" mode -* [stats](#stats) - - View live stats of CPU optimizations made by daemon +- [stats](#stats) + - View live stats of CPU optimizations made by daemon -* [force=TEXT](#overriding-governor) - - Force use of either the "powersave" or "performance" governor, or set to "reset" to go back to normal mode +- [force=TEXT](#overriding-governor) + - Force use of either the "powersave" or "performance" governor, or set to "reset" to go back to normal mode -* config=TEXT - - Use config file at designated path +- config=TEXT + - Use config file at designated path -* debug - - Show debug info (include when submitting bugs) +- debug + - Show debug info (include when submitting bugs) -* version - - Show currently installed version +- version + - Show currently installed version -* [donate](#financial-donation) - - To support the project +- [donate](#financial-donation) + - To support the project -* help - - Shows all of the above options +- help + - Shows all of the above options -* completions=TEXT - - To support shell completions (current options are "bash", "zsh", or "fish") +- completions=TEXT + - To support shell completions (current options are "bash", "zsh", or "fish") Running `auto-cpufreq --help` will print the same list of options as above. Read [auto-cpufreq modes and options](#auto-cpufreq-modes-and-options) for more details. @@ -487,8 +487,8 @@ As of [v2.2.0](https://github.com/AdnanHodzic/auto-cpufreq/releases/tag/v2.2.0), ### Supported devices -* **Lenovo ThinkPad** (thinkpad_acpi)* -* **Lenovo IdeaPad** (ideapad_acpi)* +- **Lenovo ThinkPad** (thinkpad_acpi)* +- **Lenovo IdeaPad** (ideapad_acpi)* ***Please note, your laptop must have an installed ACPI kernel driver specific to the manufacturer.** To check if you have the correct module installed and loaded run `lsmod [module]` @@ -514,10 +514,10 @@ add `ideapad_laptop_conservation_mode = true` to your `auto-cpufreq.conf` file ## Troubleshooting **Q:** If after installing auto-cpufreq you're (still) experiencing: -* high CPU temperatures -* CPU not scaling to minimum/maximum frequencies -* suboptimal CPU performance -* turbo mode not available +- high CPU temperatures +- CPU not scaling to minimum/maximum frequencies +- suboptimal CPU performance +- turbo mode not available **A:** If you're using the `intel_pstate/amd-pstate` CPU management driver, consider changing it to `acpi-cpufreq`. @@ -578,18 +578,18 @@ Once you have made the necessary changes to the `cmdline` file, you can update i ### AUR -* If the AUR installer does not work for your system, fallback to `auto-cpufreq-installer` and open an issue. +- If the AUR installer does not work for your system, fallback to `auto-cpufreq-installer` and open an issue. ## Discussion: -* Blogpost: [auto-cpufreq - Automatic CPU speed & power optimizer for Linux](http://foolcontrol.org/?p=3124) +- Blogpost: [auto-cpufreq - Automatic CPU speed & power optimizer for Linux](http://foolcontrol.org/?p=3124) ## Donate Showing your support and appreciation for the auto-cpufreq project can be done in two ways: -* Financial donation -* Code contribution +- Financial donation +- Code contribution ### Financial donation diff --git a/auto-cpufreq-installer b/auto-cpufreq-installer index 43bf330c..614cd6b4 100755 --- a/auto-cpufreq-installer +++ b/auto-cpufreq-installer @@ -5,7 +5,7 @@ SCRIPT_PATH=$(readlink -f "$0") SCRIPT_DIR=$(dirname "${SCRIPT_PATH}") -cd "${SCRIPT_DIR}" +cd "${SCRIPT_DIR}" || exit 1 # check if lsb_release exists on the system before using it if command -v lsb_release > /dev/null @@ -94,117 +94,103 @@ function completed () { } function complete_msg() { + completed separator - cat <<- _EOF_ - - auto-cpufreq tool successfully installed. + echo -e " + auto-cpufreq tool successfully installed. - For list of options, run: - auto-cpufreq --help" -_EOF_ + For list of options, run: + + auto-cpufreq --help" separator } function manual_install { - cat <<- _EOF_ - - Didn't detect Debian or RedHat based distro. + echo -e " + Didn't detect Debian or RedHat or Arch based distro. - To complete installation, you need to: - Install: python3, pip3, python3-setuptools, gobject-introspection, cairo (or cairo-devel), gcc, and gtk3 + To complete installation, you need to: + Install: python3, pip3, python3-setuptools, gobject-introspection, cairo (or cairo-devel), gcc, and gtk3 - Install necessary Python packages: - pip3 install psutil click distro power requests PyGObject - Run following sequence of lines: + Install necessary Python packages: + pip3 install psutil click distro power requests PyGObject + Run following sequence of lines: - ----- + ----- - pip3 install . - mkdir -p /usr/local/share/auto-cpufreq/ - cp -r scripts/ /usr/local/share/auto-cpufreq/ + pip3 install . + 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: + After which tool is installed, for full list of options run: - auto-cpufreq -_EOF_ + auto-cpufreq" separator - cat <<- _EOF_ + echo -e " + Consider creating a feature request to add support for your distro: + https://github.com/AdnanHodzic/auto-cpufreq/issues/new - 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: - Make sure to include following information: - - Distribution: $distro - Release: $release - Codename: $codename -_EOF_ + Distribution: $distro + Release: $release + Codename: $codename" separator } function tool_install { -separator -if [ -f /etc/debian_version ]; then - detected_distro "Debian based" - apt install python3-dev python3-pip python3-venv python3-setuptools dmidecode libgirepository1.0-dev libcairo2-dev libgtk-3-dev gcc -y - completed - complete_msg -elif [ -f /etc/redhat-release ]; then - detected_distro "RedHat based" - if [ -f /etc/centos-release ]; then - yum install platform-python-devel dmidecode gcc cairo-devel gobject-introspection-devel cairo-gobject-devel gtk3-devel - else - yum install python-devel dmidecode gcc cairo-devel gobject-introspection-devel cairo-gobject-devel gtk3-devel - fi - completed - complete_msg -elif [ -f /etc/solus-release ]; then - detected_distro "Solus" - eopkg install pip python3 python3-devel dmidecode gobject-introspection-devel libcairo-devel gcc libgtk-3 - eopkg install -c system.devel - completed - complete_msg -elif [ -f /etc/arch-release ]; then - detected_distro "Arch Linux based" - pacman -S --noconfirm --needed python python-pip python-setuptools base-devel dmidecode gobject-introspection gtk3 gcc - completed - complete_msg -elif [ -f /etc/os-release ];then - eval "$(cat /etc/os-release)" - separator - case $ID in - opensuse-leap) - detected_distro "OpenSUSE" - zypper install -y python3 python3-pip python3-setuptools python3-devel gcc dmidecode gobject-introspection-devel python3-cairo-devel gtk3 gtk3-devel - completed - ;; - opensuse-tumbleweed) - detected_distro "OpenSUSE" - echo -e "\nDetected an OpenSUSE distribution\n\nSetting up Python environment\n" - zypper install -y python38 python3-pip python3-setuptools python3-devel gcc dmidecode gobject-introspection-devel python3-cairo-devel gtk3 gtk3-devel - completed - ;; - void) - detected_distro "Void Linux" - xbps-install -Sy python3 python3-pip python3-devel python3-setuptools base-devel dmidecode cairo-devel gobject-introspection gcc gtk+3 - completed - ;; - nixos) - echo -e "NixOS detected\n" - echo -e "This installer is not supported on NixOS.\nPlease refer to the install instructions for NixOS at https://github.com/AdnanHodzic/auto-cpufreq#nixos" + separator + + if [ -f /etc/debian_version ]; then + detected_distro "Debian based" + apt install python3-dev python3-pip python3-venv python3-setuptools dmidecode libgirepository1.0-dev libcairo2-dev libgtk-3-dev gcc -y + + elif [ -f /etc/redhat-release ]; then + detected_distro "RedHat based" + if [ -f /etc/centos-release ]; then yum install platform-python-devel + else yum install python-devel + fi + yum install dmidecode gcc cairo-devel gobject-introspection-devel cairo-gobject-devel gtk3-devel + + elif [ -f /etc/solus-release ]; then + detected_distro "Solus" + eopkg install pip python3 python3-devel dmidecode gobject-introspection-devel libcairo-devel gcc libgtk-3 + eopkg install -c system.devel + + elif [ -f /etc/arch-release ]; then + detected_distro "Arch Linux based" + pacman -S --noconfirm --needed python python-pip python-setuptools base-devel dmidecode gobject-introspection gtk3 gcc + + elif [ -f /etc/os-release ];then + eval "$(cat /etc/os-release)" + separator + case $ID in + opensuse-leap) + detected_distro "OpenSUSE" + zypper install -y python3 python3-pip python3-setuptools python3-devel gcc dmidecode gobject-introspection-devel python3-cairo-devel gtk3 gtk3-devel + ;; + opensuse-tumbleweed) + detected_distro "OpenSUSE" + zypper install -y python38 python3-pip python3-setuptools python3-devel gcc dmidecode gobject-introspection-devel python3-cairo-devel gtk3 gtk3-devel + ;; + void) + detected_distro "Void Linux" + xbps-install -Sy python3 python3-pip python3-devel python3-setuptools base-devel dmidecode cairo-devel gobject-introspection gcc gtk+3 + ;; + nixos) + echo -e "NixOS detected\n" + echo -e "This installer is not supported on NixOS.\nPlease refer to the install instructions for NixOS at https://github.com/AdnanHodzic/auto-cpufreq#nixos" + exit 1 + ;; + *) manual_install;; + esac + else # In case /etc/os-release doesn't exist + manual_install exit 1 - ;; - *) #Any other distro - manual_install - completed - ;; - esac - complete_msg -else # In case /etc/os-release doesn't exist - manual_install -fi + fi + complete_msg } function tool_remove { @@ -293,33 +279,26 @@ Select a key: [i/r/q]: " answer root_check -if [[ -z "${1}" ]]; then - ask_operation +if [[ -z "${1}" ]]; then ask_operation else case "${1}" in - "--install") - answer="i" - ;; - "--remove") - answer="r" - ;; - *) - answer="n" - ;; + "--install") answer="i";; + "--remove") answer="r";; + *) answer="n";; esac fi case $answer in - I|i) - tool_install ;; - R|r) - tool_remove ;; + I|i) tool_install;; + R|r) tool_remove;; Q|q) - separator - echo "" - exit 0 ;; + separator + echo "" + exit 0 + ;; *) - separator - echo -e "\nUnknown key, aborting ...\n" - exit 1 ;; + separator + echo -e "\nUnknown key, aborting ...\n" + exit 1 + ;; esac From 7f3ee74c6e8b8d23aa1f87bfef0924da404193f3 Mon Sep 17 00:00:00 2001 From: Angel-Karasu Date: Thu, 9 May 2024 23:16:00 +0200 Subject: [PATCH 7/7] Clean code --- auto-cpufreq-installer | 60 +++++++++++++++++------------------------- 1 file changed, 24 insertions(+), 36 deletions(-) diff --git a/auto-cpufreq-installer b/auto-cpufreq-installer index 614cd6b4..c3fe32ff 100755 --- a/auto-cpufreq-installer +++ b/auto-cpufreq-installer @@ -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 @@ -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) @@ -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. @@ -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 {