Merge pull request #479 from JRGTH/master

Make sure to check/bootstrap directories first
This commit is contained in:
Christer Edwards
2022-01-13 12:20:51 -07:00
committed by GitHub
2 changed files with 120 additions and 69 deletions

View File

@@ -304,6 +304,9 @@ bootstrap_release() {
debootstrap_release() { debootstrap_release() {
# Make sure to check/bootstrap directories first.
bootstrap_directories
#check and install OS dependencies @hackacad #check and install OS dependencies @hackacad
#ToDo: add function 'linux_pre' for sysrc etc. #ToDo: add function 'linux_pre' for sysrc etc.

View File

@@ -49,7 +49,7 @@ usage() {
-v | --verbose -- Be more verbose during the ZFS send operation. -v | --verbose -- Be more verbose during the ZFS send operation.
--xz -- Export a ZFS jail using XZ(.xz) compressed image. --xz -- Export a ZFS jail using XZ(.xz) compressed image.
Tip: If no option specified, container should be exported to standard output. Note: If no export option specified, the container should be redirected to standard output.
EOF EOF
exit 1 exit 1
@@ -80,6 +80,7 @@ zfs_enable_check() {
TARGET="${1}" TARGET="${1}"
GZIP_EXPORT= GZIP_EXPORT=
XZ_EXPORT=
SAFE_EXPORT= SAFE_EXPORT=
USER_EXPORT= USER_EXPORT=
RAW_EXPORT= RAW_EXPORT=
@@ -93,67 +94,112 @@ opt_count() {
COMP_OPTION=$(expr ${COMP_OPTION} + 1) COMP_OPTION=$(expr ${COMP_OPTION} + 1)
} }
# Handle and parse option args if [ -n "${bastille_export_options}" ]; then
while [ $# -gt 0 ]; do # Overrides the case options by the user defined option(s) automatically.
case "${1}" in # Add bastille_export_options="--optionA --optionB" to bastille.conf, or simply `export bastille_export_options="--optionA --optionB"` environment variable.
--gz) # To restore the standard case options, empty bastille_export_options="" in bastille.conf, or `unset bastille_export_options` environment variable.
GZIP_EXPORT="1" # Reference "/bastille/issues/443"
TARGET="${2}"
opt_count DEFAULT_EXPORT_OPTS="${bastille_export_options}"
shift info "Default export option(s): '${DEFAULT_EXPORT_OPTS}'"
;;
--xz) for opt in ${DEFAULT_EXPORT_OPTS}; do
XZ_EXPORT="1" case "${opt}" in
TARGET="${2}" --gz)
opt_count GZIP_EXPORT="1"
shift opt_count
;; shift;;
--tgz) --xz)
TGZ_EXPORT="1" XZ_EXPORT="1"
TARGET="${2}" opt_count
opt_count shift;;
zfs_enable_check --tgz)
shift TGZ_EXPORT="1"
;; opt_count
--txz) zfs_enable_check
TXZ_EXPORT="1" shift;;
TARGET="${2}" --txz)
opt_count TXZ_EXPORT="1"
zfs_enable_check opt_count
shift zfs_enable_check
;; shift;;
-s|--safe) --safe)
SAFE_EXPORT="1" SAFE_EXPORT="1"
TARGET="${2}" shift;;
shift --raw)
;; RAW_EXPORT="1"
-r|--raw) opt_count
RAW_EXPORT="1" shift ;;
TARGET="${2}" --verbose)
opt_count OPT_ZSEND="-Rv"
shift shift;;
;; -*|--*) error_notify "Unknown Option."
-v|--verbose) usage;;
OPT_ZSEND="-Rv" esac
TARGET="${2}" done
shift else
;; # Handle and parse option args
-*|--*) while [ $# -gt 0 ]; do
error_notify "Unknown Option." case "${1}" in
usage --gz)
;; GZIP_EXPORT="1"
*) TARGET="${2}"
if echo "${1}" | grep -q "\/"; then opt_count
DIR_EXPORT="${1}" shift
else ;;
if [ $# -gt 2 ] || [ $# -lt 1 ]; then --xz)
usage XZ_EXPORT="1"
TARGET="${2}"
opt_count
shift
;;
--tgz)
TGZ_EXPORT="1"
TARGET="${2}"
opt_count
zfs_enable_check
shift
;;
--txz)
TXZ_EXPORT="1"
TARGET="${2}"
opt_count
zfs_enable_check
shift
;;
-s|--safe)
SAFE_EXPORT="1"
TARGET="${2}"
shift
;;
-r|--raw)
RAW_EXPORT="1"
TARGET="${2}"
opt_count
shift
;;
-v|--verbose)
OPT_ZSEND="-Rv"
TARGET="${2}"
shift
;;
-*|--*)
error_notify "Unknown Option."
usage
;;
*)
if echo "${1}" | grep -q "\/"; then
DIR_EXPORT="${1}"
else
if [ $# -gt 2 ] || [ $# -lt 1 ]; then
usage
fi
fi fi
fi shift
shift ;;
;; esac
esac done
done fi
# Validate for combined options # Validate for combined options
if [ "${COMP_OPTION}" -gt "1" ]; then if [ "${COMP_OPTION}" -gt "1" ]; then
@@ -200,13 +246,13 @@ create_zfs_snap() {
if [ -z "${USER_EXPORT}" ]; then if [ -z "${USER_EXPORT}" ]; then
info "Creating temporary ZFS snapshot for export..." info "Creating temporary ZFS snapshot for export..."
fi fi
zfs snapshot -r "${bastille_zfs_zpool}/${bastille_zfs_prefix}/jails/${TARGET}@bastille_export_${DATE}" zfs snapshot -r "${bastille_zfs_zpool}/${bastille_zfs_prefix}/jails/${TARGET}@bastille_${TARGET}_${DATE}"
} }
clean_zfs_snap() { clean_zfs_snap() {
# Cleanup the recursive temporary snapshot # Cleanup the recursive temporary snapshot
zfs destroy "${bastille_zfs_zpool}/${bastille_zfs_prefix}/jails/${TARGET}/root@bastille_export_${DATE}" zfs destroy "${bastille_zfs_zpool}/${bastille_zfs_prefix}/jails/${TARGET}/root@bastille_${TARGET}_${DATE}"
zfs destroy "${bastille_zfs_zpool}/${bastille_zfs_prefix}/jails/${TARGET}@bastille_export_${DATE}" zfs destroy "${bastille_zfs_zpool}/${bastille_zfs_prefix}/jails/${TARGET}@bastille_${TARGET}_${DATE}"
} }
export_check() { export_check() {
@@ -263,7 +309,7 @@ jail_export() {
export_check export_check
# Export the raw container recursively and cleanup temporary snapshots # Export the raw container recursively and cleanup temporary snapshots
zfs send ${OPT_ZSEND} "${bastille_zfs_zpool}/${bastille_zfs_prefix}/jails/${TARGET}@bastille_export_${DATE}" \ zfs send ${OPT_ZSEND} "${bastille_zfs_zpool}/${bastille_zfs_prefix}/jails/${TARGET}@bastille_${TARGET}_${DATE}" \
> "${bastille_backupsdir}/${TARGET}_${DATE}" > "${bastille_backupsdir}/${TARGET}_${DATE}"
clean_zfs_snap clean_zfs_snap
elif [ -n "${GZIP_EXPORT}" ]; then elif [ -n "${GZIP_EXPORT}" ]; then
@@ -271,7 +317,7 @@ jail_export() {
export_check export_check
# Export the raw container recursively and cleanup temporary snapshots # Export the raw container recursively and cleanup temporary snapshots
zfs send ${OPT_ZSEND} "${bastille_zfs_zpool}/${bastille_zfs_prefix}/jails/${TARGET}@bastille_export_${DATE}" | \ zfs send ${OPT_ZSEND} "${bastille_zfs_zpool}/${bastille_zfs_prefix}/jails/${TARGET}@bastille_${TARGET}_${DATE}" | \
gzip ${bastille_compress_gz_options} > "${bastille_backupsdir}/${TARGET}_${DATE}${FILE_EXT}" gzip ${bastille_compress_gz_options} > "${bastille_backupsdir}/${TARGET}_${DATE}${FILE_EXT}"
clean_zfs_snap clean_zfs_snap
elif [ -n "${XZ_EXPORT}" ]; then elif [ -n "${XZ_EXPORT}" ]; then
@@ -279,7 +325,7 @@ jail_export() {
export_check export_check
# Export the container recursively and cleanup temporary snapshots # Export the container recursively and cleanup temporary snapshots
zfs send ${OPT_ZSEND} "${bastille_zfs_zpool}/${bastille_zfs_prefix}/jails/${TARGET}@bastille_export_${DATE}" | \ zfs send ${OPT_ZSEND} "${bastille_zfs_zpool}/${bastille_zfs_prefix}/jails/${TARGET}@bastille_${TARGET}_${DATE}" | \
xz ${bastille_compress_xz_options} > "${bastille_backupsdir}/${TARGET}_${DATE}${FILE_EXT}" xz ${bastille_compress_xz_options} > "${bastille_backupsdir}/${TARGET}_${DATE}${FILE_EXT}"
clean_zfs_snap clean_zfs_snap
else else
@@ -288,8 +334,10 @@ jail_export() {
export_check export_check
# Quietly export the container recursively, user must redirect standard output # Quietly export the container recursively, user must redirect standard output
zfs send ${OPT_ZSEND} "${bastille_zfs_zpool}/${bastille_zfs_prefix}/jails/${TARGET}@bastille_export_${DATE}" if ! zfs send ${OPT_ZSEND} "${bastille_zfs_zpool}/${bastille_zfs_prefix}/jails/${TARGET}@bastille_${TARGET}_${DATE}"; then
clean_zfs_snap clean_zfs_snap
error_notify "\nError: An export option is required, see 'bastille export, otherwise the user must redirect to standard output."
fi
fi fi
fi fi
else else