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();