mirror of
https://github.com/AdnanHodzic/auto-cpufreq.git
synced 2025-07-21 12:45:03 +02:00
Add auto-cpufreq --update feature (#535)
* update feature * update feature added * '--update' * update feature
This commit is contained in:
parent
faf7134cb6
commit
3dffa23e00
26
README.md
26
README.md
@ -19,6 +19,7 @@ auto-cpufreq is looking for [co-maintainers & open source developers to help sha
|
|||||||
* [Snap store](#snap-store)
|
* [Snap store](#snap-store)
|
||||||
* [auto-cpufreq-installer](#auto-cpufreq-installer)
|
* [auto-cpufreq-installer](#auto-cpufreq-installer)
|
||||||
* [AUR package (Arch/Manjaro Linux)](#aur-package-archmanjaro-linux)
|
* [AUR package (Arch/Manjaro Linux)](#aur-package-archmanjaro-linux)
|
||||||
|
* [Update using installer](#update-using-auto-cpufreq-installer)
|
||||||
* [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)
|
||||||
@ -31,6 +32,7 @@ auto-cpufreq is looking for [co-maintainers & open source developers to help sha
|
|||||||
* [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)
|
||||||
* [Remove - auto-cpufreq daemon](#remove---auto-cpufreq-daemon)
|
* [Remove - auto-cpufreq daemon](#remove---auto-cpufreq-daemon)
|
||||||
* [stats](#stats)
|
* [stats](#stats)
|
||||||
* [Troubleshooting](#troubleshooting)
|
* [Troubleshooting](#troubleshooting)
|
||||||
@ -99,12 +101,16 @@ Get source code, run installer and follow on screen instructions:
|
|||||||
git clone https://github.com/AdnanHodzic/auto-cpufreq.git
|
git clone https://github.com/AdnanHodzic/auto-cpufreq.git
|
||||||
cd auto-cpufreq && sudo ./auto-cpufreq-installer
|
cd auto-cpufreq && sudo ./auto-cpufreq-installer
|
||||||
```
|
```
|
||||||
|
### Update using auto-cpufreq-installer
|
||||||
|
* The feature is available from version *1.9.8*.
|
||||||
|
|
||||||
|
For further information: [--update](#update---auto-cpufreq-update)
|
||||||
|
|
||||||
In case you encounter any problems with `auto-cpufreq-installer`, please [submit a bug report](https://github.com/AdnanHodzic/auto-cpufreq/issues/new).
|
In case you encounter any problems with `auto-cpufreq-installer`, please [submit a bug report](https://github.com/AdnanHodzic/auto-cpufreq/issues/new).
|
||||||
|
|
||||||
### AUR package (Arch/Manjaro Linux)
|
### AUR package (Arch/Manjaro Linux)
|
||||||
|
|
||||||
*AUR is currently unmaintained & has issues*! Until someone starts maintaining it, use the [auto-cpufreq-installer](https://github.com/AdnanHodzic/auto-cpufreq#auto-cpufreq-installer) if you intend to have the latest changes as otherwise you'll run into errors, i.e: [#471](https://github.com/AdnanHodzic/auto-cpufreq/issues/471). However, if you still wish to use AUR then follow the [Troubleshooting](#aur) section for solved known issues.
|
*AUR is currently unmaintained & has issues*! Until someone starts maintaining it, use the [auto-cpufreq-installer](#auto-cpufreq-installer) if you intend to have the latest changes as otherwise you'll run into errors, i.e: [#471](https://github.com/AdnanHodzic/auto-cpufreq/issues/471). However, if you still wish to use AUR then follow the [Troubleshooting](#aur) section for solved known issues.
|
||||||
|
|
||||||
* [Binary Package](https://aur.archlinux.org/packages/auto-cpufreq)
|
* [Binary Package](https://aur.archlinux.org/packages/auto-cpufreq)
|
||||||
(For the latest binary release on github)
|
(For the latest binary release on github)
|
||||||
@ -211,6 +217,9 @@ auto-cpufreq should be run with with one of the following options:
|
|||||||
* [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
|
||||||
|
|
||||||
|
* [update](#update---auto-cpufreq-update)
|
||||||
|
- Update the package 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.
|
||||||
|
|
||||||
@ -278,6 +287,21 @@ If the install has been performed as part of snap package, daemon status can be
|
|||||||
|
|
||||||
`systemctl status snap.auto-cpufreq.service.service`
|
`systemctl status snap.auto-cpufreq.service.service`
|
||||||
|
|
||||||
|
### Update - auto-cpufreq update
|
||||||
|
|
||||||
|
Update to the [latest version](https://github.com/AdnanHodzic/auto-cpufreq/releases) of auto-cpufreq with fixes and resolved bugs.
|
||||||
|
|
||||||
|
Manually clone auto-cpufreq to the latest release if this mode is not available in your package follow [Installing auto-cpufreq](#installing-auto-cpufreq)
|
||||||
|
|
||||||
|
Update the package by running:
|
||||||
|
|
||||||
|
`sudo auto-cpufreq --update`
|
||||||
|
|
||||||
|
This does the equivalent of:
|
||||||
|
* `systemctl stop auto-cpufreq && systemctl disable auto-cpufreq`
|
||||||
|
* Fetching new update and install
|
||||||
|
* `systemctl enable auto-cpufreq`
|
||||||
|
|
||||||
### Remove - auto-cpufreq daemon
|
### Remove - auto-cpufreq daemon
|
||||||
|
|
||||||
auto-cpufreq daemon and its systemd service, along with all its persistent changes can be removed by running:
|
auto-cpufreq daemon and its systemd service, along with all its persistent changes can be removed by running:
|
||||||
|
@ -257,6 +257,50 @@ function tool_remove {
|
|||||||
echo -e "\nauto-cpufreq tool and all its supporting files successfully removed."
|
echo -e "\nauto-cpufreq tool and all its supporting files successfully removed."
|
||||||
separator
|
separator
|
||||||
}
|
}
|
||||||
|
function tool_update {
|
||||||
|
# Specify the repository and package name
|
||||||
|
# IT IS IMPORTANT TO NOTE THAT IF THE REPOSITORY STRUCTURE IS CHANGED, THE FOLLOWING FUNCTION NEEDS TO BE UPDATED ACCORDINGLY
|
||||||
|
repository="AdnanHodzic/auto-cpufreq"
|
||||||
|
# Fetch the latest release information from GitHub API
|
||||||
|
latest_release=$(curl -s "https://api.github.com/repos/$repository/releases/latest")
|
||||||
|
# Extract the latest release version without using jq
|
||||||
|
latest_version=$(echo "$latest_release" | grep -o '"tag_name": "[^"]*' | cut -d'"' -f4)
|
||||||
|
# Get the current version of auto-cpufreq
|
||||||
|
#installed_version=$(pip list | awk '/auto-cpufreq/ {print $2}')
|
||||||
|
installed_version=$(grep -oP "(?<=__requires__ = 'auto-cpufreq==)\d+(\.\d+)+" /opt/auto-cpufreq/venv/bin/auto-cpufreq)
|
||||||
|
#Check whether the same is installed or not
|
||||||
|
if [[ -z "$installed_version" ]]; then
|
||||||
|
echo "Current version not found, please install auto-cpufreq first"
|
||||||
|
echo $installed_version
|
||||||
|
sleep 1
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
installed_version="v$installed_version"
|
||||||
|
# Compare the latest version with the installed version and perform update if necessary
|
||||||
|
if [[ "$latest_version" == "$installed_version" ]]; then
|
||||||
|
echo "auto-cpufreq is up to date"
|
||||||
|
else
|
||||||
|
echo -e "Updates are available,\nCurrent version: $installed_version\nLatest version: $latest_version \nNote that your previous custom settings might be \033[1merased\033[0m with the following update \nalong with the \033[1mcurrent\033[0m directory. "
|
||||||
|
read -p "Do you want to update auto-cpufreq to the latest release? [y/n]: " ans
|
||||||
|
if [[ "$ans" == "y" ]]; then
|
||||||
|
header "Updating auto-cpufreq to the latest release\n"
|
||||||
|
tool_remove
|
||||||
|
echo -e "deleting the current directory\n"
|
||||||
|
script_directory="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
||||||
|
mkdir "$script_directory/../auto-cpufreq $latest_version" && cd $_
|
||||||
|
rm -rf $script_directory
|
||||||
|
echo -e "cloning to the latest release\n"
|
||||||
|
git clone https://github.com/AdnanHodzic/auto-cpufreq.git
|
||||||
|
cd auto-cpufreq
|
||||||
|
separator
|
||||||
|
tool_install
|
||||||
|
else
|
||||||
|
separator
|
||||||
|
echo "Aborting..."
|
||||||
|
sleep 0.5
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
function ask_operation {
|
function ask_operation {
|
||||||
header "auto-cpufreq installer"
|
header "auto-cpufreq installer"
|
||||||
@ -264,10 +308,11 @@ function ask_operation {
|
|||||||
\nOptions:\n"
|
\nOptions:\n"
|
||||||
read -p \
|
read -p \
|
||||||
"[I]nstall
|
"[I]nstall
|
||||||
|
[U]pdate
|
||||||
[R]emove
|
[R]emove
|
||||||
[Q]uit
|
[Q]uit
|
||||||
|
|
||||||
Select a key: [i/r/q]: " answer
|
Select a key: [i/u/r/q]: " answer
|
||||||
}
|
}
|
||||||
# End of functions
|
# End of functions
|
||||||
|
|
||||||
@ -280,6 +325,9 @@ else
|
|||||||
"--install")
|
"--install")
|
||||||
answer="i"
|
answer="i"
|
||||||
;;
|
;;
|
||||||
|
"--update")
|
||||||
|
answer="u"
|
||||||
|
;;
|
||||||
"--remove")
|
"--remove")
|
||||||
answer="r"
|
answer="r"
|
||||||
;;
|
;;
|
||||||
@ -292,6 +340,8 @@ fi
|
|||||||
case $answer in
|
case $answer in
|
||||||
I|i)
|
I|i)
|
||||||
tool_install ;;
|
tool_install ;;
|
||||||
|
U|u)
|
||||||
|
tool_update ;;
|
||||||
R|r)
|
R|r)
|
||||||
tool_remove ;;
|
tool_remove ;;
|
||||||
Q|q)
|
Q|q)
|
||||||
|
40
auto_cpufreq/core.py
Normal file → Executable file
40
auto_cpufreq/core.py
Normal file → Executable file
@ -18,6 +18,8 @@ from math import isclose
|
|||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
from shutil import which
|
from shutil import which
|
||||||
from subprocess import getoutput, call, run, check_output, DEVNULL
|
from subprocess import getoutput, call, run, check_output, DEVNULL
|
||||||
|
import requests
|
||||||
|
import re
|
||||||
|
|
||||||
# execution timestamp used in countdown func
|
# execution timestamp used in countdown func
|
||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
@ -159,6 +161,40 @@ def app_version():
|
|||||||
except Exception as e:
|
except Exception as e:
|
||||||
print(repr(e))
|
print(repr(e))
|
||||||
pass
|
pass
|
||||||
|
def verify_update():
|
||||||
|
# Specify the repository and package name
|
||||||
|
# IT IS IMPORTANT TO THAT IF THE REPOSITORY STRUCTURE IS CHANGED, THE FOLLOWING FUNCTION NEEDS TO BE UPDATED ACCORDINGLY
|
||||||
|
# Fetch the latest release information from GitHub API
|
||||||
|
latest_release_url = f"https://api.github.com/repos/AdnanHodzic/auto-cpufreq/releases/latest"
|
||||||
|
latest_release = requests.get(latest_release_url).json()
|
||||||
|
latest_version = latest_release["tag_name"]
|
||||||
|
|
||||||
|
# Get the current version of auto-cpufreq
|
||||||
|
# Extract version number from the output string
|
||||||
|
output = check_output(['auto-cpufreq', '--version']).decode('utf-8')
|
||||||
|
version_line = next((re.search(r'\d+\.\d+\.\d+', line).group() for line in output.split('\n') if line.startswith('auto-cpufreq version')), None)
|
||||||
|
installed_version = "v" + version_line
|
||||||
|
#Check whether the same is installed or not
|
||||||
|
# Compare the latest version with the installed version and perform update if necessary
|
||||||
|
if latest_version == installed_version:
|
||||||
|
print("auto-cpufreq is up to date")
|
||||||
|
exit(0)
|
||||||
|
else:
|
||||||
|
print(f"Updates are available,\nCurrent version: {installed_version}\nLatest version: {latest_version}")
|
||||||
|
print("Note that your previous custom settings might be erased with the following update")
|
||||||
|
|
||||||
|
def new_update():
|
||||||
|
username = os.getlogin()
|
||||||
|
home_dir = "/home/" + username
|
||||||
|
os.chdir(home_dir)
|
||||||
|
current_working_directory = os.getcwd()
|
||||||
|
print("Cloning the latest release to the home directory: ")
|
||||||
|
print(os.getcwd())
|
||||||
|
run(["git", "clone", "https://github.com/AdnanHodzic/auto-cpufreq.git"])
|
||||||
|
os.chdir("auto-cpufreq")
|
||||||
|
print("package cloned to directory ", current_working_directory)
|
||||||
|
run(['./auto-cpufreq-installer'], input='i\n', encoding='utf-8')
|
||||||
|
|
||||||
|
|
||||||
# return formatted version for a better readability
|
# return formatted version for a better readability
|
||||||
def get_formatted_version():
|
def get_formatted_version():
|
||||||
@ -413,7 +449,8 @@ def deploy_daemon_performance():
|
|||||||
|
|
||||||
# output warning if gnome power profile is running
|
# output warning if gnome power profile is running
|
||||||
gnome_power_detect_install()
|
gnome_power_detect_install()
|
||||||
gnome_power_svc_disable_performance()
|
#"gnome_power_svc_disable_performance" is not defined
|
||||||
|
#gnome_power_svc_disable_performance()
|
||||||
|
|
||||||
# output warning if TLP service is detected
|
# output warning if TLP service is detected
|
||||||
tlp_service_detect()
|
tlp_service_detect()
|
||||||
@ -1255,3 +1292,4 @@ def not_running_daemon_check():
|
|||||||
elif os.getenv("PKG_MARKER") == "SNAP" and dcheck == "disabled":
|
elif os.getenv("PKG_MARKER") == "SNAP" and dcheck == "disabled":
|
||||||
daemon_not_running_msg()
|
daemon_not_running_msg()
|
||||||
exit(1)
|
exit(1)
|
||||||
|
|
||||||
|
@ -18,6 +18,7 @@ from auto_cpufreq.power_helper import *
|
|||||||
@click.command()
|
@click.command()
|
||||||
@click.option("--monitor", is_flag=True, help="Monitor and see suggestions for CPU optimizations")
|
@click.option("--monitor", is_flag=True, help="Monitor and see suggestions for CPU optimizations")
|
||||||
@click.option("--live", is_flag=True, help="Monitor and make (temp.) suggested CPU optimizations")
|
@click.option("--live", is_flag=True, help="Monitor and make (temp.) suggested CPU optimizations")
|
||||||
|
@click.option("--update", is_flag=True, help="Update daemon and package for (permanent) automatic CPU optimizations")
|
||||||
@click.option("--install", is_flag=True, help="Install daemon for (permanent) automatic CPU optimizations")
|
@click.option("--install", is_flag=True, help="Install daemon for (permanent) automatic CPU optimizations")
|
||||||
@click.option("--remove", is_flag=True, help="Remove daemon for (permanent) automatic CPU optimizations")
|
@click.option("--remove", is_flag=True, help="Remove daemon for (permanent) automatic CPU optimizations")
|
||||||
|
|
||||||
@ -35,7 +36,7 @@ from auto_cpufreq.power_helper import *
|
|||||||
@click.option("--donate", is_flag=True, help="Support the project")
|
@click.option("--donate", is_flag=True, help="Support the project")
|
||||||
@click.option("--log", is_flag=True, hidden=True)
|
@click.option("--log", is_flag=True, hidden=True)
|
||||||
@click.option("--daemon", is_flag=True, hidden=True)
|
@click.option("--daemon", is_flag=True, hidden=True)
|
||||||
def main(config, daemon, debug, install, remove, live, log, monitor, stats, version, donate, force, get_state):
|
def main(config, daemon, debug, update, install, remove, live, log, monitor, stats, version, donate, force, get_state):
|
||||||
|
|
||||||
# display info if config file is used
|
# display info if config file is used
|
||||||
def config_info_dialog():
|
def config_info_dialog():
|
||||||
@ -86,6 +87,8 @@ def main(config, daemon, debug, install, remove, live, log, monitor, stats, vers
|
|||||||
set_autofreq()
|
set_autofreq()
|
||||||
countdown(2)
|
countdown(2)
|
||||||
else:
|
else:
|
||||||
|
pass
|
||||||
|
#"daemon_not_found" is not defined
|
||||||
daemon_not_found()
|
daemon_not_found()
|
||||||
elif monitor:
|
elif monitor:
|
||||||
config_info_dialog()
|
config_info_dialog()
|
||||||
@ -213,6 +216,7 @@ def main(config, daemon, debug, install, remove, live, log, monitor, stats, vers
|
|||||||
|
|
||||||
auto_cpufreq_stats_path.unlink()
|
auto_cpufreq_stats_path.unlink()
|
||||||
# ToDo:
|
# ToDo:
|
||||||
|
# {the following snippet also used in --update, update it there too(if required)}
|
||||||
# * undo bluetooth boot disable
|
# * undo bluetooth boot disable
|
||||||
gnome_power_rm_reminder_snap()
|
gnome_power_rm_reminder_snap()
|
||||||
remove_complete_msg()
|
remove_complete_msg()
|
||||||
@ -220,6 +224,32 @@ def main(config, daemon, debug, install, remove, live, log, monitor, stats, vers
|
|||||||
root_check()
|
root_check()
|
||||||
remove_daemon()
|
remove_daemon()
|
||||||
remove_complete_msg()
|
remove_complete_msg()
|
||||||
|
elif update:
|
||||||
|
root_check()
|
||||||
|
if os.getenv("PKG_MARKER") == "SNAP":
|
||||||
|
print("Detected auto-cpufreq was installed using snap")
|
||||||
|
# refresh snap directly using this command
|
||||||
|
|
||||||
|
print("Please update using snap package manager, i.e: `sudo snap refresh auto-cpufreq`.")
|
||||||
|
#check for AUR
|
||||||
|
elif subprocess.run(["bash", "-c", "command -v yay >/dev/null 2>&1"]).returncode == 0 or subprocess.run(["bash", "-c", "command -v pacman >/dev/null 2>&1"]).returncode == 0:
|
||||||
|
print("Arch-based distribution with AUR support detected. Please refresh auto-cpufreq using your AUR helper.")
|
||||||
|
else:
|
||||||
|
verify_update()
|
||||||
|
ans = input ("Do you want to update auto-cpufreq to the latest release? [y/n]: ")
|
||||||
|
valid_options = ['y', 'Y', 'yes', 'YES', 'Yes']
|
||||||
|
if ans.lower() in valid_options:
|
||||||
|
remove_daemon()
|
||||||
|
remove_complete_msg()
|
||||||
|
new_update()
|
||||||
|
else:
|
||||||
|
print("incorrect input\n")
|
||||||
|
print("Aborted")
|
||||||
|
print("enabling daemon")
|
||||||
|
run(["auto-cpufreq", "--install"])
|
||||||
|
print("auto-cpufreq is installed with the latest version")
|
||||||
|
app_version()
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
|
1
requirements.txt
Normal file → Executable file
1
requirements.txt
Normal file → Executable file
@ -2,3 +2,4 @@ setuptools
|
|||||||
psutil
|
psutil
|
||||||
click
|
click
|
||||||
distro
|
distro
|
||||||
|
requests
|
||||||
|
@ -20,6 +20,7 @@ parts:
|
|||||||
python-packages:
|
python-packages:
|
||||||
- setuptools
|
- setuptools
|
||||||
- wheel
|
- wheel
|
||||||
|
- requests
|
||||||
build-packages:
|
build-packages:
|
||||||
- gcc
|
- gcc
|
||||||
- python3-dev
|
- python3-dev
|
||||||
|
Loading…
x
Reference in New Issue
Block a user