From: hayao Date: Thu, 26 Aug 2021 14:06:10 +0000 (+0900) Subject: [fix] : Fixed unit check X-Git-Tag: 20210913~22 X-Git-Url: http://git.osdn.net/view?a=commitdiff_plain;h=fed0c111e5af59cf544983c1d23fb1a0570d836e;p=alterlinux%2Falterlinux.git [fix] : Fixed unit check --- diff --git a/modules/share/airootfs.any/root/functions.sh b/modules/share/airootfs.any/root/functions.sh index a5a265be..2b9ebdec 100644 --- a/modules/share/airootfs.any/root/functions.sh +++ b/modules/share/airootfs.any/root/functions.sh @@ -92,21 +92,11 @@ _safe_systemctl(){ local _service _command="${1}" shift 1 for _service in "${@}"; do - # https://unix.stackexchange.com/questions/539147/systemctl-check-if-a-unit-service-or-target-exists - if (( "$(systemctl list-unit-files "${_service}" | wc -l)" > 3 )); then - if [[ "${_command}" = "enable" ]]; then - if [[ "$(systemctl is-enabled "${_service}")" = "enabled" ]]; then - echo "${_service} has been enabled" >&2 - else - systemctl enable "${_service}" || true - fi - else - systemctl "${_command}" "${_service}" - fi - elif echo "${_service}" | grep -q "@"; then - _safe_systemctl "${_command}" "$(echo "${_service}" | cut -d "@" -f 1)" - else - echo "${_service} was not found" >&2 + if [[ "${_command}" = "enable" ]] && [[ "$(systemctl is-enabled "${_service}")" = "enabled" ]]; then + echo "${_service} has been enabled" >&2 + continue fi + systemctl "${_command}" "${_service}" || true done + return 0 }