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
auto-cpufreq: init at 1.5.1 #106985
Merged
Merged
auto-cpufreq: init at 1.5.1 #106985
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
{ stdenv, python3Packages, fetchFromGitHub }: | ||
|
||
python3Packages.buildPythonPackage rec { | ||
pname = "auto-cpufreq"; | ||
version = "1.5.1"; | ||
|
||
src = fetchFromGitHub { | ||
owner = "AdnanHodzic"; | ||
repo = pname; | ||
rev = "v${version}"; | ||
sha256 = "uVhftO6AqFnZ0uaEYRAPvVskkouNOXPtNVYXx7WJKyw="; | ||
}; | ||
|
||
propagatedBuildInputs = with python3Packages; [ click distro psutil ]; | ||
|
||
doCheck = false; | ||
pythonImportsCheck = [ "source" ]; | ||
|
||
# patch to prevent script copying and to disable install | ||
patches = [ ./prevent-install-and-copy.patch ]; | ||
|
||
postInstall = '' | ||
# copy script manually | ||
cp ${src}/scripts/cpufreqctl.sh $out/bin/cpufreqctl | ||
''; | ||
|
||
meta = with stdenv.lib; { | ||
homepage = "https://github.com/AdnanHodzic/auto-cpufreq"; | ||
description = "Automatic CPU speed & power optimizer for Linux"; | ||
license = licenses.lgpl3Plus; | ||
platforms = platforms.linux; | ||
maintainers = [ maintainers.Technical27 ]; | ||
}; | ||
} |
178 changes: 178 additions & 0 deletions
178
pkgs/tools/system/autocpu-freq/prevent-install-and-copy.patch
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,178 @@ | ||
diff --git a/scripts/cpufreqctl.sh b/scripts/cpufreqctl.sh | ||
index 63a2b5b..e157efe 100755 | ||
--- a/scripts/cpufreqctl.sh | ||
+++ b/scripts/cpufreqctl.sh | ||
@@ -467,35 +467,21 @@ fi | ||
|
||
if [ $OPTION = "--install" ] | ||
then | ||
- echo 'installing helpers...' | ||
- cp $0 /usr/bin/ | ||
- echo 'installing policy...' | ||
- cp $(dirname "$(readlink -f "$0")")/konkor.cpufreq.policy /usr/share/polkit-1/actions/ | ||
- echo 'installing fonts...' | ||
- mkdir -p /usr/share/fonts/truetype/cpufreq | ||
- cp $(dirname "$(readlink -f "$0")")/fonts/cpufreq.ttf /usr/share/fonts/truetype/cpufreq/ | ||
- echo "done" | ||
+ echo "install is disabled in the nix package" | ||
exit | ||
fi | ||
if [ $OPTION = "--update-fonts" ] | ||
then | ||
- fc-cache -f | ||
+ echo "update-fonts is disabled in the nix package" | ||
exit | ||
fi | ||
if [ $OPTION = "--uninstall" ] | ||
then | ||
- echo 'uninstalling cpufreqctl helper...' | ||
- rm /usr/bin/cpufreqctl | ||
- echo 'uninstalling policy...' | ||
- rm /usr/share/polkit-1/actions/konkor.cpufreq.policy | ||
- echo 'uninstalling fonts...' | ||
- rm -rf /usr/share/fonts/truetype/cpufreq | ||
- echo "done" | ||
+ echo "uninstall is disabled in the nix package" | ||
exit | ||
fi | ||
if [ $OPTION = "--reset" ] | ||
then | ||
- echo 'reset to default values...' | ||
- dconf reset -f "/org/gnome/shell/extensions/cpufreq/" | ||
+ echo "reset is disabled in the nix package" | ||
exit | ||
fi | ||
diff --git a/source/core.py b/source/core.py | ||
index 531c0c4..2e27e65 100644 | ||
--- a/source/core.py | ||
+++ b/source/core.py | ||
@@ -24,8 +24,6 @@ warnings.filterwarnings("ignore") | ||
# - re-enable CPU fan speed display and make more generic and not only for thinkpad | ||
# - replace get system/CPU load from: psutil.getloadavg() | available in 5.6.2) | ||
|
||
-SCRIPTS_DIR = Path("/usr/local/share/auto-cpufreq/scripts/") | ||
- | ||
# from the highest performance to the lowest | ||
ALL_GOVERNORS = ("performance", "ondemand", "conservative", "schedutil", "userspace", "powersave") | ||
CPUS = os.cpu_count() | ||
@@ -156,34 +154,16 @@ def cpufreqctl(): | ||
""" | ||
deploy cpufreqctl script | ||
""" | ||
- | ||
- # detect if running on a SNAP | ||
- if os.getenv('PKG_MARKER') == "SNAP": | ||
- pass | ||
- else: | ||
- # deploy cpufreqctl script (if missing) | ||
- if os.path.isfile("/usr/bin/cpufreqctl"): | ||
- shutil.copy("/usr/bin/cpufreqctl", "/usr/bin/cpufreqctl.auto-cpufreq.bak") | ||
- shutil.copy(SCRIPTS_DIR / "cpufreqctl.sh", "/usr/bin/cpufreqctl") | ||
- else: | ||
- shutil.copy(SCRIPTS_DIR / "cpufreqctl.sh", "/usr/bin/cpufreqctl") | ||
+ # scripts are already in the correct place | ||
+ pass | ||
|
||
|
||
def cpufreqctl_restore(): | ||
""" | ||
restore original cpufreqctl script | ||
""" | ||
- # detect if running on a SNAP | ||
- if os.getenv('PKG_MARKER') == "SNAP": | ||
- pass | ||
- else: | ||
- # restore original cpufreqctl script | ||
- if os.path.isfile("/usr/bin/cpufreqctl.auto-cpufreq.bak"): | ||
- os.system("cp /usr/bin/cpufreqctl.auto-cpufreq.bak /usr/bin/cpufreqctl") | ||
- os.remove("/usr/bin/cpufreqctl.auto-cpufreq.bak") | ||
- # ToDo: implement mechanism to make sure cpufreqctl (auto-cpufreq) file is | ||
- # restored if overwritten by system. But during tool removal to also remove it | ||
- # in def cpufreqctl | ||
+ # no need to restore | ||
+ pass | ||
|
||
|
||
def footer(l=79): | ||
@@ -209,71 +189,13 @@ def remove_complete_msg(): | ||
|
||
|
||
def deploy_daemon(): | ||
- print("\n" + "-" * 21 + " Deploying auto-cpufreq as a daemon " + "-" * 22 + "\n") | ||
- | ||
- # deploy cpufreqctl script func call | ||
- cpufreqctl() | ||
- | ||
- print("* Turn off bluetooth on boot") | ||
- btconf = Path("/etc/bluetooth/main.conf") | ||
- try: | ||
- orig_set = "AutoEnable=true" | ||
- change_set = "AutoEnable=false" | ||
- with btconf.open(mode="r+") as f: | ||
- content = f.read() | ||
- f.seek(0) | ||
- f.truncate() | ||
- f.write(content.replace(orig_set, change_set)) | ||
- except: | ||
- print("\nERROR:\nWas unable to turn off bluetooth on boot") | ||
- | ||
- auto_cpufreq_log_file.touch(exist_ok=True) | ||
- | ||
- print("\n* Deploy auto-cpufreq install script") | ||
- shutil.copy(SCRIPTS_DIR / "auto-cpufreq-install.sh", "/usr/bin/auto-cpufreq-install") | ||
- | ||
- print("\n* Deploy auto-cpufreq remove script") | ||
- shutil.copy(SCRIPTS_DIR / "auto-cpufreq-remove.sh", "/usr/bin/auto-cpufreq-remove") | ||
- | ||
- call("/usr/bin/auto-cpufreq-install", shell=True) | ||
+ # prevent needless copying and system changes | ||
+ pass | ||
|
||
|
||
# remove auto-cpufreq daemon | ||
def remove(): | ||
- | ||
- # check if auto-cpufreq is installed | ||
- if not os.path.exists("/usr/bin/auto-cpufreq-remove"): | ||
- print("\nauto-cpufreq daemon is not installed.\n") | ||
- sys.exit(1) | ||
- | ||
- print("\n" + "-" * 21 + " Removing auto-cpufreq daemon " + "-" * 22 + "\n") | ||
- | ||
- print("* Turn on bluetooth on boot") | ||
- btconf = "/etc/bluetooth/main.conf" | ||
- try: | ||
- orig_set = "AutoEnable=true" | ||
- change_set = "AutoEnable=false" | ||
- with open(btconf, "r+") as f: | ||
- content = f.read() | ||
- f.seek(0) | ||
- f.truncate() | ||
- f.write(content.replace(change_set, orig_set)) | ||
- except: | ||
- print("\nERROR:\nWas unable to turn on bluetooth on boot") | ||
- | ||
- # run auto-cpufreq daemon install script | ||
- call("/usr/bin/auto-cpufreq-remove", shell=True) | ||
- | ||
- # remove auto-cpufreq-remove | ||
- os.remove("/usr/bin/auto-cpufreq-remove") | ||
- | ||
- # delete log file | ||
- if auto_cpufreq_log_file.exists(): | ||
- auto_cpufreq_log_file.unlink() | ||
- | ||
- # restore original cpufrectl script | ||
- cpufreqctl_restore() | ||
- | ||
+ pass | ||
|
||
def gov_check(): | ||
for gov in get_avail_gov(): | ||
@@ -798,4 +720,4 @@ def running_daemon(): | ||
exit(1) | ||
elif os.getenv("PKG_MARKER") == "SNAP" and dcheck == "enabled": | ||
deploy_complete_msg() | ||
- exit(1) | ||
\ No newline at end of file | ||
+ exit(1) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Compared to
install()
it seems to me that the installation is incomplete (missed the font install and polkit policy). Doesn't this make this program miss some features 🤔 ?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It seems that this script was copied from this repo. Those files don't even exist in anywhere in auto-cpufreq, but they do exist in the other project.