Improve compatible for Arch based distributions (#691)

* Add dinit

* Add dinit

* Change arch based informations

* More compatible for Arch based distributions

* More compatible for Arch based distributions

* Clean code

* Clean code
This commit is contained in:
Angel 2024-05-09 23:34:07 +02:00 committed by GitHub
parent b8f864e87e
commit eb0ba8aa7e
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 204 additions and 237 deletions

194
README.md
View File

@ -24,46 +24,46 @@ Example of `auto-cpufreq --stats` CLI output
## Looking for developers and co-maintainers ## 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) - 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) - 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 ## Index
* [Why do I need auto-cpufreq?](#why-do-i-need-auto-cpufreq) - [Why do I need auto-cpufreq?](#why-do-i-need-auto-cpufreq)
* [Supported architectures and devices](#supported-architectures-and-devices) - [Supported architectures and devices](#supported-architectures-and-devices)
* [Features](#features) - [Features](#features)
* [Installing auto-cpufreq](#installing-auto-cpufreq) - [Installing auto-cpufreq](#installing-auto-cpufreq)
* [auto-cpufreq-installer](#auto-cpufreq-installer) - [auto-cpufreq-installer](#auto-cpufreq-installer)
* [Snap Store](#snap-store) - [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) - [NixOS](#nixos)
* [For developers](#installation-development-mode-only) - [For developers](#installation-development-mode-only)
* [Post-installation](#post-installation) - [Post-installation](#post-installation)
* [Configuring auto-cpufreq](#configuring-auto-cpufreq) - [Configuring auto-cpufreq](#configuring-auto-cpufreq)
* [1: power_helper.py script (Snap package install only)](#1-power_helperpy-script-snap-package-install-only) - [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) - [2: `--force` governor override](#2---force-governor-override)
* [3: auto-cpufreq config file](#3-auto-cpufreq-config-file) - [3: auto-cpufreq config file](#3-auto-cpufreq-config-file)
* [Example config file contents](#example-config-file-contents) - [Example config file contents](#example-config-file-contents)
* [How to run auto-cpufreq](#how-to-run-auto-cpufreq) - [How to run auto-cpufreq](#how-to-run-auto-cpufreq)
* [auto-cpufreq modes and options](#auto-cpufreq-modes-and-options) - [auto-cpufreq modes and options](#auto-cpufreq-modes-and-options)
* [monitor](#monitor) - [monitor](#monitor)
* [live](#live) - [live](#live)
* [overriding governor](#overriding-governor) - [overriding governor](#overriding-governor)
* [Install - auto-cpufreq daemon](#install---auto-cpufreq-daemon) - [Install - auto-cpufreq daemon](#install---auto-cpufreq-daemon)
* [Update - auto-cpufreq update](#update---auto-cpufreq-update) - [Update - auto-cpufreq update](#update---auto-cpufreq-update)
* [Remove - auto-cpufreq daemon](#remove---auto-cpufreq-daemon) - [Remove - auto-cpufreq daemon](#remove---auto-cpufreq-daemon)
* [stats](#stats) - [stats](#stats)
* [Battery charging thresholds](#battery-charging-thresholds) - [Battery charging thresholds](#battery-charging-thresholds)
* [Supported Devices](#supported-devices) - [Supported Devices](#supported-devices)
* [Battery config](#battery-config) - [Battery config](#battery-config)
* [Troubleshooting](#troubleshooting) - [Troubleshooting](#troubleshooting)
* [AUR](#aur) - [AUR](#aur)
* [Discussion](#discussion) - [Discussion](#discussion)
* [Donate](#donate) - [Donate](#donate)
* [Financial donation](#financial-donation) - [Financial donation](#financial-donation)
* [Paypal](#paypal) - [Paypal](#paypal)
* [BitCoin](#bitcoin) - [BitCoin](#bitcoin)
* [Code contribution](#code-contribution) - [Code contribution](#code-contribution)
## Why do I need auto-cpufreq? ## 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 ## Features
* Monitoring - Monitoring
* Basic system information - Basic system information
* CPU frequency (system total & per core) - CPU frequency (system total & per core)
* CPU usage (system total & per core) - CPU usage (system total & per core)
* CPU temperature (total average & per core) - CPU temperature (total average & per core)
* Battery state - Battery state
* System load - System load
* CPU frequency scaling, governor, and [turbo boost](https://en.wikipedia.org/wiki/Intel_Turbo_Boost) management based on - CPU frequency scaling, governor, and [turbo boost](https://en.wikipedia.org/wiki/Intel_Turbo_Boost) management based on
* Battery state - Battery state
* CPU usage (total & per core) - CPU usage (total & per core)
* CPU temperature in combination with CPU utilization/load (to prevent overheating) - CPU temperature in combination with CPU utilization/load (to prevent overheating)
* System load - System load
* Automatic CPU & power optimization (temporary and persistent) - Automatic CPU & power optimization (temporary and persistent)
* Settings battery charging thresholds (limited support) - Settings battery charging thresholds (limited support)
## Installing auto-cpufreq ## Installing auto-cpufreq
@ -124,11 +124,11 @@ sudo snap install auto-cpufreq
``` ```
**Please note:** **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/Manjaro Linux) ### AUR package (Arch based distributions)
[![AUR package](https://repology.org/badge/version-for-repo/aur/auto-cpufreq.svg)](https://aur.archlinux.org/packages/auto-cpufreq) [![AUR package](https://repology.org/badge/version-for-repo/aur/auto-cpufreq.svg)](https://aur.archlinux.org/packages/auto-cpufreq)
@ -136,15 +136,15 @@ The AUR [Release Package](https://aur.archlinux.org/packages/auto-cpufreq) is cu
**Notices** **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 [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 build process links to `/usr/share/` instead of `/usr/local/share/`
* The daemon installer provided does not work, instead start the daemon with - The daemon installer provided does not work, instead start the daemon with
``` ```
# systemctl enable --now auto-cpufreq # 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. - 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). - 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 ### NixOS
@ -352,47 +352,47 @@ turbo = auto
## How to run auto-cpufreq ## How to run auto-cpufreq
auto-cpufreq should be run with with one of the following options: auto-cpufreq should be run with with one of the following options:
* [monitor](#monitor) - [monitor](#monitor)
- Monitor and see suggestions for CPU optimizations - Monitor and see suggestions for CPU optimizations
* [live](#live) - [live](#live)
- Monitor and automatically make (temporary) CPU optimizations - Monitor and automatically make (temporary) CPU optimizations
* [install](#install---auto-cpufreq-daemon) / [remove](#remove---auto-cpufreq-daemon) - [install](#install---auto-cpufreq-daemon) / [remove](#remove---auto-cpufreq-daemon)
- Install/remove daemon for (permanent) automatic CPU optimizations - Install/remove daemon for (permanent) automatic CPU optimizations
* [install (GUI)](#install---auto-cpufreq-daemon) - [install (GUI)](#install---auto-cpufreq-daemon)
- Install daemon via GUI for (permanent) automatic CPU optimizations - Install daemon via GUI for (permanent) automatic CPU optimizations
* [update](#update---auto-cpufreq-update) - [update](#update---auto-cpufreq-update)
- Update auto-cpufreq to the latest release - Update auto-cpufreq to the latest release
* [install_performance](#1-power_helperpy-script) - [install_performance](#1-power_helperpy-script)
- Install daemon in "performance" mode - Install daemon in "performance" mode
* [stats](#stats) - [stats](#stats)
- View live stats of CPU optimizations made by daemon - View live stats of CPU optimizations made by daemon
* [force=TEXT](#overriding-governor) - [force=TEXT](#overriding-governor)
- Force use of either the "powersave" or "performance" governor, or set to "reset" to go back to normal mode - Force use of either the "powersave" or "performance" governor, or set to "reset" to go back to normal mode
* config=TEXT - config=TEXT
- Use config file at designated path - Use config file at designated path
* debug - debug
- Show debug info (include when submitting bugs) - Show debug info (include when submitting bugs)
* version - version
- Show currently installed version - Show currently installed version
* [donate](#financial-donation) - [donate](#financial-donation)
- To support the project - To support the project
* help - help
- Shows all of the above options - Shows all of the above options
* completions=TEXT - completions=TEXT
- To support shell completions (current options are "bash", "zsh", or "fish") - 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. 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.
@ -489,8 +489,8 @@ As of [v2.2.0](https://github.com/AdnanHodzic/auto-cpufreq/releases/tag/v2.2.0),
### Supported devices ### Supported devices
* **Lenovo ThinkPad** (thinkpad_acpi)* - **Lenovo ThinkPad** (thinkpad_acpi)*
* **Lenovo IdeaPad** (ideapad_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]` ***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]`
@ -516,10 +516,10 @@ add `ideapad_laptop_conservation_mode = true` to your `auto-cpufreq.conf` file
## Troubleshooting ## Troubleshooting
**Q:** If after installing auto-cpufreq you're (still) experiencing: **Q:** If after installing auto-cpufreq you're (still) experiencing:
* high CPU temperatures - high CPU temperatures
* CPU not scaling to minimum/maximum frequencies - CPU not scaling to minimum/maximum frequencies
* suboptimal CPU performance - suboptimal CPU performance
* turbo mode not available - turbo mode not available
**A:** If you're using the `intel_pstate/amd-pstate` CPU management driver, consider changing it to `acpi-cpufreq`. **A:** If you're using the `intel_pstate/amd-pstate` CPU management driver, consider changing it to `acpi-cpufreq`.
@ -580,18 +580,18 @@ Once you have made the necessary changes to the `cmdline` file, you can update i
### AUR ### 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: ## 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 ## Donate
Showing your support and appreciation for the auto-cpufreq project can be done in two ways: Showing your support and appreciation for the auto-cpufreq project can be done in two ways:
* Financial donation - Financial donation
* Code contribution - Code contribution
### Financial donation ### Financial donation

View File

@ -3,9 +3,7 @@
# auto-cpufreq-installer: # auto-cpufreq-installer:
# auto-cpufreq source code based installer # auto-cpufreq source code based installer
SCRIPT_PATH=$(readlink -f "$0") cd "$(dirname "$(readlink -f "$0")")" || exit 1
SCRIPT_DIR=$(dirname "${SCRIPT_PATH}")
cd "${SCRIPT_DIR}"
# check if lsb_release exists on the system before using it # check if lsb_release exists on the system before using it
if command -v lsb_release > /dev/null if command -v lsb_release > /dev/null
@ -47,16 +45,6 @@ function header {
return 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 # tool install
function install { function install {
git config --global --add safe.directory $(pwd) git config --global --add safe.directory $(pwd)
@ -78,133 +66,119 @@ function install {
} }
# First argument is the distro # First argument is the distro
function detected_distro() { function detected_distro {
echo -e "\nDetected $1 distribution" echo -e "\nDetected $1 distribution"
separator separator
echo -e "\nSetting up Python environment\n" 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() {
separator
cat <<- _EOF_
auto-cpufreq tool successfully installed.
For list of options, run:
auto-cpufreq --help"
_EOF_
separator
}
function manual_install { function manual_install {
cat <<- _EOF_ echo -e "
Didn't detect Debian or RedHat or Arch based distro.
Didn't detect Debian or RedHat 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 necessary Python packages:
Install: python3, pip3, python3-setuptools, gobject-introspection, cairo (or cairo-devel), gcc, and gtk3 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"
auto-cpufreq
_EOF_
separator 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: Make sure to include following information:
https://github.com/AdnanHodzic/auto-cpufreq/issues/new
Make sure to include following information: Distribution: $distro
Release: $release
Distribution: $distro Codename: $codename"
Release: $release
Codename: $codename
_EOF_
separator separator
} }
function tool_install { function tool_install {
separator separator
if [ -f /etc/debian_version ]; then
detected_distro "Debian based" if [ -f /etc/debian_version ]; then
apt install python3-dev python3-pip python3-venv python3-setuptools dmidecode libgirepository1.0-dev libcairo2-dev libgtk-3-dev gcc -y detected_distro "Debian based"
completed apt install python3-dev python3-pip python3-venv python3-setuptools dmidecode libgirepository1.0-dev libcairo2-dev libgtk-3-dev gcc -y
complete_msg
elif [ -f /etc/redhat-release ]; then elif [ -f /etc/redhat-release ]; then
detected_distro "RedHat based" detected_distro "RedHat based"
if [ -f /etc/centos-release ]; then if [ -f /etc/centos-release ]; then yum install platform-python-devel
yum install platform-python-devel dmidecode gcc cairo-devel gobject-introspection-devel cairo-gobject-devel gtk3-devel else yum install python-devel
else fi
yum install python-devel dmidecode gcc cairo-devel gobject-introspection-devel cairo-gobject-devel gtk3-devel yum install dmidecode gcc cairo-devel gobject-introspection-devel cairo-gobject-devel gtk3-devel
fi
completed elif [ -f /etc/solus-release ]; then
complete_msg detected_distro "Solus"
elif [ -f /etc/solus-release ]; then eopkg install pip python3 python3-devel dmidecode gobject-introspection-devel libcairo-devel gcc libgtk-3
detected_distro "Solus" eopkg install -c system.devel
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
completed detected_distro "Arch Linux based"
complete_msg 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)" elif [ -f /etc/os-release ];then
separator eval "$(cat /etc/os-release)"
case $ID in separator
opensuse-leap) case $ID in
detected_distro "OpenSUSE" opensuse-leap)
zypper install -y python3 python3-pip python3-setuptools python3-devel gcc dmidecode gobject-introspection-devel python3-cairo-devel gtk3 gtk3-devel detected_distro "OpenSUSE"
completed zypper install -y python3 python3-pip python3-setuptools python3-devel gcc dmidecode gobject-introspection-devel python3-cairo-devel gtk3 gtk3-devel
;; ;;
opensuse-tumbleweed) opensuse-tumbleweed)
detected_distro "OpenSUSE" 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
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"
arch|manjaro|endeavouros|garuda|artix) xbps-install -Sy python3 python3-pip python3-devel python3-setuptools base-devel dmidecode cairo-devel gobject-introspection gcc gtk+3
detected_distro "Arch Linux based" ;;
pacman -S --noconfirm --needed python python-pip python-setuptools base-devel dmidecode gobject-introspection gtk3 gcc nixos)
completed 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"
void) exit 1
detected_distro "Void Linux" ;;
xbps-install -Sy python3 python3-pip python3-devel python3-setuptools base-devel dmidecode cairo-devel gobject-introspection gcc gtk+3 *) manual_install;;
completed esac
;; else # In case /etc/os-release doesn't exist
nixos) manual_install
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 exit 1
;; fi
*) #Any other distro
manual_install echo -e "\nInstalling necessary Python packages\n"
completed
;; venv_dir=/opt/auto-cpufreq/venv
esac mkdir -p "${venv_dir}"
complete_msg python3 -m venv "${venv_dir}"
else # In case /etc/os-release doesn't exist
manual_install source "${venv_dir}/bin/activate"
fi 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 { function tool_remove {
@ -293,33 +267,26 @@ Select a key: [i/r/q]: " answer
root_check root_check
if [[ -z "${1}" ]]; then if [[ -z "${1}" ]]; then ask_operation
ask_operation
else else
case "${1}" in case "${1}" in
"--install") "--install") answer="i";;
answer="i" "--remove") answer="r";;
;; *) answer="n";;
"--remove")
answer="r"
;;
*)
answer="n"
;;
esac esac
fi fi
case $answer in case $answer in
I|i) I|i) tool_install;;
tool_install ;; R|r) tool_remove;;
R|r)
tool_remove ;;
Q|q) Q|q)
separator separator
echo "" echo ""
exit 0 ;; exit 0
;;
*) *)
separator separator
echo -e "\nUnknown key, aborting ...\n" echo -e "\nUnknown key, aborting ...\n"
exit 1 ;; exit 1
;;
esac esac