diff --git a/usr/local/share/bastille/export.sh b/usr/local/share/bastille/export.sh index 86898b52..f4d07fd4 100644 --- a/usr/local/share/bastille/export.sh +++ b/usr/local/share/bastille/export.sh @@ -57,32 +57,17 @@ EOF exit 1 } -# Handle special-case commands first -case "$1" in -help|-h|--help) - usage - ;; +# Handle help option +case "${1}" in + help|-h|--help) + usage + ;; esac -# Check for unsupported actions -if [ "${TARGET}" = "ALL" ]; then - error_exit "Batch export is unsupported." -fi - if [ $# -gt 5 ] || [ $# -lt 1 ]; then usage fi -bastille_root_check - -zfs_enable_check() { - # Temporarily disable ZFS so we can create a standard backup archive - if checkyesno bastille_zfs_enable; then - # shellcheck disable=SC2034 - bastille_zfs_enable="NO" - fi -} - TARGET="${1}" GZIP_EXPORT= XZ_EXPORT= @@ -95,6 +80,17 @@ TGZ_EXPORT= OPT_ZSEND="-R" COMP_OPTION="0" +bastille_root_check +set_target_single "${TARGET}" + +zfs_enable_check() { + # Temporarily disable ZFS so we can create a standard backup archive + if checkyesno bastille_zfs_enable; then + # shellcheck disable=SC2034 + bastille_zfs_enable="NO" + fi +} + opt_count() { COMP_OPTION=$(expr ${COMP_OPTION} + 1) } @@ -143,7 +139,7 @@ if [ -n "${bastille_export_options}" ]; then esac done else - # Handle and parse option args + # Handle options while [ $# -gt 0 ]; do case "${1}" in --gz) diff --git a/usr/local/share/bastille/import.sh b/usr/local/share/bastille/import.sh index ade9f648..e966877e 100644 --- a/usr/local/share/bastille/import.sh +++ b/usr/local/share/bastille/import.sh @@ -41,8 +41,9 @@ usage() { cat << EOF Options: - -f | --force -- Force an archive import regardless if the checksum file does not match or missing. - -v | --verbose -- Be more verbose during the ZFS receive operation. + -f | --force Force an archive import regardless if the checksum file does not match or missing. + -v | --verbose Be more verbose during the ZFS receive operation. + -x | --debug Enable debug mode. Tip: If no option specified, container should be imported from standard input. @@ -50,49 +51,51 @@ EOF exit 1 } -# Handle special-case commands first -case "$1" in -help|-h|--help) - usage - ;; -esac +# Handle options. +FORCE=0 +ZRECV="-u" +USER_IMPORT= +while [ "$#" -gt 0 ]; do + case "${1}" in + -h|--help|help) + usage + ;; + -f|--force) + FORCE="1" + shift + ;; + -v|--verbose) + ZRECV="-u -v" + shift + ;; + -x|--debug) + enable_debug + shift + ;; + -*) + for _opt in $(echo ${1} | sed 's/-//g' | fold -w1); do + case ${_opt} in + f) FORCE=1 ;; + v) ZRECV="-u -v" ;; + x) enable_debug ;; + *) error_exit "Unknown Option: \"${1}\"" ;; + esac + done + shift + ;; + *) + break + ;; + esac +done if [ $# -gt 3 ] || [ $# -lt 1 ]; then usage fi -bastille_root_check - TARGET="${1}" -OPT_FORCE= -USER_IMPORT= -OPT_ZRECV="-u" -# Handle and parse option args -while [ $# -gt 0 ]; do - case "${1}" in - -f|--force) - OPT_FORCE="1" - TARGET="${2}" - shift - ;; - -v|--verbose) - OPT_ZRECV="-u -v" - TARGET="${2}" - shift - ;; - --*|-*) - error_notify "Unknown Option." - usage - ;; - *) - if [ $# -gt 1 ] || [ $# -lt 1 ]; then - usage - fi - shift - ;; - esac -done +bastille_root_check # Fallback to default if missing config parameters if [ -z "${bastille_decompress_xz_options}" ]; then @@ -162,7 +165,7 @@ update_jailconf() { fi } -update_fstab() { +update_fstab_import() { # Update fstab .bastille mountpoint on thin containers only # Set some variables FSTAB_CONFIG="${bastille_jailsdir}/${TARGET_TRIM}/fstab" @@ -585,7 +588,7 @@ jail_import() { # Update the jail.conf and fstab if required # This is required on foreign imports only update_jailconf - update_fstab + update_fstab_import if [ -z "${USER_IMPORT}" ]; then info "Container '${TARGET_TRIM}' imported successfully." fi