diff --git a/usr/local/bin/bastille b/usr/local/bin/bastille index dd9cbb25..a1ace43e 100755 --- a/usr/local/bin/bastille +++ b/usr/local/bin/bastille @@ -157,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 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" 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 diff --git a/usr/local/share/bastille/export.sh b/usr/local/share/bastille/export.sh index 3c14e962..76f4b279 100644 --- a/usr/local/share/bastille/export.sh +++ b/usr/local/share/bastille/export.sh @@ -72,6 +72,7 @@ if [ $# -gt 5 ] || [ $# -lt 1 ]; then fi bastille_root_check +jail_autocomplete zfs_enable_check() { # Temporarily disable ZFS so we can create a standard backup archive 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 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 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