diff --git a/usr/local/bin/bastille b/usr/local/bin/bastille index 62b97bb7..b984f342 100755 --- a/usr/local/bin/bastille +++ b/usr/local/bin/bastille @@ -127,7 +127,7 @@ shift # Handle special-case commands first. case "${CMD}" in version|-v|--version) - echo -e "${COLOR_GREEN}${BASTILLE_VERSION}${COLOR_RESET}" + info "${BASTILLE_VERSION}" exit 0 ;; help|-h|--help) diff --git a/usr/local/share/bastille/bootstrap.sh b/usr/local/share/bastille/bootstrap.sh index 7608cc1d..35ee66f9 100644 --- a/usr/local/share/bastille/bootstrap.sh +++ b/usr/local/share/bastille/bootstrap.sh @@ -68,7 +68,7 @@ validate_release_url() { if ! fetch -qo /dev/null "${UPSTREAM_URL}/MANIFEST" 2>/dev/null; then error_exit "Unable to fetch MANIFEST. See 'bootstrap urls'." fi - echo -e "${COLOR_GREEN}Bootstrapping ${PLATFORM_OS} distfiles...${COLOR_RESET}" + info "Bootstrapping ${PLATFORM_OS} distfiles..." # Alternate RELEASE/ARCH fetch support if [ "${OPTION}" = "--i386" -o "${OPTION}" = "--32bit" ]; then @@ -203,7 +203,7 @@ bootstrap_release() { if [ -z "${bastille_bootstrap_archives}" ]; then error_exit "Bootstrap appears complete." else - echo -e "${COLOR_GREEN}Bootstrapping additional distfiles...${COLOR_RESET}" + info "Bootstrapping additional distfiles..." fi fi @@ -211,7 +211,7 @@ bootstrap_release() { ## check if the dist files already exists then extract FETCH_VALIDATION="0" if [ -f "${bastille_cachedir}/${RELEASE}/${_archive}.txz" ]; then - echo -e "${COLOR_GREEN}Extracting ${PLATFORM_OS} ${RELEASE} ${_archive}.txz.${COLOR_RESET}" + info "Extracting ${PLATFORM_OS} ${RELEASE} ${_archive}.txz." if /usr/bin/tar -C "${bastille_releasesdir}/${RELEASE}" -xf "${bastille_cachedir}/${RELEASE}/${_archive}.txz"; then ## silence motd at container login touch "${bastille_releasesdir}/${RELEASE}/root/.hushlogin" @@ -267,15 +267,15 @@ bootstrap_release() { rm "${bastille_cachedir}/${RELEASE}/${_archive}.txz" error_exit "Failed validation for ${_archive}.txz. Please retry bootstrap!" else - echo -e "${COLOR_GREEN}Validated checksum for ${RELEASE}:${_archive}.txz.${COLOR_RESET}" - echo -e "${COLOR_GREEN}MANIFEST:${SHA256_DIST}${COLOR_RESET}" - echo -e "${COLOR_GREEN}DOWNLOAD:${SHA256_FILE}${COLOR_RESET}" + info "Validated checksum for ${RELEASE}: ${_archive}.txz" + info "MANIFEST: ${SHA256_DIST}" + info "DOWNLOAD: ${SHA256_FILE}" fi fi ## extract the fetched dist files if [ -f "${bastille_cachedir}/${RELEASE}/${_archive}.txz" ]; then - echo -e "${COLOR_GREEN}Extracting ${PLATFORM_OS} ${RELEASE} ${_archive}.txz.${COLOR_RESET}" + info "Extracting ${PLATFORM_OS} ${RELEASE} ${_archive}.txz." if /usr/bin/tar -C "${bastille_releasesdir}/${RELEASE}" -xf "${bastille_cachedir}/${RELEASE}/${_archive}.txz"; then ## silence motd at container login touch "${bastille_releasesdir}/${RELEASE}/root/.hushlogin" @@ -288,8 +288,8 @@ bootstrap_release() { done echo - echo -e "${COLOR_GREEN}Bootstrap successful.${COLOR_RESET}" - echo -e "${COLOR_GREEN}See 'bastille --help' for available commands.${COLOR_RESET}" + info "Bootstrap successful." + info "See 'bastille --help' for available commands." echo } diff --git a/usr/local/share/bastille/clone.sh b/usr/local/share/bastille/clone.sh index e3badf25..bc9c34e6 100644 --- a/usr/local/share/bastille/clone.sh +++ b/usr/local/share/bastille/clone.sh @@ -54,7 +54,7 @@ validate_ip() { IP6_MODE="disable" ip6=$(echo "${IP}" | grep -E '^(([a-fA-F0-9:]+$)|([a-fA-F0-9:]+\/[0-9]{1,3}$))') if [ -n "${ip6}" ]; then - echo -e "${COLOR_GREEN}Valid: (${ip6}).${COLOR_RESET}" + info "Valid: (${ip6})." IPX_ADDR="ip6.addr" IP6_MODE="new" else @@ -69,9 +69,9 @@ validate_ip() { fi done if ifconfig | grep -qw "${TEST_IP}"; then - echo -e "${COLOR_YELLOW}Warning: ip address already in use (${TEST_IP}).${COLOR_RESET}" + warn "Warning: IP address already in use (${TEST_IP})." else - echo -e "${COLOR_GREEN}Valid: (${IP}).${COLOR_RESET}" + info "Valid: (${IP})." fi else error_exit "Invalid: (${IP})." @@ -144,7 +144,7 @@ update_fstab() { clone_jail() { # Attempt container clone - echo -e "${COLOR_GREEN}Attempting to clone '${TARGET}' to ${NEWNAME}...${COLOR_RESET}" + info "Attempting to clone '${TARGET}' to ${NEWNAME}..." if ! [ -d "${bastille_jailsdir}/${NEWNAME}" ]; then if [ "${bastille_zfs_enable}" = "YES" ]; then if [ -n "${bastille_zfs_zpool}" ]; then @@ -183,7 +183,7 @@ clone_jail() { if [ "$?" -ne 0 ]; then error_exit "An error has occurred while attempting to clone '${TARGET}'." else - echo -e "${COLOR_GREEN}Cloned '${TARGET}' to '${NEWNAME}' successfully.${COLOR_RESET}" + info "Cloned '${TARGET}' to '${NEWNAME}' successfully." fi } diff --git a/usr/local/share/bastille/cmd.sh b/usr/local/share/bastille/cmd.sh index dcb63506..3ebc1ad3 100644 --- a/usr/local/share/bastille/cmd.sh +++ b/usr/local/share/bastille/cmd.sh @@ -46,7 +46,7 @@ if [ $# -eq 0 ]; then fi for _jail in ${JAILS}; do - echo -e "${COLOR_GREEN}[${_jail}]:${COLOR_RESET}" + info "[${_jail}]:" jexec -l "${_jail}" "$@" echo done diff --git a/usr/local/share/bastille/common.sh b/usr/local/share/bastille/common.sh index 285b843e..4dd30c1a 100644 --- a/usr/local/share/bastille/common.sh +++ b/usr/local/share/bastille/common.sh @@ -40,3 +40,11 @@ error_exit() { error_notify $@ exit 1 } + +info() { + echo -e "${COLOR_GREEN}$*${COLOR_RESET}" +} + +warn() { + echo -e "${COLOR_YELLOW}$*${COLOR_RESET}" +} diff --git a/usr/local/share/bastille/console.sh b/usr/local/share/bastille/console.sh index 149291d1..30066ade 100644 --- a/usr/local/share/bastille/console.sh +++ b/usr/local/share/bastille/console.sh @@ -65,7 +65,7 @@ validate_user() { } for _jail in ${JAILS}; do - echo -e "${COLOR_GREEN}[${_jail}]:${COLOR_RESET}" + info "[${_jail}]:" if [ -n "${USER}" ]; then validate_user else diff --git a/usr/local/share/bastille/convert.sh b/usr/local/share/bastille/convert.sh index 7ecc76cf..29aa7af7 100644 --- a/usr/local/share/bastille/convert.sh +++ b/usr/local/share/bastille/convert.sh @@ -101,7 +101,7 @@ revert_convert() { start_convert() { # Attempt container conversion and handle some errors if [ -d "${bastille_jailsdir}/${TARGET}" ]; then - echo -e "${COLOR_GREEN}Converting '${TARGET}' into a thickjail, this may take a while...${COLOR_RESET}" + info "Converting '${TARGET}' into a thickjail. This may take a while..." # Set some variables RELEASE=$(grep -owE '([1-9]{2,2})\.[0-9](-RELEASE|-RELEASE-i386|-RC[1-2])|([0-9]{1,2}-stable-build-[0-9]{1,3})|(current-build)-([0-9]{1,3})|(current-BUILD-LATEST)|([0-9]{1,2}-stable-BUILD-LATEST)|(current-BUILD-LATEST)' "${bastille_jailsdir}/${TARGET}/fstab") @@ -118,7 +118,7 @@ start_convert() { sed -i '' -E "s|${FSTABMOD}|# Converted from thin to thick container on $(date)|g" "${bastille_jailsdir}/${TARGET}/fstab" mv "${bastille_jailsdir}/${TARGET}/root/.bastille" "${bastille_jailsdir}/${TARGET}/root/.bastille.old" - echo -e "${COLOR_GREEN}Conversion of '${TARGET}' completed successfully!${COLOR_RESET}" + info "Conversion of '${TARGET}' completed successfully!" exit 0 else error_exit "Can't determine release version. See 'bastille bootstrap'." diff --git a/usr/local/share/bastille/cp.sh b/usr/local/share/bastille/cp.sh index 8c59ba69..3e179589 100644 --- a/usr/local/share/bastille/cp.sh +++ b/usr/local/share/bastille/cp.sh @@ -51,7 +51,7 @@ CPDEST="${2}" for _jail in ${JAILS}; do bastille_jail_path="$(jls -j "${_jail}" path)" - echo -e "${COLOR_GREEN}[${_jail}]:${COLOR_RESET}" + info "[${_jail}]:" cp -av "${CPSOURCE}" "${bastille_jail_path}/${CPDEST}" RETURN="$?" if [ "${TARGET}" = "ALL" ]; then diff --git a/usr/local/share/bastille/create.sh b/usr/local/share/bastille/create.sh index 8e69a0c8..141edfba 100644 --- a/usr/local/share/bastille/create.sh +++ b/usr/local/share/bastille/create.sh @@ -56,7 +56,7 @@ validate_ip() { IP6_MODE="disable" ip6=$(echo "${IP}" | grep -E '^(([a-fA-F0-9:]+$)|([a-fA-F0-9:]+\/[0-9]{1,3}$))') if [ -n "${ip6}" ]; then - echo -e "${COLOR_GREEN}Valid: (${ip6}).${COLOR_RESET}" + info "Valid: (${ip6})." IPX_ADDR="ip6.addr" IP6_MODE="new" else @@ -72,9 +72,9 @@ validate_ip() { fi done if ifconfig | grep -qw "${TEST_IP}"; then - echo -e "${COLOR_YELLOW}Warning: ip address already in use (${TEST_IP}).${COLOR_RESET}" + warn "Warning: IP address already in use (${TEST_IP})." else - echo -e "${COLOR_GREEN}Valid: (${IP}).${COLOR_RESET}" + info "Valid: (${IP})." fi else error_exit "Invalid: (${IP})." @@ -85,7 +85,7 @@ validate_ip() { validate_netif() { local LIST_INTERFACES=$(ifconfig -l) if echo "${LIST_INTERFACES} VNET" | grep -qwo "${INTERFACE}"; then - echo -e "${COLOR_GREEN}Valid: (${INTERFACE}).${COLOR_RESET}" + info "Valid: (${INTERFACE})." else error_exit "Invalid: (${INTERFACE})." fi @@ -248,12 +248,12 @@ create_jail() { ## MAKE SURE WE'RE IN THE RIGHT PLACE cd "${bastille_jail_path}" echo - echo -e "${COLOR_GREEN}NAME: ${NAME}.${COLOR_RESET}" - echo -e "${COLOR_GREEN}IP: ${IP}.${COLOR_RESET}" + info "NAME: ${NAME}." + info "IP: ${IP}." if [ -n "${INTERFACE}" ]; then - echo -e "${COLOR_GREEN}INTERFACE: ${INTERFACE}.${COLOR_RESET}" + info "INTERFACE: ${INTERFACE}." fi - echo -e "${COLOR_GREEN}RELEASE: ${RELEASE}.${COLOR_RESET}" + info "RELEASE: ${RELEASE}." echo if [ -z "${THICK_JAIL}" ]; then @@ -278,7 +278,7 @@ create_jail() { fi done else - echo -e "${COLOR_GREEN}Creating a thickjail, this may take a while...${COLOR_RESET}" + info "Creating a thickjail. This may take a while..." if [ "${bastille_zfs_enable}" = "YES" ]; then if [ -n "${bastille_zfs_zpool}" ]; then ## perform release base replication @@ -527,7 +527,7 @@ if [ -z "${EMPTY_JAIL}" ]; then validate_netconf fi else - echo -e "${COLOR_GREEN}Creating empty jail: ${NAME}.${COLOR_RESET}" + info "Creating empty jail: ${NAME}." fi ## check if a running jail matches name or already exist diff --git a/usr/local/share/bastille/destroy.sh b/usr/local/share/bastille/destroy.sh index fb28e360..a4bb3c57 100644 --- a/usr/local/share/bastille/destroy.sh +++ b/usr/local/share/bastille/destroy.sh @@ -54,7 +54,7 @@ destroy_jail() { fi if [ -d "${bastille_jail_base}" ]; then - echo -e "${COLOR_GREEN}Deleting Jail: ${TARGET}.${COLOR_RESET}" + info "Deleting Jail: ${TARGET}." if [ "${bastille_zfs_enable}" = "YES" ]; then if [ -n "${bastille_zfs_zpool}" ]; then if [ -n "${TARGET}" ]; then @@ -79,13 +79,13 @@ destroy_jail() { ## archive jail log if [ -f "${bastille_jail_log}" ]; then mv "${bastille_jail_log}" "${bastille_jail_log}"-"$(date +%F)" - echo -e "${COLOR_GREEN}Note: jail console logs archived.${COLOR_RESET}" - echo -e "${COLOR_GREEN}${bastille_jail_log}-$(date +%F)${COLOR_RESET}" + info "Note: jail console logs archived." + info "${bastille_jail_log}-$(date +%F)" fi ## clear any active rdr rules if [ ! -z "$(pfctl -a "rdr/${TARGET}" -Psn 2>/dev/null)" ]; then - echo -e "${COLOR_GREEN}Clearing RDR rules:${COLOR_RESET}" + info "Clearing RDR rules:" pfctl -a "rdr/${TARGET}" -Fn fi echo @@ -120,7 +120,7 @@ destroy_rel() { error_exit "Release base not found." else if [ "${BASE_HASCHILD}" -eq "0" ]; then - echo -e "${COLOR_GREEN}Deleting base: ${TARGET}.${COLOR_RESET}" + info "Deleting base: ${TARGET}" if [ "${bastille_zfs_enable}" = "YES" ]; then if [ -n "${bastille_zfs_zpool}" ]; then if [ -n "${TARGET}" ]; then diff --git a/usr/local/share/bastille/export.sh b/usr/local/share/bastille/export.sh index 09256b12..e2773376 100644 --- a/usr/local/share/bastille/export.sh +++ b/usr/local/share/bastille/export.sh @@ -90,8 +90,8 @@ jail_export() if [ "${bastille_zfs_enable}" = "YES" ]; then if [ -n "${bastille_zfs_zpool}" ]; then FILE_EXT="xz" - echo -e "${COLOR_GREEN}Exporting '${TARGET}' to a compressed .${FILE_EXT} archive.${COLOR_RESET}" - echo -e "${COLOR_GREEN}Sending zfs data stream...${COLOR_RESET}" + info "Exporting '${TARGET}' to a compressed .${FILE_EXT} archive." + info "Sending zfs data stream..." # Take a recursive temporary snapshot zfs snapshot -r "${bastille_zfs_zpool}/${bastille_zfs_prefix}/jails/${TARGET}@bastille_export_${DATE}" @@ -104,7 +104,7 @@ jail_export() else # Create standard backup archive FILE_EXT="txz" - echo -e "${COLOR_GREEN}Exporting '${TARGET}' to a compressed .${FILE_EXT} archive...${COLOR_RESET}" + info "Exporting '${TARGET}' to a compressed .${FILE_EXT} archive..." cd "${bastille_jailsdir}" && tar -cf - "${TARGET}" | xz ${bastille_compress_xz_options} > "${bastille_backupsdir}/${TARGET}_${DATE}.${FILE_EXT}" fi @@ -114,7 +114,7 @@ jail_export() # Generate container checksum file cd "${bastille_backupsdir}" sha256 -q "${TARGET}_${DATE}.${FILE_EXT}" > "${TARGET}_${DATE}.sha256" - echo -e "${COLOR_GREEN}Exported '${bastille_backupsdir}/${TARGET}_${DATE}.${FILE_EXT}' successfully.${COLOR_RESET}" + info "Exported '${bastille_backupsdir}/${TARGET}_${DATE}.${FILE_EXT}' successfully." exit 0 fi } diff --git a/usr/local/share/bastille/htop.sh b/usr/local/share/bastille/htop.sh index 6f1bdf20..df792eea 100644 --- a/usr/local/share/bastille/htop.sh +++ b/usr/local/share/bastille/htop.sh @@ -51,7 +51,7 @@ for _jail in ${JAILS}; do if [ ! -x "${bastille_jail_path}/usr/local/bin/htop" ]; then error_notify "htop not found on ${_jail}." elif [ -x "${bastille_jail_path}/usr/local/bin/htop" ]; then - echo -e "${COLOR_GREEN}[${_jail}]:${COLOR_RESET}" + info "[${_jail}]:" jexec -l ${_jail} /usr/local/bin/htop fi echo -e "${COLOR_RESET}" diff --git a/usr/local/share/bastille/import.sh b/usr/local/share/bastille/import.sh index eecad9f1..5ac259f3 100644 --- a/usr/local/share/bastille/import.sh +++ b/usr/local/share/bastille/import.sh @@ -56,25 +56,25 @@ validate_archive() { if [ "${FILE_EXT}" != ".tar.gz" ] && [ "${FILE_EXT}" != ".tar" ]; then if [ -f "${bastille_backupsdir}/${TARGET}" ]; then if [ -f "${bastille_backupsdir}/${FILE_TRIM}.sha256" ]; then - echo -e "${COLOR_GREEN}Validating file: ${TARGET}...${COLOR_RESET}" + info "Validating file: ${TARGET}..." SHA256_DIST=$(cat "${bastille_backupsdir}/${FILE_TRIM}.sha256") SHA256_FILE=$(sha256 -q "${bastille_backupsdir}/${TARGET}") if [ "${SHA256_FILE}" != "${SHA256_DIST}" ]; then error_exit "Failed validation for ${TARGET}." else - echo -e "${COLOR_GREEN}File validation successful!${COLOR_RESET}" + info "File validation successful!" fi else # Check if user opt to force import if [ "${OPTION}" = "-f" -o "${OPTION}" = "force" ]; then - echo -e "${COLOR_YELLOW}Warning: Skipping archive validation!${COLOR_RESET}" + warn "Warning: Skipping archive validation!" else error_exit "Checksum file not found. See 'bastille import TARGET -f'." fi fi fi else - echo -e "${COLOR_YELLOW}Warning: Skipping archive validation!${COLOR_RESET}" + warn "Warning: Skipping archive validation!" fi } @@ -83,7 +83,7 @@ update_zfsmount() { OLD_ZFS_MOUNTPOINT=$(zfs get -H mountpoint "${bastille_zfs_zpool}/${bastille_zfs_prefix}/jails/${TARGET_TRIM}/root" | awk '{print $3}') NEW_ZFS_MOUNTPOINT="${bastille_jailsdir}/${TARGET_TRIM}/root" if [ "${NEW_ZFS_MOUNTPOINT}" != "${OLD_ZFS_MOUNTPOINT}" ]; then - echo -e "${COLOR_GREEN}Updating zfs mountpoint...${COLOR_RESET}" + info "Updating ZFS mountpoint..." zfs set mountpoint="${bastille_jailsdir}/${TARGET_TRIM}/root" "${bastille_zfs_zpool}/${bastille_zfs_prefix}/jails/${TARGET_TRIM}/root" fi @@ -101,7 +101,7 @@ update_jailconf() { JAIL_CONFIG="${bastille_jailsdir}/${TARGET_TRIM}/jail.conf" if [ -f "${JAIL_CONFIG}" ]; then if ! grep -qw "path = ${bastille_jailsdir}/${TARGET_TRIM}/root;" "${JAIL_CONFIG}"; then - echo -e "${COLOR_GREEN}Updating jail.conf...${COLOR_RESET}" + info "Updating jail.conf..." sed -i '' "s|exec.consolelog.*=.*;|exec.consolelog = ${bastille_logsdir}/${TARGET_TRIM}_console.log;|" "${JAIL_CONFIG}" sed -i '' "s|path.*=.*;|path = ${bastille_jailsdir}/${TARGET_TRIM}/root;|" "${JAIL_CONFIG}" sed -i '' "s|mount.fstab.*=.*;|mount.fstab = ${bastille_jailsdir}/${TARGET_TRIM}/fstab;|" "${JAIL_CONFIG}" @@ -119,7 +119,7 @@ update_fstab() { if [ -n "${FSTAB_CURRENT}" ] && [ -n "${FSTAB_NEWCONF}" ]; then # If both variables are set, compare and update as needed if ! grep -qw "${bastille_releasesdir}/${FSTAB_RELEASE}.*${bastille_jailsdir}/${TARGET_TRIM}/root/.bastille" "${FSTAB_CONFIG}"; then - echo -e "${COLOR_GREEN}Updating fstab...${COLOR_RESET}" + info "Updating fstab..." sed -i '' "s|${FSTAB_CURRENT}|${FSTAB_NEWCONF}|" "${FSTAB_CONFIG}" fi fi @@ -128,7 +128,7 @@ update_fstab() { generate_config() { # Attempt to read previous config file and set required variables accordingly # If we can't get a valid interface, fallback to lo1 and warn user - echo -e "${COLOR_GREEN}Generating jail.conf...${COLOR_RESET}" + info "Generating jail.conf..." if [ "${FILE_EXT}" = ".zip" ]; then # Gather some bits from foreign/iocage config files @@ -188,7 +188,7 @@ generate_config() { IPX_ADDR="ip4.addr" IP_CONFIG="-" IP6_MODE="disable" - echo -e "${COLOR_YELLOW}Warning: See 'bastille edit ${TARGET_TRIM} jail.conf' for manual network configuration${COLOR_RESET}" + warn "Warning: See 'bastille edit ${TARGET_TRIM} jail.conf' for manual network configuration." fi if [ "${FILE_EXT}" = ".tar.gz" ]; then @@ -196,7 +196,7 @@ generate_config() { if [ -z "${CONFIG_RELEASE}" ]; then # Fallback to host version CONFIG_RELEASE=$(freebsd-version | sed 's/\-[pP].*//') - echo -e "${COLOR_YELLOW}Warning: ${CONFIG_RELEASE} was set by default!${COLOR_RESET}" + warn "Warning: ${CONFIG_RELEASE} was set by default!" fi mkdir "${bastille_jailsdir}/${TARGET_TRIM}/root/.bastille" echo "${bastille_releasesdir}/${CONFIG_RELEASE} ${bastille_jailsdir}/${TARGET_TRIM}/root/.bastille nullfs ro 0 0" \ @@ -241,7 +241,7 @@ update_config() { if [ -z "${CONFIG_RELEASE}" ]; then # Fallback to host version CONFIG_RELEASE=$(freebsd-version | sed 's/\-[pP].*//') - echo -e "${COLOR_YELLOW}Warning: ${CONFIG_RELEASE} was set by default!${COLOR_RESET}" + warn "Warning: ${CONFIG_RELEASE} was set by default!" fi mkdir "${bastille_jailsdir}/${TARGET_TRIM}/root/.bastille" echo "${bastille_releasesdir}/${CONFIG_RELEASE} ${bastille_jailsdir}/${TARGET_TRIM}/root/.bastille nullfs ro 0 0" \ @@ -282,11 +282,11 @@ update_symlinks() { # Just warn user to bootstrap the release if missing if [ ! -d "${bastille_releasesdir}/${CONFIG_RELEASE}" ]; then - echo -e "${COLOR_YELLOW}Warning: ${CONFIG_RELEASE} must be bootstrapped, See 'bastille bootstrap'.${COLOR_RESET}" + warn "Warning: ${CONFIG_RELEASE} must be bootstrapped. See 'bastille bootstrap'." fi # Update old symlinks - echo -e "${COLOR_GREEN}Updating symlinks...${COLOR_RESET}" + info "Updating symlinks..." for _link in ${SYMLINKS}; do if [ -L "${_link}" ]; then ln -sf /.bastille/${_link} ${_link} @@ -296,8 +296,8 @@ update_symlinks() { create_zfs_datasets() { # Prepare the ZFS environment and restore from file - echo -e "${COLOR_GREEN}Importing '${TARGET_TRIM}' from foreign compressed ${FILE_EXT} archive.${COLOR_RESET}" - echo -e "${COLOR_GREEN}Preparing zfs environment...${COLOR_RESET}" + info "Importing '${TARGET_TRIM}' from foreign compressed ${FILE_EXT} archive." + info "Preparing ZFS environment..." # Create required ZFS datasets, mountpoint inherited from system zfs create ${bastille_zfs_options} "${bastille_zfs_zpool}/${bastille_zfs_prefix}/jails/${TARGET_TRIM}" @@ -321,8 +321,8 @@ jail_import() { if [ -n "${bastille_zfs_zpool}" ]; then if [ "${FILE_EXT}" = ".xz" ]; then # Import from compressed xz on ZFS systems - echo -e "${COLOR_GREEN}Importing '${TARGET_TRIM}' from compressed ${FILE_EXT} archive.${COLOR_RESET}" - echo -e "${COLOR_GREEN}Receiving zfs data stream...${COLOR_RESET}" + info "Importing '${TARGET_TRIM}' from compressed ${FILE_EXT} archive." + info "Receiving ZFS data stream..." xz ${bastille_decompress_xz_options} "${bastille_backupsdir}/${TARGET}" | \ zfs receive -u "${bastille_zfs_zpool}/${bastille_zfs_prefix}/jails/${TARGET_TRIM}" @@ -334,7 +334,7 @@ jail_import() { create_zfs_datasets # Extract required files to the new datasets - echo -e "${COLOR_GREEN}Extracting files from '${TARGET}' archive...${COLOR_RESET}" + info "Extracting files from '${TARGET}' archive..." tar --exclude='root' -Jxf "${bastille_backupsdir}/${TARGET}" --strip-components 1 -C "${bastille_jailsdir}/${TARGET_TRIM}" tar -Jxf "${bastille_backupsdir}/${TARGET}" --strip-components 2 -C "${bastille_jailsdir}/${TARGET_TRIM}/root" "${TARGET_TRIM}/root" if [ "$?" -ne 0 ]; then @@ -342,7 +342,7 @@ jail_import() { fi elif [ "${FILE_EXT}" = ".zip" ]; then # Attempt to import a foreign/iocage container - echo -e "${COLOR_GREEN}Importing '${TARGET_TRIM}' from foreign compressed ${FILE_EXT} archive.${COLOR_RESET}" + info "Importing '${TARGET_TRIM}' from foreign compressed ${FILE_EXT} archive." # Sane bastille zfs options ZFS_OPTIONS=$(echo ${bastille_zfs_options} | sed 's/-o//g') @@ -352,7 +352,7 @@ jail_import() { error_exit "Failed to extract files from '${TARGET}' archive." rm -f "${FILE_TRIM}" "${FILE_TRIM}_root" fi - echo -e "${COLOR_GREEN}Receiving zfs data stream...${COLOR_RESET}" + info "Receiving ZFS data stream..." zfs receive -u "${bastille_zfs_zpool}/${bastille_zfs_prefix}/jails/${TARGET_TRIM}" < "${FILE_TRIM}" zfs set ${ZFS_OPTIONS} "${bastille_zfs_zpool}/${bastille_zfs_prefix}/jails/${TARGET_TRIM}" zfs receive -u "${bastille_zfs_zpool}/${bastille_zfs_prefix}/jails/${TARGET_TRIM}/root" < "${FILE_TRIM}_root" @@ -376,7 +376,7 @@ jail_import() { create_zfs_datasets # Extract required files to the new datasets - echo -e "${COLOR_GREEN}Extracting files from '${TARGET}' archive...${COLOR_RESET}" + info "Extracting files from '${TARGET}' archive..." tar --exclude='ezjail/' -xf "${bastille_backupsdir}/${TARGET}" -C "${bastille_jailsdir}/${TARGET_TRIM}" tar -xf "${bastille_backupsdir}/${TARGET}" --strip-components 1 -C "${bastille_jailsdir}/${TARGET_TRIM}/root" if [ "$?" -ne 0 ]; then @@ -391,7 +391,7 @@ jail_import() { workout_components # Extract required files to the new datasets - echo -e "${COLOR_GREEN}Extracting files from '${TARGET}' archive...${COLOR_RESET}" + info "Extracting files from '${TARGET}' archive..." tar -xf "${bastille_backupsdir}/${TARGET}" --strip-components "${CONF_TRIM}" -C "${bastille_jailsdir}/${TARGET_TRIM}" "${JAIL_CONF}" tar -xf "${bastille_backupsdir}/${TARGET}" --strip-components "${DIRS_PLUS}" -C "${bastille_jailsdir}/${TARGET_TRIM}/root" "${JAIL_PATH}" if [ -f "${bastille_jailsdir}/${TARGET_TRIM}/${TARGET_TRIM}" ]; then @@ -410,18 +410,18 @@ jail_import() { else # Import from standard supported archives on UFS systems if [ "${FILE_EXT}" = ".txz" ]; then - echo -e "${COLOR_GREEN}Extracting files from '${TARGET}' archive...${COLOR_RESET}" + info "Extracting files from '${TARGET}' archive..." tar -Jxf "${bastille_backupsdir}/${TARGET}" -C "${bastille_jailsdir}" elif [ "${FILE_EXT}" = ".tar.gz" ]; then # Attempt to import/configure foreign/ezjail container - echo -e "${COLOR_GREEN}Extracting files from '${TARGET}' archive...${COLOR_RESET}" + info "Extracting files from '${TARGET}' archive..." mkdir "${bastille_jailsdir}/${TARGET_TRIM}" tar -xf "${bastille_backupsdir}/${TARGET}" -C "${bastille_jailsdir}/${TARGET_TRIM}" mv "${bastille_jailsdir}/${TARGET_TRIM}/ezjail" "${bastille_jailsdir}/${TARGET_TRIM}/root" generate_config elif [ "${FILE_EXT}" = ".tar" ]; then # Attempt to import/configure foreign/qjail container - echo -e "${COLOR_GREEN}Extracting files from '${TARGET}' archive...${COLOR_RESET}" + info "Extracting files from '${TARGET}' archive..." mkdir -p "${bastille_jailsdir}/${TARGET_TRIM}/root" workout_components tar -xf "${bastille_backupsdir}/${TARGET}" --strip-components "${CONF_TRIM}" -C "${bastille_jailsdir}/${TARGET_TRIM}" "${JAIL_CONF}" @@ -442,7 +442,7 @@ jail_import() { # This is required on foreign imports only update_jailconf update_fstab - echo -e "${COLOR_GREEN}Container '${TARGET_TRIM}' imported successfully.${COLOR_RESET}" + info "Container '${TARGET_TRIM}' imported successfully." exit 0 fi else diff --git a/usr/local/share/bastille/limits.sh b/usr/local/share/bastille/limits.sh index 1d4de5cb..ca48427d 100644 --- a/usr/local/share/bastille/limits.sh +++ b/usr/local/share/bastille/limits.sh @@ -59,7 +59,7 @@ OPTION="${1}" VALUE="${2}" for _jail in ${JAILS}; do - echo -e "${COLOR_GREEN}[${_jail}]:${COLOR_RESET}" + info "[${_jail}]:" _rctl_rule="jail:${_jail}:${OPTION}:deny=${VALUE}/jail" diff --git a/usr/local/share/bastille/mount.sh b/usr/local/share/bastille/mount.sh index 21173ab7..fc37b1e5 100644 --- a/usr/local/share/bastille/mount.sh +++ b/usr/local/share/bastille/mount.sh @@ -60,37 +60,37 @@ _checks=$(echo "${_fstab}" | awk '{print $5" "$6}') ## if any variables are empty, bail out if [ -z "${_hostpath}" ] || [ -z "${_jailpath}" ] || [ -z "${_type}" ] || [ -z "${_perms}" ] || [ -z "${_checks}" ]; then error_notify "FSTAB format not recognized." - echo -e "${COLOR_YELLOW}Format: /host/path jail/path nullfs ro 0 0${COLOR_RESET}" - echo -e "${COLOR_YELLOW}Read: ${_fstab}${COLOR_RESET}" + warn "Format: /host/path jail/path nullfs ro 0 0" + warn "Read: ${_fstab}" exit 1 fi ## if host path doesn't exist or type is not "nullfs" if [ ! -d "${_hostpath}" ] || [ "${_type}" != "nullfs" ]; then error_notify "Detected invalid host path or incorrect mount type in FSTAB." - echo -e "${COLOR_YELLOW}Format: /host/path jail/path nullfs ro 0 0${COLOR_RESET}" - echo -e "${COLOR_YELLOW}Read: ${_fstab}${COLOR_RESET}" + warn "Format: /host/path jail/path nullfs ro 0 0" + warn "Read: ${_fstab}" exit 1 fi ## if mount permissions are not "ro" or "rw" if [ "${_perms}" != "ro" ] && [ "${_perms}" != "rw" ]; then error_notify "Detected invalid mount permissions in FSTAB." - echo -e "${COLOR_YELLOW}Format: /host/path jail/path nullfs ro 0 0${COLOR_RESET}" - echo -e "${COLOR_YELLOW}Read: ${_fstab}${COLOR_RESET}" + warn "Format: /host/path jail/path nullfs ro 0 0" + warn "Read: ${_fstab}" exit 1 fi ## if check & pass are not "0 0 - 1 1"; bail out if [ "${_checks}" != "0 0" ] && [ "${_checks}" != "1 0" ] && [ "${_checks}" != "0 1" ] && [ "${_checks}" != "1 1" ]; then error_notify "Detected invalid fstab options in FSTAB." - echo -e "${COLOR_YELLOW}Format: /host/path jail/path nullfs ro 0 0${COLOR_RESET}" - echo -e "${COLOR_YELLOW}Read: ${_fstab}${COLOR_RESET}" + warn "Format: /host/path jail/path nullfs ro 0 0" + warn "Read: ${_fstab}" exit 1 fi for _jail in ${JAILS}; do - echo -e "${COLOR_GREEN}[${_jail}]:${COLOR_RESET}" + info "[${_jail}]:" ## aggregate variables into FSTAB entry _jailpath="${bastille_jailsdir}/${_jail}/root/${_jailpath}" diff --git a/usr/local/share/bastille/pkg.sh b/usr/local/share/bastille/pkg.sh index d3f7181c..715b6438 100644 --- a/usr/local/share/bastille/pkg.sh +++ b/usr/local/share/bastille/pkg.sh @@ -46,7 +46,7 @@ if [ $# -lt 1 ]; then fi for _jail in ${JAILS}; do - echo -e "${COLOR_GREEN}[${_jail}]:${COLOR_RESET}" + info "[${_jail}]:" jexec -l "${_jail}" /usr/sbin/pkg "$@" echo done diff --git a/usr/local/share/bastille/rename.sh b/usr/local/share/bastille/rename.sh index 14541fb2..94fca660 100644 --- a/usr/local/share/bastille/rename.sh +++ b/usr/local/share/bastille/rename.sh @@ -88,7 +88,7 @@ update_fstab() { change_name() { # Attempt container name change - echo -e "${COLOR_GREEN}Attempting to rename '${TARGET}' to ${NEWNAME}...${COLOR_RESET}" + info "Attempting to rename '${TARGET}' to ${NEWNAME}..." if [ "${bastille_zfs_enable}" = "YES" ]; then if [ -n "${bastille_zfs_zpool}" ] && [ -n "${bastille_zfs_prefix}" ]; then # Check and rename container ZFS dataset accordingly @@ -131,7 +131,7 @@ change_name() { if [ "$?" -ne 0 ]; then error_exit "An error has occurred while attempting to rename '${TARGET}'." else - echo -e "${COLOR_GREEN}Renamed '${TARGET}' to '${NEWNAME}' successfully.${COLOR_RESET}" + info "Renamed '${TARGET}' to '${NEWNAME}' successfully." fi } diff --git a/usr/local/share/bastille/service.sh b/usr/local/share/bastille/service.sh index b90b881b..9ef37a72 100644 --- a/usr/local/share/bastille/service.sh +++ b/usr/local/share/bastille/service.sh @@ -46,7 +46,7 @@ if [ $# -ne 2 ]; then fi for _jail in ${JAILS}; do - echo -e "${COLOR_GREEN}[${_jail}]:${COLOR_RESET}" + info "[${_jail}]:" jexec -l "${_jail}" /usr/sbin/service "$@" echo done diff --git a/usr/local/share/bastille/start.sh b/usr/local/share/bastille/start.sh index 47f135a8..145c7be5 100644 --- a/usr/local/share/bastille/start.sh +++ b/usr/local/share/bastille/start.sh @@ -76,7 +76,7 @@ for _jail in ${JAILS}; do fi ## start the container - echo -e "${COLOR_GREEN}[${_jail}]:${COLOR_RESET}" + info "[${_jail}]:" jail -f "${bastille_jailsdir}/${_jail}/jail.conf" -c "${_jail}" ## add rctl limits diff --git a/usr/local/share/bastille/stop.sh b/usr/local/share/bastille/stop.sh index 21e84931..1aac57e2 100644 --- a/usr/local/share/bastille/stop.sh +++ b/usr/local/share/bastille/stop.sh @@ -64,7 +64,7 @@ for _jail in ${JAILS}; do fi ## stop container - echo -e "${COLOR_GREEN}[${_jail}]:${COLOR_RESET}" + info "[${_jail}]:" jail -f "${bastille_jailsdir}/${_jail}/jail.conf" -r "${_jail}" fi echo diff --git a/usr/local/share/bastille/sysrc.sh b/usr/local/share/bastille/sysrc.sh index 2ab807d1..eb368ee3 100644 --- a/usr/local/share/bastille/sysrc.sh +++ b/usr/local/share/bastille/sysrc.sh @@ -46,7 +46,7 @@ if [ $# -lt 1 ]; then fi for _jail in ${JAILS}; do - echo -e "${COLOR_GREEN}[${_jail}]:${COLOR_RESET}" + info "[${_jail}]:" jexec -l "${_jail}" /usr/sbin/sysrc "$@" echo -e "${COLOR_RESET}" done diff --git a/usr/local/share/bastille/template.sh b/usr/local/share/bastille/template.sh index 8ec25ca8..2f1e7a7e 100644 --- a/usr/local/share/bastille/template.sh +++ b/usr/local/share/bastille/template.sh @@ -101,7 +101,7 @@ render() { elif [ -f "${_file_path}" ]; then eval "sed -i '' ${ARG_REPLACEMENTS} '${_file_path}'" else - echo -e "${COLOR_YELLOW}Path not found for render: ${2}${COLOR_RESET}" + warn "Path not found for render: ${2}" fi } @@ -122,7 +122,7 @@ case ${TEMPLATE} in http?://github.com/*/*|http?://gitlab.com/*/*) TEMPLATE_DIR=$(echo "${TEMPLATE}" | awk -F / '{ print $4 "/" $5 }') if [ ! -d "${bastille_templatesdir}/${TEMPLATE_DIR}" ]; then - echo -e "${COLOR_GREEN}Bootstrapping ${TEMPLATE}...${COLOR_RESET}" + info "Bootstrapping ${TEMPLATE}..." if ! bastille bootstrap "${TEMPLATE}"; then error_exit "Failed to bootstrap template: ${TEMPLATE}" fi @@ -172,18 +172,18 @@ for _jail in ${JAILS}; do ## jail-specific variables. bastille_jail_path=$(jls -j "${_jail}" path) - echo -e "${COLOR_GREEN}[${_jail}]:${COLOR_RESET}" - echo -e "${COLOR_GREEN}Applying template: ${TEMPLATE}...${COLOR_RESET}" + info "[${_jail}]:" + info "Applying template: ${TEMPLATE}..." ## TARGET if [ -s "${bastille_template}/TARGET" ]; then if grep -qw "${_jail}" "${bastille_template}/TARGET"; then - echo -e "${COLOR_GREEN}TARGET: !${_jail}.${COLOR_RESET}" + info "TARGET: !${_jail}." echo continue fi if ! grep -Eq "(^|\b)(${_jail}|ALL)($|\b)" "${bastille_template}/TARGET"; then - echo -e "${COLOR_GREEN}TARGET: ?${_jail}.${COLOR_RESET}" + info "TARGET: ?${_jail}." echo continue fi @@ -199,7 +199,7 @@ for _jail in ${JAILS}; do _arg_name=$(get_arg_name "${_line}") _arg_value=$(get_arg_value "${_line}" "$@") if [ -z "${_arg_value}" ]; then - echo -e "${COLOR_YELLOW}No value provided for arg: ${_arg_name}${COLOR_RESET}" + warn "No value provided for arg: ${_arg_name}" fi # Build a list of sed commands like this: -e 's/${username}/root/g' -e 's/${domain}/example.com/g' ARG_REPLACEMENTS="${ARG_REPLACEMENTS} -e 's/\${${_arg_name}}/${_arg_value}/g'" @@ -225,7 +225,7 @@ for _jail in ${JAILS}; do _arg_name=$(get_arg_name "${_args}") _arg_value=$(get_arg_value "${_args}" "$@") if [ -z "${_arg_value}" ]; then - echo -e "${COLOR_YELLOW}No value provided for arg: ${_arg_name}${COLOR_RESET}" + warn "No value provided for arg: ${_arg_name}" fi # Build a list of sed commands like this: -e 's/${username}/root/g' -e 's/${domain}/example.com/g' ARG_REPLACEMENTS="${ARG_REPLACEMENTS} -e 's/\${${_arg_name}}/${_arg_value}/g'" @@ -279,7 +279,7 @@ for _jail in ${JAILS}; do # Override default command/args for some hooks. -- cwells case ${_hook} in CONFIG) - echo -e "${COLOR_YELLOW}CONFIG deprecated; rename to OVERLAY.${COLOR_RESET}" + warn "CONFIG deprecated; rename to OVERLAY." _args_template='${bastille_template}/${_line} /' _cmd='cp' ;; FSTAB) @@ -290,7 +290,7 @@ for _jail in ${JAILS}; do _args_template='${bastille_template}/${_line} /' _cmd='cp' ;; PF) - echo -e "${COLOR_GREEN}NOT YET IMPLEMENTED.${COLOR_RESET}" + info "NOT YET IMPLEMENTED." continue ;; PRE) _cmd='cmd' ;; @@ -300,7 +300,7 @@ for _jail in ${JAILS}; do ;; esac - echo -e "${COLOR_GREEN}[${_jail}]:${_hook} -- START${COLOR_RESET}" + info "[${_jail}]:${_hook} -- START" if [ "${_hook}" = 'CMD' ] || [ "${_hook}" = 'PRE' ]; then bastille cmd "${_jail}" /bin/sh < "${bastille_template}/${_hook}" || exit 1 elif [ "${_hook}" = 'PKG' ]; then @@ -317,11 +317,11 @@ for _jail in ${JAILS}; do bastille "${_cmd}" "${_jail}" ${_args} || exit 1 done < "${bastille_template}/${_hook}" fi - echo -e "${COLOR_GREEN}[${_jail}]:${_hook} -- END${COLOR_RESET}" + info "[${_jail}]:${_hook} -- END" echo fi done - echo -e "${COLOR_GREEN}Template complete.${COLOR_RESET}" + info "Template complete." echo done diff --git a/usr/local/share/bastille/top.sh b/usr/local/share/bastille/top.sh index 5f248653..05e23953 100644 --- a/usr/local/share/bastille/top.sh +++ b/usr/local/share/bastille/top.sh @@ -46,7 +46,7 @@ if [ $# -ne 0 ]; then fi for _jail in ${JAILS}; do - echo -e "${COLOR_GREEN}[${_jail}]:${COLOR_RESET}" + info "[${_jail}]:" jexec -l "${_jail}" /usr/bin/top echo -e "${COLOR_RESET}" done diff --git a/usr/local/share/bastille/umount.sh b/usr/local/share/bastille/umount.sh index 0b1894d2..518461b0 100644 --- a/usr/local/share/bastille/umount.sh +++ b/usr/local/share/bastille/umount.sh @@ -49,7 +49,7 @@ fi MOUNT_PATH=$1 for _jail in ${JAILS}; do - echo -e "${COLOR_GREEN}[${_jail}]:${COLOR_RESET}" + info "[${_jail}]:" _jailpath="${bastille_jailsdir}/${_jail}/root/${MOUNT_PATH}" diff --git a/usr/local/share/bastille/verify.sh b/usr/local/share/bastille/verify.sh index 13479a50..7239e252 100644 --- a/usr/local/share/bastille/verify.sh +++ b/usr/local/share/bastille/verify.sh @@ -55,22 +55,22 @@ verify_template() { _path=${_template_path}/${_hook} if [ -s "${_path}" ]; then _hook_validate=$((_hook_validate+1)) - echo -e "${COLOR_GREEN}Detected ${_hook} hook.${COLOR_RESET}" + info "Detected ${_hook} hook." ## line count must match newline count if [ $(wc -l "${_path}" | awk '{print $1}') -ne $(grep -c $'\n' "${_path}") ]; then - echo -e "${COLOR_GREEN}[${_hook}]:${COLOR_RESET}" + info "[${_hook}]:" error_notify "${BASTILLE_TEMPLATE}:${_hook} [failed]." error_notify "Line numbers don't match line breaks." echo error_exit "Template validation failed." ## if INCLUDE; recursive verify elif [ ${_hook} = 'INCLUDE' ]; then - echo -e "${COLOR_GREEN}[${_hook}]:${COLOR_RESET}" + info "[${_hook}]:" cat "${_path}" echo while read _include; do - echo -e "${COLOR_GREEN}[${_hook}]:[${_include}]:${COLOR_RESET}" + info "[${_hook}]:[${_include}]:" case ${_include} in http?://github.com/*/*|http?://gitlab.com/*/*) @@ -89,11 +89,11 @@ verify_template() { ## if tree; tree -a bastille_template/_dir elif [ ${_hook} = 'OVERLAY' ]; then - echo -e "${COLOR_GREEN}[${_hook}]:${COLOR_RESET}" + info "[${_hook}]:" cat "${_path}" echo while read _dir; do - echo -e "${COLOR_GREEN}[${_hook}]:[${_dir}]:${COLOR_RESET}" + info "[${_hook}]:[${_dir}]:" if [ -x /usr/local/bin/tree ]; then /usr/local/bin/tree -a "${_template_path}/${_dir}" else @@ -102,7 +102,7 @@ verify_template() { echo done < "${_path}" else - echo -e "${COLOR_GREEN}[${_hook}]:${COLOR_RESET}" + info "[${_hook}]:" cat "${_path}" echo fi @@ -119,7 +119,7 @@ verify_template() { ## if validated; ready to use if [ ${_hook_validate} -gt 0 ]; then - echo -e "${COLOR_GREEN}Template ready to use.${COLOR_RESET}" + info "Template ready to use." fi } diff --git a/usr/local/share/bastille/zfs.sh b/usr/local/share/bastille/zfs.sh index 0f34f328..da4f065d 100644 --- a/usr/local/share/bastille/zfs.sh +++ b/usr/local/share/bastille/zfs.sh @@ -37,7 +37,7 @@ usage() { zfs_snapshot() { for _jail in ${JAILS}; do - echo -e "${COLOR_GREEN}[${_jail}]:${COLOR_RESET}" + info "[${_jail}]:" zfs snapshot -r "${bastille_zfs_zpool}/${bastille_zfs_prefix}/jails/${_jail}"@"${TAG}" echo done @@ -45,7 +45,7 @@ done zfs_set_value() { for _jail in ${JAILS}; do - echo -e "${COLOR_GREEN}[${_jail}]:${COLOR_RESET}" + info "[${_jail}]:" zfs "${ATTRIBUTE}" "${bastille_zfs_zpool}/${bastille_zfs_prefix}/jails/${_jail}" echo done @@ -53,7 +53,7 @@ done zfs_get_value() { for _jail in ${JAILS}; do - echo -e "${COLOR_GREEN}[${_jail}]:${COLOR_RESET}" + info "[${_jail}]:" zfs get "${ATTRIBUTE}" "${bastille_zfs_zpool}/${bastille_zfs_prefix}/jails/${_jail}" echo done @@ -61,7 +61,7 @@ done zfs_disk_usage() { for _jail in ${JAILS}; do - echo -e "${COLOR_GREEN}[${_jail}]:${COLOR_RESET}" + info "[${_jail}]:" zfs list -t all -o name,used,avail,refer,mountpoint,compress,ratio -r "${bastille_zfs_zpool}/${bastille_zfs_prefix}/jails/${_jail}" echo done