fix(utilities.sh): simplify do_action_service

Signed-off-by: Dominik Willner th33xitus@gmail.com
This commit is contained in:
th33xitus
2022-04-03 14:40:25 +02:00
parent eaaa0ce02b
commit b26c0faf67

View File

@@ -282,23 +282,16 @@ set_klipper_cfg_path(){
} }
do_action_service(){ do_action_service(){
shopt -s extglob # enable extended globbing local action=${1} service=${2}
SERVICES="${SYSTEMD}/$2?(-*([0-9])).service" services=$(find "${SYSTEMD}" -maxdepth 1 -regextype posix-extended -regex "${SYSTEMD}/${service}(-[^0])?[0-9]*.service")
### set a variable for the ok and status messages if [ -n "${services}" ]; then
[ "$1" == "start" ] && ACTION1="started" && ACTION2="Starting" for service in ${services}; do
[ "$1" == "stop" ] && ACTION1="stopped" && ACTION2="Stopping" service=$(echo "${service}" | rev | cut -d"/" -f1 | rev)
[ "$1" == "restart" ] && ACTION1="restarted" && ACTION2="Restarting" status_msg "${action^} ${service} ..."
[ "$1" == "enable" ] && ACTION1="enabled" && ACTION2="Enabling" sudo systemctl "${action}" "${service}"
[ "$1" == "disable" ] && ACTION1="disabled" && ACTION2="Disabling" ok_msg "OK!"
if ls "${SERVICES}" 2>/dev/null 1>&2; then
for service in $(ls "${SERVICES}" | rev | cut -d"/" -f1 | rev); do
status_msg "${ACTION2} ${service} ..."
sudo systemctl "${1}" "${service}"
ok_msg "${service} ${ACTION1}!"
done done
fi fi
shopt -u extglob # disable extended globbing
} }
start_klipperscreen(){ start_klipperscreen(){