From 00eca65c824e45077c987f1dd9d8f8c308f28951 Mon Sep 17 00:00:00 2001 From: AdwaitAdk <95954371+AdwaitAdk@users.noreply.github.com> Date: Sat, 18 Dec 2021 19:00:02 +0000 Subject: [PATCH] Support for openrc (#314) * Added support for openrc. * Added main script from upstream. * Added thankyou note. --- scripts/auto-cpufreq | 12 ++++++++++++ scripts/auto-cpufreq-install.sh | 15 ++++++++++++--- scripts/auto-cpufreq-remove.sh | 11 ++++++++++- 3 files changed, 34 insertions(+), 4 deletions(-) create mode 100644 scripts/auto-cpufreq diff --git a/scripts/auto-cpufreq b/scripts/auto-cpufreq new file mode 100644 index 0000000..83df4b6 --- /dev/null +++ b/scripts/auto-cpufreq @@ -0,0 +1,12 @@ +#!/sbin/openrc-run + +name=$RC_SVCNAME +description="auto-cpufreq - Automatic CPU speed & power optimizer for Linux" +supervisor="supervise-daemon" +command="/usr/bin/auto-cpufreq" +command_args="--daemon" +command_user="root" + +depend() { + after net +} diff --git a/scripts/auto-cpufreq-install.sh b/scripts/auto-cpufreq-install.sh index 585c80c..1bae02e 100755 --- a/scripts/auto-cpufreq-install.sh +++ b/scripts/auto-cpufreq-install.sh @@ -2,7 +2,7 @@ # # auto-cpufreq daemon install script # reference: https://github.com/AdnanHodzic/auto-cpufreq - +# Thanks to https://github.com/errornonamer for openrc fix echo -e "\n------------------ Running auto-cpufreq daemon install script ------------------" if [[ $EUID != 0 ]]; @@ -50,8 +50,6 @@ if [ "$(ps h -o comm 1)" = "runit" ];then *) echo -e "\n* Runit init detected but your distro is not supported\n" echo -e "\n* Please open an issue on https://github.com/AdnanHodzic/auto-cpufreq\n" - - esac fi # Install script for systemd @@ -70,6 +68,17 @@ elif [ "$(ps h -o comm 1)" = "systemd" ];then echo -e "\n* Enabling auto-cpufreq daemon (systemd) service at boot" systemctl enable auto-cpufreq +# Install script for openrc +elif [ "$(ps h -o comm 1)" = "init" ];then + echo -e "\n* Deploying auto-cpufreq openrc unit file" + cp /usr/local/share/auto-cpufreq/scripts/auto-cpufreq /etc/init.d/auto-cpufreq + chmod +x /etc/init.d/auto-cpufreq + + echo -e "Starting auto-cpufreq daemon (openrc) service" + rc-service auto-cpufreq start + + echo -e "\n* Enabling auto-cpufreq daemon (openrc) service at boot" + rc-update add auto-cpufreq else echo -e "\n* Unsupported init system detected, could not install the daemon\n" echo -e "\n* Please open an issue on https://github.com/AdnanHodzic/auto-cpufreq\n" diff --git a/scripts/auto-cpufreq-remove.sh b/scripts/auto-cpufreq-remove.sh index 5990bfe..293fa48 100755 --- a/scripts/auto-cpufreq-remove.sh +++ b/scripts/auto-cpufreq-remove.sh @@ -2,6 +2,7 @@ # # auto-cpufreq daemon removal script # reference: https://github.com/AdnanHodzic/auto-cpufreq +# Thanks to https://github.com/errornonamer for openrc fix echo -e "\n------------------ Running auto-cpufreq daemon removal script ------------------" @@ -10,7 +11,6 @@ if [[ $EUID != 0 ]]; then exit 1 fi - # First argument is the "sv" path, second argument is the "service" path rm_sv() { echo -e "\n* Stopping auto-cpufreq daemon (runit) service" @@ -52,6 +52,15 @@ elif [ "$(ps h -o comm 1)" = "systemd" ];then echo -e "reset failed" systemctl reset-failed +elif [ "$(ps h -o comm 1)" = "init" ];then + echo -e "\n* Stopping auto-cpufreq daemon (openrc) service" + rc-service auto-cpufreq stop + + echo -e "\n* Disabling auto-cpufreq daemon (openrc) at boot" + rc-update del auto-cpufreq + + echo -e "\n* Removing auto-cpufreq daemon (openrc) unit file" + rm /etc/init.d/auto-cpufreq else echo -e "\n* Unsupported init system detected, could not remove the daemon\n" echo -e "\n* Please open an issue on https://github.com/AdnanHodzic/auto-cpufreq\n"