Merge pull request #1330 from BastilleBSD/upgrade-fix

update/upgrade: simplify vars
This commit is contained in:
tschettervictor
2025-12-02 13:14:25 -07:00
committed by GitHub
3 changed files with 40 additions and 26 deletions

View File

@@ -617,7 +617,7 @@ case "${RELEASE}" in
UPSTREAM_URL=$(echo "${bastille_url_freebsd}${HW_MACHINE}/${HW_MACHINE_ARCH}/${NAME_VERIFY}" | sed 's/releases/snapshots/') UPSTREAM_URL=$(echo "${bastille_url_freebsd}${HW_MACHINE}/${HW_MACHINE_ARCH}/${NAME_VERIFY}" | sed 's/releases/snapshots/')
FREEBSD_BRANCH="current" FREEBSD_BRANCH="current"
;; ;;
*-RELEASE|*-release|*-RC[1-9]|*-rc[1-9]|*-BETA[1-9]) *-release|*-RELEASE|*-rc[1-9]|*-RC[1-9]|*-beta[1-9]|*-BETA[1-9])
### FreeBSD ### ### FreeBSD ###
PLATFORM_OS="FreeBSD" PLATFORM_OS="FreeBSD"
NAME_VERIFY=$(echo "${RELEASE}" | grep -iwE '^([0-9]+)\.[0-9](-RELEASE|-RC[1-9]|-BETA[1-9])$' | tr '[:lower:]' '[:upper:]') NAME_VERIFY=$(echo "${RELEASE}" | grep -iwE '^([0-9]+)\.[0-9](-RELEASE|-RC[1-9]|-BETA[1-9])$' | tr '[:lower:]' '[:upper:]')

View File

