From c94f653e0b0448809a8d6e9158ac924510c87a4d Mon Sep 17 00:00:00 2001 From: Lars Engels Date: Tue, 14 Mar 2023 22:03:16 +0100 Subject: [PATCH] Refactor --- usr/local/share/bastille/tags.sh | 36 ++++++++++++++++---------------- 1 file changed, 18 insertions(+), 18 deletions(-) diff --git a/usr/local/share/bastille/tags.sh b/usr/local/share/bastille/tags.sh index c342855..2cb76b7 100644 --- a/usr/local/share/bastille/tags.sh +++ b/usr/local/share/bastille/tags.sh @@ -57,32 +57,32 @@ TAGS="${2}" for _jail in ${JAILS}; do bastille_jail_tags="${bastille_jailsdir}/${_jail}/tags" - if [ "${ACTION}" = "list" ]; then - [ -f "${bastille_jail_tags}" ] && cat "${bastille_jail_tags}" - continue - fi - for _tag in $(echo ${TAGS} | tr , ' '); do - case ${ACTION} in - add) + case ${ACTION} in + add) + for _tag in $(echo ${TAGS} | tr , ' '); do echo ${_tag} >> "${bastille_jail_tags}" tmpfile="$(mktemp)" sort "${bastille_jail_tags}" | uniq > "${tmpfile}" mv "${tmpfile}" "${bastille_jail_tags}" - ;; - del*) - if [ ! -f "${bastille_jail_tags}" ]; then - break - fi + done + ;; + del*) + for _tag in $(echo ${TAGS} | tr , ' '); do + [ ! -f "${bastille_jail_tags}" ] && break # skip if no tags file tmpfile="$(mktemp)" grep -Ev "^${_tag}\$" "${bastille_jail_tags}" > "${tmpfile}" mv "${tmpfile}" "${bastille_jail_tags}" # delete tags file if empty [ ! -s "${bastille_jail_tags}" ] && rm "${bastille_jail_tags}" - ;; - *) - usage - ;; - esac - done + done + ;; + list) + [ -f "${bastille_jail_tags}" ] && cat "${bastille_jail_tags}" + continue + ;; + *) + usage + ;; + esac done