Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update feature added #526

Closed
wants to merge 15 commits into from
27 changes: 27 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ auto-cpufreq is looking for [co-maintainers & open source developers to help sha
* [Snap store](https://github.com/AdnanHodzic/auto-cpufreq/#snap-store)
* [auto-cpufreq-installer](https://github.com/AdnanHodzic/auto-cpufreq/#auto-cpufreq-installer)
* [AUR package (Arch/Manjaro Linux)](https://github.com/AdnanHodzic/auto-cpufreq/#aur-package-archmanjaro-linux)
* [Update using installer](https://github.com/AdnanHodzic/auto-cpufreq/#update-using-auto-cpufreq-installer)
* [Post Installation](https://github.com/AdnanHodzic/auto-cpufreq/#post-installation)
* [Configuring auto-cpufreq](https://github.com/AdnanHodzic/auto-cpufreq/#configuring-auto-cpufreq)
* [1: power_helper.py script (Snap package install only)](https://github.com/AdnanHodzic/auto-cpufreq/#1-power_helperpy-script-snap-package-install-only)
Expand All @@ -31,6 +32,7 @@ auto-cpufreq is looking for [co-maintainers & open source developers to help sha
* [live](https://github.com/AdnanHodzic/auto-cpufreq/#live)
* [overriding governor](https://github.com/AdnanHodzic/auto-cpufreq/#overriding-governor)
* [Install - auto-cpufreq daemon](https://github.com/AdnanHodzic/auto-cpufreq/#install---auto-cpufreq-daemon)
* [Update - auto-cpufreq daemon](https://github.com/AdnanHodzic/auto-cpufreq/#update---auto-cpufreq-update)
* [Remove - auto-cpufreq daemon](https://github.com/AdnanHodzic/auto-cpufreq/#remove---auto-cpufreq-daemon)
* [stats](https://github.com/AdnanHodzic/auto-cpufreq/#stats)
* [Troubleshooting](https://github.com/AdnanHodzic/auto-cpufreq/#troubleshooting)
Expand Down Expand Up @@ -99,6 +101,16 @@ Get source code, run installer and follow on screen instructions:
git clone https://github.com/AdnanHodzic/auto-cpufreq.git
cd auto-cpufreq && sudo ./auto-cpufreq-installer
```
### Update using auto-cpufreq-installer
AdnanHodzic marked this conversation as resolved.
Show resolved Hide resolved
* The feature is available in version >= *1.9.9*. If your current version is below the same, Get source code, run installer and follow on screen instructions:

```
git clone https://github.com/AdnanHodzic/auto-cpufreq.git
cd auto-cpufreq && sudo ./auto-cpufreq-installer
```
and choose 'Update' option

* For version >= *1.9.9*, try [--update](https://github.com/AdnanHodzic/auto-cpufreq/#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).

Expand Down Expand Up @@ -211,6 +223,9 @@ auto-cpufreq should be run with with one of the following options:
* [install](https://github.com/AdnanHodzic/auto-cpufreq/#install---auto-cpufreq-daemon) / [remove](https://github.com/AdnanHodzic/auto-cpufreq/#remove---auto-cpufreq-daemon)
- Install/remove daemon for (permanent) automatic CPU optimizations

* [update](https://github.com/AdnanHodzic/auto-cpufreq/#update---auto-cpufreq-update)
- Update the package to the latest release

* [install_performance](https://github.com/AdnanHodzic/auto-cpufreq/#1-power_helperpy-script)
- Install daemon in "performance" mode.

Expand Down Expand Up @@ -278,6 +293,18 @@ If the install has been performed as part of snap package, daemon status can be

`systemctl status snap.auto-cpufreq.service.service`

### Update - auto-cpufreq update

Update to the [latest version](https://github.com/AdnanHodzic/auto-cpufreq) 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](https://github.com/AdnanHodzic/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

auto-cpufreq daemon and its systemd service, along with all its persistent changes can be removed by running:
Expand Down
56 changes: 53 additions & 3 deletions auto-cpufreq-installer
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ function completed () {
echo -e "\nInstalling necessary Python packages\n"
setup_venv
separator
echo -e "\ninstalling auto-cpufreq tool\n"
echo -e "\n installing auto-cpufreq tool\n"
cosmos1721 marked this conversation as resolved.
Show resolved Hide resolved
install
}

Expand Down Expand Up @@ -254,20 +254,65 @@ function tool_remove {
rm -rf "${venv_path}"

separator
echo -e "\nauto-cpufreq tool and all its supporting files successfully removed."
echo -e "\nauto-cpufreq tool and all its supporting files successfully removed."
cosmos1721 marked this conversation as resolved.
Show resolved Hide resolved
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 {
header "auto-cpufreq installer"
echo -e "Welcome to auto-cpufreq tool installer.
\nOptions:\n"
read -p \
"[I]nstall
[U]pdate
[R]emove
[Q]uit

Select a key: [i/r/q]: " answer
Select a key: [i/u/r/q]: " answer
}
# End of functions

Expand All @@ -280,6 +325,9 @@ else
"--install")
answer="i"
;;
"--update")
answer="u"
;;
"--remove")
answer="r"
;;
Expand All @@ -292,6 +340,8 @@ fi
case $answer in
I|i)
tool_install ;;
U|u)
tool_update ;;
R|r)
tool_remove ;;
Q|q)
Expand Down
41 changes: 39 additions & 2 deletions auto_cpufreq/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
from pathlib import Path
from shutil import which
from subprocess import getoutput, call, run, check_output, DEVNULL
import requests

# execution timestamp used in countdown func
from datetime import datetime
Expand Down Expand Up @@ -160,7 +161,41 @@ def app_version():
except Exception as e:
print(repr(e))
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(line for line in output.split('\n') if line.startswith('auto-cpufreq version'))
installed_version = "v" + version_line.split(':')[1].split('(')[0].strip()
#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(current_working_directory)
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")
run(['./auto-cpufreq-installer'], input='i\n', encoding='utf-8')
print("enabling daemon")

# return formatted version for a better readability
def get_formatted_version():
literal_version = pkg_resources.require("auto-cpufreq")[0].version
Expand Down Expand Up @@ -414,7 +449,8 @@ def deploy_daemon_performance():

# output warning if gnome power profile is running
gnome_power_detect_install()
gnome_power_svc_disable_performance()
#"gnome_power_svc_disable_performance" is not defined
# gnome_power_svc_disable_performance()
cosmos1721 marked this conversation as resolved.
Show resolved Hide resolved

# output warning if TLP service is detected
tlp_service_detect()
Expand Down Expand Up @@ -1256,3 +1292,4 @@ def not_running_daemon_check():
elif os.getenv("PKG_MARKER") == "SNAP" and dcheck == "disabled":
daemon_not_running_msg()
exit(1)

35 changes: 32 additions & 3 deletions bin/auto-cpufreq
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ from auto_cpufreq.power_helper import *
@click.command()
@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("--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("--remove", is_flag=True, help="Remove daemon for (permanent) automatic CPU optimizations")

Expand All @@ -35,7 +36,7 @@ from auto_cpufreq.power_helper import *
@click.option("--donate", is_flag=True, help="Support the project")
@click.option("--log", 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
def config_info_dialog():
Expand Down Expand Up @@ -85,7 +86,9 @@ def main(config, daemon, debug, install, remove, live, log, monitor, stats, vers
set_autofreq()
countdown(2)
else:
daemon_not_found()
pass
#"daemon_not_found" is not defined
cosmos1721 marked this conversation as resolved.
Show resolved Hide resolved
#daemon_not_found()
elif monitor:
config_info_dialog()
root_check()
Expand Down Expand Up @@ -211,14 +214,40 @@ def main(config, daemon, debug, install, remove, live, log, monitor, stats, vers
auto_cpufreq_stats_file.close()

auto_cpufreq_stats_path.unlink()
# ToDo:
# ToDo:
# {the following snippet also used in --update, update it there too(if required)}
AdnanHodzic marked this conversation as resolved.
Show resolved Hide resolved
# * undo bluetooth boot disable
gnome_power_rm_reminder_snap()
remove_complete_msg()
else:
root_check()
remove_daemon()
remove_complete_msg()
elif update:
verify_update()
ans = input ("Do you want to update auto-cpufreq to the latest release? [y/n]: ")
if ans =='y':
root_check()
if os.getenv("PKG_MARKER") == "SNAP":
run("snapctl set daemon=disabled", shell=True)
run("snapctl stop --disable auto-cpufreq", shell=True)
if auto_cpufreq_stats_path.exists():
if auto_cpufreq_stats_file is not None:
auto_cpufreq_stats_file.close()
auto_cpufreq_stats_path.unlink()
# * undo bluetooth boot disable
gnome_power_rm_reminder_snap()
remove_complete_msg()
else:
remove_daemon()
remove_complete_msg()
new_update()
run(["auto-cpufreq", "--install"])
print("auto-cpufreq has been updated to the latest release ")
app_version()
else:
print("Aborted")



if __name__ == "__main__":
Expand Down
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@ setuptools
psutil
click
distro
requests
AdnanHodzic marked this conversation as resolved.
Show resolved Hide resolved
7 changes: 5 additions & 2 deletions setup.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import os

import requests
from setuptools import setup

with open("README.md") as readme_file:
Expand All @@ -13,7 +13,10 @@ def read(name):
return f.read()

# Used for the tar.gz/snap releases
VERSION = "1.9.8"
latest_release_url = f"https://api.github.com/repos/AdnanHodzic/auto-cpufreq/releases/latest"
latest_release = requests.get(latest_release_url).json()
VERSION = latest_release["tag_name"]
AdnanHodzic marked this conversation as resolved.
Show resolved Hide resolved


setup(
name="auto-cpufreq",
Expand Down