From 46e7f19388b1ffbf31df4494826d2d636ea551ca Mon Sep 17 00:00:00 2001 From: AmerXz <122235086+AmerXz@users.noreply.github.com> Date: Sun, 12 Nov 2023 16:47:28 +0300 Subject: [PATCH 01/16] Create auto-cpufreq-sysvinit A sysvinit daemon for auto-cpufreq generated THANKS TO :- https://github.com/yunginnanet/sysvinit-service-generator fork of https://github.com/wyhasany/sysvinit-service-generator It should be inside /etc/init.d/ --- scripts/auto-cpufreq-sysvinit | 98 +++++++++++++++++++++++++++++++++++ 1 file changed, 98 insertions(+) create mode 100644 scripts/auto-cpufreq-sysvinit diff --git a/scripts/auto-cpufreq-sysvinit b/scripts/auto-cpufreq-sysvinit new file mode 100644 index 00000000..01eb7aa3 --- /dev/null +++ b/scripts/auto-cpufreq-sysvinit @@ -0,0 +1,98 @@ +#!/bin/sh +### BEGIN INIT INFO +# Provides: auto-cpufreq +# Required-Start: $local_fs $network $named $time $syslog +# Required-Stop: $local_fs $network $named $time $syslog +# Default-Start: 2 3 4 5 +# Default-Stop: 0 1 6 +# Description: Automatic\ CPU\ speed\ \&\ power\ optimizer\ for\ Linux +### END INIT INFO + +SCRIPT="/home/Abdulhafez/.scripts/Auto-cpufreq.sh" +RUNAS=root + +PIDFILE=/var/run/auto-cpufreq.pid +LOGFILE=/var/log/auto-cpufreq.log + +start() { + if [ -f $PIDFILE ] && [ -s $PIDFILE ] && kill -0 $(cat $PIDFILE); then + echo 'Service already running' >&2 + return 1 + fi + echo 'Starting service…' >&2 + local CMD="$SCRIPT &> \"$LOGFILE\" & echo \$!" + su -c "$CMD" $RUNAS > "$PIDFILE" + # Try with this command line instead of above if not workable + # su -s /bin/sh $RUNAS -c "$CMD" > "$PIDFILE" + + sleep 2 + PID=$(cat $PIDFILE) + if pgrep -u $RUNAS -f $NAME > /dev/null + then + echo "$NAME is now running, the PID is $PID" + else + echo '' + echo "Error! Could not start $NAME!" + fi +} + +stop() { + if [ ! -f "$PIDFILE" ] || ! kill -0 $(cat "$PIDFILE"); then + echo 'Service not running' >&2 + return 1 + fi + echo 'Stopping service…' >&2 + kill -15 $(cat "$PIDFILE") && rm -f "$PIDFILE" + echo 'Service stopped' >&2 +} + +uninstall() { + echo -n "Are you really sure you want to uninstall this service? That cannot be undone. [yes|No] " + local SURE + read SURE + if [ "$SURE" = "yes" ]; then + stop + rm -f "$PIDFILE" + echo "Notice: log file was not removed: $LOGFILE" >&2 + update-rc.d -f $NAME remove + rm -fv "$0" + else + echo "Abort!" + fi +} + +status() { + printf "%-50s" "Checking auto-cpufreq..." + if [ -f $PIDFILE ] && [ -s $PIDFILE ]; then + PID=$(cat $PIDFILE) + if [ -z "$(ps axf | grep ${PID} | grep -v grep)" ]; then + printf "%s\n" "The process appears to be dead but pidfile still exists" + else + echo "Running, the PID is $PID" + fi + else + printf "%s\n" "Service not running" + fi +} + + +case "$1" in + start) + start + ;; + stop) + stop + ;; + status) + status + ;; + uninstall) + uninstall + ;; + restart) + stop + start + ;; + *) + echo "Usage: $0 {start|stop|status|restart|uninstall}" +esac From 20f8c585f963800f71b6b3b7112198ee85054ae6 Mon Sep 17 00:00:00 2001 From: AmerXz <122235086+AmerXz@users.noreply.github.com> Date: Sun, 12 Nov 2023 17:01:52 +0300 Subject: [PATCH 02/16] Create auto-cpufreq-run Run script For auto-cpufreq That can make sysvinit recognise auto-cpufreq Note You can Also use the runscript inside auto-cpufreq/scripts/auto-cpufreq-s6 By @AnasR7 /run --- scripts/auto-cpufreq-run | 3 +++ 1 file changed, 3 insertions(+) create mode 100644 scripts/auto-cpufreq-run diff --git a/scripts/auto-cpufreq-run b/scripts/auto-cpufreq-run new file mode 100644 index 00000000..4643ed1e --- /dev/null +++ b/scripts/auto-cpufreq-run @@ -0,0 +1,3 @@ +!#/bin/bash + +exec /usr/local/bin/auto-cpufreq --daemon From 74d5c28e4ed3495be2edea02c7f1a1f5c01cc67d Mon Sep 17 00:00:00 2001 From: AmerXz <122235086+AmerXz@users.noreply.github.com> Date: Wed, 15 Nov 2023 19:41:06 +0300 Subject: [PATCH 03/16] Delete scripts/auto-cpufreq-run --- scripts/auto-cpufreq-run | 3 --- 1 file changed, 3 deletions(-) delete mode 100644 scripts/auto-cpufreq-run diff --git a/scripts/auto-cpufreq-run b/scripts/auto-cpufreq-run deleted file mode 100644 index 4643ed1e..00000000 --- a/scripts/auto-cpufreq-run +++ /dev/null @@ -1,3 +0,0 @@ -!#/bin/bash - -exec /usr/local/bin/auto-cpufreq --daemon From 5a9715821374775530f33437a19f03e1f3cfd30f Mon Sep 17 00:00:00 2001 From: AmerXz <122235086+AmerXz@users.noreply.github.com> Date: Wed, 22 Nov 2023 09:32:30 +0300 Subject: [PATCH 04/16] Update auto-cpufreq-install.sh --- scripts/auto-cpufreq-install.sh | 28 +++++++++++++++++++++------- 1 file changed, 21 insertions(+), 7 deletions(-) diff --git a/scripts/auto-cpufreq-install.sh b/scripts/auto-cpufreq-install.sh index a1923208..0c00d94c 100755 --- a/scripts/auto-cpufreq-install.sh +++ b/scripts/auto-cpufreq-install.sh @@ -68,17 +68,31 @@ 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 +# Install script for openrc / sysvinit 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-openrc /etc/init.d/auto-cpufreq - chmod +x /etc/init.d/auto-cpufreq - - echo -e "Starting auto-cpufreq daemon (openrc) service" + mkdir /etc/inittab + if [ -e "/etc/inittab" ]; then + echo -e "\n* Deploy auto-cpufreq sysvinit unit file" + cp /usr/local/share/auto-cpufreq/scripts/auto-cpufreq-openrc /etc/init.d/auto-cpufreq + + echo -e "\n* "Reloading sysvinit manager configuration" + service auto-cpufreq reload + + echo -e "\n* "Starting auto-cpufreq daemon (sysvinit) service" + service auto-cpufreq start + + echo -e "\n* "Enabling auto-cpufreq daemon (sysvinit) service at boot" + chkconfig auto-cpufreq-sysvinit on + else + echo -e "\n* Deploy auto-cpufreq openrc unit file" + cp /usr/local/share/auto-cpufreq/scripts/auto-cpufreq-openrc /etc/init.d/auto-cpufreq + echo -e "\n* "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 + rc-update add auto-cpufreqlocal/share/auto-cpufreq/scripts/auto-cpufreq-openrc /etc/init.d/auto-cpufreq + + fi # Install script for s6 elif [ "$(ps h -o comm 1)" = "s6-svscan" ];then echo -e "\n* Deploying auto-cpufreq s6 unit file" From 625c35eb810213fc462ad341530cc0c8ce1d9719 Mon Sep 17 00:00:00 2001 From: AmerXz <122235086+AmerXz@users.noreply.github.com> Date: Thu, 11 Jan 2024 21:35:24 +0300 Subject: [PATCH 05/16] Update auto-cpufreq-install.sh applied some suggested fixes and replace (mkdir) command with (ls) and also replaced deprecated (chkconfig) command with (sysv-rc-conf) last but not least I need to have auto-cpufreq-sysvinit inside '/usr/local/share/auto-cpufreq/scripts/' for testing I tried to copy auto-cpufreq-sysvinit file to '/usr/local/share/auto-cpufreq/scripts/' manually to check if the install script will work and I had the output below ''' /etc/inittab * Deploy auto-cpufreq sysvinit unit file * Starting auto-cpufreq daemon (sysvinit) service * Enabling auto-cpufreq daemon (sysvinit) service at boot ''' --- scripts/auto-cpufreq-install.sh | 20 ++++++++------------ 1 file changed, 8 insertions(+), 12 deletions(-) diff --git a/scripts/auto-cpufreq-install.sh b/scripts/auto-cpufreq-install.sh index 0c00d94c..ca1e990e 100755 --- a/scripts/auto-cpufreq-install.sh +++ b/scripts/auto-cpufreq-install.sh @@ -70,29 +70,25 @@ elif [ "$(ps h -o comm 1)" = "systemd" ];then systemctl enable auto-cpufreq # Install script for openrc / sysvinit elif [ "$(ps h -o comm 1)" = "init" ];then - mkdir /etc/inittab + ls /etc/inittab if [ -e "/etc/inittab" ]; then echo -e "\n* Deploy auto-cpufreq sysvinit unit file" - cp /usr/local/share/auto-cpufreq/scripts/auto-cpufreq-openrc /etc/init.d/auto-cpufreq - - echo -e "\n* "Reloading sysvinit manager configuration" - service auto-cpufreq reload + cp /usr/local/share/auto-cpufreq/scripts/auto-cpufreq-sysvinit /etc/init.d/auto-cpufreq - echo -e "\n* "Starting auto-cpufreq daemon (sysvinit) service" - service auto-cpufreq start + echo -e "\n* Starting auto-cpufreq daemon (sysvinit) service" + sysv-rc-conf --level auto-cpufreq start - echo -e "\n* "Enabling auto-cpufreq daemon (sysvinit) service at boot" - chkconfig auto-cpufreq-sysvinit on + echo -e "\n* Enabling auto-cpufreq daemon (sysvinit) service at boot" + sysv-rc-conf --level auto-cpufreq-sysvinit on else echo -e "\n* Deploy auto-cpufreq openrc unit file" cp /usr/local/share/auto-cpufreq/scripts/auto-cpufreq-openrc /etc/init.d/auto-cpufreq - echo -e "\n* "Starting auto-cpufreq daemon (openrc) service" + echo -e "\n* 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-cpufreqlocal/share/auto-cpufreq/scripts/auto-cpufreq-openrc /etc/init.d/auto-cpufreq - - fi +fi # Install script for s6 elif [ "$(ps h -o comm 1)" = "s6-svscan" ];then echo -e "\n* Deploying auto-cpufreq s6 unit file" From 8bc2be0b37d497322636fbd4b9d82861a9e29cfc Mon Sep 17 00:00:00 2001 From: AmerXz <122235086+AmerXz@users.noreply.github.com> Date: Wed, 21 Feb 2024 21:27:47 +0300 Subject: [PATCH 06/16] Update auto-cpufreq-sysvinit change SCRIPT to use runfile inside "/usr/local/share/auto-cpufreq/scripts/auto-cpufreq-s6/" --- scripts/auto-cpufreq-sysvinit | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/scripts/auto-cpufreq-sysvinit b/scripts/auto-cpufreq-sysvinit index 01eb7aa3..6bfb5622 100644 --- a/scripts/auto-cpufreq-sysvinit +++ b/scripts/auto-cpufreq-sysvinit @@ -5,10 +5,10 @@ # Required-Stop: $local_fs $network $named $time $syslog # Default-Start: 2 3 4 5 # Default-Stop: 0 1 6 -# Description: Automatic\ CPU\ speed\ \&\ power\ optimizer\ for\ Linux +# Description: Automatic CPU speed & power optimizer for Linux ### END INIT INFO -SCRIPT="/home/Abdulhafez/.scripts/Auto-cpufreq.sh" +SCRIPT="/usr/local/share/auto-cpufreq/scripts/auto-cpufreq-s6/run" RUNAS=root PIDFILE=/var/run/auto-cpufreq.pid From 52f03c00dff12cf5f054f56172e0428822b887a0 Mon Sep 17 00:00:00 2001 From: AmerXz <122235086+AmerXz@users.noreply.github.com> Date: Wed, 21 Feb 2024 21:39:53 +0300 Subject: [PATCH 07/16] Fix auto-cpufreq-install.sh (with sysvinit support) I forget that (sysvinit-service-generator I used earlier) had some small tutorial at the end of running script to make the service work so I replaced sysvinit daemon install section with commands inspired from that script and added commands to make the service and the run script inside auto-cpufreq-s6 to run as executables --- scripts/auto-cpufreq-install.sh | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/scripts/auto-cpufreq-install.sh b/scripts/auto-cpufreq-install.sh index ca1e990e..28acab61 100755 --- a/scripts/auto-cpufreq-install.sh +++ b/scripts/auto-cpufreq-install.sh @@ -74,12 +74,14 @@ elif [ "$(ps h -o comm 1)" = "init" ];then if [ -e "/etc/inittab" ]; then echo -e "\n* Deploy auto-cpufreq sysvinit unit file" cp /usr/local/share/auto-cpufreq/scripts/auto-cpufreq-sysvinit /etc/init.d/auto-cpufreq - + chmod +x /etc/init.d/auto-cpufreq + chmod +x /usr/local/share/auto-cpufreq/scripts/auto-cpufreq-s6/run + echo -e "\n* Starting auto-cpufreq daemon (sysvinit) service" - sysv-rc-conf --level auto-cpufreq start + service auto-cpufreq start echo -e "\n* Enabling auto-cpufreq daemon (sysvinit) service at boot" - sysv-rc-conf --level auto-cpufreq-sysvinit on + update-rc.d auto-cpufreq defaults else echo -e "\n* Deploy auto-cpufreq openrc unit file" cp /usr/local/share/auto-cpufreq/scripts/auto-cpufreq-openrc /etc/init.d/auto-cpufreq @@ -87,7 +89,7 @@ elif [ "$(ps h -o comm 1)" = "init" ];then rc-service auto-cpufreq start echo -e "\n* Enabling auto-cpufreq daemon (openrc) service at boot" - rc-update add auto-cpufreqlocal/share/auto-cpufreq/scripts/auto-cpufreq-openrc /etc/init.d/auto-cpufreq + rc-update add auto-cpufreq local/share/auto-cpufreq/scripts/auto-cpufreq-openrc /etc/init.d/auto-cpufreq fi # Install script for s6 elif [ "$(ps h -o comm 1)" = "s6-svscan" ];then @@ -103,3 +105,4 @@ 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" fi + From 24d7c6ff88a57a888030edd883b2526fe3a89580 Mon Sep 17 00:00:00 2001 From: AmerXz <122235086+AmerXz@users.noreply.github.com> Date: Wed, 21 Feb 2024 21:50:02 +0300 Subject: [PATCH 08/16] Update auto-cpufreq-remove.sh to support sysvinit sysvinit-service-generator script aslo helped me know how to uninstall sysvinit service I added the commands that are inspired by these scripts I have to thank @wyhasany for making the script and @yunginnanet for his fork with the needed fixes otherwise I wouldn't be able to get auto-cpufreq-sysvinit to work --- scripts/auto-cpufreq-remove.sh | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/scripts/auto-cpufreq-remove.sh b/scripts/auto-cpufreq-remove.sh index 659e7ab2..210b7026 100755 --- a/scripts/auto-cpufreq-remove.sh +++ b/scripts/auto-cpufreq-remove.sh @@ -52,7 +52,20 @@ elif [ "$(ps h -o comm 1)" = "systemd" ];then echo -e "reset failed" systemctl reset-failed +# Install script for openrc / sysvinit elif [ "$(ps h -o comm 1)" = "init" ];then + ls /etc/inittab + if [ -e "/etc/inittab" ]; then + echo -e "\n* Stopping auto-cpufreq daemon (sysvinit) service" + service auto-cpufreq stop + + echo -e "\n* disabling auto-cpufreq daemon (sysvinit) service at boot" + update-rc.d -f auto-cpufreq + + echo -e "\n* Removing auto-cpufreq sysvinit unit file" + rm /etc/init.d/auto-cpufreq + + else echo -e "\n* Stopping auto-cpufreq daemon (openrc) service" rc-service auto-cpufreq stop @@ -61,6 +74,7 @@ elif [ "$(ps h -o comm 1)" = "init" ];then echo -e "\n* Removing auto-cpufreq daemon (openrc) unit file" rm /etc/init.d/auto-cpufreq +fi # Remove service for s6 elif [ "$(ps h -o comm 1)" = "s6-svscan" ];then echo -e "\n* Disabling auto-cpufreq daemon (s6) at boot" @@ -73,3 +87,4 @@ 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" fi + From 27a2f93fdf2af05575f1bbff0fa3f1c08471fd0f Mon Sep 17 00:00:00 2001 From: AmerXz <122235086+AmerXz@users.noreply.github.com> Date: Wed, 21 Feb 2024 21:58:13 +0300 Subject: [PATCH 09/16] Update auto-cpufreq-install.sh small Fix for small mistake --- scripts/auto-cpufreq-install.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/auto-cpufreq-install.sh b/scripts/auto-cpufreq-install.sh index 28acab61..d71ae34c 100755 --- a/scripts/auto-cpufreq-install.sh +++ b/scripts/auto-cpufreq-install.sh @@ -89,7 +89,7 @@ elif [ "$(ps h -o comm 1)" = "init" ];then rc-service auto-cpufreq start echo -e "\n* Enabling auto-cpufreq daemon (openrc) service at boot" - rc-update add auto-cpufreq local/share/auto-cpufreq/scripts/auto-cpufreq-openrc /etc/init.d/auto-cpufreq + rc-update add auto-cpufreq fi # Install script for s6 elif [ "$(ps h -o comm 1)" = "s6-svscan" ];then From bf045bbe775474874ad88c2b28049ef7b4ea93ef Mon Sep 17 00:00:00 2001 From: AmerXz <122235086+AmerXz@users.noreply.github.com> Date: Sun, 31 Mar 2024 21:32:27 +0300 Subject: [PATCH 10/16] Update auto-cpufreq-install.sh Remove note needed code in line 78 --- scripts/auto-cpufreq-install.sh | 1 - 1 file changed, 1 deletion(-) diff --git a/scripts/auto-cpufreq-install.sh b/scripts/auto-cpufreq-install.sh index d71ae34c..30cd9dd3 100755 --- a/scripts/auto-cpufreq-install.sh +++ b/scripts/auto-cpufreq-install.sh @@ -75,7 +75,6 @@ elif [ "$(ps h -o comm 1)" = "init" ];then echo -e "\n* Deploy auto-cpufreq sysvinit unit file" cp /usr/local/share/auto-cpufreq/scripts/auto-cpufreq-sysvinit /etc/init.d/auto-cpufreq chmod +x /etc/init.d/auto-cpufreq - chmod +x /usr/local/share/auto-cpufreq/scripts/auto-cpufreq-s6/run echo -e "\n* Starting auto-cpufreq daemon (sysvinit) service" service auto-cpufreq start From f5e36db516fb6b10e4db3c2ad7fdcc16d1fb87fc Mon Sep 17 00:00:00 2001 From: AmerXz <122235086+AmerXz@users.noreply.github.com> Date: Fri, 14 Jun 2024 21:05:25 +0300 Subject: [PATCH 11/16] Revert "Update auto-cpufreq-install.sh" This reverts commit 27a2f93fdf2af05575f1bbff0fa3f1c08471fd0f. --- scripts/auto-cpufreq-install.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/auto-cpufreq-install.sh b/scripts/auto-cpufreq-install.sh index 30cd9dd3..dd296af4 100755 --- a/scripts/auto-cpufreq-install.sh +++ b/scripts/auto-cpufreq-install.sh @@ -88,7 +88,7 @@ elif [ "$(ps h -o comm 1)" = "init" ];then rc-service auto-cpufreq start echo -e "\n* Enabling auto-cpufreq daemon (openrc) service at boot" - rc-update add auto-cpufreq + rc-update add auto-cpufreq local/share/auto-cpufreq/scripts/auto-cpufreq-openrc /etc/init.d/auto-cpufreq fi # Install script for s6 elif [ "$(ps h -o comm 1)" = "s6-svscan" ];then From ca8c3492739e754a3aa72b20d3f80e049cc33755 Mon Sep 17 00:00:00 2001 From: AmerXz <122235086+AmerXz@users.noreply.github.com> Date: Fri, 14 Jun 2024 21:52:41 +0300 Subject: [PATCH 12/16] Update auto-cpufreq-install.sh test --- scripts/auto-cpufreq-install.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/auto-cpufreq-install.sh b/scripts/auto-cpufreq-install.sh index dd296af4..3b433f41 100755 --- a/scripts/auto-cpufreq-install.sh +++ b/scripts/auto-cpufreq-install.sh @@ -74,7 +74,7 @@ elif [ "$(ps h -o comm 1)" = "init" ];then if [ -e "/etc/inittab" ]; then echo -e "\n* Deploy auto-cpufreq sysvinit unit file" cp /usr/local/share/auto-cpufreq/scripts/auto-cpufreq-sysvinit /etc/init.d/auto-cpufreq - chmod +x /etc/init.d/auto-cpufreq + chmod +x /usr/local/share/auto-cpufreq/scripts/auto-cpufreq-s6/ echo -e "\n* Starting auto-cpufreq daemon (sysvinit) service" service auto-cpufreq start From 13d09aea8253f049aaee6553f25d6d9ebd62fbd0 Mon Sep 17 00:00:00 2001 From: AmerXz <122235086+AmerXz@users.noreply.github.com> Date: Fri, 14 Jun 2024 15:52:32 -0400 Subject: [PATCH 13/16] Update auto-cpufreq-install.sh I hope this will work --- scripts/auto-cpufreq-install.sh | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/scripts/auto-cpufreq-install.sh b/scripts/auto-cpufreq-install.sh index 3b433f41..247a0d0c 100755 --- a/scripts/auto-cpufreq-install.sh +++ b/scripts/auto-cpufreq-install.sh @@ -74,7 +74,8 @@ elif [ "$(ps h -o comm 1)" = "init" ];then if [ -e "/etc/inittab" ]; then echo -e "\n* Deploy auto-cpufreq sysvinit unit file" cp /usr/local/share/auto-cpufreq/scripts/auto-cpufreq-sysvinit /etc/init.d/auto-cpufreq - chmod +x /usr/local/share/auto-cpufreq/scripts/auto-cpufreq-s6/ + chmod +x /usr/local/share/auto-cpufreq/scripts/auto-cpufreq-s6/run + chmod +x /etc/init.d/auto-cpufreq echo -e "\n* Starting auto-cpufreq daemon (sysvinit) service" service auto-cpufreq start From 1779d5ab19f52f2ebc0ce60ce207d3cbf32fe195 Mon Sep 17 00:00:00 2001 From: AmerXz <122235086+AmerXz@users.noreply.github.com> Date: Fri, 26 Jul 2024 20:29:23 +0300 Subject: [PATCH 14/16] Fix Conflict auto-cpufreq-install.sh --- scripts/auto-cpufreq-install.sh | 172 ++++++++++++++++---------------- 1 file changed, 85 insertions(+), 87 deletions(-) diff --git a/scripts/auto-cpufreq-install.sh b/scripts/auto-cpufreq-install.sh index 247a0d0c..405dd903 100755 --- a/scripts/auto-cpufreq-install.sh +++ b/scripts/auto-cpufreq-install.sh @@ -3,106 +3,104 @@ # 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 ]]; -then - echo -e "\nERROR\nMust be run as root (i.e: 'sudo $0')\n" - exit 1 -fi +MID="$((`tput cols` / 2))" -# First argument is the "sv" path, second argument is the "service" path this -# only exist because the path between distros may vary -runit_ln() { - echo -e "\n* Deploy auto-cpufreq runit unit file" - mkdir "$1"/sv/auto-cpufreq - cp /usr/local/share/auto-cpufreq/scripts/auto-cpufreq-runit "$1"/sv/auto-cpufreq/run - chmod +x "$1"/sv/auto-cpufreq/run +echo +printf "%0.s─" $(seq $((MID-(${#1}/2)-2))) +printf " Running auto-cpufreq daemon install script " +printf "%0.s─" $(seq $((MID-(${#1}/2)-2))) +echo; echo - echo -e "\n* Creating symbolic link ($2/service/auto-cpufreq -> $1/sv/auto-cpufreq)" - ln -s "$1"/sv/auto-cpufreq "$2"/service -} +# root check +if ((EUID != 0)); then + echo; echo "Must be run as root (i.e: 'sudo $0')."; echo + exit 1 +fi -# sv commands -sv_cmd() { - echo -e "\n* Stopping auto-cpufreq daemon (runit) service" - sv stop auto-cpufreq - echo -e "\n* Starting auto-cpufreq daemon (runit) service" - sv start auto-cpufreq - sv up auto-cpufreq +# First argument is the init name, second argument is the start command, third argument is the enable command +function auto_cpufreq_install { + echo -e "\n* Starting auto-cpufreq daemon ($1) service" + $2 + echo -e "\n* Enabling auto-cpufreq daemon ($1) at boot" + $3 } -# Installation for runit, we still look for the distro because of the path may -# vary. -if [ "$(ps h -o comm 1)" = "runit" ];then - if [ -f /etc/os-release ];then - eval "$(cat /etc/os-release)" - case $ID in - void) - runit_ln /etc /var - sv_cmd - ;; - artix) - # Note: Artix supports other inits than runnit - runit_ln /etc/runit /run/runit - sv_cmd - ;; - *) - 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 -elif [ "$(ps h -o comm 1)" = "systemd" ];then - echo -e "\n* Deploy auto-cpufreq systemd unit file" +case "$(ps h -o comm 1)" in + dinit) + echo -e "\n* Deploying auto-cpufreq (dinit) unit file" + cp /usr/local/share/auto-cpufreq/scripts/auto-cpufreq-dinit /etc/dinit.d/auto-cpufreq + + auto_cpufreq_install "dinit" "dinitctl start auto-cpufreq" "dinitctl enable auto-cpufreq" + ;; + init) + ls /etc/inittab + if [ -e "/etc/inittab" ]; then + echo -e "\n* Deploy auto-cpufreq sysvinit unit file" + cp /usr/local/share/auto-cpufreq/scripts/auto-cpufreq-sysvinit /etc/init.d/auto-cpufreq + chmod +x /usr/local/share/auto-cpufreq/scripts/auto-cpufreq-s6/run + chmod +x /etc/init.d/auto-cpufreq + + auto_cpufreq_install "sysvinit" "service auto-cpufreq start" "update-rc.d auto-cpufreq defaults" + else + echo -e "\n* Deploying auto-cpufreq openrc unit file" + cp /usr/local/share/auto-cpufreq/scripts/auto-cpufreq-openrc /etc/init.d/auto-cpufreq + chmod +x /etc/init.d/auto-cpufreq + + auto_cpufreq_install "openrc" "rc-service auto-cpufreq start" "rc-update add auto-cpufreq" + fi + ;; + runit) + # First argument is the "sv" path, second argument is the "service" path + runit_ln() { + echo -e "\n* Deploying auto-cpufreq (runit) unit file" + mkdir "$1"/sv/auto-cpufreq + cp /usr/local/share/auto-cpufreq/scripts/auto-cpufreq-runit "$1"/sv/auto-cpufreq/run + chmod +x "$1"/sv/auto-cpufreq/run + + echo -e "\n* Creating symbolic link ($2/service/auto-cpufreq -> $1/sv/auto-cpufreq)" + ln -s "$1"/sv/auto-cpufreq "$2"/service + + auto_cpufreq_install "runit" + + sv start auto-cpufreq + sv up auto-cpufreq + } + + if [ -f /etc/os-release ];then + eval "$(cat /etc/os-release)" + case $ID in + void) runit_ln /etc /var;; + artix) runit_ln /etc/runit /run/runit;; + *) + 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 + ;; + systemd) + echo -e "\n* Deploying auto-cpufreq systemd unit file" cp /usr/local/share/auto-cpufreq/scripts/auto-cpufreq.service /etc/systemd/system/auto-cpufreq.service echo -e "\n* Reloading systemd manager configuration" systemctl daemon-reload - echo -e "\n* Stopping auto-cpufreq daemon (systemd) service" - systemctl stop auto-cpufreq - - 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 -# Install script for openrc / sysvinit -elif [ "$(ps h -o comm 1)" = "init" ];then - ls /etc/inittab - if [ -e "/etc/inittab" ]; then - echo -e "\n* Deploy auto-cpufreq sysvinit unit file" - cp /usr/local/share/auto-cpufreq/scripts/auto-cpufreq-sysvinit /etc/init.d/auto-cpufreq - chmod +x /usr/local/share/auto-cpufreq/scripts/auto-cpufreq-s6/run - chmod +x /etc/init.d/auto-cpufreq - - echo -e "\n* Starting auto-cpufreq daemon (sysvinit) service" - service auto-cpufreq start - - echo -e "\n* Enabling auto-cpufreq daemon (sysvinit) service at boot" - update-rc.d auto-cpufreq defaults - else - echo -e "\n* Deploy auto-cpufreq openrc unit file" - cp /usr/local/share/auto-cpufreq/scripts/auto-cpufreq-openrc /etc/init.d/auto-cpufreq - echo -e "\n* 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 local/share/auto-cpufreq/scripts/auto-cpufreq-openrc /etc/init.d/auto-cpufreq -fi -# Install script for s6 -elif [ "$(ps h -o comm 1)" = "s6-svscan" ];then - echo -e "\n* Deploying auto-cpufreq s6 unit file" + auto_cpufreq_install "systemd" "systemctl start auto-cpufreq" "systemctl enable auto-cpufreq" + ;; + s6-svscan) + echo -e "\n* Deploying auto-cpufreq (s6) unit file" cp -r /usr/local/share/auto-cpufreq/scripts/auto-cpufreq-s6 /etc/s6/sv/auto-cpufreq + echo -e "\n* Add auto-cpufreq service (s6) to default bundle" s6-service add default auto-cpufreq - echo -e "Starting auto-cpufreq daemon (s6) service" - s6-rc -u change auto-cpufreq default + + auto_cpufreq_install "s6" "s6-rc -u change auto-cpufreq default" + echo -e "\n* Update daemon service bundle (s6)" s6-db-reload -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" -fi - + ;; + *) + 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" + ;; +esac From b26b106c79fab8c98a75c4d6194cd045919ab54f Mon Sep 17 00:00:00 2001 From: AmerXz <122235086+AmerXz@users.noreply.github.com> Date: Fri, 26 Jul 2024 20:30:03 +0300 Subject: [PATCH 15/16] Fix conflict auto-cpufreq-remove.sh --- scripts/auto-cpufreq-remove.sh | 137 +++++++++++++++------------------ 1 file changed, 63 insertions(+), 74 deletions(-) diff --git a/scripts/auto-cpufreq-remove.sh b/scripts/auto-cpufreq-remove.sh index 210b7026..2bcd3a0f 100755 --- a/scripts/auto-cpufreq-remove.sh +++ b/scripts/auto-cpufreq-remove.sh @@ -4,87 +4,76 @@ # 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 ------------------" - -if [[ $EUID != 0 ]]; then - echo -e "\nERROR\nMust be run as root (i.e: 'sudo $0')\n" - exit 1 +MID="$((`tput cols` / 2))" + +echo +printf "%0.s─" $(seq $((MID-(${#1}/2)-2))) +printf " Running auto-cpufreq daemon removal script " +printf "%0.s─" $(seq $((MID-(${#1}/2)-2))) +echo; echo + +# root check +if ((EUID != 0)); then + echo; echo "Must be run as root (i.e: 'sudo $0')."; echo + 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" - sv stop auto-cpufreq - - echo -e "\n* Removing auto-cpufreq daemon (runit) unit files" - rm -rf "$1"/sv/auto-cpufreq - rm -rf "$2"/service/auto-cpufreq +# First argument is the init name, second argument is the stop command, third argument is the disable command and the fourth is the "service" path +function auto_cpufreq_remove { + echo -e "\n* Stopping auto-cpufreq daemon ($1) service" + $2 + echo -e "\n* Disabling auto-cpufreq daemon ($1) at boot" + $3 + echo -e "\n* Removing auto-cpufreq daemon ($1) unit file" + rm $4 } -# Remove service for runit -if [ "$(ps h -o comm 1)" = "runit" ];then - if [ -f /etc/os-release ];then - eval "$(cat /etc/os-release)" - case $ID in - void) - rm_sv /etc /var ;; - artix) - rm_sv /etc/runit /run/runit ;; - *) - 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 -# Remove service for systemd -elif [ "$(ps h -o comm 1)" = "systemd" ];then - echo -e "\n* Stopping auto-cpufreq daemon (systemd) service" - systemctl stop auto-cpufreq - - echo -e "\n* Disabling auto-cpufreq daemon (systemd) at boot" - systemctl disable auto-cpufreq - - echo -e "\n* Removing auto-cpufreq daemon (systemd) unit file" - rm /etc/systemd/system/auto-cpufreq.service +case "$(ps h -o comm 1)" in + dinit) auto_cpufreq_remove "dinit" "dinitctl stop auto-cpufreq" "dinitctl disable auto-cpufreq" "/etc/dinit.d/auto-cpufreq";; + init) + ls /etc/inittab + if [ -e "/etc/inittab" ]; then + auto_cpufreq_remove "sysvinit" "service auto-cpufreq stop" "update-rc.d -f auto-cpufreq remove" "rm /etc/init.d/auto-cpufreq" + else + auto_cpufreq_remove "openrc" "rc-service auto-cpufreq stop" "rc-update del auto-cpufreq" "/etc/init.d/auto-cpufreq" + fi + ;; + + runit) + # First argument is the "sv" path, second argument is the "service" path + rm_sv() { + auto_cpufreq_remove "runit" "sv stop auto-cpufreq" "" "-rf $1/sv/auto-cpufreq $2/service/auto-cpufreq" + } + + if [ -f /etc/os-release ]; then + . /etc/os-release + case $ID in + void) rm_sv /etc /var;; + artix) rm_sv /etc/runit /run/runit;; + *) + 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 + ;; + systemd) + auto_cpufreq_remove "systemd" "systemctl stop auto-cpufreq" "systemctl disable auto-cpufreq" "/etc/systemd/system/auto-cpufreq.service" echo -e "\n* Reloading systemd manager configuration" systemctl daemon-reload - echo -e "reset failed" + echo "reset failed" systemctl reset-failed -# Install script for openrc / sysvinit -elif [ "$(ps h -o comm 1)" = "init" ];then - ls /etc/inittab - if [ -e "/etc/inittab" ]; then - echo -e "\n* Stopping auto-cpufreq daemon (sysvinit) service" - service auto-cpufreq stop - - echo -e "\n* disabling auto-cpufreq daemon (sysvinit) service at boot" - update-rc.d -f auto-cpufreq - - echo -e "\n* Removing auto-cpufreq sysvinit unit file" - rm /etc/init.d/auto-cpufreq - - else - 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 -fi -# Remove service for s6 -elif [ "$(ps h -o comm 1)" = "s6-svscan" ];then - echo -e "\n* Disabling auto-cpufreq daemon (s6) at boot" - s6-service delete default auto-cpufreq - echo -e "\n* Removing auto-cpufreq daemon (s6) unit file" - rm -rf /etc/s6/sv/auto-cpufreq + ;; + s6-svscan) + auto_cpufreq_remove "s6" "" "s6-service delete default auto-cpufreq" "-rf /etc/s6/sv/auto-cpufreq" + echo -e "\n* Update daemon service bundle (s6)" - s6-db-reload -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" -fi - + s6-db-reload + ;; + *) + echo -e "\n* Unsupported init system detected, could not remove the daemon" + echo -e "\n* Please open an issue on https://github.com/AdnanHodzic/auto-cpufreq\n" + ;; +esac From dc64e732145f46b01826033047ef4cdf27c1f1bb Mon Sep 17 00:00:00 2001 From: AmerXz <122235086+AmerXz@users.noreply.github.com> Date: Tue, 15 Oct 2024 18:59:07 +0300 Subject: [PATCH 16/16] trying & experimenting to fix remove script --- scripts/auto-cpufreq-remove.sh | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/scripts/auto-cpufreq-remove.sh b/scripts/auto-cpufreq-remove.sh index 2bcd3a0f..031fda38 100755 --- a/scripts/auto-cpufreq-remove.sh +++ b/scripts/auto-cpufreq-remove.sh @@ -31,13 +31,14 @@ function auto_cpufreq_remove { case "$(ps h -o comm 1)" in dinit) auto_cpufreq_remove "dinit" "dinitctl stop auto-cpufreq" "dinitctl disable auto-cpufreq" "/etc/dinit.d/auto-cpufreq";; init) - ls /etc/inittab - if [ -e "/etc/inittab" ]; then - auto_cpufreq_remove "sysvinit" "service auto-cpufreq stop" "update-rc.d -f auto-cpufreq remove" "rm /etc/init.d/auto-cpufreq" - else - auto_cpufreq_remove "openrc" "rc-service auto-cpufreq stop" "rc-update del auto-cpufreq" "/etc/init.d/auto-cpufreq" + ls /etc/inittab + if [ -e "/etc/inittab" ]; then + rm /etc/init.d/auto-cpufreq + auto_cpufreq_remove "sysvinit" "service auto-cpufreq stop" "update-rc.d -f auto-cpufreq remove" + else + auto_cpufreq_remove "openrc" "rc-service auto-cpufreq stop" "rc-update del auto-cpufreq" "/etc/init.d/auto-cpufreq" fi - ;; +;; runit) # First argument is the "sv" path, second argument is the "service" path