From f0d855674d496dce627768d007269ef4f5d87cbb Mon Sep 17 00:00:00 2001 From: Jose Date: Thu, 28 Nov 2019 04:27:37 -0400 Subject: [PATCH] Display container release version, ability to upgrade/downgrade container base --- CHANGELOG | 1 + bastille-init | 82 +++++++++++++++++++++++++++++-- gui/bastille_manager-lib.inc | 19 +++++++ gui/bastille_manager_add.php | 14 ------ gui/bastille_manager_gui.php | 7 ++- gui/bastille_manager_tarballs.php | 6 ++- gui/bastille_manager_util.php | 54 ++++++++++++++++++++ version | 2 +- 8 files changed, 162 insertions(+), 23 deletions(-) diff --git a/CHANGELOG b/CHANGELOG index 647c405..a13478e 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -3,6 +3,7 @@ ====================== Version Description +1.0.17......Display container release version, ability to upgrade/downgrade container base. 1.0.16......Enable logging on error. 1.0.15......Ability to restore .tgz archives on ZFS, be more verbose. 1.0.14......Destroy ZFS dataset before rename. diff --git a/bastille-init b/bastille-init index be93149..6ddca46 100755 --- a/bastille-init +++ b/bastille-init @@ -75,7 +75,8 @@ BATSILLE_URL="https://github.com/BastilleBSD/${APPNAME}/archive/${BRANCH}.zip" # BASTILE_VERSION="https://raw.githubusercontent.com/BastilleBSD/${APPNAME}/${BRANCH}/usr/local/bin/${APPNAME}" GITURL="https://github.com/JRGTH/xigmanas-${APPNAME}-extension/archive/${BRANCH}.zip" VERFILE="https://raw.githubusercontent.com/JRGTH/xigmanas-${APPNAME}-extension/${BRANCH}/version" -ARG="$2" +OPT="${1}" +NAME="${2}" # Required if [ -f "${BASTILLECONF}" ]; then @@ -488,7 +489,7 @@ jail_backup() # Backup container on request. ZFS_COMPRESS=$(sysrc -f ${CWDIR}${EXTCONF} -qn ZFS_COMPRESS) ZFS_SENDPARAMS=$(sysrc -f ${CWDIR}${EXTCONF} -qn ZFS_SENDPARAMS) - JAIL_NAME="${ARG}" + JAIL_NAME="${NAME}" DATE=$(date +%Y-%m-%d-%H%M%S) EXCLUDE="--exclude=.bastille --exclude=.template" if [ -n "${JAIL_NAME}" ]; then @@ -528,7 +529,7 @@ jail_restore() # Restore container on request. ZFS_DECOMPRESS=$(sysrc -f ${CWDIR}${EXTCONF} -qn ZFS_DECOMPRESS) ZFS_RECVPARAM=$(sysrc -f ${CWDIR}${EXTCONF} -qn ZFS_RECVPARAM) - BACKUP_FILE="${ARG}" + BACKUP_FILE="${NAME}" NAME_TRIM=$(echo ${BACKUP_FILE} | awk '{print $1}' | grep -o '[^/]*$' | cut -d '-' -f1) FILE_EXT=$(echo ${BACKUP_FILE} | awk '{print $1}' | grep -o '[^/]*$' | cut -d '.' -f2) if [ -f "${CWDIR}/backups/${BACKUP_FILE}" ]; then @@ -583,6 +584,61 @@ jail_restore() fi } +jail_osrelease() +{ + # Verify user input and handle some errors. + if [ -d "${bastille_jailsdir}/${NAME}" ]; then + if [ -d "${bastille_releasesdir}/${RELEASE}" ]; then + if [ -f "${bastille_releasesdir}/${RELEASE}/COPYRIGHT" ]; then + if [ -d "${bastille_releasesdir}/${NEWRELEASE}" ]; then + if [ -f "${bastille_releasesdir}/${NEWRELEASE}/COPYRIGHT" ]; then + if [ -f "${bastille_jailsdir}/${NAME}/fstab" ]; then + # Check if the container is running. + if [ $(jls name | grep -w "${NAME}") ]; then + echo -e "Jail running." + echo -e "See 'bastille stop ${NAME}'." + exit 1 + elif [ "${RELEASE}" = "${NEWRELEASE}" ]; then + echo -e "Specified releases name match." + exit 0 + fi + # Check if is a thin container. + if cat "${bastille_jailsdir}/${NAME}/fstab" | grep "${RELEASE}" | grep -q ".bastille"; then + # If the previous conditions meets, proceed with the container fstab edit. + sed -i '' "s/${RELEASE}/${NEWRELEASE}/g" ${bastille_jailsdir}/${NAME}/fstab + echo -e "${NAME} release changed to ${NEWRELEASE}." + elif cat "${bastille_jailsdir}/${NAME}/fstab" | grep "${NEWRELEASE}" | grep -q ".bastille"; then + echo -e "${NAME} already using ${NEWRELEASE}." + else + echo -e "${NAME} is not a thin container." + exit 1 + fi + else + echo -e "${NAME} fstab not found." + exit 1 + fi + else + echo -e "Unknown ${NEWRELEASE}. See bootstrap." + exit 1 + fi + else + echo -e "${NEWRELEASE} not found. See bootstrap." + exit 1 + fi + else + echo -e "Unknown ${RELEASE}. See bootstrap." + fi + else + echo -e "${RELEASE} not found. See bootstrap." + exit 1 + fi + else + echo -e "${NAME} not found. See create." + exit 1 + fi + exit 0 +} + zfs_activate() { # Check if ZFS is already configured. @@ -911,6 +967,20 @@ bastille_init() # Run-time configuration. runtime_config +# Handle additional commands. +case "${OPT}" in +osrelease|--osrelease) + if [ $# -gt 4 ] || [ $# -lt 4 ]; then + echo "Usage: ${SCRIPTNAME} [osrelease|--osrelease] [container] [release] [newrelease]" + exit 1 + fi + NAME="${2}" + RELEASE="${3}" + NEWRELEASE="${4}" + jail_osrelease + ;; +esac + while getopts ":ospruxUvgtBRZh" option; do case ${option} in [h]) echo "Usage: ${SCRIPTNAME} -[option] | [container]"; @@ -927,7 +997,11 @@ while getopts ":ospruxUvgtBRZh" option; do echo " -Z Activate ZFS for ${PRDNAME} Extension." echo " -x Reset ${PRDNAME}/Extension config." echo " -U Uninstall ${PRDNAME} (Extension files only)." - echo " -h Display this help message."; exit 0;; + echo " -h Display this help message." + echo + echo "Advanced Usage: ${SCRIPTNAME} [option] [container] [argument1] [argument2]" + echo "Options:" + echo " osrelease|--osrelease Quickly upgrade/downgrade a thin container base release."; exit 0;; [o]) OBI_INSTALL="ON";; # To prevent nested PHP-CGI call for installation with OBI. [s]) bastille_start;; [p]) bastille_stop;; diff --git a/gui/bastille_manager-lib.inc b/gui/bastille_manager-lib.inc index e505e77..37d3126 100755 --- a/gui/bastille_manager-lib.inc +++ b/gui/bastille_manager-lib.inc @@ -127,6 +127,20 @@ function get_all_interface_list() { return $iflist; } +// list base releases +$a_release = get_all_release_list(); +$l_release = []; +foreach($a_release as $k_release => $release): + $l_release[$k_release] = $k_release; +endforeach; + +// list of configured interfaces +$a_interface = get_all_interface_list(); +$l_interfaces = []; +foreach($a_interface as $k_interface => $ifinfo): + $l_interfaces[$k_interface] = $k_interface; +endforeach; + // Get jail infos. function get_jail_infos() { global $img_path; @@ -163,6 +177,11 @@ function get_jail_infos() { if (!$r['ip']): $r['ip'] = "-"; endif; + // Display release. + $r['rel'] = exec("/usr/sbin/jexec {$item} freebsd-version 2>/dev/null"); + if (!$r['rel']): + $r['rel'] = "-"; + endif; // Display interfaces. $r['nic'] = exec("/usr/bin/grep -w 'interface' {$jail_dir}/{$item}/jail.conf | /usr/bin/awk '{print $3}' | /usr/bin/tr -d ';'"); if (!$r['nic']): diff --git a/gui/bastille_manager_add.php b/gui/bastille_manager_add.php index c5ef637..ec8761a 100644 --- a/gui/bastille_manager_add.php +++ b/gui/bastille_manager_add.php @@ -48,20 +48,6 @@ if(!$pconfig['ipaddress']): $pconfig['ipaddress'] = ''; endif; -// list of configured interfaces -$a_interface = get_all_interface_list(); -$l_interfaces = []; -foreach($a_interface as $k_interface => $ifinfo): - $l_interfaces[$k_interface] = $k_interface; -endforeach; - -// list base releases -$a_release = get_all_release_list(); -$l_release = []; -foreach($a_release as $k_release => $release): - $l_release[$k_release] = $k_release; -endforeach; - if(!get_all_release_list()): $errormsg = gtext('No base releases extracted yet.') . ' ' diff --git a/gui/bastille_manager_gui.php b/gui/bastille_manager_gui.php index fac3b48..d1a095f 100644 --- a/gui/bastille_manager_gui.php +++ b/gui/bastille_manager_gui.php @@ -241,6 +241,7 @@ $document->render(); + @@ -251,13 +252,14 @@ $document->render(); + @@ -290,6 +292,7 @@ $document->render();       +       @@ -331,7 +334,7 @@ $document->render(); - + <?=$gt_record_add;?> diff --git a/gui/bastille_manager_tarballs.php b/gui/bastille_manager_tarballs.php index 1a1c864..9e333ed 100644 --- a/gui/bastille_manager_tarballs.php +++ b/gui/bastille_manager_tarballs.php @@ -205,8 +205,10 @@ $document->render(); > {$logfile}"); + //header('Location: bastille_manager_gui.php'); + //exit; + else: + $errormsg .= 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)): @@ -253,6 +281,8 @@ function action_change() { showElementById('advanced_tr', 'hide'); showElementById('readonly_tr', 'hide'); showElementById('createdir_tr', 'hide'); + showElementById('jail_release_tr', 'hide'); + showElementById('release_tr','hide'); //showElementById('dateadd_tr','hide'); var action = document.iform.action.value; switch (action) { @@ -260,6 +290,14 @@ function action_change() { showElementById('confirmname_tr','hide'); showElementById('nowstop_tr','hide'); break; + + case "base": + showElementById('confirmname_tr','hide'); + showElementById('nowstop_tr','hide'); + showElementById('jail_release_tr', 'show'); + showElementById('release_tr','show'); + break; + case "autoboot": showElementById('confirmname_tr','hide'); showElementById('nowstop_tr','hide'); @@ -329,11 +367,23 @@ $document->render(); /dev/null"); + unset($disable_base_change); + $current_release = exec("/usr/bin/grep '\-RELEASE' {$jail_dir}/{$pconfig['jailname']}/fstab | awk '{print $1}' | grep -o '[^/]*$'"); + if (!$current_release): + $current_release = exec("/usr/bin/grep 'releng' {$jail_dir}/{$pconfig['jailname']}/root/COPYRIGHT | cut -d '/' -f2"); + $disable_base_change = "1"; + if (!$current_release): + $current_release = "-"; + endif; + endif; $pconfig['source_path'] = "/mnt"; $pconfig['target_path'] = "{$rootfolder}/jails/{$pconfig['jailname']}/root/mnt/"; html_text2('jailname',gettext('Container name:'),htmlspecialchars($pconfig['jailname'])); $a_action = [ 'backup' => gettext('Backup'), + 'base' => gettext('Release'), 'autoboot' => gettext('Autoboot'), 'noauto' => gettext('Noauto'), 'fstab' => gettext('Fstab'), @@ -348,6 +398,10 @@ $document->render(); html_checkbox2('advanced',gettext('Advanced jail configuration Files'),!empty($pconfig['advanced']) ? true : false,gettext('I understand the risks, take me to the advanced jail config files.'),'',true); html_checkbox2('readonly',gettext('Read-Only Mode'),!empty($pconfig['readonly']) ? true : false,gettext('Set target directory in Read-Only mode.'),'',false); html_checkbox2('createdir',gettext('Create Target Directory'),!empty($pconfig['createdir']) ? true : true,gettext('Create target directory if missing (recommended).'),'',true); + html_text2('jail_release',gettext('Current base release:'),htmlspecialchars($current_release)); + if (!$disable_base_change): + html_combobox2('release',gettext('New base release'),$pconfig['release'],$b_action,gettext("Warning: this will change current base to the selected base on the thin container only, the user is responsible for package updates and/or general incompatibilities issues."),true,false,); + endif; //html_checkbox2('dateadd',gettext('Date'),!empty($pconfig['dateadd']) ? true : false,gettext('Append the date in the following format: ITEM-XXXX-XX-XX-XXXXXX.'),'',false); ?> diff --git a/version b/version index b668c3b..8fc77d0 100644 --- a/version +++ b/version @@ -1 +1 @@ -1.0.16 +1.0.17