Merge pull request #273 from JRGTH/master

Upgrade thick jails from bastille
This commit is contained in:
Christer Edwards
2020-11-27 10:07:35 -07:00
committed by GitHub
2 changed files with 130 additions and 29 deletions

View File

@@ -42,41 +42,72 @@ help|-h|--help)
;; ;;
esac esac
if [ $# -gt 1 ] || [ $# -lt 1 ]; then if [ $# -gt 2 ] || [ $# -lt 1 ]; then
usage usage
fi fi
TARGET="${1}" TARGET="${1}"
shift OPTION="${2}"
# Handle options
case "${OPTION}" in
-f|--force)
OPTION="-F"
;;
*)
OPTION=
;;
esac
# Check for unsupported actions
if [ "${TARGET}" = "ALL" ]; then
error_exit "Batch upgrade is unsupported."
fi
if freebsd-version | grep -qi HBSD; then if freebsd-version | grep -qi HBSD; then
error_exit "Not yet supported on HardenedBSD." error_exit "Not yet supported on HardenedBSD."
fi fi
if [ -d "${bastille_jailsdir}/${TARGET}" ]; then jail_check() {
if ! grep -qw ".bastille" "${bastille_jailsdir}/${TARGET}/fstab"; then # Check if the jail is thick and is running
if [ "$(jls name | awk "/^${TARGET}$/")" ]; then if [ ! "$(jls name | awk "/^${TARGET}$/")" ]; then
# Update a thick container. error_exit "[${TARGET}]: Not started. See 'bastille start ${TARGET}'."
else
if grep -qw "${bastille_jailsdir}/${TARGET}/root/.bastille" "${bastille_jailsdir}/${TARGET}/fstab"; then
error_exit "${TARGET} is not a thick container."
fi
fi
}
jail_update() {
# Update a thick container
if [ -d "${bastille_jailsdir}/${TARGET}" ]; then
jail_check
CURRENT_VERSION=$(/usr/sbin/jexec -l "${TARGET}" freebsd-version 2>/dev/null) CURRENT_VERSION=$(/usr/sbin/jexec -l "${TARGET}" freebsd-version 2>/dev/null)
if [ -z "${CURRENT_VERSION}" ]; then if [ -z "${CURRENT_VERSION}" ]; then
error_exit "Can't determine '${TARGET}' version." error_exit "Can't determine '${TARGET}' version."
else else
env PAGER="/bin/cat" freebsd-update --not-running-from-cron -b "${bastille_jailsdir}/${TARGET}/root" \ env PAGER="/bin/cat" freebsd-update ${OPTION} --not-running-from-cron -b "${bastille_jailsdir}/${TARGET}/root" \
fetch install --currently-running "${CURRENT_VERSION}" fetch install --currently-running "${CURRENT_VERSION}"
fi fi
else else
error_notify "${TARGET} is not running." error_exit "${TARGET} not found. See 'bastille bootstrap'."
error_exit "See 'bastille start ${TARGET}'."
fi fi
else }
error_exit "${TARGET} is not a thick container."
fi release_update() {
else # Update a release base(affects child containers)
if [ -d "${bastille_releasesdir}/${TARGET}" ]; then if [ -d "${bastille_releasesdir}/${TARGET}" ]; then
# Update container base(affects child containers). env PAGER="/bin/cat" freebsd-update ${OPTION} --not-running-from-cron -b "${bastille_releasesdir}/${TARGET}" \
env PAGER="/bin/cat" freebsd-update --not-running-from-cron -b "${bastille_releasesdir}/${TARGET}" \
fetch install --currently-running "${TARGET}" fetch install --currently-running "${TARGET}"
else else
error_exit "${TARGET} not found. See 'bastille bootstrap'." error_exit "${TARGET} not found. See 'bastille bootstrap'."
fi fi
}
# Check what we should update
if echo "${TARGET}" | grep -q "[0-9]\{2\}.[0-9]-RELEASE"; then
release_update
else
jail_update
fi fi

