diff --git a/bin/auto-cpufreq b/bin/auto-cpufreq index 9006960..84b6dfa 100755 --- a/bin/auto-cpufreq +++ b/bin/auto-cpufreq @@ -9,6 +9,8 @@ import sys sys.path.append('../') from source.core import * +# ToD: replace every s.call with s.run + # cli @click.command() @click.option("--monitor", is_flag=True, help="Monitor and suggest CPU optimizations") @@ -29,8 +31,7 @@ def main(monitor, live, daemon, install, log): footer(79) else: if daemon: - #if os.getenv("PKG_MARKER") == "SNAP" and os.getenv("DAEMON") == "ENABLED": - if os.getenv("PKG_MARKER") == "SNAP": + if os.getenv("PKG_MARKER") == "SNAP" and dcheck == "enabled": while True: root_check() gov_check() @@ -40,6 +41,7 @@ def main(monitor, live, daemon, install, log): countdown(5) subprocess.call("clear") elif os.getenv("PKG_MARKER") != "SNAP": + # ToDo: disable running daemon without install (like on snap) while True: root_check() gov_check() @@ -49,10 +51,13 @@ def main(monitor, live, daemon, install, log): countdown(5) subprocess.call("clear") else: - sys.exit("Daemon non ENABLED") + print("\n" + "-" * 32 + " Daemon check " + "-" * 33 + "\n") + print("ERROR:\n\nDaemon not enabled, must run install first, i.e: \nsudo auto-cpufreq --install") + footer(79) exit(1) elif monitor: while True: + # ToDo: doesn't work on snap running_check() root_check() gov_check() @@ -63,6 +68,7 @@ def main(monitor, live, daemon, install, log): subprocess.call("clear") elif live: while True: + # ToDo: doesn't work on snap running_check() root_check() gov_check() @@ -79,19 +85,20 @@ def main(monitor, live, daemon, install, log): running_check() root_check() gov_check() - #os.environ["DAEMON"] = "ENABLED" + s.run("snapctl set daemon=enabled", shell=True) s.run("snapctl start --enable auto-cpufreq", shell=True) + deploy_complete_msg() else: running_check() root_check() gov_check() deploy() + deploy_complete_msg() elif remove: if os.getenv('PKG_MARKER') == "SNAP": root_check() - #s.run("snapctl stop --disable auto-cpufreq", shell=True) + s.run("snapctl set daemon=disabled", shell=True) s.run("snapctl stop --disable auto-cpufreq", shell=True) - else: root_check() remove() diff --git a/scripts/auto-cpufreq-install.sh b/scripts/auto-cpufreq-install.sh index 0243758..c800e60 100755 --- a/scripts/auto-cpufreq-install.sh +++ b/scripts/auto-cpufreq-install.sh @@ -24,11 +24,4 @@ echo -e "\n* Starting auto-cpufreq daemon (systemd) service" systemctl start auto-cpufreq echo -e "\n* Enabling auto-cpufreq daemon (systemd) service at boot" -systemctl enable auto-cpufreq - -echo -e "\n------------------ auto-cpufreq daemon installed and running -----------------\n" - -echo -e "To view live log, run:\nauto-cpufreq --log" -echo -e "\nTo disable and remove auto-cpufreq daemon, run:\nsudo auto-cpufreq --remove" - -echo -e "\n-------------------------------------------------------------------------------\n" +systemctl enable auto-cpufreq \ No newline at end of file diff --git a/snap/snapcraft.yaml b/snap/snapcraft.yaml index 5ad853f..a8124fa 100644 --- a/snap/snapcraft.yaml +++ b/snap/snapcraft.yaml @@ -37,6 +37,5 @@ apps: LC_ALL: C.UTF-8 LANG: C.UTF-8 PKG_MARKER: SNAP - DAEMON: DISABLED daemon: simple \ No newline at end of file diff --git a/source/core.py b/source/core.py index a484c8a..f64a83e 100644 --- a/source/core.py +++ b/source/core.py @@ -36,6 +36,9 @@ bat_state = power.PowerManagement().get_providing_power_source_type() # auto-cpufreq log file auto_cpufreq_log_file = "/var/log/auto-cpufreq.log" +# daemon check +dcheck = subprocess.getoutput("snapctl get daemon") + # deploy cpufreqctl script def cpufreqctl(): # detect if running on a SNAP @@ -48,9 +51,16 @@ def cpufreqctl(): else: os.system("cp /usr/local/share/auto-cpufreq/scripts/cpufreqctl.sh /usr/bin/cpufreqctl") +# print footer func def footer(l): print("\n" + "-" * l + "\n") +def deploy_complete_msg(): + print("\n" + "-" * 17 + " auto-cpufreq daemon installed and running " + "-" * 17 + "\n") + print("To view live log, run:\nauto-cpufreq --log") + print("\nTo disable and remove auto-cpufreq daemon, run:\nsudo auto-cpufreq --remove") + footer(79) + # deploy auto-cpufreq daemon def deploy(): @@ -165,12 +175,10 @@ def set_powersave(): elif cpuload > 50: print("High CPU load, setting turbo boost: on") s.run("echo 0 > /sys/devices/system/cpu/intel_pstate/no_turbo", shell=True) - #print("\n" + "-" * 60 + "\n") footer(79) else: print("Load optimal, setting turbo boost: off") s.run("echo 1 > /sys/devices/system/cpu/intel_pstate/no_turbo", shell=True) - #print("\n" + "-" * 60 + "\n") footer(79) # make turbo suggestions in powersave @@ -228,12 +236,10 @@ def set_performance(): elif cpuload > 20: print("High CPU load, setting turbo boost: on") s.run("echo 0 > /sys/devices/system/cpu/intel_pstate/no_turbo", shell=True) - #print("\n" + "-" * 60 + "\n") footer(79) else: print("Load optimal, setting turbo boost: off") s.run("echo 1 > /sys/devices/system/cpu/intel_pstate/no_turbo", shell=True) - #print("\n" + "-" * 60 + "\n") footer(79) # make turbo suggestions in performance