diff --git a/auto-cpufreq.py b/auto-cpufreq.py index ab78501..977b3ff 100755 --- a/auto-cpufreq.py +++ b/auto-cpufreq.py @@ -76,7 +76,10 @@ def deploy(): os.system("cp auto-cpufreq.py /usr/bin/auto-cpufreq") print("\n* Deploy auto-cpufreq daemon deploy script") - os.system("cp scripts/auto-cpufreq-daemon.sh /usr/bin/auto-cpufreq-daemon") + os.system("cp scripts/auto-cpufreq-deploy.sh /usr/bin/auto-cpufreq-deploy") + + #print("\n* Deploy auto-cpufreq daemon run script") + #os.system("cp scripts/auto-cpufreq-run.sh /usr/bin/auto-cpufreq-run") print("\n* Deploy auto-cpufreq daemon removal script") os.system("cp scripts/auto-cpufreq-remove.sh /usr/bin/auto-cpufreq-remove") @@ -85,13 +88,13 @@ def deploy(): os.system("cp scripts/auto-cpufreq.service /lib/systemd/system/auto-cpufreq.service") # run auto-cpufreq daemon deploy script - s.call("/usr/bin/auto-cpufreq-daemon", shell=True) + s.call("/usr/bin/auto-cpufreq-deploy", shell=True) - print("auto-cpufreq daemon started and will automatically start at boot time.") - print("\nTo disable and remove auto-cpufreq daemon, run:\nsudo auto-cpufreq --remove") + #print("auto-cpufreq daemon started and will automatically start at boot time.") + #print("\nTo disable and remove auto-cpufreq daemon, run:\nsudo auto-cpufreq --remove") - print("\nTo view live auto-cpufreq daemon logs, run:\nauto-cpufreq --log") - footer(79) + #print("\nTo view live auto-cpufreq daemon logs, run:\nauto-cpufreq --log") + #footer(79) # remove auto-cpufreq daemon def remove(): @@ -102,7 +105,8 @@ def remove(): #if os.path.exists(auto_cpufreq_log_file): # os.remove(auto_cpufreq_log_file) # delete /var/log/auto-cpufreq.log file - os.remove(auto_cpufreq_log_file) + #print("\n* Delete log file") + #os.remove(auto_cpufreq_log_file) print("* Turn on bluetooth on boot") btconf="/etc/bluetooth/main.conf" @@ -115,20 +119,35 @@ def remove(): f.truncate() f.write(content.replace(change_set, orig_set)) except: - print("\nERROR:\nWas unable to turn off bluetooth on boot") + print("\nERROR:\nWas unable to turn on bluetooth on boot") - print("\n* Remove auto-cpufreq daemon deploy script") - os.remove("/usr/bin/auto-cpufreq-daemon") + #f os.path("/usr/bin/auto-cpufreq-deploy"): + ## print("\n* Remove auto-cpufreq daemon deploy script") + # os.remove("/usr/bin/auto-cpufreq-deploy") + + #if os.path("/usr/bin/auto-cpufreq-run"): + # print("\n* Remove auto-cpufreq daemon run script") + # os.remove("/usr/bin/auto-cpufreq-run") # run auto-cpufreq daemon deploy script s.call("/usr/bin/auto-cpufreq-remove", shell=True) - if os.path.isfile("/lib/systemd/system/auto-cpufreq.service"): - print("\n* Remove auto-cpufreq systemd unit file") - os.remove("/lib/systemd/system/auto-cpufreq.service") + #if os.path("/usr/bin/auto-cpufreq-remove"): + # print("\n* Remove auto-cpufreq-remove script") + # os.remove("/usr/bin/auto-cpufreq-remove") - print("\n* Remove auto-cpufreq binary") - os.remove("/usr/bin/auto-cpufreq") + #if os.path.isfile("/lib/systemd/system/auto-cpufreq.service"): + # print("\n* Remove auto-cpufreq systemd unit file") + # os.remove("/lib/systemd/system/auto-cpufreq.service") + + #if os.path("/usr/bin/auto-cpufreq"): + # print("\n* Remove auto-cpufreq binary") + # os.remove("/usr/bin/auto-cpufreq") + + # delete /var/log/auto-cpufreq.log if it exists + #if os.path.exists(auto_cpufreq_log_file): + # print("\n* Delete log file") + # os.remove(auto_cpufreq_log_file) print("\nauto-cpufreq daemon removed") @@ -157,12 +176,17 @@ def root_check(): # refresh countdown def countdown(s): + # Fix for wrong log output and "TERM environment variable not set" + os.environ['TERM'] = 'xterm' + for remaining in range(s, 0, -1): sys.stdout.write("\r") sys.stdout.write("\t\t\t\"auto-cpufreq\" refresh in:{:2d}".format(remaining)) sys.stdout.flush() time.sleep(1) + #sys.stdout.write("\rComplete! \n") + # set powersave and enable turbo def set_powersave(): print("Setting to use: powersave") @@ -368,6 +392,7 @@ def sysinfo(): #print("\nCPU fan speed:", current_fans, "RPM") def read_log(): + # deploy cpufreqctl script (if missing) if os.path.isfile(auto_cpufreq_log_file): # read /var/log/auto-cpufreq.log @@ -386,6 +411,10 @@ def log_check(): footer(79) sys.exit() +def trunk(): + with open(auto_cpufreq_log_file, 'w'): + pass + # cli @click.command() @click.option("--monitor", is_flag=True, help="Monitor and suggest CPU optimizations") @@ -416,7 +445,7 @@ def cli(monitor, live, daemon, log): subprocess.call("clear") elif live: while True: - log_check() + #log_check() root_check() gov_check() cpufreqctl() diff --git a/scripts/auto-cpufreq-daemon.sh b/scripts/auto-cpufreq-deploy.sh similarity index 78% rename from scripts/auto-cpufreq-daemon.sh rename to scripts/auto-cpufreq-deploy.sh index d5dccd8..94a0bf1 100755 --- a/scripts/auto-cpufreq-daemon.sh +++ b/scripts/auto-cpufreq-deploy.sh @@ -11,7 +11,7 @@ then exit 1 fi -logs_file="/var/log/auto-cpufreq.log" +#touch /var/log/auto-cpufreq.log echo -e "\n* Reloading systemd manager configuration" systemctl daemon-reload @@ -22,10 +22,10 @@ systemctl stop auto-cpufreq echo -e "\n* Starting auto-cpufreq systemd service" systemctl start auto-cpufreq -echo -e "\n* Enabling auto-cpufreq systemd service at boot" -systemctl enable auto-cpufreq +#echo -e "\n* Enabling auto-cpufreq systemd service at boot" +#systemctl enable auto-cpufreq -echo -e "\n* Running auto-cpufreq binary" +#echo -e "\n* Running auto-cpufreq binary" #/usr/bin/python3 /usr/bin/auto-cpufreq --live > $logs_file 2>&1 & echo -e "\n------\n" \ No newline at end of file diff --git a/scripts/auto-cpufreq-remove.sh b/scripts/auto-cpufreq-remove.sh index f140294..31dc1c6 100755 --- a/scripts/auto-cpufreq-remove.sh +++ b/scripts/auto-cpufreq-remove.sh @@ -11,11 +11,42 @@ then exit 1 fi -echo -e "\n* Disabling auto-cpufreq systemd service at boot" -systemctl disable auto-cpufreq - echo -e "\n* Stopping auto-cpufreq systemd service" systemctl stop auto-cpufreq +echo -e "\n* Disabling auto-cpufreq systemd service at boot" +systemctl disable auto-cpufreq + +#if [ -f /lib/systemd/system/auto-cpufreq.service ]; +#then +# rm /lib/systemd/system/auto-cpufreq.service +# systemctl daemon-reload + +#if [ -f /etc/systemd/system/auto-cpufreq.service ]; +#then +# rm /etc/systemd/system/auto-cpufreq.service +# systemctl daemon-reload + +rm /lib/systemd/system/auto-cpufreq.service +rm /etc/systemd/system/auto-cpufreq.service + echo -e "\n* Reloading systemd manager configuration" -systemctl daemon-reload \ No newline at end of file +systemctl daemon-reload + +echo -e "reset failed" +systemctl reset-failed + +echo -e "\n* Removing auto-cpufreq daemon deploy script" +rm /usr/bin/auto-cpufreq-deploy + +echo -e "\n* Removing auto-cpufreq daemon run script" +rm /usr/bin/auto-cpufreq-run + +echo -e "\n* Removing auto-cpufreq binary" +rm /usr/bin/auto-cpufreq + +echo -e "\n* Removing auto-cpufreq log file" +rm /var/log/auto-cpufreq.log + +echo "kill any remaining instances" +pkill -f auto-cpufreq \ No newline at end of file diff --git a/scripts/auto-cpufreq.service b/scripts/auto-cpufreq.service index 4af4f55..65e4eb0 100644 --- a/scripts/auto-cpufreq.service +++ b/scripts/auto-cpufreq.service @@ -5,9 +5,7 @@ After=network.target network-online.target [Service] Type=simple User=root -#ExecStart=/bin/bash /usr/bin/auto-cpufreq-daemon -# ToDo: new script which just starts auto-cpufreq (no systemd) ExecStart=/usr/bin/python3 /usr/bin/auto-cpufreq --live - +StandardOutput=file:/var/log/auto-cpufreq.log [Install] WantedBy=multi-user.target \ No newline at end of file