Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

"WIP" Create auto-cpufreq-sysvinit #599

Open
wants to merge 20 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
157 changes: 84 additions & 73 deletions scripts/auto-cpufreq-install.sh
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I suggest you prepend "WIP" (work in progress) to title of this PR, and then please remove WIP part & announce it when it's ready for review.

Thanks!

Original file line number Diff line number Diff line change
Expand Up @@ -3,93 +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"
cp /usr/local/share/auto-cpufreq/scripts/auto-cpufreq.service /etc/systemd/system/auto-cpufreq.service
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

echo -e "\n* Reloading systemd manager configuration"
systemctl daemon-reload
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

echo -e "\n* Stopping auto-cpufreq daemon (systemd) service"
systemctl stop 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* Starting auto-cpufreq daemon (systemd) service"
systemctl start auto-cpufreq
echo -e "\n* Creating symbolic link ($2/service/auto-cpufreq -> $1/sv/auto-cpufreq)"
ln -s "$1"/sv/auto-cpufreq "$2"/service

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-openrc /etc/init.d/auto-cpufreq
chmod +x /etc/init.d/auto-cpufreq
auto_cpufreq_install "runit"

echo -e "Starting auto-cpufreq daemon (openrc) service"
rc-service auto-cpufreq start
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* Enabling auto-cpufreq daemon (openrc) service at boot"
rc-update add auto-cpufreq
# Install script for s6
elif [ "$(ps h -o comm 1)" = "s6-svscan" ];then
echo -e "\n* Deploying auto-cpufreq s6 unit file"
echo -e "\n* Reloading systemd manager configuration"
systemctl daemon-reload

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
119 changes: 62 additions & 57 deletions scripts/auto-cpufreq-remove.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,72 +4,77 @@
# 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 ------------------"
MID="$((`tput cols` / 2))"

if [[ $EUID != 0 ]]; then
echo -e "\nERROR\nMust be run as root (i.e: 'sudo $0')\n"
exit 1
fi
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

# 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
# root check
if ((EUID != 0)); then
echo; echo "Must be run as root (i.e: 'sudo $0')."; echo
exit 1
fi

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
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
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
rm_sv() {
auto_cpufreq_remove "runit" "sv stop auto-cpufreq" "" "-rf $1/sv/auto-cpufreq $2/service/auto-cpufreq"
}

echo -e "\n* Removing auto-cpufreq daemon (systemd) unit file"
rm /etc/systemd/system/auto-cpufreq.service
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
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
# 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
Loading