From da4752ebd59ae847aa7cb1803867d0685666d6f1 Mon Sep 17 00:00:00 2001 From: tschettervictor <85497460+tschettervictor@users.noreply.github.com> Date: Thu, 27 Feb 2025 17:00:30 -0700 Subject: [PATCH] list: Use new functions --- usr/local/share/bastille/list.sh | 130 ++++++++++++++++++------------- 1 file changed, 76 insertions(+), 54 deletions(-) diff --git a/usr/local/share/bastille/list.sh b/usr/local/share/bastille/list.sh index 5679a8d2..d8e3d1c2 100644 --- a/usr/local/share/bastille/list.sh +++ b/usr/local/share/bastille/list.sh @@ -34,26 +34,16 @@ . /usr/local/etc/bastille/bastille.conf usage() { - error_exit "Usage: bastille list [-j|-a] [release [-p]|template|(jail|container)|log|limit|ports|(import|export|backup)]" + error_notify "Usage: bastille list [option(s)] [-j|-a] [release [-p]|template|(jail|container)|log|limit|(import|export|backup)]" + cat << EOF + Options: + + -x | --debug Enable debug mode. + +EOF + exit 1 } -if [ "${1}" = help ] || [ "${1}" = "-h" ] || [ "${1}" = "--help" ]; then - usage -fi - -bastille_root_check - -if [ $# -eq 0 ]; then - /usr/sbin/jls -fi - -if [ "${1}" = "-j" ]; then - /usr/sbin/jls -N --libxo json - exit 0 -fi - -TARGET= - list_all(){ if [ -d "${bastille_jailsdir}" ]; then DEFAULT_VALUE="-" @@ -93,7 +83,7 @@ list_all(){ JAIL_LIST="${TARGET}" else # Query all info for all jails(default). - JAIL_LIST=$(ls "${bastille_jailsdir}" | sed "s/\n//g") + JAIL_LIST=$(ls --color=never "${bastille_jailsdir}" | sed "s/\n//g") fi for _JAIL in ${JAIL_LIST}; do if [ -f "${bastille_jailsdir}/${_JAIL}/jail.conf" ]; then @@ -243,42 +233,74 @@ list_ports(){ fi } -if [ $# -gt 0 ]; then - # Handle special-case commands first. +bastille_root_check + +if [ "$#" -eq 0 ]; then + /usr/sbin/jls +fi + +TARGET="" + +# Handle options. +while [ "$#" -gt 0 ]; do case "${1}" in - all|-a|--all) - list_all - ;; - port|ports) - list_ports - ;; - release|releases) - list_release "${2}" - ;; - template|templates) - list_template - ;; - jail|jails|container|containers) - list_jail - ;; - log|logs) - list_log - ;; - limit|limits) - list_limit - ;; - import|imports|export|exports|backup|backups) - list_import - exit 0 - ;; - *) - # Check if we want to query all info for a specific jail instead. - if [ -f "${bastille_jailsdir}/${1}/jail.conf" ]; then - TARGET="${1}" + -h|--help|help) + usage + ;; + -a|--all|all) list_all - else - usage - fi - ;; + exit 0 + ;; + -j|--json) + /usr/sbin/jls -N --libxo json + exit 0 + ;; + -x|--debug) + enable_debug + shift + ;; + -*) + error_exit "Unknown option: \"${1}\"" + ;; + *) + break + ;; + esac +done + +if [ "$#" -gt 0 ]; then + case "${1}" in + port|ports) + list_ports + ;; + release|releases) + list_release "${2}" + ;; + template|templates) + list_template + ;; + jail|jails|container|containers) + list_jail + ;; + log|logs) + list_log + ;; + limit|limits) + list_limit + ;; + import|imports|export|exports|backup|backups) + list_import + exit 0 + ;; + *) + # Check if we want to query all info for a specific jail instead. + if [ -f "${bastille_jailsdir}/${1}/jail.conf" ]; then + TARGET="${1}" + set_target "${TARGET}" + list_all + else + usage + fi + ;; esac fi