From 98cf9d85f047192271f21e964f87d902309cde1d Mon Sep 17 00:00:00 2001 From: JRGTH Date: Mon, 8 Sep 2025 01:52:27 -0400 Subject: [PATCH] Re-add release change and code improvements --- CHANGELOG | 1 + bastille-init | 43 +++++++++++++++++++++----- gui/bastille_manager_util.php | 57 +++++++++++++++++++++++++++++++++++ version | 2 +- 4 files changed, 95 insertions(+), 8 deletions(-) diff --git a/CHANGELOG b/CHANGELOG index 93234d4..5014ca4 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -3,6 +3,7 @@ ====================== Version Description +1.1.52......Re-add Thin jail release change and code improvements. 1.1.51......Code update/improvements, update jail config/util pages and bastille-init. 1.1.50......Disable linux_compat due incompatibility with later releases. 1.1.49......Disable basic interface to comply with bastille new syntax. diff --git a/bastille-init b/bastille-init index c162010..65ffe1a 100644 --- a/bastille-init +++ b/bastille-init @@ -727,10 +727,15 @@ release_upgrade() exit 0 fi # Upgrade a release base. + if [ -n "${_forceopt}" ]; then + echo "Performing a forced release upgrade..." + else + echo "Performing a release upgrade..." + fi echo "=> Run the command below several times when asked to finish installing updates." echo "bastille-init install ${TARGET}" echo - env PAGER="/bin/cat" ${FREEBSD_UPDATE}/freebsd-update --not-running-from-cron -f ${FREEBSD_UPDATE}/freebsd-update.conf \ + env PAGER="/bin/cat" ${FREEBSD_UPDATE}/freebsd-update ${_forceopt} --not-running-from-cron -f ${FREEBSD_UPDATE}/freebsd-update.conf \ -d ${CWDIR}/freebsd-update -b "${bastille_releasesdir}/${TARGET}" --currently-running "${TARGET}" -r ${RELEASE} upgrade echo echo "=> Please run: 'bastille-init install ${TARGET}' to finish installing updates." @@ -847,11 +852,16 @@ thickjail_upgrade() if [ -f "${bastille_jailsdir}/${TARGET}/root/COPYRIGHT" ]; then if [ "$(jls name | grep -w "${TARGET}")" ]; then # Upgrade a thick container. + if [ -n "${_forceopt}" ]; then + echo "Performing a forced jail upgrade..." + else + echo "Performing a jail upgrade..." + fi echo "=> Run the command below several times when asked to finish installing updates." echo "bastille-init install ${TARGET}" echo CURRENT_VERSION=$(jexec -l ${TARGET} freebsd-version) - env PAGER="/bin/cat" ${FREEBSD_UPDATE}/freebsd-update --not-running-from-cron -f ${FREEBSD_UPDATE}/freebsd-update.conf \ + env PAGER="/bin/cat" ${FREEBSD_UPDATE}/freebsd-update ${_forceopt} --not-running-from-cron -f ${FREEBSD_UPDATE}/freebsd-update.conf \ -d ${CWDIR}/freebsd-update -b "${bastille_jailsdir}/${TARGET}/root" --currently-running "${CURRENT_VERSION}" -r ${RELEASE} upgrade echo echo "=> Please run: 'bastille-init install ${TARGET}' to finish installing updates." @@ -1441,6 +1451,24 @@ upgrade|--upgrade) fi release_change fi + _forceopt= + ;; +upgrade_force|--upgrade-force) + # Check container type to upgrade + if [ -z "${NEWRELEASE}" ]; then + if [ $# -gt 3 ] || [ $# -lt 3 ]; then + echo "Usage: ${SCRIPTNAME} [upgrade_force|--upgrade-force] [container|release] [release]" + exit 1 + fi + thickjail_upgrade + else + if [ $# -gt 4 ] || [ $# -lt 4 ]; then + echo "Usage: ${SCRIPTNAME} [upgrade_force|--upgrade-force] [container] [release] [newrelease]" + exit 1 + fi + release_change + fi + _forceopt="-F" ;; update|--update) if [ $# -gt 2 ] || [ $# -lt 2 ]; then @@ -1494,11 +1522,12 @@ while getopts ":ospruxUvgtZh" option; do echo echo "Advanced Usage: ${SCRIPTNAME} [option] [container] [release] | [newrelease]" echo "Options:" - echo " update|--update Update a container/release to base -pX release." - echo " update_force|--update-force Update a container/release to base -pX release forcefully." - echo " upgrade|--upgrade Upgrade a container/release to X.Y-RELEASE." - echo " install|--install Finish installing pending updates on container/release." - echo " clean|--clean Cleanup the FreeBSD update/upgrade cached files/folders." + echo " update|--update Update a container/release to base -pX release." + echo " update_force|--update-force Update a container/release to base -pX release forcefully." + echo " upgrade|--upgrade Upgrade a container/release to X.Y-RELEASE." + echo " upgrade_force|--upgrade-force Upgrade a container/release to X.Y-RELEASE. forcefully" + echo " install|--install Finish installing pending updates on container/release." + echo " clean|--clean Cleanup the FreeBSD update/upgrade cached files/folders." echo "" echo "" echo "Experimental:" diff --git a/gui/bastille_manager_util.php b/gui/bastille_manager_util.php index 77cf1fa..3c0b7fe 100644 --- a/gui/bastille_manager_util.php +++ b/gui/bastille_manager_util.php @@ -258,6 +258,35 @@ if($_POST): endif; break; + case 'base': + // Input validation not required + if(empty($input_errors)): + $container = []; + $container['uuid'] = $_POST['uuid']; + $container['jailname'] = $_POST['jailname']; + $item = $container['jailname']; + $current_release = exec("/usr/bin/grep '\-RELEASE' {$jail_dir}/{$item}/fstab | awk '{print $1}' | grep -o '[^/]*$'"); + $new_release = $pconfig['release']; + + if(!$current_release): + $savemsg .= gtext("This is a thick container and should be interactively upgraded through the command line."); + else: + $cmd = ("/usr/local/sbin/bastille-init --upgrade {$item} {$current_release} {$new_release}"); + unset($output,$retval);mwexec2($cmd,$output,$retval); + if($retval == 0): + $savemsg .= sprintf(gtext("Container base release changed to %s successfully."),$new_release); + exec("/usr/local/bin/bastille config {$item} set osrelease $new_release"); + exec("echo '{$date}: {$application}: Container base release changed to {$new_release} on {$item} successfully' >> {$logfile}"); + //header('Location: bastille_manager_gui.php'); + //exit; + else: + $input_errors[] = sprintf(gtext("Failed to change container base release to %s, either it is running or is not a thin container."),$new_release); + exec("echo '{$date}: {$application}: Failed to change container base release to {$new_release} on {$item}' >> {$logfile}"); + endif; + endif; + endif; + break; + case 'autoboot': // Input validation not required if(empty($input_errors)): @@ -444,6 +473,8 @@ function action_change() { showElementById('readonly_tr', 'hide'); showElementById('createdir_tr', 'hide'); showElementById('automount_tr', 'hide'); + showElementById('jail_release_tr', 'hide'); + showElementById('release_tr','hide'); showElementById('update_base_tr','hide'); showElementById('update_jail_tr','hide'); showElementById('update_base_force_tr', 'hide'); @@ -475,6 +506,10 @@ function action_change() { showElementById('update_base_force_tr', 'show'); showElementById('update_jail_force_tr', 'show'); break; + case "base": + showElementById('jail_release_tr', 'show'); + showElementById('release_tr','show'); + break; case "autoboot": showElementById('auto_boot_tr', 'show'); break; @@ -545,7 +580,23 @@ $document->render(); /dev/null"); + $current_release = ""; + $disable_base_change = "no"; + $current_release = exec("/usr/bin/grep '\-RELEASE' {$jail_dir}/{$pconfig['jailname']}/fstab | awk '{print $1}' | grep -o '[^/]*$'"); $is_thinjail = exec("/usr/bin/grep -w '/.*/.bastille' {$jail_dir}/{$pconfig['jailname']}/fstab"); + if (!$current_release): + $current_release = exec("/usr/bin/grep 'releng' {$jail_dir}/{$pconfig['jailname']}/root/COPYRIGHT | cut -d '/' -f2"); + if(!$current_release): + //Assume is a running thickjail. + $current_release = exec("/usr/sbin/jexec {$pconfig['jailname']} freebsd-version 2>/dev/null"); + endif; + $disable_base_change = "yes"; + if (!$current_release): + $current_release = "-"; + endif; + endif; $pconfig['source_path'] = ""; $pconfig['target_path'] = "{$rootfolder}/jails/{$pconfig['jailname']}/root/mnt/"; html_text2('jailname',gettext('Container name:'),htmlspecialchars($pconfig['jailname'])); @@ -553,6 +604,7 @@ $document->render(); 'backup' => gettext('Backup'), 'clone' => gettext('Clone'), 'update' => gettext('Update'), + 'base' => gettext('Release'), 'autoboot' => gettext('Autoboot'), 'noauto' => gettext('Noauto'), 'priority' => gettext('Priority'), @@ -603,9 +655,14 @@ $document->render(); html_checkbox2('update_jail',gettext('Container update confirm:'),!empty($pconfig['update_jail']) ? true : false,gettext('This is a thick container, therefore the update will be performed within its root, current containers are not affected.'),'',true); html_checkbox2('update_jail_force',gettext('Container update force confirm:'),!empty($pconfig['update_jail']) ? true : false,gettext('This will perform a forced jail update, current containers are not affected.'),'',true); endif; + html_text2('jail_release',gettext('Current base release:'),htmlspecialchars($current_release)); html_text2('auto_boot',gettext('Enable container auto-startup'),htmlspecialchars("This will cause the container to automatically start each time the system restart.")); html_text2('no_autoboot',gettext('Disable container auto-startup'),htmlspecialchars("This will disable the container automatic startup.")); html_text2('backup',gettext('Export container'),htmlspecialchars("This will export a container to a compressed file/image, please execute `bastille export` for more info in regards exporting formats, Default is .XZ on ZFS setups or .TXZ otherwise, For faster compressed backups consider .GZ/.TGZ.")); + + if ($disable_base_change == "no"): + html_combobox2('release',gettext('New base release'),!empty($pconfig['release']),$b_action,gettext("Warning: This will change current shared base to the selected base on the thin container only, the user is responsible for package updates and/or general incompatibilities issues, or use the command line for native upgrade."),true,false,); + endif; ?> diff --git a/version b/version index 3baec79..cf6931b 100644 --- a/version +++ b/version @@ -1 +1 @@ -1.1.51 +1.1.52