Merge pull request #994 from BastilleBSD/newline-jail

Newline jail
This commit is contained in:
tschettervictor
2025-04-30 13:40:35 -06:00
committed by GitHub
37 changed files with 242 additions and 215 deletions

View File

@@ -268,9 +268,6 @@ esac
# shellcheck disable=SC2154
SCRIPTPATH="${bastille_sharedir}/${CMD}.sh"
# Start with blank line
echo
if [ -f "${SCRIPTPATH}" ]; then
: "${UMASK:=022}"

View File

@@ -35,6 +35,7 @@
usage() {
error_notify "Usage: bastille bootstrap [option(s)] [RELEASE|TEMPLATE] [update|arch]"
cat << EOF
Options:
-x | --debug Enable debug mode.
@@ -288,7 +289,7 @@ bootstrap_release() {
info "Bootstrap successful."
info "See 'bastille --help' for available commands."
echo
}
debootstrap_release() {
@@ -384,7 +385,6 @@ debootstrap_release() {
info "Bootstrap successful."
info "See 'bastille --help' for available commands."
echo
}
bootstrap_template() {
@@ -658,3 +658,5 @@ case "${OPTION}" in
bastille update "${RELEASE}"
;;
esac
echo

View File

@@ -33,8 +33,9 @@
. /usr/local/share/bastille/common.sh
usage() {
error_notify "Usage: bastille clone [option(s)] TARGET NEW_NAME IP_ADDRESS"
error_notify "Usage: bastille clone [option(s)] TARGET NEWNAME IPADDRESS"
cat << EOF
Options:
-a | --auto Auto mode. Start/stop jail(s) if required. Cannot be used with [-l|--live].
@@ -373,19 +374,22 @@ update_jailconf_vnet() {
clone_jail() {
info "Attempting to clone ${TARGET} to ${NEWNAME}..."
info "\n[${TARGET}]:"
echo "Attempting clone to ${NEWNAME}..."
if ! [ -d "${bastille_jailsdir}/${NEWNAME}" ]; then
if checkyesno bastille_zfs_enable; then
if [ "${LIVE}" -eq 1 ]; then
check_target_is_running "${TARGET}" || error_exit "[-l|--live] can only be used with a running jail."
else check_target_is_stopped "${TARGET}" || if [ "${AUTO}" -eq 1 ]; then
echo "Auto-stopping ${TARGET}..."
bastille stop "${TARGET}"
else
error_notify "Jail is running."
error_exit "Use [-a|--auto] to force stop the jail, or [-l|--live] (ZFS only) to clone a running jail."
fi
fi
if [ -n "${bastille_zfs_zpool}" ]; then
# Replicate the existing container
DATE=$(date +%F-%H%M%S)
@@ -401,14 +405,18 @@ clone_jail() {
zfs destroy "${bastille_zfs_zpool}/${bastille_zfs_prefix}/jails/${NEWNAME}@bastille_clone_${DATE}"
fi
else
# Perform container file copy (archive mode)
check_target_is_stopped "${TARGET}" || if [ "${AUTO}" -eq 1 ]; then
echo "Auto-stopping ${TARGET}..."
bastille stop "${TARGET}"
else
error_notify "Jail is running."
error_exit "Use [-a|--auto] to force stop the jail."
fi
# Perform container file copy (archive mode)
cp -a "${bastille_jailsdir}/${TARGET}" "${bastille_jailsdir}/${NEWNAME}"
fi
else
error_exit "${NEWNAME} already exists."
@@ -441,4 +449,6 @@ else
usage
fi
clone_jail
clone_jail
echo

View File

@@ -33,8 +33,9 @@
. /usr/local/share/bastille/common.sh
usage() {
error_notify "Usage: bastille cmd [option(s)] TARGET command"
error_notify "Usage: bastille cmd [option(s)] TARGET COMMAND"
cat << EOF
Options:
-a | --auto Auto mode. Start/stop jail(s) if required.
@@ -90,15 +91,15 @@ set_target "${TARGET}"
for _jail in ${JAILS}; do
info "\n[${_jail}]:"
check_target_is_running "${_jail}" || if [ "${AUTO}" -eq 1 ]; then
echo "Auto-starting ${_jail}..."
bastille start "${_jail}"
else
info "[${_jail}]:"
error_notify "Jail is not running."
error_continue_next_jail "Use [-a|--auto] to auto-start the jail."
error_continue "Use [-a|--auto] to auto-start the jail."
fi
info "[${_jail}]:"
COUNT=$(($COUNT+1))
if grep -qw "linsysfs" "${bastille_jailsdir}/${_jail}/fstab"; then
@@ -116,15 +117,13 @@ for _jail in ${JAILS}; do
else
RETURN=$(($RETURN+$ERROR_CODE))
fi
# Print blank line
echo ""
done
# Check when a command is executed in all running jails. (bastille cmd ALL ...)
if [ "${COUNT}" -gt 1 ] && [ "${RETURN}" -gt 0 ]; then
RETURN=1
return "${RETURN}"
fi
return "${RETURN}"
echo

View File

@@ -72,22 +72,13 @@ error_continue() {
continue
}
# Notify message on error, and continue to next jail
# Echo blank line
error_continue_next_jail() {
error_notify "$@"
echo
# shellcheck disable=SC2104
continue
}
# Notify message on error, but do not exit
error_notify() {
echo -e "${COLOR_RED}$*${COLOR_RESET}" 1>&2
}
# Notify message on error and exit
# Echo blank line
# Echo blank line when exiting
error_exit() {
error_notify "$@"
echo
@@ -209,14 +200,15 @@ set_target() {
if get_jail_name "${_jail}" > /dev/null; then
_jail="$(get_jail_name ${_jail})"
else
error_continue_next_jail "Error: JID \"${_jail}\" not found. Is jail running?"
error_continue "Error: JID \"${_jail}\" not found. Is jail running?"
fi
elif ! check_target_exists "${_jail}"; then
if jail_autocomplete "${_jail}" > /dev/null; then
_jail="$(jail_autocomplete ${_jail})"
elif [ $? -eq 2 ]; then
error_continue_next_jail "Jail not found \"${_jail}\""
error_continue "Jail not found \"${_jail}\""
else
echo
exit 1
fi
fi
@@ -253,6 +245,7 @@ set_target_single() {
elif [ $? -eq 2 ]; then
error_exit "Jail not found \"${_TARGET}\""
else
echo
exit 1
fi
fi

View File

@@ -34,8 +34,9 @@
usage() {
error_notify "Usage: bastille config TARGET [get|set|remove] PROPERTY [VALUE]"
error_notify "Usage: bastille config TARGET [get|set|remove] PROPERTY VALUE"
cat << EOF
Options:
-x | --debug Enable debug mode.

View File

@@ -35,6 +35,7 @@
usage() {
error_notify "Usage: bastille console [option(s)] TARGET [user]"
cat << EOF
Options:
-a | --auto Auto mode. Start/stop jail(s) if required.
@@ -115,15 +116,15 @@ check_fib() {
}
for _jail in ${JAILS}; do
info "\n[${_jail}]:"
check_target_is_running "${_jail}" || if [ "${AUTO}" -eq 1 ]; then
echo "Auto-starting ${_jail}..."
bastille start "${_jail}"
else
info "[${_jail}]:"
error_notify "Jail is not running."
error_continue_next_jail "Use [-a|--auto] to auto-start the jail."
error_continue "Use [-a|--auto] to auto-start the jail."
fi
info "[${_jail}]:"
LOGIN="$(jexec -l "${_jail}" which login)"
if [ -n "${USER}" ]; then
@@ -133,8 +134,7 @@ for _jail in ${JAILS}; do
LOGIN="$(jexec -l "${_jail}" which login)"
${_setfib} jexec -l "${_jail}" $LOGIN -f root
fi
# Print blank line
echo ""
done
echo

View File

@@ -34,8 +34,8 @@
usage() {
error_notify "Usage: bastille convert [option(s)] [TARGET|TARGET RELEASE]"
cat << EOF
Options:
-a | --auto Auto mode. Start/stop jail(s) if required.
@@ -81,7 +81,11 @@ CONVERT_RELEASE="${2}"
bastille_root_check
set_target_single "${TARGET}"
info "\n[${TARGET}]:"
check_target_is_stopped "${TARGET}" || if [ "${AUTO}" -eq 1 ]; then
echo "Auto-stopping ${TARGET}..."
bastille stop "${TARGET}"
else
error_notify "Jail is running."
@@ -103,7 +107,7 @@ convert_jail_to_release() {
_jailname="${1}"
_release="${2}"
info "Creating ${_release} from ${_jailname}..."
echo "Creating ${_release} from ${_jailname}..."
if checkyesno bastille_zfs_enable; then
if [ -n "${bastille_zfs_zpool}" ]; then
@@ -162,7 +166,7 @@ convert_symlinks() {
done
# Copy new files to destination jail
info "Copying required base files to container..."
echo "Copying required base files to container..."
for _link in ${SYMLINKS}; do
if [ ! -d "${_link}" ]; then
if [ -d "${bastille_releasesdir}/${RELEASE}/${_link}" ]; then
@@ -274,3 +278,5 @@ elif [ "$#" -eq 2 ]; then
else
usage
fi
echo

View File

@@ -35,6 +35,7 @@
usage() {
error_notify "Usage: bastille cp [option(s)] TARGET HOST_PATH JAIL_PATH"
cat << EOF
Options:
-q | --quiet Suppress output.
@@ -88,16 +89,15 @@ set_target "${TARGET}"
for _jail in ${JAILS}; do
info "[${_jail}]:"
info "\n[${_jail}]:"
host_path="${HOST_PATH}"
jail_path="$(echo ${bastille_jailsdir}/${_jail}/root/${JAIL_PATH} | sed 's#//#/#g')"
if ! cp "${OPTION}" "${host_path}" "${jail_path}"; then
error_continue_next_jail "CP failed: ${host_path} -> ${jail_path}"
error_continue "CP failed: ${host_path} -> ${jail_path}"
fi
# Print blank line
echo ""
done
done
echo

View File

@@ -401,7 +401,7 @@ create_jail() {
if [ -z "${THICK_JAIL}" ] && [ -z "${CLONE_JAIL}" ]; then
LINK_LIST="bin boot lib libexec rescue sbin usr/bin usr/include usr/lib usr/lib32 usr/libdata usr/libexec usr/sbin usr/share usr/src"
info "Creating a thinjail..."
info "\nCreating a thinjail..."
for _link in ${LINK_LIST}; do
ln -sf /.bastille/${_link} ${_link}
done
@@ -432,7 +432,7 @@ create_jail() {
if checkyesno bastille_zfs_enable; then
if [ -n "${bastille_zfs_zpool}" ]; then
if [ -n "${CLONE_JAIL}" ]; then
info "Creating a clonejail...\n"
info "\nCreating a clonejail...\n"
## clone the release base to the new basejail
SNAP_NAME="bastille-clone-$(date +%Y-%m-%d-%H%M%S)"
# shellcheck disable=SC2140
@@ -444,7 +444,7 @@ create_jail() {
# Check and apply required settings.
post_create_jail
elif [ -n "${THICK_JAIL}" ]; then
info "Creating a thickjail. This may take a while...\n"
info "\nCreating a thickjail. This may take a while...\n"
## perform release base replication
## sane bastille zfs options
@@ -971,7 +971,7 @@ if [ -z "${EMPTY_JAIL}" ]; then
validate_netconf
fi
else
info "Creating empty jail: ${NAME}."
info "\nCreating empty jail: ${NAME}."
fi
# May not exist on deployments created before Bastille 0.7.20200714, so creating it. -- cwells
@@ -1008,3 +1008,5 @@ if check_target_exists "${NAME}"; then
fi
create_jail "${NAME}" "${RELEASE}" "${IP}" "${INTERFACE}"
echo

View File

@@ -35,6 +35,7 @@
usage() {
error_notify "Usage: bastille destroy [option(s)] [JAIL|RELEASE]"
cat << EOF
Options:
-a | --auto Auto mode. Start/stop jail(s) if required.
@@ -51,16 +52,18 @@ destroy_jail() {
local OPTIONS
for _jail in ${JAILS}; do
info "[${_jail}]:"
bastille_jail_base="${bastille_jailsdir}/${_jail}"
bastille_jail_log="${bastille_logsdir}/${_jail}_console.log"
check_target_is_stopped "${_jail}" || if [ "${AUTO}" -eq 1 ]; then
echo "Auto-stopping ${_jail}..."
bastille stop "${_jail}"
else
info "[${_jail}]:"
error_notify "Jail is running."
error_continue_next_jail "Use [-a|--auto] to auto-stop the jail."
error_continue "Use [-a|--auto] to auto-stop the jail."
fi
if [ -d "${bastille_jail_base}" ]; then
@@ -109,9 +112,6 @@ destroy_jail() {
pfctl -a "rdr/${_jail}" -Fn
fi
fi
# Print blank line
echo ""
done
}
@@ -304,3 +304,5 @@ case "${TARGET}" in
destroy_jail "${JAILS}"
;;
esac
echo

View File

@@ -35,6 +35,7 @@
usage() {
error_notify "Usage: bastille edit [option(s)] TARGET [filename]"
cat << EOF
Options:
-x | --debug Enable debug mode.

View File

@@ -32,6 +32,7 @@
usage() {
error_notify "Usage: bastille etcupdate [option(s)] [bootstrap|TARGET] [diff|resolve|update RELEASE]"
cat << EOF
Options:
-d | --dry-run Show output, but do not apply.
@@ -59,40 +60,40 @@ bootstrap_etc_release() {
bootstrap_etc_tarball() {
local _release="${1}"
if [ ! -f ${bastille_cachedir}/${_release}.tbz2 ]; then
echo "Building tarball, please wait..."
echo "\nBuilding tarball, please wait..."
if ! etcupdate build -d /tmp/etcupdate -s ${bastille_releasesdir}/${_release}/usr/src ${bastille_cachedir}/${_release}.tbz2; then
error_exit "Failed to build etcupdate tarball \"${_release}.tbz2\""
else
info "Etcupdate bootstrap complete: ${_release}"
info "\nEtcupdate bootstrap complete: ${_release}"
fi
elif [ -f ${bastille_cachedir}/${_release}.tbz2 ] && [ "${FORCE}" -eq 1 ]; then
rm -f "${bastille_cachedir}/${_release}.tbz2"
echo "Building tarball, please wait..."
if ! etcupdate build -d /tmp/etcupdate -s ${bastille_releasesdir}/${_release}/usr/src ${bastille_cachedir}/${_release}.tbz2; then
error_exit "Failed to build etcupdate tarball: ${_release}.tbz2"
error_exit "[ERROR]: Failed to build etcupdate tarball: ${_release}.tbz2"
else
info "Etcupdate bootstrap complete: ${_release}"
info "\nEtcupdate bootstrap complete: ${_release}"
fi
else
info "Etcupdate release has already been prepared for application: ${_release}"
info "\nEtcupdate release has already been prepared for application: ${_release}"
fi
}
diff_review() {
local _jail="${1}"
if [ "${DRY_RUN}" -eq 1 ]; then
warn "Warning: diff mode does not support [-d|--dryrun]"
error_exit "[ERROR]: diff mode does not support [-d|--dryrun]"
fi
info "[${_jail}]: etcupdate --diff mode"
info "\n[${_jail}]: etcupdate --diff mode"
etcupdate diff -D "${bastille_jailsdir}/${_jail}/root"
}
resolve_conflicts() {
local _jail="${1}"
if [ "${DRY_RUN}" -eq 1 ]; then
warn "Warning: resolve mode does not support [-d|--dryrun]"
error_exit "[ERROR]: resolve mode does not support [-d|--dryrun]"
fi
info "[${_jail}]: etcupdate resolve"
info "\n[${_jail}]: etcupdate resolve"
etcupdate resolve -D "${bastille_jailsdir}/${_jail}/root"
}
@@ -103,10 +104,10 @@ update_jail_etc() {
error_exit "Error: Please run \"bastille etcupdate bootstrap RELEASE\" first."
fi
if [ "${DRY_RUN}" -eq 1 ]; then
info "[${_jail}]: etcupdate update --dry-run"
info "\n[${_jail}]: etcupdate update --dry-run"
etcupdate -n -D "${bastille_jailsdir}/${_jail}/root" -t ${bastille_cachedir}/${_release}.tbz2
else
info "[${_jail}]: etcupdate update"
info "\n[${_jail}]: etcupdate update"
etcupdate -D "${bastille_jailsdir}/${_jail}/root" -t ${bastille_cachedir}/${_release}.tbz2
fi
}
@@ -194,3 +195,5 @@ while [ "$#" -gt 0 ]; do
;;
esac
done
echo

View File

@@ -39,6 +39,7 @@ usage() {
# If no compression option specified, user must redirect standard output
error_notify "Usage: bastille export [option(s)] TARGET PATH"
cat << EOF
Options:
--gz Export a ZFS jail using GZIP(.gz) compressed image.
@@ -240,7 +241,7 @@ fi
create_zfs_snap() {
# Take a recursive temporary snapshot
if [ -z "${USER_EXPORT}" ]; then
info "Creating temporary ZFS snapshot for export..."
echo "Creating temporary ZFS snapshot for export..."
fi
zfs snapshot -r "${bastille_zfs_zpool}/${bastille_zfs_prefix}/jails/${TARGET}@bastille_${TARGET}_${DATE}"
}
@@ -296,6 +297,9 @@ export_check() {
}
jail_export() {
info "\n[${_jail}]:"
# Attempt to export the container
DATE=$(date +%F-%H%M%S)
if checkyesno bastille_zfs_enable; then
@@ -387,3 +391,5 @@ if [ -n "${TARGET}" ]; then
fi
jail_export
fi
echo

View File

@@ -35,6 +35,7 @@
usage() {
error_notify "Usage: bastille htop [option(s)] TARGET"
cat << EOF
Options:
-a | --auto Auto mode. Start/stop jail(s) if required.
@@ -84,16 +85,16 @@ TARGET="${1}"
bastille_root_check
set_target_single "${TARGET}"
info "[${TARGET}]:"
check_target_is_running "${TARGET}" || if [ "${AUTO}" -eq 1 ]; then
echo "Auto-starting ${TARGET}..."
bastille start "${TARGET}"
else
info "[${TARGET}]:"
else
error_notify "Jail is not running."
error_continue_next_jail "Use [-a|--auto] to auto-start the jail."
fi
info "[${TARGET}]:"
if [ ! -x "${bastille_jailsdir}/${TARGET}/root/usr/local/bin/htop" ]; then
error_notify "htop not found on ${TARGET}."
elif [ -x "${bastille_jailsdir}/${TARGET}/root/usr/local/bin/htop" ]; then

View File

@@ -36,8 +36,8 @@ usage() {
# Build an independent usage for the import command
# If no file/extension specified, will import from standard input
error_notify "Usage: bastille import [option(s)] FILE [RELEASE]"
cat << EOF
Options:
-f | --force Force an archive import regardless if the checksum file does not match or missing.
@@ -748,3 +748,5 @@ fi
if [ -n "${TARGET}" ]; then
jail_import
fi
echo

View File

@@ -35,6 +35,7 @@
usage() {
error_notify "Usage: bastille jcp [option(s)] SOURCE_JAIL JAIL_PATH DEST_JAIL JAIL_PATH"
cat << EOF
Options:
-q | --quiet Suppress output.
@@ -94,17 +95,16 @@ for _jail in ${DEST_TARGET}; do
continue
else
info "[${_jail}]:"
info "\n[${_jail}]:"
source_path="$(echo ${bastille_jailsdir}/${SOURCE_TARGET}/root/${SOURCE_PATH} | sed 's#//#/#g')"
dest_path="$(echo ${bastille_jailsdir}/${_jail}/root/${DEST_PATH} | sed 's#//#/#g')"
if ! cp "${OPTION}" "${source_path}" "${dest_path}"; then
error_continue_next_jail "JCP failed: ${source_path} -> ${dest_path}"
error_continue "JCP failed: ${source_path} -> ${dest_path}"
fi
# Print blank line
echo
fi
done
done
echo

View File

@@ -37,6 +37,7 @@ usage() {
error_notify "Usage: bastille limits [option(s)] TARGET [add OPTION VALUE|remove OPTION|clear|reset|[list|show] (active)|stats]"
echo -e "Example: bastille limits TARGET add memoryuse 1G"
cat << EOF
Options:
-a | --auto Auto mode. Start/stop jail(s) if required.
@@ -53,10 +54,10 @@ while [ "$#" -gt 0 ]; do
-h|--help|help)
usage
;;
-a|--auto)
AUTO=1
shift
;;
-a|--auto)
AUTO=1
shift
;;
-x|--debug)
enable_debug
shift
@@ -102,15 +103,16 @@ set_target "${TARGET}"
for _jail in ${JAILS}; do
info "\n[${_jail}]:"
check_target_is_running "${_jail}" || if [ "${AUTO}" -eq 1 ]; then
echo "Auto-starting ${_jail}..."
bastille start "${_jail}"
else
info "[${_jail}]:"
error_notify "Jail is not running."
error_continue_next_jail "Use [-a|--auto] to auto-start the jail."
error_continue "Use [-a|--auto] to auto-start the jail."
fi
info "[${_jail}]:"
case "${ACTION}" in
add)
@@ -153,43 +155,42 @@ for _jail in ${JAILS}; do
while read _limits; do
rctl -r "${_limits}" 2>/dev/null
done < "${bastille_jailsdir}/${_jail}/rctl.conf"
info "[${_jail}]: RCTL limits cleared."
echo "RCTL limits cleared."
fi
;;
list|show)
# Show limits
if [ -s "${bastille_jailsdir}/${_jail}/rctl.conf" ]; then
if [ "${1}" = "active" ]; then
rctl jail:${_jail} 2>/dev/null
else
cat "${bastille_jailsdir}/${_jail}/rctl.conf"
fi
if [ "${1}" = "active" ]; then
rctl jail:${_jail} 2>/dev/null
else
cat "${bastille_jailsdir}/${_jail}/rctl.conf"
fi
fi
;;
stats)
# Show statistics
if [ -s "${bastille_jailsdir}/${_jail}/rctl.conf" ]; then
rctl -hu jail:${_jail} 2>/dev/null
rctl -hu jail:${_jail} 2>/dev/null
fi
;;
reset)
# Remove limits and delete rctl.conf
if [ -s "${bastille_jailsdir}/${_jail}/rctl.conf" ]; then
if [ -s "${bastille_jailsdir}/${_jail}/rctl.conf" ]; then
while read _limits; do
rctl -r "${_limits}" 2>/dev/null
done < "${bastille_jailsdir}/${_jail}/rctl.conf"
info "[${TARGET}]: RCTL limits cleared."
echo "RCTL limits cleared."
fi
if [ -s "${bastille_jailsdir}/${_jail}/rctl.conf" ]; then
rm -f "${bastille_jailsdir}/${_jail}/rctl.conf"
info "[${TARGET}]: rctl.conf removed."
echo "rctl.conf removed."
else
error_continue_next_jail "[${TARGET}]: rctl.conf not found."
error_continue "rctl.conf not found."
fi
;;
esac
# Print blank line
echo
done
echo

View File

@@ -35,6 +35,7 @@
usage() {
error_notify "Usage: bastille mount [option(s)] TARGET HOST_PATH JAIL_PATH [filesystem_type options dump pass_number]"
cat << EOF
Options:
-a | --auto Auto mode. Start/stop jail(s) if required.
@@ -142,16 +143,16 @@ fi
for _jail in ${JAILS}; do
info "\n[${_jail}]:"
check_target_is_running "${_jail}" || if [ "${AUTO}" -eq 1 ]; then
echo "Auto-starting ${_jail}..."
bastille start "${_jail}"
else
info "[${_jail}]:"
error_notify "Jail is not running."
error_continue_next_jail "Use [-a|--auto] to auto-start the jail."
error_continue "Use [-a|--auto] to auto-start the jail."
fi
info "[${_jail}]:"
_fullpath_fstab="$( echo "${bastille_jailsdir}/${_jail}/root/${_jailpath_fstab}" 2>/dev/null | sed 's#//#/#' )"
_fullpath="$( echo "${bastille_jailsdir}/${_jail}/root/${_jailpath}" 2>/dev/null | sed 's#//#/#' )"
_fstab_entry="${_hostpath_fstab} ${_fullpath_fstab} ${_type} ${_perms} ${_checks}"
@@ -167,13 +168,13 @@ for _jail in ${JAILS}; do
# Create mount point if it does not exist
if [ -d "${_hostpath}" ] && [ ! -d "${_fullpath}" ]; then
mkdir -p "${_fullpath}" || error_continue_next_jail "Failed to create mount point."
mkdir -p "${_fullpath}" || error_continue "Failed to create mount point."
elif [ -f "${_hostpath}" ] ; then
_filename="$( basename ${_hostpath} )"
if echo "${_fullpath}" 2>/dev/null | grep -qow "${_filename}"; then
mkdir -p "$( dirname "${_fullpath}" )" || error_continue_next_jail "Failed to create mount point."
mkdir -p "$( dirname "${_fullpath}" )" || error_continue "Failed to create mount point."
if [ ! -f "${_fullpath}" ]; then
touch "${_fullpath}" || error_continue_next_jail "Failed to create mount point."
touch "${_fullpath}" || error_continue "Failed to create mount point."
else
error_notify "Failed. File exists at mount point."
warn "${_fullpath}"
@@ -183,9 +184,9 @@ for _jail in ${JAILS}; do
_fullpath_fstab="$( echo "${bastille_jailsdir}/${_jail}/root/${_jailpath_fstab}/${_filename}" 2>/dev/null | sed 's#//#/#' )"
_fullpath="$( echo "${bastille_jailsdir}/${_jail}/root/${_jailpath}/${_filename}" 2>/dev/null | sed 's#//#/#' )"
_fstab_entry="${_hostpath_fstab} ${_fullpath_fstab} ${_type} ${_perms} ${_checks}"
mkdir -p "$( dirname "${_fullpath}" )" || error_continue_next_jail "Failed to create mount point."
mkdir -p "$( dirname "${_fullpath}" )" || error_continue "Failed to create mount point."
if [ ! -f "${_fullpath}" ]; then
touch "${_fullpath}" || error_continue_next_jail "Failed to create mount point."
touch "${_fullpath}" || error_continue "Failed to create mount point."
else
error_notify "Failed. File exists at mount point."
warn "${_fullpath}"
@@ -195,11 +196,10 @@ for _jail in ${JAILS}; do
fi
# Add entry to fstab and mount
echo "${_fstab_entry}" >> "${bastille_jailsdir}/${_jail}/fstab" || error_continue_next_jail "Failed to create fstab entry: ${_fstab_entry}"
mount -F "${bastille_jailsdir}/${_jail}/fstab" -a || error_continue_next_jail "Failed to mount volume: ${_fullpath}"
echo "${_fstab_entry}" >> "${bastille_jailsdir}/${_jail}/fstab" || error_continue "Failed to create fstab entry: ${_fstab_entry}"
mount -F "${bastille_jailsdir}/${_jail}/fstab" -a || error_continue "Failed to mount volume: ${_fullpath}"
echo "Added: ${_fstab_entry}"
# Print blank line
echo
done
echo

View File

@@ -36,6 +36,7 @@
usage() {
error_notify "Usage: bastille network [option(s)] TARGET [remove|add] INTERFACE [IP_ADDRESS]"
cat << EOF
Options:
-a | --auto Start/stop the jail(s) if required.
@@ -135,7 +136,6 @@ if [ "${ACTION}" = "add" ] && [ "${NO_IP}" -eq 0 ] && [ -n "${4}" ]; then
IP="${4}"
elif [ "${NO_IP}" -eq 1 ] && [ -n "${4}" ]; then
error_notify "IP should not be present when using -n|--no-ip."
usage
else
IP=""
fi
@@ -165,7 +165,9 @@ fi
bastille_root_check
set_target_single "${TARGET}"
check_target_is_stopped "${TARGET}" || if [ "${AUTO}" -eq 1 ]; then
echo "Auto-stopping ${TARGET}..."
bastille stop "${TARGET}"
else
error_notify "Jail is running."
@@ -301,7 +303,6 @@ EOF
fi
fi
info "[${_jailname}]:"
echo "Added interface: \"${_if}\""
elif [ "${VNET}" -eq 1 ]; then
@@ -349,7 +350,6 @@ EOF
fi
fi
info "[${_jailname}]:"
echo "Added VNET interface: \"${_if}\""
elif [ "${bastille_network_vnet_type}" = "netgraph" ]; then
for _num in $(seq 0 "${_bastille_if_num_range}"); do
@@ -391,8 +391,6 @@ EOF
sysrc -f "${_jail_rc_config}" ifconfig_${_if_vnet}="inet ${_ip}"
fi
fi
info "[${_jailname}]:"
echo "Added VNET interface: \"${_if}\""
fi
elif [ "${PASSTHROUGH}" -eq 1 ]; then
@@ -414,7 +412,6 @@ EOF
fi
fi
info "[${_jailname}]:"
echo "Added Passthrough interface: \"${_if}\""
elif [ "${CLASSIC}" -eq 1 ]; then
@@ -425,7 +422,6 @@ EOF
fi
fi
info "[${_jailname}]:"
echo "Added interface: \"${_if}\""
}
@@ -525,8 +521,7 @@ remove_interface() {
error_exit "Failed to remove interface from jail.conf"
fi
fi
info "[${_jailname}]:"
echo "Removed interface: \"${_if}\""
}
@@ -554,10 +549,11 @@ add_vlan() {
bastille restart "${_jailname}"
fi
info "[${_jailname}]:"
info "Added VLAN ${_vlan_id} to interface: \"${_jail_vnet}\""
echo "Added VLAN ${_vlan_id} to interface: \"${_jail_vnet}\""
}
info "\n[${TARGET}]:"
case "${ACTION}" in
add)
validate_netconf
@@ -566,6 +562,7 @@ case "${ACTION}" in
error_exit "Interface is already added: \"${INTERFACE}\""
elif { [ "${VNET}" -eq 1 ] || [ "${BRIDGE}" -eq 1 ] || [ "${PASSTHROUGH}" -eq 1 ]; } && [ -n "${VLAN_ID}" ]; then
add_vlan "${TARGET}" "${INTERFACE}" "${IP}" "${VLAN_ID}"
echo
exit 0
fi
## validate IP if not empty

View File

@@ -35,6 +35,7 @@
usage() {
error_notify "Usage: bastille pkg [option(s)] TARGET COMMAND args"
cat << EOF
Options:
-a | --auto Auto mode. Start/stop jail(s) if required.
@@ -96,15 +97,15 @@ errors=0
for _jail in ${JAILS}; do
info "\n[${_jail}]:"
check_target_is_running "${_jail}" || if [ "${AUTO}" -eq 1 ]; then
echo "Auto-starting ${_jail}..."
bastille start "${_jail}"
else
info "[${_jail}]:"
error_notify "Jail is not running."
error_continue_next_jail "Use [-a|--auto] to auto-start the jail."
fi
info "[${_jail}]:"
bastille_jail_path="${bastille_jailsdir}/${_jail}/root"
if [ -f "/usr/sbin/mport" ]; then
@@ -125,11 +126,10 @@ for _jail in ${JAILS}; do
fi
fi
# Print blank line
echo
done
if [ $errors -ne 0 ]; then
error_exit "Failed to apply on some jails, please check logs"
fi
echo

View File

@@ -35,6 +35,7 @@
usage() {
error_notify "Usage: bastille rcp [option(s)] TARGET JAIL_PATH HOST_PATH"
cat << EOF
Options:
-q | --quiet Suppress output.
@@ -86,7 +87,7 @@ HOST_PATH="${3}"
bastille_root_check
set_target_single "${TARGET}"
info "[${TARGET}]:"
info "\n[${TARGET}]:"
host_path="${HOST_PATH}"
jail_path="$(echo ${bastille_jailsdir}/${TARGET}/root/${JAIL_PATH} | sed 's#//#/#g')"

View File

@@ -35,6 +35,7 @@
usage() {
error_notify "Usage: bastille rdr [option(s)] TARGET [clear|reset|list|(tcp|udp)] HOST_PORT JAIL_PORT [log ['(' logopts ')'] ]"
cat << EOF
Options:
-d | --destination [destination ip] Limit rdr to a destination IP. Useful if you have multiple IPs on one interface.
@@ -159,7 +160,6 @@ load_rdr_rule() {
| pfctl -a "rdr/${TARGET}" -f-; then
error_exit "Failed to create IPv4 rdr rule \"${if_name} ${src} ${dst} ${proto} ${host_port} ${jail_port}\""
else
info "[${TARGET}]:"
echo "IPv4 ${proto}/${host_port}:${jail_port} on ${if_name}"
fi
fi
@@ -171,7 +171,6 @@ load_rdr_rule() {
| pfctl -a "rdr/${TARGET}" -f-; then
error_exit "Failed to create IPv6 rdr rule \"${if_name} ${src} ${dst} ${proto} ${host_port} ${jail_port}\""
else
info "[${TARGET}]:"
echo "IPv6 ${proto}/${host_port}:${jail_port} on ${if_name}"
fi
fi
@@ -196,7 +195,6 @@ load_rdr_log_rule() {
| pfctl -a "rdr/${TARGET}" -f-; then
error_exit "Failed to create logged IPv4 rdr rule \"${if_name} ${src} ${dst} ${proto} ${host_port} ${jail_port}\""
else
info "[${TARGET}]:"
echo "IPv4 ${proto}/${host_port}:${jail_port} on ${if_name}"
fi
fi
@@ -208,7 +206,6 @@ load_rdr_log_rule() {
| pfctl -a "rdr/${TARGET}" -f-; then
error_exit "Failed to create logged IPv6 rdr rule \"${if_name} ${src} ${dst} ${proto} ${host_port} ${jail_port}\""
else
info "[${TARGET}]:"
echo "IPv6 ${proto}/${host_port}:${jail_port} on ${if_name}"
fi
fi
@@ -286,6 +283,8 @@ shift
bastille_root_check
set_target_single "${TARGET}"
info "\n[${TARGET}]:"
while [ "$#" -gt 0 ]; do
case "${1}" in
list)
@@ -320,9 +319,9 @@ while [ "$#" -gt 0 ]; do
check_jail_validity
echo "${TARGET} redirects:"
pfctl -a "rdr/${TARGET}" -Fn
if rm -f "${bastille_jailsdir}/${TARGET}/rdr.conf"; then
info "[${TARGET}]: rdr.conf removed"
fi
if rm -f "${bastille_jailsdir}/${TARGET}/rdr.conf"; then
echo "rdr.conf removed"
fi
fi
shift
;;
@@ -403,3 +402,5 @@ while [ "$#" -gt 0 ]; do
;;
esac
done
echo

View File

@@ -78,7 +78,9 @@ NEWNAME="${2}"
bastille_root_check
set_target_single "${TARGET}"
check_target_is_stopped "${TARGET}" || if [ "${AUTO}" -eq 1 ]; then
echo "Auto-stopping ${TARGET}..."
bastille stop "${TARGET}"
else
error_notify "Jail is running."
@@ -225,4 +227,6 @@ if [ -d "${bastille_jailsdir}/${NEWNAME}" ]; then
error_exit "Jail: ${NEWNAME} already exists."
fi
change_name
change_name
echo

View File

@@ -35,6 +35,7 @@
usage() {
error_notify "Usage: bastille restart [option(s)] TARGET"
cat << EOF
Options:
-b | --boot Respect jail boot setting.

View File

@@ -35,6 +35,7 @@
usage() {
error_notify "Usage: bastille service [options(s)] TARGET SERVICE_NAME ACTION"
cat << EOF
Options:
-a | --auto Auto mode. Start/stop jail(s) if required.
@@ -86,20 +87,19 @@ bastille_root_check
set_target "${TARGET}"
for _jail in ${JAILS}; do
info "\n[${_jail}]:"
check_target_is_running "${_jail}" || if [ "${AUTO}" -eq 1 ]; then
echo "Auto-starting ${_jail}..."
bastille start "${_jail}"
else
info "[${_jail}]:"
error_notify "Jail is not running."
error_continue_next_jail "Use [-a|--auto] to auto-start the jail."
fi
info "[${_jail}]:"
jexec -l "${_jail}" /usr/sbin/service "$@"
# Print blank line
echo
done
echo

View File

@@ -35,6 +35,7 @@
usage() {
error_notify "Usage: bastille start [option(s)] TARGET"
cat << EOF
Options:
-b | --boot Respect jail boot setting.
@@ -110,14 +111,13 @@ for _jail in ${JAILS}; do
continue
fi
fi
info "\n[${_jail}]:"
if check_target_is_running "${_jail}"; then
info "[${_jail}]:"
error_continue_next_jail "Jail is already running."
error_continue "Jail is already running."
fi
info "[${_jail}]:"
# Validate interfaces and add IPs to firewall table
if [ "$(bastille config ${_jail} get vnet)" != 'enabled' ]; then
_ip4_interfaces="$(bastille config ${_jail} get ip4.addr | sed 's/,/ /g')"
@@ -141,7 +141,7 @@ for _jail in ${JAILS}; do
pfctl -q -t "${bastille_network_pf_table}" -T add "${_ip}"
fi
else
error_continue_next_jail "Error: ${_if} interface does not exist."
error_continue "Error: ${_if} interface does not exist."
fi
done
fi
@@ -164,7 +164,7 @@ for _jail in ${JAILS}; do
pfctl -q -t "${bastille_network_pf_table}" -T add "${_ip}"
fi
else
error_continue_next_jail "Error: ${_if} interface does not exist."
error_continue "Error: ${_if} interface does not exist."
fi
done
fi
@@ -189,8 +189,7 @@ for _jail in ${JAILS}; do
# Delay between jail action
sleep "${DELAY_TIME}"
# Print blank line
echo
done
echo

View File

@@ -35,6 +35,7 @@
usage() {
error_notify "Usage: bastille stop [option(s)] TARGET"
cat << EOF
Options:
-v | --verbose Print every action on jail stop.
@@ -86,13 +87,12 @@ set_target "${TARGET}" "reverse"
for _jail in ${JAILS}; do
info "\n[${_jail}]:"
if check_target_is_stopped "${_jail}"; then
info "[${_jail}]:"
error_continue_next_jail "Jail is already stopped."
error_continue "Jail is already stopped."
fi
info "[${_jail}]:"
# Remove RDR rules
if [ "$(bastille config ${_jail} get vnet)" != "enabled" ] && [ -f "${bastille_pf_conf}" ]; then
_ip4="$(bastille config ${_jail} get ip4.addr | sed 's/,/ /g')"
@@ -135,8 +135,7 @@ for _jail in ${JAILS}; do
pfctl -q -t "${bastille_network_pf_table}" -T delete "${_ip}"
done
fi
# Print blank line
echo
done
echo

View File

@@ -35,6 +35,7 @@
usage() {
error_notify "Usage: bastille sysrc [option(s)] TARGET args"
cat << EOF
Options:
-a | --auto Auto mode. Start/stop jail(s) if required.
@@ -86,20 +87,17 @@ bastille_root_check
set_target "${TARGET}"
for _jail in ${JAILS}; do
info "\n[${_jail}]:"
check_target_is_running "${_jail}" || if [ "${AUTO}" -eq 1 ]; then
echo "Auto-starting ${_jail}..."
bastille start "${_jail}"
else
info "[${_jail}]:"
error_notify "Jail is not running."
error_continue_next_jail "Use [-a|--auto] to auto-start the jail."
error_continue "Use [-a|--auto] to auto-start the jail."
fi
info "[${_jail}]:"
jexec -l "${_jail}" /usr/sbin/sysrc "$@"
# Print blank line
echo
done

View File

@@ -36,6 +36,7 @@
usage() {
error_notify "Usage: bastille tags TARGET [add|delete|list] [tag1,tag2]"
cat << EOF
Options:
-x | --debug Enable debug mode.
@@ -117,8 +118,5 @@ for _jail in ${JAILS}; do
;;
esac
# Print blank line
echo
done

View File

@@ -270,15 +270,15 @@ fi
for _jail in ${JAILS}; do
info "\n[${_jail}]:"
check_target_is_running "${_jail}" || if [ "${AUTO}" -eq 1 ]; then
echo "Auto-starting ${_jail}..."
bastille start "${_jail}"
else
info "[${_jail}]:"
error_notify "Jail is not running."
error_continue_next_jail "Use [-a|--auto] to auto-start the jail."
error_continue "Use [-a|--auto] to auto-start the jail."
fi
info "[${_jail}]:"
info "Applying template: ${TEMPLATE}..."
@@ -469,10 +469,9 @@ for _jail in ${JAILS}; do
echo
fi
done
# Print blank line
echo
info "Template applied: ${TEMPLATE}"
done
echo

View File

@@ -35,6 +35,7 @@
usage() {
error_notify "Usage: bastille top [options(s)] TARGET"
cat << EOF
Options:
-a | --auto Auto mode. Start/stop jail(s) if required.
@@ -84,9 +85,10 @@ TARGET="${1}"
bastille_root_check
set_target_single "${TARGET}"
info "[${TARGET}]:"
info "\n[${TARGET}]:"
check_target_is_running "${TARGET}" || if [ "${AUTO}" -eq 1 ]; then
echo "Auto-starting ${TARGET}..."
bastille start "${TARGET}"
else
error_notify "Jail is not running."
@@ -94,3 +96,5 @@ else
fi
jexec -l "${TARGET}" /usr/bin/top
echo

View File

@@ -35,6 +35,7 @@
usage() {
error_notify "Usage: bastille umount [option(s)] TARGET JAIL_PATH"
cat << EOF
Options:
-a | --auto Auto mode. Start/stop jail(s) if required.
@@ -87,12 +88,14 @@ set_target "${TARGET}"
for _jail in ${JAILS}; do
info "\n[${_jail}]:"
check_target_is_running "${_jail}" || if [ "${AUTO}" -eq 1 ]; then
echo "Auto-starting ${_jail}..."
bastille start "${_jail}"
else
info "[${_jail}]:"
error_notify "Jail is not running."
error_continue_next_jail "Use [-a|--auto] to auto-start the jail."
error_continue "Use [-a|--auto] to auto-start the jail."
fi
info "[${_jail}]:"
@@ -104,29 +107,28 @@ for _jail in ${JAILS}; do
# Exit if mount point non-existent
if [ -z "${_mount}" ] && [ -z "${_fstab_entry}" ]; then
error_continue_next_jail "The specified mount point does not exist."
error_continue "The specified mount point does not exist."
fi
# Unmount
if [ -n "${_mount}" ]; then
umount "${_jailpath}" || error_continue_next_jail "Failed to unmount volume: ${MOUNT_PATH}"
umount "${_jailpath}" || error_continue "Failed to unmount volume: ${MOUNT_PATH}"
fi
# Remove entry from fstab
if [ -n "${_fstab_entry}" ]; then
if ! sed -E -i '' "\, +${_jailpath_fstab} +,d" "${bastille_jailsdir}/${_jail}/fstab"; then
error_continue_next_jail "Failed to delete fstab entry: ${MOUNT_PATH}"
error_continue "Failed to delete fstab entry: ${MOUNT_PATH}"
fi
fi
# Delete if mount point was a file
if [ -f "${_jailpath}" ]; then
rm -f "${_jailpath}" || error_continue_next_jail "Failed to unmount volume: ${MOUNT_PATH}"
rm -f "${_jailpath}" || error_continue "Failed to unmount volume: ${MOUNT_PATH}"
fi
echo "Unmounted: ${_jailpath}"
# Print blank line
echo
done
echo

View File

@@ -110,14 +110,13 @@ jail_check() {
# Check if the jail is thick and is running
set_target_single "${TARGET}"
check_target_is_running "${TARGET}" || if [ "${AUTO}" -eq 1 ]; then
echo "Auto-starting ${TARGET}..."
bastille start "${TARGET}"
else
info "[${TARGET}]:"
error_notify "Jail is not running."
error_exit "Use [-a|--auto] to auto-start the jail."
fi
if grep -qw "${bastille_jailsdir}/${TARGET}/root/.bastille" "${bastille_jailsdir}/${TARGET}/fstab"; then
info "[${TARGET}]:"
error_notify "${TARGET} is not a thick container."
error_exit "See 'bastille update RELEASE' to update thin jails."
fi
@@ -217,6 +216,9 @@ elif echo "${TARGET}" | grep -q "[0-9]\{2\}.[0-9]-RELEASE"; then
arch_check
release_update
else
info "\n[${TARGET}]:"
jail_check
jail_update "${TARGET}"
fi
echo

View File

@@ -35,6 +35,7 @@
usage() {
error_notify "Usage: bastille upgrade [option(s)] TARGET [NEWRELEASE|install]"
cat << EOF
Options:
-a | --auto Auto mode. Start/stop jail(s) if required.
@@ -106,9 +107,9 @@ thick_jail_check() {
local _jail="${1}"
# Check if the jail is thick and is running
check_target_is_running "${_jail}" || if [ "${AUTO}" -eq 1 ]; then
echo "Auto-starting ${_jail}..."
bastille start "${_jail}"
else
info "[${TARGET}]:"
error_notify "Jail is not running."
error_exit "Use [-a|--auto] to auto-start the jail."
fi
@@ -118,9 +119,9 @@ thin_jail_check() {
local _jail="${1}"
# Check if the jail is thick and is running
check_target_is_stopped "${_jail}" || if [ "${AUTO}" -eq 1 ]; then
echo "Auto-stopping ${_jail}..."
bastille stop "${_jail}"
else
info "[${TARGET}]:"
error_notify "Jail is running."
error_exit "Use [-a|--auto] to auto-stop the jail."
fi
@@ -206,6 +207,8 @@ if grep -qw "${bastille_jailsdir}/${TARGET}/root/.bastille" "${bastille_jailsdir
THIN_JAIL=1
fi
info "\n[${TARGET}]:"
# Check what we should upgrade
if [ "${NEWRELEASE}" = "install" ]; then
if [ "${THIN_JAIL}" -eq 1 ]; then
@@ -223,3 +226,5 @@ else
fi
jail_upgrade "${TARGET}" "${NEWRELEASE}"
fi
echo

View File

@@ -35,6 +35,7 @@
usage() {
error_notify "Usage: bastille verify [RELEASE|TEMPLATE]"
cat << EOF
Options:
-x | --debug Enable debug mode.
@@ -198,3 +199,5 @@ case "${1}" in
usage
;;
esac
echo

View File

@@ -35,6 +35,7 @@
usage() {
error_notify "Usage: bastille zfs TARGET [set|get|snap|destroy_snap|df|usage] [key=value|date]"
cat << EOF
Options:
-x | --debug Enable debug mode.
@@ -46,40 +47,31 @@ EOF
zfs_snapshot() {
for _jail in ${JAILS}; do
info "[${_jail}]:"
info "\n[${_jail}]:"
# shellcheck disable=SC2140
zfs snapshot -r "${bastille_zfs_zpool}/${bastille_zfs_prefix}/jails/${_jail}"@"${TAG}"
# Print blank line
echo
done
}
zfs_destroy_snapshot() {
for _jail in ${JAILS}; do
info "[${_jail}]:"
info "\n[${_jail}]:"
# shellcheck disable=SC2140
zfs destroy -r "${bastille_zfs_zpool}/${bastille_zfs_prefix}/jails/${_jail}"@"${TAG}"
# Print blank line
echo
done
}
zfs_set_value() {
for _jail in ${JAILS}; do
info "[${_jail}]:"
info "\n[${_jail}]:"
zfs "${ATTRIBUTE}" "${bastille_zfs_zpool}/${bastille_zfs_prefix}/jails/${_jail}"
# Print blank line
echo
done
}
@@ -87,11 +79,8 @@ done
zfs_get_value() {
for _jail in ${JAILS}; do
info "[${_jail}]:"
info "\n[${_jail}]:"
zfs get "${ATTRIBUTE}" "${bastille_zfs_zpool}/${bastille_zfs_prefix}/jails/${_jail}"
# Print blank line
echo
done
}
@@ -99,12 +88,9 @@ done
zfs_disk_usage() {
for _jail in ${JAILS}; do
info "[${_jail}]:"
info "\n[${_jail}]:"
zfs list -t all -o name,used,avail,refer,mountpoint,compress,ratio -r "${bastille_zfs_zpool}/${bastille_zfs_prefix}/jails/${_jail}"
# Print blank line
echo
done
}
@@ -174,3 +160,5 @@ case "${ACTION}" in
usage
;;
esac
echo