From 41000b13259e205652919ae9765df2e27231d024 Mon Sep 17 00:00:00 2001 From: tschettervictor <85497460+tschettervictor@users.noreply.github.com> Date: Mon, 25 Nov 2024 10:08:47 -0700 Subject: [PATCH 01/10] Add autocomplete function to main bastille executable This will allow a user to simple begin typing a jail name. If bastille finds more than one jail starting with what is typed, it will error. If it only find one jail, it will set that jail as the $TARGET --- usr/local/bin/bastille | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/usr/local/bin/bastille b/usr/local/bin/bastille index a6f6967d..5f0e7844 100755 --- a/usr/local/bin/bastille +++ b/usr/local/bin/bastille @@ -138,6 +138,16 @@ check_target_is_running() { fi } +jail_autocomplete() { + AUTOTARGET=$( ls "${bastille_jailsdir}" | grep "${TARGET}" ) + if [ $( echo "${AUTOTARGET}" | wc -l ) -eq 1 ]; then + TARGET="${AUTOTARGET}" + return 0 + else + error_exit "Multiple jails found for $TARGET:\n$AUTOTARGET" + fi +} + # Handle special-case commands first. case "${CMD}" in version|-v|--version) @@ -187,6 +197,7 @@ clone|config|cmd|console|convert|cp|edit|htop|limits|mount|pkg|rcp|rename|servic # checks. The command will simply convert a template from hooks to a Bastillefile. -- cwells : else + jail_autocomplete JAILS="${TARGET}" # Ensure the target exists. -- cwells From a4d78e9b0d3dc0aaf86a6602f23a4fba1580da3d Mon Sep 17 00:00:00 2001 From: tschettervictor <85497460+tschettervictor@users.noreply.github.com> Date: Mon, 25 Nov 2024 10:51:37 -0700 Subject: [PATCH 02/10] Update bastille - move jail_autocomplete function to more llogical place --- usr/local/bin/bastille | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/usr/local/bin/bastille b/usr/local/bin/bastille index 5f0e7844..576dee2b 100755 --- a/usr/local/bin/bastille +++ b/usr/local/bin/bastille @@ -188,6 +188,7 @@ clone|config|cmd|console|convert|cp|edit|htop|limits|mount|pkg|rcp|rename|servic if [ "${TARGET}" = 'ALL' ]; then target_all_jails else + jail_autocomplete JAILS="${TARGET}" check_target_is_running fi @@ -197,7 +198,6 @@ clone|config|cmd|console|convert|cp|edit|htop|limits|mount|pkg|rcp|rename|servic # checks. The command will simply convert a template from hooks to a Bastillefile. -- cwells : else - jail_autocomplete JAILS="${TARGET}" # Ensure the target exists. -- cwells From 89b23977e8c2b6c15d90c9f7ff847b42b8568075 Mon Sep 17 00:00:00 2001 From: tschettervictor <85497460+tschettervictor@users.noreply.github.com> Date: Mon, 25 Nov 2024 11:18:03 -0700 Subject: [PATCH 03/10] Update bastille - move jail_autocomplet to sensible position + remove function (will be placed in common.sh) --- usr/local/bin/bastille | 16 ++++------------ 1 file changed, 4 insertions(+), 12 deletions(-) diff --git a/usr/local/bin/bastille b/usr/local/bin/bastille index 576dee2b..beaa35ec 100755 --- a/usr/local/bin/bastille +++ b/usr/local/bin/bastille @@ -138,16 +138,6 @@ check_target_is_running() { fi } -jail_autocomplete() { - AUTOTARGET=$( ls "${bastille_jailsdir}" | grep "${TARGET}" ) - if [ $( echo "${AUTOTARGET}" | wc -l ) -eq 1 ]; then - TARGET="${AUTOTARGET}" - return 0 - else - error_exit "Multiple jails found for $TARGET:\n$AUTOTARGET" - fi -} - # Handle special-case commands first. case "${CMD}" in version|-v|--version) @@ -167,7 +157,10 @@ clone|config|cmd|console|convert|cp|edit|htop|limits|mount|pkg|rcp|rename|servic elif [ "${1}" != 'help' ] && [ "${1}" != '-h' ] && [ "${1}" != '--help' ]; then TARGET="${1}" shift - + # If TARGET is not ALL, attempt to autocomplet given jail name + if [ "${TARGET}" != ALL ]; then + jail_autocomplete + fi # This is needed to handle the special case of 'bastille rcp' and 'bastille cp' with the '-q' or '--quiet' # option specified before the TARGET. Also seems the cp and rcp commands does not support ALL as a target, so # that's why is handled here. Maybe this behaviour needs an improvement later. -- yaazkal @@ -188,7 +181,6 @@ clone|config|cmd|console|convert|cp|edit|htop|limits|mount|pkg|rcp|rename|servic if [ "${TARGET}" = 'ALL' ]; then target_all_jails else - jail_autocomplete JAILS="${TARGET}" check_target_is_running fi From c6a43f028657258d209647164c88a49a48605a68 Mon Sep 17 00:00:00 2001 From: tschettervictor <85497460+tschettervictor@users.noreply.github.com> Date: Mon, 25 Nov 2024 11:18:43 -0700 Subject: [PATCH 04/10] Update common.sh - add autocomplete jail name function --- usr/local/share/bastille/common.sh | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/usr/local/share/bastille/common.sh b/usr/local/share/bastille/common.sh index aef59e38..3223fbfc 100644 --- a/usr/local/share/bastille/common.sh +++ b/usr/local/share/bastille/common.sh @@ -70,6 +70,16 @@ warn() { echo -e "${COLOR_YELLOW}$*${COLOR_RESET}" } +jail_autocomplete() { + AUTOTARGET=$( ls "${bastille_jailsdir}" | grep "${TARGET}" ) + if [ $( echo "${AUTOTARGET}" | wc -l ) -eq 1 ]; then + TARGET="${AUTOTARGET}" + return 0 + else + error_exit "Multiple jails found for $TARGET:\n$AUTOTARGET" + fi +} + generate_vnet_jail_netblock() { local jail_name="$1" local use_unique_bridge="$2" From 64d399a1c2899513bfaaedf55572d5da39310540 Mon Sep 17 00:00:00 2001 From: tschettervictor <85497460+tschettervictor@users.noreply.github.com> Date: Mon, 25 Nov 2024 11:30:39 -0700 Subject: [PATCH 05/10] Update start.sh - add jail autocomplete function --- usr/local/share/bastille/start.sh | 1 + 1 file changed, 1 insertion(+) diff --git a/usr/local/share/bastille/start.sh b/usr/local/share/bastille/start.sh index f9e5a180..b7ea64d4 100644 --- a/usr/local/share/bastille/start.sh +++ b/usr/local/share/bastille/start.sh @@ -55,6 +55,7 @@ if [ "${TARGET}" = 'ALL' ]; then JAILS=$(bastille list jails) fi if [ "${TARGET}" != 'ALL' ]; then + jail_autocomplete JAILS=$(bastille list jails | awk "/^${TARGET}$/") ## check if exist if [ ! -d "${bastille_jailsdir}/${TARGET}" ]; then From ddd8724e6fb7fabc454f705bc1e1d3311f0e8918 Mon Sep 17 00:00:00 2001 From: tschettervictor <85497460+tschettervictor@users.noreply.github.com> Date: Mon, 25 Nov 2024 11:33:08 -0700 Subject: [PATCH 06/10] Update update.sh - add autocomplete function --- usr/local/share/bastille/update.sh | 3 +++ 1 file changed, 3 insertions(+) diff --git a/usr/local/share/bastille/update.sh b/usr/local/share/bastille/update.sh index 3bd033f8..17675495 100644 --- a/usr/local/share/bastille/update.sh +++ b/usr/local/share/bastille/update.sh @@ -82,6 +82,9 @@ arch_check() { fi } +# Attempt to autocomplete jail name +jail_autocomplete + jail_check() { # Check if the jail is thick and is running if [ ! "$(/usr/sbin/jls name | awk "/^${TARGET}$/")" ]; then From f7e93238b3b8a1c6503199d56fecfdd55692515f Mon Sep 17 00:00:00 2001 From: tschettervictor <85497460+tschettervictor@users.noreply.github.com> Date: Mon, 25 Nov 2024 11:34:08 -0700 Subject: [PATCH 07/10] Update upgrade.sh - add autocomplete function --- usr/local/share/bastille/upgrade.sh | 3 +++ 1 file changed, 3 insertions(+) diff --git a/usr/local/share/bastille/upgrade.sh b/usr/local/share/bastille/upgrade.sh index 39422582..d99714ee 100644 --- a/usr/local/share/bastille/upgrade.sh +++ b/usr/local/share/bastille/upgrade.sh @@ -76,6 +76,9 @@ case "${OPTION}" in ;; esac +# Attempt to autocomplete jail name +jail_autocomplete + jail_check() { # Check if the jail is thick and is running if [ ! "$(/usr/sbin/jls name | awk "/^${TARGET}$/")" ]; then From 33a4012bcc87d9affa31ea39007b688fbef81313 Mon Sep 17 00:00:00 2001 From: tschettervictor <85497460+tschettervictor@users.noreply.github.com> Date: Mon, 25 Nov 2024 11:36:10 -0700 Subject: [PATCH 08/10] Update export.sh - add autocomplete function --- usr/local/share/bastille/export.sh | 3 +++ 1 file changed, 3 insertions(+) diff --git a/usr/local/share/bastille/export.sh b/usr/local/share/bastille/export.sh index 3c14e962..ab04a739 100644 --- a/usr/local/share/bastille/export.sh +++ b/usr/local/share/bastille/export.sh @@ -73,6 +73,9 @@ fi bastille_root_check +# Attempt to autocomplete jail name +jail_autocomplete + zfs_enable_check() { # Temporarily disable ZFS so we can create a standard backup archive if checkyesno bastille_zfs_enable; then From 9ec28606ac417ecd23375c70f85796e55aea7dad Mon Sep 17 00:00:00 2001 From: tschettervictor <85497460+tschettervictor@users.noreply.github.com> Date: Mon, 25 Nov 2024 11:37:14 -0700 Subject: [PATCH 09/10] Update destroy.sh - add autocomplete function --- usr/local/share/bastille/destroy.sh | 1 + 1 file changed, 1 insertion(+) diff --git a/usr/local/share/bastille/destroy.sh b/usr/local/share/bastille/destroy.sh index 9d9e9996..1545e5aa 100644 --- a/usr/local/share/bastille/destroy.sh +++ b/usr/local/share/bastille/destroy.sh @@ -211,6 +211,7 @@ if [ $# -gt 1 ] || [ $# -lt 1 ]; then fi bastille_root_check +jail_autocomplete ## check what should we clean case "${TARGET}" in From 01fa6145eaef306ab80abe8f94a2154909067b2d Mon Sep 17 00:00:00 2001 From: tschettervictor <85497460+tschettervictor@users.noreply.github.com> Date: Mon, 25 Nov 2024 11:37:50 -0700 Subject: [PATCH 10/10] Update export.sh --- usr/local/share/bastille/export.sh | 2 -- 1 file changed, 2 deletions(-) diff --git a/usr/local/share/bastille/export.sh b/usr/local/share/bastille/export.sh index ab04a739..76f4b279 100644 --- a/usr/local/share/bastille/export.sh +++ b/usr/local/share/bastille/export.sh @@ -72,8 +72,6 @@ if [ $# -gt 5 ] || [ $# -lt 1 ]; then fi bastille_root_check - -# Attempt to autocomplete jail name jail_autocomplete zfs_enable_check() {