@@ -123,18 +123,18 @@ jail_check() {
JAIL_PLATFORM_OS="FreeBSD" JAIL_PLATFORM_OS="FreeBSD"
fi fi
# Set CURRENT_VERSION # Set OLD_RELEASE
CURRENT_VERSION=$(/usr/sbin/jexec -l "${TARGET}" freebsd-version 2>/dev/null) OLD_RELEASE=$(/usr/sbin/jexec -l "${TARGET}" freebsd-version 2>/dev/null)
if [ -z "${CURRENT_VERSION}" ]; then if [ -z "${OLD_RELEASE}" ]; then
error_exit "[ERROR]: Can't determine '${TARGET}' version." error_exit "[ERROR]: Can't determine '${TARGET}' version."
fi fi
# Validate method (Legacy/PkgBase) # Validate method (Legacy/PkgBase)
if [ "${JAIL_PLATFORM_OS}" = "FreeBSD" ]; then if [ "${JAIL_PLATFORM_OS}" = "FreeBSD" ]; then
# Validate update method # Validate update method
MINOR_VERSION=$(echo ${CURRENT_VERSION} | sed -E 's/^[0-9]+\.([0-9]+)-.*$/\1/') MINOR_VERSION=$(echo ${OLD_RELEASE} | sed -E 's/^[0-9]+\.([0-9]+)-.*$/\1/')
MAJOR_VERSION=$(echo ${CURRENT_VERSION} | grep -Eo '^[0-9]+') MAJOR_VERSION=$(echo ${OLD_RELEASE} | grep -Eo '^[0-9]+')
if echo "${CURRENT_VERSION}" | grep -oq "\-CURRENT"; then if echo "${OLD_RELEASE}" | grep -oq "\-CURRENT"; then
FREEBSD_BRANCH="current" FREEBSD_BRANCH="current"
else else
FREEBSD_BRANCH="release" FREEBSD_BRANCH="release"
@@ -181,10 +181,10 @@ jail_update() {
fi fi
# Update release version (including patch level) # Update release version (including patch level)
NEW_VERSION=$(/usr/sbin/jexec -l "${TARGET}" freebsd-version 2>/dev/null) UPDATED_RELEASE=$(/usr/sbin/jexec -l "${TARGET}" freebsd-version 2>/dev/null)
if [ "${CURRENT_VERSION}" != "${NEW_VERSION}" ]; then if [ "${OLD_RELEASE}" != "${UPDATED_RELEASE}" ]; then
bastille config ${TARGET} set osrelease ${NEW_VERSION} >/dev/null bastille config ${TARGET} set osrelease ${UPDATED_RELEASE} >/dev/null
info "\nUpgrade complete: ${CURRENT_VERSION} > ${NEW_VERSION}\n" info "\nUpgrade complete: ${OLD_RELEASE} > ${UPDATED_RELEASE}\n"
else else
info "\nNo updates available.\n" info "\nNo updates available.\n"
fi fi
@@ -233,10 +233,10 @@ jail_update_pkgbase() {
fi fi
# Update release version (including patch level) # Update release version (including patch level)
NEW_VERSION=$(/usr/sbin/jexec -l "${TARGET}" freebsd-version 2>/dev/null) UPDATED_RELEASE=$(/usr/sbin/jexec -l "${TARGET}" freebsd-version 2>/dev/null)
if [ "${CURRENT_VERSION}" != "${NEW_VERSION}" ]; then if [ "${OLD_RELEASE}" != "${UPDATED_RELEASE}" ]; then
bastille config ${TARGET} set osrelease ${NEW_VERSION} >/dev/null bastille config ${TARGET} set osrelease ${UPDATED_RELEASE} >/dev/null
info "\nUpgrade complete: ${CURRENT_VERSION} > ${NEW_VERSION}\n" info "\nUpgrade complete: ${OLD_RELEASE} > ${UPDATED_RELEASE}\n"
else else
info "\nNo updates available.\n" info "\nNo updates available.\n"
fi fi
@@ -436,9 +436,9 @@ case "${TARGET}" in
NAME_VERIFY=$(echo "${TARGET}" | grep -iwE '^([1-9]+)\.[0-9](-STABLE)$' | tr '[:lower:]' '[:upper:]') NAME_VERIFY=$(echo "${TARGET}" | grep -iwE '^([1-9]+)\.[0-9](-STABLE)$' | tr '[:lower:]' '[:upper:]')
UPDATE_TARGET="RELEASE" UPDATE_TARGET="RELEASE"
;; ;;
*-release|*-RELEASE) *-release|*-RELEASE|*-rc[1-9]|*-RC[1-9]|*-beta[1-9]|*-BETA[1-9])
PLATFORM_OS="FreeBSD" PLATFORM_OS="FreeBSD"
NAME_VERIFY=$(echo "${TARGET}" | grep -iwE '^([0-9]+)\.[0-9](-RELEASE)$' | tr '[:lower:]' '[:upper:]') NAME_VERIFY=$(echo "${TARGET}" | grep -iwE '^([0-9]+)\.[0-9](-RELEASE|-RC[1-9]|-BETA[1-9])$' | tr '[:lower:]' '[:upper:]')
UPDATE_TARGET="RELEASE" UPDATE_TARGET="RELEASE"
;; ;;
current|CURRENT) current|CURRENT)

View File