View File

@@ -32,7 +32,7 @@
. /usr/local/etc/bastille/bastille.conf . /usr/local/etc/bastille/bastille.conf
usage() { usage() {
error_exit "Usage: bastille upgrade release newrelease" error_exit "Usage: bastille upgrade release newrelease | target newrelease | target install | [option]"
} }
# Handle special-case commands first. # Handle special-case commands first.
@@ -42,20 +42,90 @@ help|-h|--help)
;; ;;
esac esac
if [ $# -gt 2 ] || [ $# -lt 2 ]; then if [ $# -gt 3 ] || [ $# -lt 2 ]; then
usage usage
fi fi
RELEASE="$1" TARGET="$1"
shift NEWRELEASE="$2"
NEWRELEASE="$1" OPTION="$3"
# Check for unsupported actions
if [ "${TARGET}" = "ALL" ]; then
error_exit "Batch upgrade is unsupported."
fi
if freebsd-version | grep -qi HBSD; then if freebsd-version | grep -qi HBSD; then
error_exit "Not yet supported on HardenedBSD." error_exit "Not yet supported on HardenedBSD."
fi fi
if [ -d "${bastille_releasesdir}/${RELEASE}" ]; then # Handle options
freebsd-update -b "${bastille_releasesdir}/${RELEASE}" -r "${NEWRELEASE}" upgrade case "${OPTION}" in
-f|--force)
OPTION="-F"
;;
*)
OPTION=
;;
esac
jail_check() {
# Check if the jail is thick and is running
if [ ! "$(jls name | awk "/^${TARGET}$/")" ]; then
error_exit "[${TARGET}]: Not started. See 'bastille start ${TARGET}'."
else
if grep -qw "${bastille_jailsdir}/${TARGET}/root/.bastille" "${bastille_jailsdir}/${TARGET}/fstab"; then
error_exit "${TARGET} is not a thick container."
fi
fi
}
release_check() {
# Validate the release
if ! echo "${NEWRELEASE}" | grep -q "[0-9]\{2\}.[0-9]-RELEASE"; then
error_exit "${NEWRELEASE} is not a valid release."
fi
}
release_upgrade() {
# Upgrade a release
if [ -d "${bastille_releasesdir}/${TARGET}" ]; then
release_check
freebsd-update ${OPTION} -b "${bastille_releasesdir}/${TARGET}" -r "${NEWRELEASE}" upgrade
else
error_exit "${TARGET} not found. See 'bastille bootstrap'."
fi
}
jail_upgrade() {
# Upgrade a thick container
if [ -d "${bastille_jailsdir}/${TARGET}" ]; then
jail_check
release_check
CURRENT_VERSION=$(jexec -l ${TARGET} freebsd-version)
env PAGER="/bin/cat" freebsd-update ${OPTION} --not-running-from-cron -b "${bastille_jailsdir}/${TARGET}/root" --currently-running "${CURRENT_VERSION}" -r ${NEWRELEASE} upgrade
echo
echo -e "${COLOR_YELLOW}Please run 'bastille upgrade ${TARGET} install' to finish installing updates.${COLOR_RESET}"
else
error_exit "${TARGET} not found. See 'bastille bootstrap'."
fi
}
jail_updates_install() {
# Finish installing upgrade on a thick container
if [ -d "${bastille_jailsdir}/${TARGET}" ]; then
jail_check
env PAGER="/bin/cat" freebsd-update ${OPTION} --not-running-from-cron -b "${bastille_jailsdir}/${TARGET}/root" install
else
error_exit "${TARGET} not found. See 'bastille bootstrap'."
fi
}
# Check what we should upgrade
if echo "${TARGET}" | grep -q "[0-9]\{2\}.[0-9]-RELEASE"; then
release_upgrade
elif [ "${NEWRELEASE}" = "install" ]; then
jail_updates_install
else else
error_exit "${RELEASE} not found. See 'bastille bootstrap'." jail_upgrade
fi fi