From 4fee7b680ba897677634a5bef963d2a9af118c7a Mon Sep 17 00:00:00 2001 From: Animesh Sahu Date: Thu, 4 Nov 2021 07:32:50 +0000 Subject: [PATCH] Turning Bluetooth off/on & Void Linux improvements (#269) --- auto-cpufreq-installer | 2 +- auto_cpufreq/core.py | 55 +++++++++++++++++++-------------- scripts/auto-cpufreq-install.sh | 1 - scripts/auto-cpufreq-remove.sh | 1 - 4 files changed, 32 insertions(+), 27 deletions(-) diff --git a/auto-cpufreq-installer b/auto-cpufreq-installer index 525d862..7f70637 100755 --- a/auto-cpufreq-installer +++ b/auto-cpufreq-installer @@ -130,7 +130,7 @@ elif [ -f /etc/os-release ];then ;; void) detected_distro "Void Linux" - xbps-install -Suy python3 python3-pip python3-devel python3-setuptools base-devel dmidecode + xbps-install -Sy python3 python3-pip python3-devel python3-setuptools base-devel dmidecode ;; *) #Any other distro manual_install diff --git a/auto_cpufreq/core.py b/auto_cpufreq/core.py index cfb390c..3f9e418 100644 --- a/auto_cpufreq/core.py +++ b/auto_cpufreq/core.py @@ -14,6 +14,7 @@ import warnings import configparser from math import isclose from pathlib import Path +from shutil import which from subprocess import getoutput, call, run, check_output, DEVNULL @@ -293,18 +294,21 @@ def deploy_daemon(): # 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 Exception as e: - print(f"\nERROR:\nWas unable to turn off bluetooth on boot\n{repr(e)}") + if which("bluetoothctl") is not None: + 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 Exception as e: + print(f"\nERROR:\nWas unable to turn off bluetooth on boot\n{repr(e)}") + else: + print("* Turn off bluetooth on boot [skipping] (package providing bluetooth access is not present)") auto_cpufreq_stats_path.touch(exist_ok=True) @@ -329,18 +333,21 @@ def remove(): 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 Exception as e: - print(f"\nERROR:\nWas unable to turn on bluetooth on boot\n{repr(e)}") + if which("bluetoothctl") is not None: + 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 Exception as e: + print(f"\nERROR:\nWas unable to turn on bluetooth on boot\n{repr(e)}") + else: + print("* Turn on bluetooth on boot [skipping] (package providing bluetooth access is not present)") # run auto-cpufreq daemon install script call("/usr/bin/auto-cpufreq-remove", shell=True) diff --git a/scripts/auto-cpufreq-install.sh b/scripts/auto-cpufreq-install.sh index 4a3f3a2..6df8621 100755 --- a/scripts/auto-cpufreq-install.sh +++ b/scripts/auto-cpufreq-install.sh @@ -37,7 +37,6 @@ sv_cmd() { if [ "$(ps h -o comm 1)" = "runit" ];then if [ -f /etc/os-release ];then eval "$(cat /etc/os-release)" - separator case $ID in void) runit_ln /etc /var diff --git a/scripts/auto-cpufreq-remove.sh b/scripts/auto-cpufreq-remove.sh index 3e88c2e..73dfc1c 100755 --- a/scripts/auto-cpufreq-remove.sh +++ b/scripts/auto-cpufreq-remove.sh @@ -25,7 +25,6 @@ rm_sv() { if [ "$(ps h -o comm 1)" = "runit" ];then if [ -f /etc/os-release ];then eval "$(cat /etc/os-release)" - separator case $ID in void) rm_sv /etc /var ;;