@@ -137,7 +137,7 @@ thick_jail_check() {
# Set VERSION # Set VERSION
OLD_RELEASE="$(${bastille_jailsdir}/${TARGET}/root/bin/freebsd-version 2>/dev/null)" OLD_RELEASE="$(${bastille_jailsdir}/${TARGET}/root/bin/freebsd-version 2>/dev/null)"
OLD_CONFIG_RELEASE="$(bastille config ${TARGET} get osrelease)" OLD_CONFIG_RELEASE="$(bastille config ${TARGET} get osrelease)"
if [ -z "${OLD_RELEASE}" ]; then if [ -z "${OLD_RELEASE}" ] || [ -z "${OLD_CONFIG_RELEASE}" ]; then
error_exit "[ERROR]: Can't determine '${TARGET}' version." error_exit "[ERROR]: Can't determine '${TARGET}' version."
fi fi
@@ -189,9 +189,9 @@ release_check() {
PLATFORM_OS="FreeBSD" PLATFORM_OS="FreeBSD"
NAME_VERIFY=$(echo "${NEW_RELEASE}" | grep -iwE '^([1-9]+)\.[0-9](-STABLE)$' | tr '[:lower:]' '[:upper:]') NAME_VERIFY=$(echo "${NEW_RELEASE}" | grep -iwE '^([1-9]+)\.[0-9](-STABLE)$' | tr '[:lower:]' '[:upper:]')
;; ;;
*-release|*-RELEASE) *-release|*-RELEASE|*-rc[1-9]|*-RC[1-9]|*-beta[1-9]|*-BETA[1-9])
PLATFORM_OS="FreeBSD" PLATFORM_OS="FreeBSD"
NAME_VERIFY=$(echo "${NEW_RELEASE}" | grep -iwE '^([0-9]+)\.[0-9](-RELEASE)$' | tr '[:lower:]' '[:upper:]') NAME_VERIFY=$(echo "${NEW_RELEASE}" | grep -iwE '^([0-9]+)\.[0-9](-RELEASE|-RC[1-9]|-BETA[1-9])$' | tr '[:lower:]' '[:upper:]')
;; ;;
current|CURRENT) current|CURRENT)
PLATFORM_OS="HardenedBSD" PLATFORM_OS="HardenedBSD"
@@ -321,9 +321,18 @@ jail_upgrade_pkgbase() {
info "\n[${TARGET}]:" info "\n[${TARGET}]:"
if [ "${OLD_RELEASE}" = "${NEW_RELEASE}" ]; then # Verify trusted pkg keys
error_notify "[ERROR]: Jail is already running '${NEW_RELEASE}'" if [ ! -f "${fingerprints}/trusted/awskms-${NEW_MAJOR_VERSION}" ]; then
error_exit "See 'bastille update TARGET' to update jail." if ! fetch -o "${fingerprints}/trusted" https://cgit.freebsd.org/src/tree/share/keys/pkgbase-${NEW_MAJOR_VERSION}/trusted/awskms-${NEW_MAJOR_VERSION}
then
error_exit "[ERROR]: Failed to fetch trusted pkg keys."
fi
fi
if [ ! -f "${fingerprints}/trusted/backup-signing-${NEW_MAJOR_VERSION}" ]; then
if ! fetch -o "${fingerprints}/trusted" https://cgit.freebsd.org/src/tree/share/keys/pkgbase-${NEW_MAJOR_VERSION}/trusted/backup-signing-${NEW_MAJOR_VERSION}
then
error_exit "[ERROR]: Failed to fetch trusted backup pkg keys."
fi
fi fi
# Upgrade jail with pkgbase (thick only) # Upgrade jail with pkgbase (thick only)
@@ -356,10 +365,15 @@ jail_upgrade_pkgbase() {
fi fi
# Update release version (including patch level) # Update release version (including patch level)
NEW_VERSION=$(/usr/sbin/jexec -l "${TARGET}" freebsd-version 2>/dev/null) UPGRADED_RELEASE=$(/usr/sbin/jexec -l "${TARGET}" freebsd-version 2>/dev/null)
bastille config ${TARGET} set osrelease ${NEW_VERSION} >/dev/null 2>/dev/null if [ "${OLD_RELEASE}" != "${UPGRADED_RELEASE}" ]; then
bastille config ${TARGET} set osrelease ${UPGRADED_RELEASE} >/dev/null 2>/dev/null
info "\nUpgrade complete: ${OLD_RELEASE} > ${UPGRADED_RELEASE}\n"
else
info "\nNo updates available.\n"
fi
info "\nUpgraded ${TARGET}: ${OLD_RELEASE} -> ${NEW_RELEASE}" info "\nUpgraded ${TARGET}: ${OLD_RELEASE} -> ${UPGRADED_RELEASE}"
else else
error_exit "[ERROR]: Not implemented for platform: ${PLATFORM_OS}" error_exit "[ERROR]: Not implemented for platform: ${PLATFORM_OS}"
fi fi