From 046cf87e79b536ea4a3a019a9546805cbf734568 Mon Sep 17 00:00:00 2001 From: tschettervictor Date: Tue, 29 Apr 2025 21:51:24 -0600 Subject: [PATCH] rework blank line --- usr/local/share/bastille/cmd.sh | 15 +++++++++------ usr/local/share/bastille/common.sh | 16 +++++++--------- usr/local/share/bastille/console.sh | 13 ++++++++----- usr/local/share/bastille/cp.sh | 8 +++++--- usr/local/share/bastille/destroy.sh | 8 +++++--- usr/local/share/bastille/jcp.sh | 8 +++++--- usr/local/share/bastille/limits.sh | 11 +++++++---- usr/local/share/bastille/mount.sh | 15 +++++++++------ usr/local/share/bastille/pkg.sh | 15 +++++++++------ usr/local/share/bastille/service.sh | 15 +++++++++------ usr/local/share/bastille/start.sh | 8 +++++--- usr/local/share/bastille/stop.sh | 8 +++++--- usr/local/share/bastille/sysrc.sh | 15 +++++++++------ usr/local/share/bastille/tags.sh | 7 ++++--- usr/local/share/bastille/template.sh | 15 +++++++++------ usr/local/share/bastille/umount.sh | 13 ++++++++----- 16 files changed, 113 insertions(+), 77 deletions(-) diff --git a/usr/local/share/bastille/cmd.sh b/usr/local/share/bastille/cmd.sh index 015f4c53..4dc06487 100644 --- a/usr/local/share/bastille/cmd.sh +++ b/usr/local/share/bastille/cmd.sh @@ -90,15 +90,18 @@ set_target "${TARGET}" for _jail in ${JAILS}; do - echo "" - info "[${_jail}]:" - check_target_is_running "${_jail}" || if [ "${AUTO}" -eq 1 ]; then bastille start "${_jail}" - else + else + info "[${_jail}]:" error_notify "Jail is not running." error_continue "Use [-a|--auto] to auto-start the jail." fi + + # Print blank line in front of first jail + [ "${_jail}" = "${_FIRST_JAIL}" ] && echo "" + + info "[${_jail}]:" COUNT=$(($COUNT+1)) if grep -qw "linsysfs" "${bastille_jailsdir}/${_jail}/fstab"; then @@ -117,8 +120,8 @@ for _jail in ${JAILS}; do RETURN=$(($RETURN+$ERROR_CODE)) fi - # Print blank line on last jail - [ "${_jail}" = "${_LAST_JAIL}" ] && echo "" + # Print blank line + echo "" done diff --git a/usr/local/share/bastille/common.sh b/usr/local/share/bastille/common.sh index edc2d869..1b246da6 100644 --- a/usr/local/share/bastille/common.sh +++ b/usr/local/share/bastille/common.sh @@ -67,9 +67,7 @@ fi # Notify message on error, and continue to next jail error_continue() { error_notify "$@" - # Print blank line on last jail - # We can use _TARGET from check_target_is_(running|stopped) for this - [ "${_TARGET}" = "${_LAST_JAIL}" ] && echo "" + echo "" # shellcheck disable=SC2104 continue } @@ -211,10 +209,10 @@ set_target() { TARGET="$(list_jail_priority "${TARGET}" | sort -k2 -nr | awk '{print $1}')" JAILS="$(list_jail_priority "${TARGET}" | sort -k2 -nr | awk '{print $1}')" fi - _LAST_JAIL="$(echo ${JAILS} | awk '{print $NF}')" + _FIRST_JAIL="$(echo ${JAILS} | awk '{print $1}')" export TARGET export JAILS - export _LAST_JAIL + export _FIRST_JAIL fi } @@ -241,10 +239,10 @@ set_target_single() { fi TARGET="${_TARGET}" JAILS="${_TARGET}" - _LAST_JAIL="$(echo ${JAILS} | awk '{print $NF}')" + _FIRST_JAIL="$(echo ${JAILS} | awk '{print $1}')" export TARGET export JAILS - export _LAST_JAIL + export _FIRST_JAIL } target_all_jails() { @@ -260,9 +258,9 @@ target_all_jails() { elif [ "${_order}" = "reverse" ]; then JAILS="$(list_jail_priority "${JAILS}" | sort -k2 -nr | awk '{print $1}')" fi - _LAST_JAIL="$(echo ${JAILS} | awk '{print $NF}')" + _FIRST_JAIL="$(echo ${JAILS} | awk '{print $1}')" export JAILS - export _LAST_JAIL + export _FIRST_JAIL } update_fstab() { diff --git a/usr/local/share/bastille/console.sh b/usr/local/share/bastille/console.sh index a50e5c3b..e51a16fa 100644 --- a/usr/local/share/bastille/console.sh +++ b/usr/local/share/bastille/console.sh @@ -115,15 +115,18 @@ check_fib() { } for _jail in ${JAILS}; do - echo "" - info "[${_jail}]:" - check_target_is_running "${_jail}" || if [ "${AUTO}" -eq 1 ]; then bastille start "${_jail}" else + info "[${_jail}]:" error_notify "Jail is not running." error_continue "Use [-a|--auto] to auto-start the jail." fi + + # Print blank line in front of first jail + [ "${_jail}" = "${_FIRST_JAIL}" ] && echo "" + + info "[${_jail}]:" LOGIN="$(jexec -l "${_jail}" which login)" if [ -n "${USER}" ]; then @@ -134,7 +137,7 @@ for _jail in ${JAILS}; do ${_setfib} jexec -l "${_jail}" $LOGIN -f root fi - # Print blank line on last jail - [ "${_jail}" = "${_LAST_JAIL}" ] && echo "" + # Print blank line + echo "" done diff --git a/usr/local/share/bastille/cp.sh b/usr/local/share/bastille/cp.sh index 51454f47..94c11bc8 100644 --- a/usr/local/share/bastille/cp.sh +++ b/usr/local/share/bastille/cp.sh @@ -88,7 +88,9 @@ set_target "${TARGET}" for _jail in ${JAILS}; do - echo "" + # Print blank line in front of first jail + [ "${_jail}" = "${_FIRST_JAIL}" ] && echo "" + info "[${_jail}]:" host_path="${HOST_PATH}" @@ -98,7 +100,7 @@ for _jail in ${JAILS}; do error_continue "CP failed: ${host_path} -> ${jail_path}" fi - # Print blank line on last jail - [ "${_jail}" = "${_LAST_JAIL}" ] && echo "" + # Print blank line + echo "" done \ No newline at end of file diff --git a/usr/local/share/bastille/destroy.sh b/usr/local/share/bastille/destroy.sh index af55236f..b6134a1c 100644 --- a/usr/local/share/bastille/destroy.sh +++ b/usr/local/share/bastille/destroy.sh @@ -52,7 +52,8 @@ destroy_jail() { for _jail in ${JAILS}; do - echo "" + # Print blank line in front of first jail + [ "${_jail}" = "${_FIRST_JAIL}" ] && echo "" bastille_jail_base="${bastille_jailsdir}/${_jail}" bastille_jail_log="${bastille_logsdir}/${_jail}_console.log" @@ -60,6 +61,7 @@ destroy_jail() { check_target_is_stopped "${_jail}" || if [ "${AUTO}" -eq 1 ]; then bastille stop "${_jail}" else + info "[${_jail}]:" error_notify "Jail is running." error_continue "Use [-a|--auto] to auto-stop the jail." fi @@ -111,8 +113,8 @@ destroy_jail() { fi fi - # Print blank line on last jail - [ "${_jail}" = "${_LAST_JAIL}" ] && echo "" + # Print blank line + echo "" done } diff --git a/usr/local/share/bastille/jcp.sh b/usr/local/share/bastille/jcp.sh index 7c3dbaf9..ee44bbba 100644 --- a/usr/local/share/bastille/jcp.sh +++ b/usr/local/share/bastille/jcp.sh @@ -94,7 +94,9 @@ for _jail in ${DEST_TARGET}; do continue else - echo "" + # Print blank line in front of first jail + [ "${_jail}" = "${_FIRST_JAIL}" ] && echo "" + info "[${_jail}]:" source_path="$(echo ${bastille_jailsdir}/${SOURCE_TARGET}/root/${SOURCE_PATH} | sed 's#//#/#g')" @@ -104,8 +106,8 @@ for _jail in ${DEST_TARGET}; do error_continue "JCP failed: ${source_path} -> ${dest_path}" fi - # Print blank line on last jail - [ "${_jail}" = "${_LAST_JAIL}" ] && echo "" + # Print blank line + echo "" fi done \ No newline at end of file diff --git a/usr/local/share/bastille/limits.sh b/usr/local/share/bastille/limits.sh index 569d8ca8..ce2318ec 100644 --- a/usr/local/share/bastille/limits.sh +++ b/usr/local/share/bastille/limits.sh @@ -102,15 +102,18 @@ set_target "${TARGET}" for _jail in ${JAILS}; do - echo "" - info "[${_jail}]:" - check_target_is_running "${_jail}" || if [ "${AUTO}" -eq 1 ]; then bastille start "${_jail}" - else + else + info "[${_jail}]:" error_notify "Jail is not running." error_continue "Use [-a|--auto] to auto-start the jail." fi + + # Print blank line in front of first jail + [ "${_jail}" = "${_FIRST_JAIL}" ] && echo "" + + info "[${_jail}]:" case "${ACTION}" in add) diff --git a/usr/local/share/bastille/mount.sh b/usr/local/share/bastille/mount.sh index 4642478c..694f29aa 100644 --- a/usr/local/share/bastille/mount.sh +++ b/usr/local/share/bastille/mount.sh @@ -142,16 +142,19 @@ fi for _jail in ${JAILS}; do - echo "" - info "[${_jail}]:" - check_target_is_running "${_jail}" || if [ "${AUTO}" -eq 1 ]; then bastille start "${_jail}" else + info "[${_jail}]:" error_notify "Jail is not running." error_exit "Use [-a|--auto] to auto-start the jail." fi - + + # Print blank line in front of first jail + [ "${_jail}" = "${_FIRST_JAIL}" ] && echo "" + + info "[${_jail}]:" + _fullpath_fstab="$( echo "${bastille_jailsdir}/${_jail}/root/${_jailpath_fstab}" 2>/dev/null | sed 's#//#/#' )" _fullpath="$( echo "${bastille_jailsdir}/${_jail}/root/${_jailpath}" 2>/dev/null | sed 's#//#/#' )" _fstab_entry="${_hostpath_fstab} ${_fullpath_fstab} ${_type} ${_perms} ${_checks}" @@ -199,7 +202,7 @@ for _jail in ${JAILS}; do mount -F "${bastille_jailsdir}/${_jail}/fstab" -a || error_continue "Failed to mount volume: ${_fullpath}" echo "Added: ${_fstab_entry}" - # Print blank line on last jail - [ "${_jail}" = "${_LAST_JAIL}" ] && echo "" + # Print blank line + echo "" done diff --git a/usr/local/share/bastille/pkg.sh b/usr/local/share/bastille/pkg.sh index 0b6d4927..3b854e64 100644 --- a/usr/local/share/bastille/pkg.sh +++ b/usr/local/share/bastille/pkg.sh @@ -96,15 +96,18 @@ errors=0 for _jail in ${JAILS}; do - echo "" - info "[${_jail}]:" - check_target_is_running "${_jail}" || if [ "${AUTO}" -eq 1 ]; then bastille start "${_jail}" - else + else + info "[${_jail}]:" error_notify "Jail is not running." error_continue "Use [-a|--auto] to auto-start the jail." fi + + # Print blank line in front of first jail + [ "${_jail}" = "${_FIRST_JAIL}" ] && echo "" + + info "[${_jail}]:" bastille_jail_path="${bastille_jailsdir}/${_jail}/root" if [ -f "/usr/sbin/mport" ]; then @@ -125,8 +128,8 @@ for _jail in ${JAILS}; do fi fi - # Print blank line on last jail - [ "${_jail}" = "${_LAST_JAIL}" ] && echo "" + # Print blank line + echo "" done diff --git a/usr/local/share/bastille/service.sh b/usr/local/share/bastille/service.sh index 6bd5cfd8..7f2124b5 100644 --- a/usr/local/share/bastille/service.sh +++ b/usr/local/share/bastille/service.sh @@ -86,20 +86,23 @@ bastille_root_check set_target "${TARGET}" for _jail in ${JAILS}; do - - echo "" - info "[${_jail}]:" check_target_is_running "${_jail}" || if [ "${AUTO}" -eq 1 ]; then bastille start "${_jail}" - else + else + info "[${_jail}]:" error_notify "Jail is not running." error_continue "Use [-a|--auto] to auto-start the jail." fi + # Print blank line in front of first jail + [ "${_jail}" = "${_FIRST_JAIL}" ] && echo "" + + info "[${_jail}]:" + jexec -l "${_jail}" /usr/sbin/service "$@" - # Print blank line on last jail - [ "${_jail}" = "${_LAST_JAIL}" ] && echo "" + # Print blank line + echo "" done diff --git a/usr/local/share/bastille/start.sh b/usr/local/share/bastille/start.sh index 221760a7..3b3d1ee1 100644 --- a/usr/local/share/bastille/start.sh +++ b/usr/local/share/bastille/start.sh @@ -111,7 +111,9 @@ for _jail in ${JAILS}; do fi fi - echo "" + # Print blank line in front of first jail + [ "${_jail}" = "${_FIRST_JAIL}" ] && echo "" + info "[${_jail}]:" check_target_is_stopped "${_jail}" || error_continue "Jail is already running." @@ -188,7 +190,7 @@ for _jail in ${JAILS}; do # Delay between jail action sleep "${DELAY_TIME}" - # Print blank line on last jail - [ "${_jail}" = "${_LAST_JAIL}" ] && echo "" + # Print blank line + echo "" done diff --git a/usr/local/share/bastille/stop.sh b/usr/local/share/bastille/stop.sh index 7bf99f28..15795c61 100644 --- a/usr/local/share/bastille/stop.sh +++ b/usr/local/share/bastille/stop.sh @@ -86,7 +86,9 @@ set_target "${TARGET}" "reverse" for _jail in ${JAILS}; do - echo "" + # Print blank line in front of first jail + [ "${_jail}" = "${_FIRST_JAIL}" ] && echo "" + info "[${_jail}]:" check_target_is_running "${_jail}" || error_continue "Jail is already stopped." @@ -134,7 +136,7 @@ for _jail in ${JAILS}; do done fi - # Print blank line on last jail - [ "${_jail}" = "${_LAST_JAIL}" ] && echo "" + # Print blank line + echo "" done diff --git a/usr/local/share/bastille/sysrc.sh b/usr/local/share/bastille/sysrc.sh index 360a02ba..f30f3666 100644 --- a/usr/local/share/bastille/sysrc.sh +++ b/usr/local/share/bastille/sysrc.sh @@ -86,20 +86,23 @@ bastille_root_check set_target "${TARGET}" for _jail in ${JAILS}; do - - echo "" - info "[${_jail}]:" check_target_is_running "${_jail}" || if [ "${AUTO}" -eq 1 ]; then bastille start "${_jail}" - else + else + info "[${_jail}]:" error_notify "Jail is not running." error_continue "Use [-a|--auto] to auto-start the jail." fi + # Print blank line in front of first jail + [ "${_jail}" = "${_FIRST_JAIL}" ] && echo "" + + info "[${_jail}]:" + jexec -l "${_jail}" /usr/sbin/sysrc "$@" - # Print blank line on last jail - [ "${_jail}" = "${_LAST_JAIL}" ] && echo "" + # Print blank line + echo "" done diff --git a/usr/local/share/bastille/tags.sh b/usr/local/share/bastille/tags.sh index ef9254a9..2be4fbcc 100644 --- a/usr/local/share/bastille/tags.sh +++ b/usr/local/share/bastille/tags.sh @@ -76,7 +76,8 @@ set_target "${TARGET}" for _jail in ${JAILS}; do - echo "" + # Print blank line in front of first jail + [ "${_jail}" = "${_FIRST_JAIL}" ] && echo "" bastille_jail_tags="${bastille_jailsdir}/${_jail}/tags" case ${ACTION} in @@ -119,8 +120,8 @@ for _jail in ${JAILS}; do ;; esac - # Print blank line on last jail - [ "${_jail}" = "${_LAST_JAIL}" ] && echo "" + # Print blank line + echo "" done diff --git a/usr/local/share/bastille/template.sh b/usr/local/share/bastille/template.sh index 875078d2..9c361b31 100644 --- a/usr/local/share/bastille/template.sh +++ b/usr/local/share/bastille/template.sh @@ -270,15 +270,18 @@ fi for _jail in ${JAILS}; do - echo "" - info "[${_jail}]:" - check_target_is_running "${_jail}" || if [ "${AUTO}" -eq 1 ]; then bastille start "${_jail}" - else + else + info "[${_jail}]:" error_notify "Jail is not running." error_continue "Use [-a|--auto] to auto-start the jail." fi + + # Print blank line in front of first jail + [ "${_jail}" = "${_FIRST_JAIL}" ] && echo "" + + info "[${_jail}]:" info "Applying template: ${TEMPLATE}..." @@ -470,8 +473,8 @@ for _jail in ${JAILS}; do fi done - # Print blank line on last jail - [ "${_jail}" = "${_LAST_JAIL}" ] && echo "" + # Print blank line + echo "" info "Template applied: ${TEMPLATE}" diff --git a/usr/local/share/bastille/umount.sh b/usr/local/share/bastille/umount.sh index 0b89e202..8fc36133 100644 --- a/usr/local/share/bastille/umount.sh +++ b/usr/local/share/bastille/umount.sh @@ -87,15 +87,18 @@ set_target "${TARGET}" for _jail in ${JAILS}; do - echo "" - info "[${_jail}]:" - check_target_is_running "${_jail}" || if [ "${AUTO}" -eq 1 ]; then bastille start "${_jail}" else + info "[${_jail}]:" error_notify "Jail is not running." error_exit "Use [-a|--auto] to auto-start the jail." fi + + # Print blank line in front of first jail + [ "${_jail}" = "${_FIRST_JAIL}" ] && echo "" + + info "[${_jail}]:" _jailpath="$( echo "${bastille_jailsdir}/${_jail}/root/${MOUNT_PATH}" 2>/dev/null | sed 's#//#/#' | sed 's#\\##g')" _mount="$( mount | grep -Eo "[[:blank:]]${_jailpath}[[:blank:]]" )" @@ -126,7 +129,7 @@ for _jail in ${JAILS}; do echo "Unmounted: ${_jailpath}" - # Print blank line on last jail - [ "${_jail}" = "${_LAST_JAIL}" ] && echo "" + # Print blank line + echo "" done