Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add autocomplete jail name function #750

Closed
wants to merge 11 commits into from
Closed
5 changes: 4 additions & 1 deletion usr/local/bin/bastille
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
10 changes: 10 additions & 0 deletions usr/local/share/bastille/common.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
1 change: 1 addition & 0 deletions usr/local/share/bastille/destroy.sh
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,7 @@ if [ $# -gt 1 ] || [ $# -lt 1 ]; then
fi

bastille_root_check
jail_autocomplete

## check what should we clean
case "${TARGET}" in
Expand Down
1 change: 1 addition & 0 deletions usr/local/share/bastille/export.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions usr/local/share/bastille/start.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 3 additions & 0 deletions usr/local/share/bastille/update.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 3 additions & 0 deletions usr/local/share/bastille/upgrade.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down