From 32fa8449ef849e11a947b346740971cb7133f32e Mon Sep 17 00:00:00 2001 From: Aamaruvi Yogamani <38222826+Technical27@users.noreply.github.com> Date: Sun, 24 Jan 2021 08:47:01 -0500 Subject: [PATCH] auto-cpufreq: 1.5.1 -> 1.5.3 The attribute is also changed from autocpu-freq to autocpu-freq --- .../default.nix | 13 +- .../prevent-install-and-copy.patch | 252 ++++++++---------- pkgs/top-level/all-packages.nix | 2 +- 3 files changed, 128 insertions(+), 139 deletions(-) rename pkgs/tools/system/{autocpu-freq => auto-cpufreq}/default.nix (64%) rename pkgs/tools/system/{autocpu-freq => auto-cpufreq}/prevent-install-and-copy.patch (69%) diff --git a/pkgs/tools/system/autocpu-freq/default.nix b/pkgs/tools/system/auto-cpufreq/default.nix similarity index 64% rename from pkgs/tools/system/autocpu-freq/default.nix rename to pkgs/tools/system/auto-cpufreq/default.nix index 7e23b8b5b0f..5a94cff19e1 100644 --- a/pkgs/tools/system/autocpu-freq/default.nix +++ b/pkgs/tools/system/auto-cpufreq/default.nix @@ -2,26 +2,31 @@ python3Packages.buildPythonPackage rec { pname = "auto-cpufreq"; - version = "1.5.1"; + version = "1.5.3"; src = fetchFromGitHub { owner = "AdnanHodzic"; repo = pname; rev = "v${version}"; - sha256 = "uVhftO6AqFnZ0uaEYRAPvVskkouNOXPtNVYXx7WJKyw="; + sha256 = "sha256-NDIdQ4gUN2jG+VWXsv3fdUogZxOOiNtnbekD30+jx6M="; }; propagatedBuildInputs = with python3Packages; [ click distro psutil ]; doCheck = false; - pythonImportsCheck = [ "source" ]; + pythonImportsCheck = [ "auto_cpufreq" ]; # 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 + cp ${src}/scripts/cpufreqctl.sh $out/bin/cpufreqctl.auto-cpufreq + + # systemd service + mkdir -p $out/lib/systemd/system + cp ${src}/scripts/auto-cpufreq.service $out/lib/systemd/system + substituteInPlace $out/lib/systemd/system/auto-cpufreq.service --replace "/usr/local" $out ''; meta = with lib; { diff --git a/pkgs/tools/system/autocpu-freq/prevent-install-and-copy.patch b/pkgs/tools/system/auto-cpufreq/prevent-install-and-copy.patch similarity index 69% rename from pkgs/tools/system/autocpu-freq/prevent-install-and-copy.patch rename to pkgs/tools/system/auto-cpufreq/prevent-install-and-copy.patch index 28c524e1497..232ac780341 100644 --- a/pkgs/tools/system/autocpu-freq/prevent-install-and-copy.patch +++ b/pkgs/tools/system/auto-cpufreq/prevent-install-and-copy.patch @@ -1,3 +1,121 @@ +diff --git a/auto_cpufreq/core.py b/auto_cpufreq/core.py +index 482a544..d142013 100644 +--- a/auto_cpufreq/core.py ++++ b/auto_cpufreq/core.py +@@ -163,31 +163,13 @@ def get_current_gov(): + return print("Currently using:", getoutput("cpufreqctl.auto-cpufreq --governor").strip().split(" ")[0], "governor") + + def cpufreqctl(): +- """ +- deploy cpufreqctl script +- """ +- +- # detect if running on a SNAP +- if os.getenv('PKG_MARKER') == "SNAP": +- pass +- else: +- # deploy cpufreqctl.auto-cpufreq script +- if os.path.isfile("/usr/bin/cpufreqctl"): +- shutil.copy(SCRIPTS_DIR / "cpufreqctl.sh", "/usr/bin/cpufreqctl.auto-cpufreq") +- else: +- shutil.copy(SCRIPTS_DIR / "cpufreqctl.sh", "/usr/bin/cpufreqctl.auto-cpufreq") ++ # scripts are already in the correct place ++ pass + + + def cpufreqctl_restore(): +- """ +- remove cpufreqctl.auto-cpufreq script +- """ +- # detect if running on a SNAP +- if os.getenv('PKG_MARKER') == "SNAP": +- pass +- else: +- if os.path.isfile("/usr/bin/cpufreqctl.auto-cpufreq"): +- os.remove("/usr/bin/cpufreqctl.auto-cpufreq") ++ # no need to restore ++ pass + + def footer(l=79): + print("\n" + "-" * l + "\n") +@@ -212,74 +194,12 @@ 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_path.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_path.exists(): +- if auto_cpufreq_log_file is not None: +- auto_cpufreq_log_file.close() +- +- auto_cpufreq_log_path.unlink() +- +- # restore original cpufrectl script +- cpufreqctl_restore() +- ++ pass + + def gov_check(): + for gov in get_avail_gov(): diff --git a/scripts/cpufreqctl.sh b/scripts/cpufreqctl.sh index 63a2b5b..e157efe 100755 --- a/scripts/cpufreqctl.sh @@ -42,137 +160,3 @@ index 63a2b5b..e157efe 100755 + 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) diff --git a/pkgs/top-level/all-packages.nix b/pkgs/top-level/all-packages.nix index 71ec34213a3..3dbb9e26bd0 100644 --- a/pkgs/top-level/all-packages.nix +++ b/pkgs/top-level/all-packages.nix @@ -29143,7 +29143,7 @@ in ssh-audit = callPackage ../tools/security/ssh-audit { }; - autocpu-freq = callPackage ../tools/system/autocpu-freq { }; + auto-cpufreq = callPackage ../tools/system/auto-cpufreq { }; thermald = callPackage ../tools/system/thermald { };