From d69b86e54204b6efcbe7d11d76e3e41de6941965 Mon Sep 17 00:00:00 2001 From: tschettervictor <85497460+tschettervictor@users.noreply.github.com> Date: Sun, 6 Jul 2025 15:05:53 -0600 Subject: [PATCH] list: Allow listing jail type separately --- usr/local/share/bastille/list.sh | 47 +++++++++++++++++++++++++++++++- 1 file changed, 46 insertions(+), 1 deletion(-) diff --git a/usr/local/share/bastille/list.sh b/usr/local/share/bastille/list.sh index 0c332a67..12caae74 100644 --- a/usr/local/share/bastille/list.sh +++ b/usr/local/share/bastille/list.sh @@ -435,7 +435,6 @@ list_ips() { print_info } - list_paths() { _tmp_list= @@ -541,6 +540,41 @@ list_state() { print_info } +list_type() { + + _tmp_list= + + get_max_lengths + get_jail_list + + # Print header + printf " JID%*sName%*sType\n" "$((${MAX_LENGTH_JID} + ${SPACER} - 3))" "" "$((${MAX_LENGTH_JAIL_NAME} + ${SPACER} - 4))" "" + + for _jail in ${JAIL_LIST}; do + + # Validate jail.conf existence + if [ -f "${bastille_jailsdir}/${_jail}/jail.conf" ]; then + _tmp_jail=$(mktemp /tmp/bastille-list-${_jail}) + else + continue + fi + + ( + + get_jail_info "${_jail}" + + printf " ${JID}%*s${JAIL_NAME}%*s${JAIL_TYPE}\n" "$((${MAX_LENGTH_JID} - ${#JID} + ${SPACER}))" "" "$((${MAX_LENGTH_JAIL_NAME} - ${#JAIL_NAME} + ${SPACER}))" "" + + ) > "${_tmp_jail}" & + + _tmp_list="$(printf "%s\n%s" "${_tmp_list}" "${_tmp_jail}")" + + done + wait + + print_info +} + # TODO: Check the correct usage or arguments here. See SC2120. # shellcheck disable=SC2120 list_release(){ @@ -740,6 +774,17 @@ if [ "$#" -eq 1 ]; then list_state fi ;; + type) + if [ "${OPT_JSON}" -eq 1 ]; then + if [ "${OPT_PRETTY}" -eq 1 ]; then + list_type | awk 'BEGIN{print "["} NR>1{if(NR>2)print ","; printf " {\"JID\":\"%s\",\"Name\":\"%s\",\"Type\":\"%s\"}",$1,$2,$3} END{print "\n]"}' | pretty_json + else + list_type | awk 'BEGIN{print "["} NR>1{if(NR>2)print ","; printf " {\"JID\":\"%s\",\"Name\":\"%s\",\"Type\":\"%s\"}",$1,$2,$3} END{print "\n]"}' + fi + else + list_type + fi + ;; release|releases) list_release "${2}" ;;