From e4fb6e3ca6d184b0213a427610dc9d36b6d36840 Mon Sep 17 00:00:00 2001 From: tschettervictor <85497460+tschettervictor@users.noreply.github.com> Date: Mon, 16 Dec 2024 12:18:40 -0700 Subject: [PATCH 01/43] begin moving functions to common.sh --- usr/local/share/bastille/common.sh | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/usr/local/share/bastille/common.sh b/usr/local/share/bastille/common.sh index 9940d9e6..012259e6 100644 --- a/usr/local/share/bastille/common.sh +++ b/usr/local/share/bastille/common.sh @@ -70,6 +70,36 @@ warn() { echo -e "${COLOR_YELLOW}$*${COLOR_RESET}" } +# This is where I am placing all new functions. +check_if_jail_exists() { + TARGET="${1}" + JAILS="" + if [ -d "${bastille_jailsdir}/${TARGET}" ]; then + JAILS="${TARGET}" + return 0 + else + error_exit "Jail not found." + fi +} + +check_target_is_running() { + TARGET="${1}" + if [ ! "$(/usr/sbin/jls name | awk "/^${TARGET}$/")" ]; then + error_exit "[${TARGET}]: Not started. See 'bastille start ${TARGET}'." + fi +} + +target_all_jails() { + _JAILS=$(/usr/sbin/jls name) + JAILS="" + for _jail in ${_JAILS}; do + _JAILPATH=$(/usr/sbin/jls -j "${_jail}" path) + if [ -z ${_JAILPATH##${bastille_jailsdir}*} ]; then + JAILS="${JAILS} ${_jail}" + fi + done +} + generate_vnet_jail_netblock() { local jail_name="$1" local use_unique_bridge="$2" From e4487077c9341b8495c8bbb7de86bb180b136bbc Mon Sep 17 00:00:00 2001 From: tschettervictor <85497460+tschettervictor@users.noreply.github.com> Date: Mon, 16 Dec 2024 12:19:09 -0700 Subject: [PATCH 02/43] rename to be consistent --- usr/local/share/bastille/common.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/usr/local/share/bastille/common.sh b/usr/local/share/bastille/common.sh index 012259e6..8d2faa4e 100644 --- a/usr/local/share/bastille/common.sh +++ b/usr/local/share/bastille/common.sh @@ -71,7 +71,7 @@ warn() { } # This is where I am placing all new functions. -check_if_jail_exists() { +check_jail_exists() { TARGET="${1}" JAILS="" if [ -d "${bastille_jailsdir}/${TARGET}" ]; then From 5bc7cd8c738d9c70c1938a804e94381a48ab59ca Mon Sep 17 00:00:00 2001 From: tschettervictor <85497460+tschettervictor@users.noreply.github.com> Date: Mon, 16 Dec 2024 12:24:46 -0700 Subject: [PATCH 03/43] begin function define in top --- usr/local/share/bastille/top.sh | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/usr/local/share/bastille/top.sh b/usr/local/share/bastille/top.sh index 1e8cbb9c..7c319ed3 100644 --- a/usr/local/share/bastille/top.sh +++ b/usr/local/share/bastille/top.sh @@ -35,12 +35,22 @@ usage() { } # Handle special-case commands first. -case "$1" in -help|-h|--help) - usage - ;; +case "${1}" in + help|-h|--help) + usage + ;; esac +TARGET="${1}" +shift + +if [ "${TARGET}" = "ALL" ]; then + target_all_jails +else + check_jail_exists "${TARGET}" + check_target_is_running "${TARGET}" +fi + if [ $# -ne 0 ]; then usage fi From e0dfc33e4611705d8144b3419ec6f06467372b51 Mon Sep 17 00:00:00 2001 From: tschettervictor <85497460+tschettervictor@users.noreply.github.com> Date: Mon, 16 Dec 2024 12:26:46 -0700 Subject: [PATCH 04/43] move jail running check to for loop --- usr/local/share/bastille/top.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/usr/local/share/bastille/top.sh b/usr/local/share/bastille/top.sh index 7c319ed3..029b88d7 100644 --- a/usr/local/share/bastille/top.sh +++ b/usr/local/share/bastille/top.sh @@ -47,8 +47,7 @@ shift if [ "${TARGET}" = "ALL" ]; then target_all_jails else - check_jail_exists "${TARGET}" - check_target_is_running "${TARGET}" + check_target_exists "${TARGET}" fi if [ $# -ne 0 ]; then @@ -58,6 +57,7 @@ fi bastille_root_check for _jail in ${JAILS}; do + check_target_is_running "${TARGET}" info "[${_jail}]:" jexec -l "${_jail}" /usr/bin/top echo -e "${COLOR_RESET}" From 0e3f7a5c0c6d89f7df3c3731de7be12336335540 Mon Sep 17 00:00:00 2001 From: tschettervictor <85497460+tschettervictor@users.noreply.github.com> Date: Mon, 16 Dec 2024 12:27:07 -0700 Subject: [PATCH 05/43] rename function to target --- usr/local/share/bastille/common.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/usr/local/share/bastille/common.sh b/usr/local/share/bastille/common.sh index 8d2faa4e..945810e8 100644 --- a/usr/local/share/bastille/common.sh +++ b/usr/local/share/bastille/common.sh @@ -71,7 +71,7 @@ warn() { } # This is where I am placing all new functions. -check_jail_exists() { +check_target_exists() { TARGET="${1}" JAILS="" if [ -d "${bastille_jailsdir}/${TARGET}" ]; then From 63314675afec37043929a5a7e3e3479c72304215 Mon Sep 17 00:00:00 2001 From: tschettervictor <85497460+tschettervictor@users.noreply.github.com> Date: Mon, 16 Dec 2024 12:29:00 -0700 Subject: [PATCH 06/43] htop function add --- usr/local/share/bastille/htop.sh | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/usr/local/share/bastille/htop.sh b/usr/local/share/bastille/htop.sh index de82387b..9c8a9913 100644 --- a/usr/local/share/bastille/htop.sh +++ b/usr/local/share/bastille/htop.sh @@ -37,11 +37,20 @@ usage() { # Handle special-case commands first. case "$1" in -help|-h|--help) - usage - ;; + help|-h|--help) + usage + ;; esac +TARGET="${1}" +shift + +if [ "${TARGET}" = "ALL" ]; then + target_all_jails +else + check_target_exists "${TARGET}" +fi + if [ $# -ne 0 ]; then usage fi @@ -49,6 +58,7 @@ fi bastille_root_check for _jail in ${JAILS}; do + check_target_is_running "${_jail}" bastille_jail_path=$(/usr/sbin/jls -j "${_jail}" path) if [ ! -x "${bastille_jail_path}/usr/local/bin/htop" ]; then error_notify "htop not found on ${_jail}." From 3c927338c8cffd38c3a32f52ded35561105e7b0d Mon Sep 17 00:00:00 2001 From: tschettervictor <85497460+tschettervictor@users.noreply.github.com> Date: Mon, 16 Dec 2024 12:29:09 -0700 Subject: [PATCH 07/43] Update top.sh --- usr/local/share/bastille/top.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/usr/local/share/bastille/top.sh b/usr/local/share/bastille/top.sh index 029b88d7..f3cddd9a 100644 --- a/usr/local/share/bastille/top.sh +++ b/usr/local/share/bastille/top.sh @@ -57,7 +57,7 @@ fi bastille_root_check for _jail in ${JAILS}; do - check_target_is_running "${TARGET}" + check_target_is_running "${_jail}" info "[${_jail}]:" jexec -l "${_jail}" /usr/bin/top echo -e "${COLOR_RESET}" From dc5588188967f63878c340fb921045fd2c9979df Mon Sep 17 00:00:00 2001 From: tschettervictor <85497460+tschettervictor@users.noreply.github.com> Date: Mon, 16 Dec 2024 12:44:05 -0700 Subject: [PATCH 08/43] source config from common.sh --- usr/local/share/bastille/common.sh | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/usr/local/share/bastille/common.sh b/usr/local/share/bastille/common.sh index 945810e8..35d4ff0d 100644 --- a/usr/local/share/bastille/common.sh +++ b/usr/local/share/bastille/common.sh @@ -28,6 +28,9 @@ # OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +# Source config file +. /usr/local/etc/bastille/bastille.conf + COLOR_RED= COLOR_GREEN= COLOR_YELLOW= @@ -74,7 +77,7 @@ warn() { check_target_exists() { TARGET="${1}" JAILS="" - if [ -d "${bastille_jailsdir}/${TARGET}" ]; then + if [ -d "${bastille_jailsdir}"/"${TARGET}" ]; then JAILS="${TARGET}" return 0 else From 538ec8159dcfff381686652a43ca11dcd4043619 Mon Sep 17 00:00:00 2001 From: tschettervictor <85497460+tschettervictor@users.noreply.github.com> Date: Mon, 16 Dec 2024 12:45:13 -0700 Subject: [PATCH 09/43] move top and htop to no action command --- usr/local/bin/bastille | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/usr/local/bin/bastille b/usr/local/bin/bastille index dd9cbb25..49d27950 100755 --- a/usr/local/bin/bastille +++ b/usr/local/bin/bastille @@ -147,10 +147,10 @@ version|-v|--version) help|-h|--help) usage ;; -bootstrap|create|destroy|export|import|list|rdr|restart|setup|start|update|upgrade|verify) +bootstrap|create|destroy|export|htop|import|list|rdr|restart|setup|start|top|update|upgrade|verify) # Nothing "extra" to do for these commands. -- cwells ;; -clone|config|cmd|console|convert|cp|edit|htop|limits|mount|pkg|rcp|rename|service|stop|sysrc|tags|template|top|umount|zfs) +clone|config|cmd|console|convert|cp|edit|limits|mount|pkg|rcp|rename|service|stop|sysrc|tags|template|umount|zfs) # Parse the target and ensure it exists. -- cwells if [ $# -eq 0 ]; then # No target was given, so show the command's help. -- cwells PARAMS='help' @@ -195,7 +195,7 @@ clone|config|cmd|console|convert|cp|edit|htop|limits|mount|pkg|rcp|rename|servic fi case "${CMD}" in - cmd|console|htop|pkg|service|stop|sysrc|template|top) + cmd|console|pkg|service|stop|sysrc|template) check_target_is_running ;; convert|rename) From fe029c034492cdb9256b667aae344d8383bd57fa Mon Sep 17 00:00:00 2001 From: tschettervictor <85497460+tschettervictor@users.noreply.github.com> Date: Mon, 16 Dec 2024 12:48:09 -0700 Subject: [PATCH 10/43] exit if no args --- usr/local/share/bastille/top.sh | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/usr/local/share/bastille/top.sh b/usr/local/share/bastille/top.sh index f3cddd9a..20a039fb 100644 --- a/usr/local/share/bastille/top.sh +++ b/usr/local/share/bastille/top.sh @@ -41,8 +41,12 @@ case "${1}" in ;; esac -TARGET="${1}" -shift +if [ $# -eq 0 ]; then + usage +else + TARGET="${1}" + shift +fi if [ "${TARGET}" = "ALL" ]; then target_all_jails From d2943bdf3f103d97db9a401ac6ce6f96c49fa56e Mon Sep 17 00:00:00 2001 From: tschettervictor <85497460+tschettervictor@users.noreply.github.com> Date: Mon, 16 Dec 2024 12:48:23 -0700 Subject: [PATCH 11/43] exit if no args --- usr/local/share/bastille/htop.sh | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/usr/local/share/bastille/htop.sh b/usr/local/share/bastille/htop.sh index 9c8a9913..3dc9dbe6 100644 --- a/usr/local/share/bastille/htop.sh +++ b/usr/local/share/bastille/htop.sh @@ -42,8 +42,12 @@ case "$1" in ;; esac -TARGET="${1}" -shift +if [ $# -eq 0 ]; then + usage +else + TARGET="${1}" + shift +fi if [ "${TARGET}" = "ALL" ]; then target_all_jails From 6d2e9c2ec9bc2b5c7de47784373c3d8489438920 Mon Sep 17 00:00:00 2001 From: tschettervictor <85497460+tschettervictor@users.noreply.github.com> Date: Mon, 16 Dec 2024 12:49:11 -0700 Subject: [PATCH 12/43] also source config file --- usr/local/share/bastille/top.sh | 1 + 1 file changed, 1 insertion(+) diff --git a/usr/local/share/bastille/top.sh b/usr/local/share/bastille/top.sh index 20a039fb..088ece5c 100644 --- a/usr/local/share/bastille/top.sh +++ b/usr/local/share/bastille/top.sh @@ -29,6 +29,7 @@ # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. . /usr/local/share/bastille/common.sh +. /usr/local/etc/bastille/bastille.conf usage() { error_exit "Usage: bastille top TARGET" From 1fce1925a6d61a23b7d05fdc82e8882db9f07bc3 Mon Sep 17 00:00:00 2001 From: tschettervictor <85497460+tschettervictor@users.noreply.github.com> Date: Mon, 16 Dec 2024 16:58:41 -0700 Subject: [PATCH 13/43] spacing --- usr/local/share/bastille/common.sh | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/usr/local/share/bastille/common.sh b/usr/local/share/bastille/common.sh index 35d4ff0d..85310110 100644 --- a/usr/local/share/bastille/common.sh +++ b/usr/local/share/bastille/common.sh @@ -87,20 +87,20 @@ check_target_exists() { check_target_is_running() { TARGET="${1}" - if [ ! "$(/usr/sbin/jls name | awk "/^${TARGET}$/")" ]; then - error_exit "[${TARGET}]: Not started. See 'bastille start ${TARGET}'." - fi + if [ ! "$(/usr/sbin/jls name | awk "/^${TARGET}$/")" ]; then + error_exit "[${TARGET}]: Not started. See 'bastille start ${TARGET}'." + fi } target_all_jails() { - _JAILS=$(/usr/sbin/jls name) - JAILS="" - for _jail in ${_JAILS}; do - _JAILPATH=$(/usr/sbin/jls -j "${_jail}" path) - if [ -z ${_JAILPATH##${bastille_jailsdir}*} ]; then - JAILS="${JAILS} ${_jail}" - fi - done + _JAILS=$(/usr/sbin/jls name) + JAILS="" + for _jail in ${_JAILS}; do + _JAILPATH=$(/usr/sbin/jls -j "${_jail}" path) + if [ -z ${_JAILPATH##${bastille_jailsdir}*} ]; then + JAILS="${JAILS} ${_jail}" + fi + done } generate_vnet_jail_netblock() { From 31cc087ef30d801ea402e0ed615d2db0ed8b006d Mon Sep 17 00:00:00 2001 From: tschettervictor <85497460+tschettervictor@users.noreply.github.com> Date: Mon, 16 Dec 2024 17:44:36 -0700 Subject: [PATCH 14/43] Add set_target function --- usr/local/share/bastille/common.sh | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/usr/local/share/bastille/common.sh b/usr/local/share/bastille/common.sh index 85310110..42eb4b66 100644 --- a/usr/local/share/bastille/common.sh +++ b/usr/local/share/bastille/common.sh @@ -92,6 +92,15 @@ check_target_is_running() { fi } +set_target() { + if [ "{1}" = ALL ] || [ "{1}" = all]; then + target_all_jails + else + TARGET="{1}" + check_target_exists "{TARGET}" + fi +} + target_all_jails() { _JAILS=$(/usr/sbin/jls name) JAILS="" From 0ddd4d98cf2e12c52de38d53926dd2331bb93122 Mon Sep 17 00:00:00 2001 From: tschettervictor <85497460+tschettervictor@users.noreply.github.com> Date: Mon, 16 Dec 2024 17:48:21 -0700 Subject: [PATCH 15/43] Fox vars --- usr/local/share/bastille/common.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/usr/local/share/bastille/common.sh b/usr/local/share/bastille/common.sh index 42eb4b66..be7a656a 100644 --- a/usr/local/share/bastille/common.sh +++ b/usr/local/share/bastille/common.sh @@ -93,10 +93,10 @@ check_target_is_running() { } set_target() { - if [ "{1}" = ALL ] || [ "{1}" = all]; then + if [ "${1}" = ALL ] || [ "${1}" = all ]; then target_all_jails else - TARGET="{1}" + TARGET="${1}" check_target_exists "{TARGET}" fi } From 0874e02f18c51604db6396c7b974856542153abb Mon Sep 17 00:00:00 2001 From: tschettervictor <85497460+tschettervictor@users.noreply.github.com> Date: Mon, 16 Dec 2024 17:50:35 -0700 Subject: [PATCH 16/43] Update common.sh --- usr/local/share/bastille/common.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/usr/local/share/bastille/common.sh b/usr/local/share/bastille/common.sh index be7a656a..c8d1b621 100644 --- a/usr/local/share/bastille/common.sh +++ b/usr/local/share/bastille/common.sh @@ -97,7 +97,7 @@ set_target() { target_all_jails else TARGET="${1}" - check_target_exists "{TARGET}" + check_target_exists "${TARGET}" fi } From 42a6a29b8e874bf01fcd7ecc0b9f1e18e7f6ef53 Mon Sep 17 00:00:00 2001 From: tschettervictor <85497460+tschettervictor@users.noreply.github.com> Date: Mon, 16 Dec 2024 19:05:35 -0700 Subject: [PATCH 17/43] only accept one target for top --- usr/local/share/bastille/top.sh | 19 ++++--------------- 1 file changed, 4 insertions(+), 15 deletions(-) diff --git a/usr/local/share/bastille/top.sh b/usr/local/share/bastille/top.sh index 088ece5c..d7567f8b 100644 --- a/usr/local/share/bastille/top.sh +++ b/usr/local/share/bastille/top.sh @@ -42,26 +42,15 @@ case "${1}" in ;; esac -if [ $# -eq 0 ]; then - usage -else - TARGET="${1}" - shift -fi - -if [ "${TARGET}" = "ALL" ]; then - target_all_jails -else - check_target_exists "${TARGET}" -fi - -if [ $# -ne 0 ]; then +# Accept only one argument +if [ $# -eq 0 ] || [ $# -gt 1 ]; then usage fi +set_target_single "${1}" bastille_root_check -for _jail in ${JAILS}; do +for _jail in "${JAILS}"; do check_target_is_running "${_jail}" info "[${_jail}]:" jexec -l "${_jail}" /usr/bin/top From 9e8cd7bec5fc9f1ec9b39a71722c82b9448802ad Mon Sep 17 00:00:00 2001 From: tschettervictor <85497460+tschettervictor@users.noreply.github.com> Date: Mon, 16 Dec 2024 19:08:26 -0700 Subject: [PATCH 18/43] accept only one arg on htop --- usr/local/share/bastille/htop.sh | 23 ++++++----------------- 1 file changed, 6 insertions(+), 17 deletions(-) diff --git a/usr/local/share/bastille/htop.sh b/usr/local/share/bastille/htop.sh index 3dc9dbe6..685d59d4 100644 --- a/usr/local/share/bastille/htop.sh +++ b/usr/local/share/bastille/htop.sh @@ -42,33 +42,22 @@ case "$1" in ;; esac -if [ $# -eq 0 ]; then - usage -else - TARGET="${1}" - shift -fi - -if [ "${TARGET}" = "ALL" ]; then - target_all_jails -else - check_target_exists "${TARGET}" -fi - -if [ $# -ne 0 ]; then +# Accept only one argument. +if [ $# -eq 0 ] || [ $# -gt 1 ]; then usage fi +set_target_single "${1}" bastille_root_check -for _jail in ${JAILS}; do +for _jail in "${JAILS}"; do check_target_is_running "${_jail}" - bastille_jail_path=$(/usr/sbin/jls -j "${_jail}" path) + bastille_jail_path="$(/usr/sbin/jls -j "${_jail}" path)" if [ ! -x "${bastille_jail_path}/usr/local/bin/htop" ]; then error_notify "htop not found on ${_jail}." elif [ -x "${bastille_jail_path}/usr/local/bin/htop" ]; then info "[${_jail}]:" - jexec -l ${_jail} /usr/local/bin/htop + jexec -l "${_jail}" /usr/local/bin/htop fi echo -e "${COLOR_RESET}" done From b22532078fdc9cf827774bb6dee242164ece1e9b Mon Sep 17 00:00:00 2001 From: tschettervictor <85497460+tschettervictor@users.noreply.github.com> Date: Mon, 16 Dec 2024 19:12:34 -0700 Subject: [PATCH 19/43] accept only one arg with htop --- usr/local/share/bastille/htop.sh | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/usr/local/share/bastille/htop.sh b/usr/local/share/bastille/htop.sh index 685d59d4..7b6084b6 100644 --- a/usr/local/share/bastille/htop.sh +++ b/usr/local/share/bastille/htop.sh @@ -1,3 +1,4 @@ + #!/bin/sh # # Copyright (c) 2018-2024, Christer Edwards @@ -47,17 +48,16 @@ if [ $# -eq 0 ] || [ $# -gt 1 ]; then usage fi -set_target_single "${1}" +TARGET="${1}" +set_target_single "${TARGET}" bastille_root_check +check_target_is_running "${TARGET}" -for _jail in "${JAILS}"; do - check_target_is_running "${_jail}" - bastille_jail_path="$(/usr/sbin/jls -j "${_jail}" path)" - if [ ! -x "${bastille_jail_path}/usr/local/bin/htop" ]; then - error_notify "htop not found on ${_jail}." - elif [ -x "${bastille_jail_path}/usr/local/bin/htop" ]; then - info "[${_jail}]:" - jexec -l "${_jail}" /usr/local/bin/htop - fi - echo -e "${COLOR_RESET}" -done +bastille_jail_path="$(/usr/sbin/jls -j "${TARGET}" path)" +if [ ! -x "${bastille_jail_path}/usr/local/bin/htop" ]; then + error_notify "htop not found on ${_jail}." +elif [ -x "${bastille_jail_path}/usr/local/bin/htop" ]; then + info "[${_jail}]:" + jexec -l "${_jail}" /usr/local/bin/htop +fi +echo -e "${COLOR_RESET}" From bff6b936f88ae5fb7827106ca1896265fa0f6549 Mon Sep 17 00:00:00 2001 From: tschettervictor <85497460+tschettervictor@users.noreply.github.com> Date: Mon, 16 Dec 2024 19:13:50 -0700 Subject: [PATCH 20/43] Update top.sh --- usr/local/share/bastille/top.sh | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/usr/local/share/bastille/top.sh b/usr/local/share/bastille/top.sh index d7567f8b..c87cf786 100644 --- a/usr/local/share/bastille/top.sh +++ b/usr/local/share/bastille/top.sh @@ -47,12 +47,11 @@ if [ $# -eq 0 ] || [ $# -gt 1 ]; then usage fi -set_target_single "${1}" +TARGET="${1}" +set_target_single "${TARGET}" bastille_root_check +check_target_is_running "${_jail}" -for _jail in "${JAILS}"; do - check_target_is_running "${_jail}" - info "[${_jail}]:" - jexec -l "${_jail}" /usr/bin/top - echo -e "${COLOR_RESET}" -done +info "[${_jail}]:" +jexec -l "${_jail}" /usr/bin/top +echo -e "${COLOR_RESET}" From 1bcd44cbb38f64cdee87cad56a034d1b8075bd05 Mon Sep 17 00:00:00 2001 From: tschettervictor <85497460+tschettervictor@users.noreply.github.com> Date: Mon, 16 Dec 2024 19:16:49 -0700 Subject: [PATCH 21/43] add set_target_single function to only allow single jail targetting --- usr/local/share/bastille/common.sh | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/usr/local/share/bastille/common.sh b/usr/local/share/bastille/common.sh index c8d1b621..da92ff5a 100644 --- a/usr/local/share/bastille/common.sh +++ b/usr/local/share/bastille/common.sh @@ -73,12 +73,9 @@ warn() { echo -e "${COLOR_YELLOW}$*${COLOR_RESET}" } -# This is where I am placing all new functions. check_target_exists() { - TARGET="${1}" - JAILS="" + local TARGET="${1}" if [ -d "${bastille_jailsdir}"/"${TARGET}" ]; then - JAILS="${TARGET}" return 0 else error_exit "Jail not found." @@ -95,6 +92,14 @@ check_target_is_running() { set_target() { if [ "${1}" = ALL ] || [ "${1}" = all ]; then target_all_jails + else + TARGET="${1}" + fi +} + +set_target_single() { + if [ "${1}" = ALL ] || [ "${1}" = all ]; then + error_exit "[all|ALL] not supported with this command." else TARGET="${1}" check_target_exists "${TARGET}" From ac30b36b57dc6ef9d37c9a8f694c6b2eb2281af1 Mon Sep 17 00:00:00 2001 From: tschettervictor <85497460+tschettervictor@users.noreply.github.com> Date: Mon, 16 Dec 2024 19:18:24 -0700 Subject: [PATCH 22/43] only set target with set_target_single --- usr/local/share/bastille/common.sh | 1 - 1 file changed, 1 deletion(-) diff --git a/usr/local/share/bastille/common.sh b/usr/local/share/bastille/common.sh index da92ff5a..94e95555 100644 --- a/usr/local/share/bastille/common.sh +++ b/usr/local/share/bastille/common.sh @@ -102,7 +102,6 @@ set_target_single() { error_exit "[all|ALL] not supported with this command." else TARGET="${1}" - check_target_exists "${TARGET}" fi } From 1b23c044de1be0f167b19b92aa22306773b7bb2e Mon Sep 17 00:00:00 2001 From: tschettervictor <85497460+tschettervictor@users.noreply.github.com> Date: Mon, 16 Dec 2024 19:19:20 -0700 Subject: [PATCH 23/43] Update top.sh --- usr/local/share/bastille/top.sh | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/usr/local/share/bastille/top.sh b/usr/local/share/bastille/top.sh index c87cf786..351a2dfe 100644 --- a/usr/local/share/bastille/top.sh +++ b/usr/local/share/bastille/top.sh @@ -48,10 +48,11 @@ if [ $# -eq 0 ] || [ $# -gt 1 ]; then fi TARGET="${1}" -set_target_single "${TARGET}" bastille_root_check -check_target_is_running "${_jail}" +set_target_single "${TARGET}" +check_target_exists "${TARGET}" +check_target_is_running "${TARGET}" -info "[${_jail}]:" -jexec -l "${_jail}" /usr/bin/top +info "[${TARGET}]:" +jexec -l "${TARGET}" /usr/bin/top echo -e "${COLOR_RESET}" From f86ad1ff891c343eb120324cd2617759cb06df6a Mon Sep 17 00:00:00 2001 From: tschettervictor <85497460+tschettervictor@users.noreply.github.com> Date: Mon, 16 Dec 2024 19:20:22 -0700 Subject: [PATCH 24/43] Update htop.sh --- usr/local/share/bastille/htop.sh | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/usr/local/share/bastille/htop.sh b/usr/local/share/bastille/htop.sh index 7b6084b6..c7e255a0 100644 --- a/usr/local/share/bastille/htop.sh +++ b/usr/local/share/bastille/htop.sh @@ -49,15 +49,16 @@ if [ $# -eq 0 ] || [ $# -gt 1 ]; then fi TARGET="${1}" -set_target_single "${TARGET}" bastille_root_check +set_target_single "${TARGET}" +check_target_exists "${TARGET}" check_target_is_running "${TARGET}" bastille_jail_path="$(/usr/sbin/jls -j "${TARGET}" path)" if [ ! -x "${bastille_jail_path}/usr/local/bin/htop" ]; then - error_notify "htop not found on ${_jail}." + error_notify "htop not found on ${TARGET}." elif [ -x "${bastille_jail_path}/usr/local/bin/htop" ]; then - info "[${_jail}]:" - jexec -l "${_jail}" /usr/local/bin/htop + info "[${TARGET}]:" + jexec -l "${TARGET}" /usr/local/bin/htop fi echo -e "${COLOR_RESET}" From 0d9a793ed9026febf56907e9c2a37401cda97e13 Mon Sep 17 00:00:00 2001 From: tschettervictor <85497460+tschettervictor@users.noreply.github.com> Date: Mon, 16 Dec 2024 19:21:17 -0700 Subject: [PATCH 25/43] Update top.sh --- usr/local/share/bastille/top.sh | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/usr/local/share/bastille/top.sh b/usr/local/share/bastille/top.sh index 351a2dfe..7cc4713a 100644 --- a/usr/local/share/bastille/top.sh +++ b/usr/local/share/bastille/top.sh @@ -53,6 +53,11 @@ set_target_single "${TARGET}" check_target_exists "${TARGET}" check_target_is_running "${TARGET}" -info "[${TARGET}]:" -jexec -l "${TARGET}" /usr/bin/top +bastille_jail_path="$(/usr/sbin/jls -j "${TARGET}" path)" +if [ ! -x "${bastille_jail_path}/usr/local/bin/top" ]; then + error_notify "top not found on ${TARGET}." +elif [ -x "${bastille_jail_path}/usr/local/bin/top" ]; then + info "[${TARGET}]:" + jexec -l "${TARGET}" /usr/local/bin/htop +fi echo -e "${COLOR_RESET}" From 4248ea9b0b2c560cb0e4bf3ae6d5f99353af946c Mon Sep 17 00:00:00 2001 From: tschettervictor <85497460+tschettervictor@users.noreply.github.com> Date: Mon, 16 Dec 2024 19:22:46 -0700 Subject: [PATCH 26/43] Update common.sh --- usr/local/share/bastille/common.sh | 2 ++ 1 file changed, 2 insertions(+) diff --git a/usr/local/share/bastille/common.sh b/usr/local/share/bastille/common.sh index 94e95555..6de5d62b 100644 --- a/usr/local/share/bastille/common.sh +++ b/usr/local/share/bastille/common.sh @@ -86,6 +86,8 @@ check_target_is_running() { TARGET="${1}" if [ ! "$(/usr/sbin/jls name | awk "/^${TARGET}$/")" ]; then error_exit "[${TARGET}]: Not started. See 'bastille start ${TARGET}'." + else + return 0 fi } From 4276e63de86c7cb1ef357e03ca3e1bbf4af7142b Mon Sep 17 00:00:00 2001 From: tschettervictor <85497460+tschettervictor@users.noreply.github.com> Date: Mon, 16 Dec 2024 19:24:35 -0700 Subject: [PATCH 27/43] Update htop.sh --- usr/local/share/bastille/htop.sh | 1 - 1 file changed, 1 deletion(-) diff --git a/usr/local/share/bastille/htop.sh b/usr/local/share/bastille/htop.sh index c7e255a0..fb0ece2a 100644 --- a/usr/local/share/bastille/htop.sh +++ b/usr/local/share/bastille/htop.sh @@ -1,4 +1,3 @@ - #!/bin/sh # # Copyright (c) 2018-2024, Christer Edwards From 9da73d6cf090fe624c0570425c055ef4241e2084 Mon Sep 17 00:00:00 2001 From: tschettervictor <85497460+tschettervictor@users.noreply.github.com> Date: Mon, 16 Dec 2024 19:28:50 -0700 Subject: [PATCH 28/43] set TARGET to local only for some functions --- usr/local/share/bastille/common.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/usr/local/share/bastille/common.sh b/usr/local/share/bastille/common.sh index 6de5d62b..22531c85 100644 --- a/usr/local/share/bastille/common.sh +++ b/usr/local/share/bastille/common.sh @@ -83,7 +83,7 @@ check_target_exists() { } check_target_is_running() { - TARGET="${1}" + local TARGET="${1}" if [ ! "$(/usr/sbin/jls name | awk "/^${TARGET}$/")" ]; then error_exit "[${TARGET}]: Not started. See 'bastille start ${TARGET}'." else From cbcd3881b10007b020ec57fe2392618088f56a09 Mon Sep 17 00:00:00 2001 From: tschettervictor <85497460+tschettervictor@users.noreply.github.com> Date: Thu, 19 Dec 2024 16:55:01 -0700 Subject: [PATCH 29/43] organize functions in alphabetical order --- usr/local/share/bastille/common.sh | 128 ++++++++++++++++++----------- 1 file changed, 80 insertions(+), 48 deletions(-) diff --git a/usr/local/share/bastille/common.sh b/usr/local/share/bastille/common.sh index 22531c85..ebe66325 100644 --- a/usr/local/share/bastille/common.sh +++ b/usr/local/share/bastille/common.sh @@ -54,7 +54,7 @@ if [ -z "${NO_COLOR}" ] && [ -t 1 ]; then enable_color fi -# Notify message on error, but do not exit +# Error/Info functions error_notify() { echo -e "${COLOR_RED}$*${COLOR_RESET}" 1>&2 } @@ -73,49 +73,56 @@ warn() { echo -e "${COLOR_YELLOW}$*${COLOR_RESET}" } +# Main functions check_target_exists() { - local TARGET="${1}" - if [ -d "${bastille_jailsdir}"/"${TARGET}" ]; then - return 0 + local _TARGET="${1}" + if [ ! -d "${bastille_jailsdir}"/"${_TARGET}" ]; then + error_notify "Jail not found \"${_TARGET}\"" + return 1 else - error_exit "Jail not found." + return 0 fi } check_target_is_running() { - local TARGET="${1}" - if [ ! "$(/usr/sbin/jls name | awk "/^${TARGET}$/")" ]; then - error_exit "[${TARGET}]: Not started. See 'bastille start ${TARGET}'." + local _TARGET="${1}" + if [ ! "$(/usr/sbin/jls name | awk "/^${_TARGET}$/")" ]; then + error_notify "[${_TARGET}]: Not started. See 'bastille start ${_TARGET}'." + return 1 else return 0 fi } -set_target() { - if [ "${1}" = ALL ] || [ "${1}" = all ]; then - target_all_jails +check_target_is_stopped() { + local _TARGET="${1}" + if [ "$(/usr/sbin/jls name | awk "/^${_TARGET}$/")" ]; then + error_notify "${_TARGET} is running. See 'bastille stop ${_TARGET}'." + return 1 else - TARGET="${1}" + return 0 fi } -set_target_single() { - if [ "${1}" = ALL ] || [ "${1}" = all ]; then - error_exit "[all|ALL] not supported with this command." - else - TARGET="${1}" - fi -} - -target_all_jails() { - _JAILS=$(/usr/sbin/jls name) - JAILS="" - for _jail in ${_JAILS}; do - _JAILPATH=$(/usr/sbin/jls -j "${_jail}" path) - if [ -z ${_JAILPATH##${bastille_jailsdir}*} ]; then - JAILS="${JAILS} ${_jail}" - fi - done +checkyesno() { + ## copied from /etc/rc.subr -- cedwards (20231125) + ## issue #368 (lowercase values should be parsed) + ## now used for all bastille_zfs_enable=YES|NO tests + ## example: if checkyesno bastille_zfs_enable; then ... + ## returns 0 for enabled; returns 1 for disabled + eval _value=\$${1} + case $_value in + [Yy][Ee][Ss]|[Tt][Rr][Uu][Ee]|[Oo][Nn]|1) + return 0 + ;; + [Nn][Oo]|[Ff][Aa][Ll][Ss][Ee]|[Oo][Ff][Ff]|0) + return 1 + ;; + *) + warn "\$${1} is not set properly - see rc.conf(5)." + return 1 + ;; + esac } generate_vnet_jail_netblock() { @@ -166,23 +173,48 @@ EOF fi } -checkyesno() { - ## copied from /etc/rc.subr -- cedwards (20231125) - ## issue #368 (lowercase values should be parsed) - ## now used for all bastille_zfs_enable=YES|NO tests - ## example: if checkyesno bastille_zfs_enable; then ... - ## returns 0 for enabled; returns 1 for disabled - eval _value=\$${1} - case $_value in - [Yy][Ee][Ss]|[Tt][Rr][Uu][Ee]|[Oo][Nn]|1) - return 0 - ;; - [Nn][Oo]|[Ff][Aa][Ll][Ss][Ee]|[Oo][Ff][Ff]|0) - return 1 - ;; - *) - warn "\$${1} is not set properly - see rc.conf(5)." - return 1 - ;; - esac +set_target() { + if [ "${1}" = ALL ] || [ "${1}" = all ]; then + target_all_jails + else + TARGET="${1}" + fi +} + +set_target() { + local _TARGET="${1}" + if [ "${_TARGET}" = ALL ] || [ "${_TARGET}" = all ]; then + target_all_jails + else + check_target_exists "${_TARGET}" + JAILS="${_TARGET}" + TARGET="${_TARGET}" + export JAILS + export TARGET + fi +} + +set_target_single() { + local _TARGET="${1}" + if [ "${_TARGET}" = ALL ] || [ "${_TARGET}" = all ]; then + error_notify "[all|ALL] not supported with this command." + return 1 + else + check_target_exists "${_TARGET}" + JAILS="${_TARGET}" + TARGET="${_TARGET}" + export JAILS + export TARGET + fi +} + +target_all_jails() { + local _JAILS="$(bastille list jails)" + JAILS="" + for _jail in ${_JAILS}; do + if [ -d "${bastille_jailsdir}/${_jail}" ]; then + JAILS="${JAILS} ${_jail}" + fi + done + export JAILS } From 76e6113962a791e1f9295cde1e0bf2c4a1410d85 Mon Sep 17 00:00:00 2001 From: tschettervictor <85497460+tschettervictor@users.noreply.github.com> Date: Thu, 19 Dec 2024 16:57:36 -0700 Subject: [PATCH 30/43] error handling --- usr/local/share/bastille/htop.sh | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/usr/local/share/bastille/htop.sh b/usr/local/share/bastille/htop.sh index fb0ece2a..15ff7584 100644 --- a/usr/local/share/bastille/htop.sh +++ b/usr/local/share/bastille/htop.sh @@ -42,16 +42,15 @@ case "$1" in ;; esac -# Accept only one argument. -if [ $# -eq 0 ] || [ $# -gt 1 ]; then +if [ $# -ne 1 ]; then usage fi TARGET="${1}" + bastille_root_check set_target_single "${TARGET}" -check_target_exists "${TARGET}" -check_target_is_running "${TARGET}" +check_target_is_running "${TARGET}" || exit 0 bastille_jail_path="$(/usr/sbin/jls -j "${TARGET}" path)" if [ ! -x "${bastille_jail_path}/usr/local/bin/htop" ]; then From 5b68630df94601cb1ebac1318822069a89f4d30e Mon Sep 17 00:00:00 2001 From: tschettervictor <85497460+tschettervictor@users.noreply.github.com> Date: Thu, 19 Dec 2024 16:58:35 -0700 Subject: [PATCH 31/43] remove 0 --- usr/local/share/bastille/htop.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/usr/local/share/bastille/htop.sh b/usr/local/share/bastille/htop.sh index 15ff7584..8b79906b 100644 --- a/usr/local/share/bastille/htop.sh +++ b/usr/local/share/bastille/htop.sh @@ -50,7 +50,7 @@ TARGET="${1}" bastille_root_check set_target_single "${TARGET}" -check_target_is_running "${TARGET}" || exit 0 +check_target_is_running "${TARGET}" || exit bastille_jail_path="$(/usr/sbin/jls -j "${TARGET}" path)" if [ ! -x "${bastille_jail_path}/usr/local/bin/htop" ]; then From 200321cf9b01aa057182c27005542ce33e73ca38 Mon Sep 17 00:00:00 2001 From: tschettervictor <85497460+tschettervictor@users.noreply.github.com> Date: Thu, 19 Dec 2024 16:59:41 -0700 Subject: [PATCH 32/43] error handling --- usr/local/share/bastille/top.sh | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/usr/local/share/bastille/top.sh b/usr/local/share/bastille/top.sh index 7cc4713a..34f7fa71 100644 --- a/usr/local/share/bastille/top.sh +++ b/usr/local/share/bastille/top.sh @@ -42,16 +42,15 @@ case "${1}" in ;; esac -# Accept only one argument -if [ $# -eq 0 ] || [ $# -gt 1 ]; then +if [ $# -ne 1 ]; then usage fi TARGET="${1}" + bastille_root_check set_target_single "${TARGET}" -check_target_exists "${TARGET}" -check_target_is_running "${TARGET}" +check_target_is_running "${TARGET}" || exit bastille_jail_path="$(/usr/sbin/jls -j "${TARGET}" path)" if [ ! -x "${bastille_jail_path}/usr/local/bin/top" ]; then From d458ed8ee16b768a323eab96c554d24d141c60ca Mon Sep 17 00:00:00 2001 From: tschettervictor <85497460+tschettervictor@users.noreply.github.com> Date: Fri, 20 Dec 2024 22:39:53 -0700 Subject: [PATCH 33/43] Update common.sh --- usr/local/share/bastille/common.sh | 15 +++------------ 1 file changed, 3 insertions(+), 12 deletions(-) diff --git a/usr/local/share/bastille/common.sh b/usr/local/share/bastille/common.sh index ebe66325..f6eaedb0 100644 --- a/usr/local/share/bastille/common.sh +++ b/usr/local/share/bastille/common.sh @@ -173,20 +173,12 @@ EOF fi } -set_target() { - if [ "${1}" = ALL ] || [ "${1}" = all ]; then - target_all_jails - else - TARGET="${1}" - fi -} - set_target() { local _TARGET="${1}" if [ "${_TARGET}" = ALL ] || [ "${_TARGET}" = all ]; then target_all_jails else - check_target_exists "${_TARGET}" + check_target_exists "${_TARGET}" || exit JAILS="${_TARGET}" TARGET="${_TARGET}" export JAILS @@ -197,10 +189,9 @@ set_target() { set_target_single() { local _TARGET="${1}" if [ "${_TARGET}" = ALL ] || [ "${_TARGET}" = all ]; then - error_notify "[all|ALL] not supported with this command." - return 1 + error_exit "[all|ALL] not supported with this command." else - check_target_exists "${_TARGET}" + check_target_exists "${_TARGET}" || exit JAILS="${_TARGET}" TARGET="${_TARGET}" export JAILS From 4a93f61c2aea370a940f34b706275ef1cffb4895 Mon Sep 17 00:00:00 2001 From: tschettervictor <85497460+tschettervictor@users.noreply.github.com> Date: Fri, 20 Dec 2024 22:41:00 -0700 Subject: [PATCH 34/43] Update htop.sh --- usr/local/share/bastille/htop.sh | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/usr/local/share/bastille/htop.sh b/usr/local/share/bastille/htop.sh index 8b79906b..d9741d15 100644 --- a/usr/local/share/bastille/htop.sh +++ b/usr/local/share/bastille/htop.sh @@ -36,7 +36,7 @@ usage() { } # Handle special-case commands first. -case "$1" in +case "${1}" in help|-h|--help) usage ;; @@ -52,11 +52,11 @@ bastille_root_check set_target_single "${TARGET}" check_target_is_running "${TARGET}" || exit -bastille_jail_path="$(/usr/sbin/jls -j "${TARGET}" path)" +bastille_jail_path=$(/usr/sbin/jls -j "${_jail}" path) if [ ! -x "${bastille_jail_path}/usr/local/bin/htop" ]; then - error_notify "htop not found on ${TARGET}." + error_notify "htop not found on ${_jail}." elif [ -x "${bastille_jail_path}/usr/local/bin/htop" ]; then - info "[${TARGET}]:" - jexec -l "${TARGET}" /usr/local/bin/htop + info "[${_jail}]:" + jexec -l ${_jail} /usr/local/bin/htop fi echo -e "${COLOR_RESET}" From 5913fcc6890ad9291746f8a4fbf2843fe9ac4ef9 Mon Sep 17 00:00:00 2001 From: tschettervictor <85497460+tschettervictor@users.noreply.github.com> Date: Fri, 20 Dec 2024 22:41:18 -0700 Subject: [PATCH 35/43] Update top.sh --- usr/local/share/bastille/top.sh | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/usr/local/share/bastille/top.sh b/usr/local/share/bastille/top.sh index 34f7fa71..f7d97ee6 100644 --- a/usr/local/share/bastille/top.sh +++ b/usr/local/share/bastille/top.sh @@ -52,11 +52,7 @@ bastille_root_check set_target_single "${TARGET}" check_target_is_running "${TARGET}" || exit -bastille_jail_path="$(/usr/sbin/jls -j "${TARGET}" path)" -if [ ! -x "${bastille_jail_path}/usr/local/bin/top" ]; then - error_notify "top not found on ${TARGET}." -elif [ -x "${bastille_jail_path}/usr/local/bin/top" ]; then - info "[${TARGET}]:" - jexec -l "${TARGET}" /usr/local/bin/htop -fi + +info "[${TARGET}]:" +jexec -l "${TARGET}" /usr/bin/top echo -e "${COLOR_RESET}" From 0413a94896f592cee8ad66cfab1f2e3cfdb5c2e5 Mon Sep 17 00:00:00 2001 From: tschettervictor <85497460+tschettervictor@users.noreply.github.com> Date: Sat, 21 Dec 2024 21:45:27 -0700 Subject: [PATCH 36/43] spacing --- usr/local/share/bastille/top.sh | 1 - 1 file changed, 1 deletion(-) diff --git a/usr/local/share/bastille/top.sh b/usr/local/share/bastille/top.sh index f7d97ee6..9a8a6ba2 100644 --- a/usr/local/share/bastille/top.sh +++ b/usr/local/share/bastille/top.sh @@ -52,7 +52,6 @@ bastille_root_check set_target_single "${TARGET}" check_target_is_running "${TARGET}" || exit - info "[${TARGET}]:" jexec -l "${TARGET}" /usr/bin/top echo -e "${COLOR_RESET}" From d293db2c54dd2f0cb1542f738ea17cb6e5b87c05 Mon Sep 17 00:00:00 2001 From: tschettervictor <85497460+tschettervictor@users.noreply.github.com> Date: Tue, 24 Dec 2024 07:39:26 -0700 Subject: [PATCH 37/43] move help into options block --- usr/local/share/bastille/top.sh | 42 ++++++++++++++++++++++++++------- 1 file changed, 33 insertions(+), 9 deletions(-) diff --git a/usr/local/share/bastille/top.sh b/usr/local/share/bastille/top.sh index 9a8a6ba2..d787ead2 100644 --- a/usr/local/share/bastille/top.sh +++ b/usr/local/share/bastille/top.sh @@ -32,17 +32,37 @@ . /usr/local/etc/bastille/bastille.conf usage() { - error_exit "Usage: bastille top TARGET" + error_exit "Usage: bastille top [options(s)] TARGET" + cat << EOF + Options: + + -f | --force -- Start the jail if it is stopped. + +EOF + exit 1 } -# Handle special-case commands first. -case "${1}" in - help|-h|--help) - usage - ;; -esac +# Handle options. +FORCE=0 +while [ "$#" -gt 0 ]; do + case "${1}" in + -h|--help|help) + usage + ;; + -f|--force) + FORCE=1 + shift + ;; + -*) + error_exit "Unknown option: \"${1}\"" + ;; + *) + break + ;; + esac +done -if [ $# -ne 1 ]; then +if [ "$#" -ne 1 ]; then usage fi @@ -50,7 +70,11 @@ TARGET="${1}" bastille_root_check set_target_single "${TARGET}" -check_target_is_running "${TARGET}" || exit +check_target_is_running "${TARGET}" || if [ "${FORCE}" -eq 1 ]; then + bastille start "${TARGET}" +else + exit +fi info "[${TARGET}]:" jexec -l "${TARGET}" /usr/bin/top From 54bf9d6d53d0df695d61f31e46a5fb3eb709fc76 Mon Sep 17 00:00:00 2001 From: tschettervictor <85497460+tschettervictor@users.noreply.github.com> Date: Tue, 24 Dec 2024 07:40:02 -0700 Subject: [PATCH 38/43] move help into options block --- usr/local/share/bastille/htop.sh | 55 ++++++++++++++++++++++---------- 1 file changed, 39 insertions(+), 16 deletions(-) diff --git a/usr/local/share/bastille/htop.sh b/usr/local/share/bastille/htop.sh index d9741d15..c706cf17 100644 --- a/usr/local/share/bastille/htop.sh +++ b/usr/local/share/bastille/htop.sh @@ -32,15 +32,35 @@ . /usr/local/etc/bastille/bastille.conf usage() { - error_exit "Usage: bastille htop TARGET" + error_exit "Usage: bastille htop [option(s)] TARGET" + cat << EOF + Options: + + -f | --force -- Start the jail if it is stopped. + +EOF + exit 1 } -# Handle special-case commands first. -case "${1}" in - help|-h|--help) - usage - ;; -esac +# Handle options. +FORCE=0 +while [ "$#" -gt 0 ]; do + case "${1}" in + -h|--help|help) + usage + ;; + -f|--force) + FORCE=1 + shift + ;; + -*) + error_exit "Unknown option: \"${1}\"" + ;; + *) + break + ;; + esac +done if [ $# -ne 1 ]; then usage @@ -50,13 +70,16 @@ TARGET="${1}" bastille_root_check set_target_single "${TARGET}" -check_target_is_running "${TARGET}" || exit - -bastille_jail_path=$(/usr/sbin/jls -j "${_jail}" path) -if [ ! -x "${bastille_jail_path}/usr/local/bin/htop" ]; then - error_notify "htop not found on ${_jail}." -elif [ -x "${bastille_jail_path}/usr/local/bin/htop" ]; then - info "[${_jail}]:" - jexec -l ${_jail} /usr/local/bin/htop +check_target_is_running "${TARGET}" || if [ "${FORCE}" -eq 1 ]; then + bastille start "${TARGET}" +else + exit +fi + +bastille_jail_path="${bastille_jailsdir}/${TARGET}/root" +if [ ! -x "${bastille_jail_path}/usr/local/bin/htop" ]; then + error_notify "htop not found on ${TARGET}." +elif [ -x "${bastille_jail_path}/usr/local/bin/htop" ]; then + info "[${TARGET}]:" + jexec -l ${TARGET} /usr/local/bin/htop fi -echo -e "${COLOR_RESET}" From db0f5c5e09997766b67ab9643ebac3f0ac33a277 Mon Sep 17 00:00:00 2001 From: tschettervictor <85497460+tschettervictor@users.noreply.github.com> Date: Fri, 27 Dec 2024 08:16:38 -0700 Subject: [PATCH 39/43] minor tweak --- usr/local/share/bastille/common.sh | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/usr/local/share/bastille/common.sh b/usr/local/share/bastille/common.sh index f6eaedb0..b6001610 100644 --- a/usr/local/share/bastille/common.sh +++ b/usr/local/share/bastille/common.sh @@ -178,7 +178,7 @@ set_target() { if [ "${_TARGET}" = ALL ] || [ "${_TARGET}" = all ]; then target_all_jails else - check_target_exists "${_TARGET}" || exit + check_target_exists "${_TARGET}" || error_exit "Jail not found \"${_TARGET}\"" JAILS="${_TARGET}" TARGET="${_TARGET}" export JAILS @@ -191,7 +191,7 @@ set_target_single() { if [ "${_TARGET}" = ALL ] || [ "${_TARGET}" = all ]; then error_exit "[all|ALL] not supported with this command." else - check_target_exists "${_TARGET}" || exit + check_target_exists "${_TARGET}" || error_exit "Jail not found \"${_TARGET}\"" JAILS="${_TARGET}" TARGET="${_TARGET}" export JAILS @@ -209,3 +209,4 @@ target_all_jails() { done export JAILS } + From 82a8d5479b2d9be36c94ecf3e1c4e94f86250d68 Mon Sep 17 00:00:00 2001 From: tschettervictor <85497460+tschettervictor@users.noreply.github.com> Date: Fri, 27 Dec 2024 08:17:49 -0700 Subject: [PATCH 40/43] minor tweak --- usr/local/share/bastille/htop.sh | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/usr/local/share/bastille/htop.sh b/usr/local/share/bastille/htop.sh index c706cf17..10795da1 100644 --- a/usr/local/share/bastille/htop.sh +++ b/usr/local/share/bastille/htop.sh @@ -62,7 +62,7 @@ while [ "$#" -gt 0 ]; do esac done -if [ $# -ne 1 ]; then +if [ "$#" -ne 1 ]; then usage fi @@ -70,16 +70,18 @@ TARGET="${1}" bastille_root_check set_target_single "${TARGET}" + +info "[${TARGET}]:" check_target_is_running "${TARGET}" || if [ "${FORCE}" -eq 1 ]; then bastille start "${TARGET}" -else - exit +else + error_notify "Jail is not running." + error_continue "Use [-f|--force] to force start the jail." fi bastille_jail_path="${bastille_jailsdir}/${TARGET}/root" if [ ! -x "${bastille_jail_path}/usr/local/bin/htop" ]; then error_notify "htop not found on ${TARGET}." elif [ -x "${bastille_jail_path}/usr/local/bin/htop" ]; then - info "[${TARGET}]:" jexec -l ${TARGET} /usr/local/bin/htop fi From 9b354c1a2fbdaac7481a34a0809f9a3a87910600 Mon Sep 17 00:00:00 2001 From: tschettervictor <85497460+tschettervictor@users.noreply.github.com> Date: Fri, 27 Dec 2024 08:18:33 -0700 Subject: [PATCH 41/43] minor tweak --- usr/local/share/bastille/top.sh | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/usr/local/share/bastille/top.sh b/usr/local/share/bastille/top.sh index d787ead2..669c1164 100644 --- a/usr/local/share/bastille/top.sh +++ b/usr/local/share/bastille/top.sh @@ -32,7 +32,7 @@ . /usr/local/etc/bastille/bastille.conf usage() { - error_exit "Usage: bastille top [options(s)] TARGET" + error_notify "Usage: bastille top [options(s)] TARGET" cat << EOF Options: @@ -70,12 +70,12 @@ TARGET="${1}" bastille_root_check set_target_single "${TARGET}" -check_target_is_running "${TARGET}" || if [ "${FORCE}" -eq 1 ]; then - bastille start "${TARGET}" -else - exit -fi info "[${TARGET}]:" +check_target_is_running "${TARGET}" || if [ "${FORCE}" -eq 1 ]; then + bastille start "${TARGET}" +else + error_notify "Jail is not running." + error_continue "Use [-f|--force] to force start the jail." +fi jexec -l "${TARGET}" /usr/bin/top -echo -e "${COLOR_RESET}" From 4bc76d5064e81b785ae2a69ba23dd994fbc89c67 Mon Sep 17 00:00:00 2001 From: tschettervictor <85497460+tschettervictor@users.noreply.github.com> Date: Tue, 31 Dec 2024 15:00:12 -0700 Subject: [PATCH 42/43] fix brace --- usr/local/share/bastille/common.sh | 1 + 1 file changed, 1 insertion(+) diff --git a/usr/local/share/bastille/common.sh b/usr/local/share/bastille/common.sh index 2d6038f8..006f4a1d 100644 --- a/usr/local/share/bastille/common.sh +++ b/usr/local/share/bastille/common.sh @@ -205,6 +205,7 @@ target_all_jails() { fi done export JAILS +} checkyesno() { ## copied from /etc/rc.subr -- cedwards (20231125) From fedc7aa60c58a35a7c99d792a1d2b6997d26684e Mon Sep 17 00:00:00 2001 From: tschettervictor <85497460+tschettervictor@users.noreply.github.com> Date: Tue, 31 Dec 2024 15:27:45 -0700 Subject: [PATCH 43/43] Remove message on return 1 --- usr/local/share/bastille/common.sh | 2 -- 1 file changed, 2 deletions(-) diff --git a/usr/local/share/bastille/common.sh b/usr/local/share/bastille/common.sh index 006f4a1d..da03dc3f 100644 --- a/usr/local/share/bastille/common.sh +++ b/usr/local/share/bastille/common.sh @@ -92,7 +92,6 @@ check_target_exists() { check_target_is_running() { local _TARGET="${1}" if [ ! "$(/usr/sbin/jls name | awk "/^${_TARGET}$/")" ]; then - error_notify "[${_TARGET}]: Not started. See 'bastille start ${_TARGET}'." return 1 else return 0 @@ -102,7 +101,6 @@ check_target_is_running() { check_target_is_stopped() { local _TARGET="${1}" if [ "$(/usr/sbin/jls name | awk "/^${_TARGET}$/")" ]; then - error_notify "${_TARGET} is running. See 'bastille stop ${_TARGET}'." return 1 else return 0