diff --git a/CHANGELOG b/CHANGELOG index 1bdcf51..904c710 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -3,6 +3,7 @@ ====================== Version Description +1.0.53......Add initial ZFS activation guided support. 1.0.52......Switch repository for early updates and bug fixes. 1.0.51......Jail rename to last position, prevent for null autoboot variables. 1.0.50......Cosmetic changes, add misc configuration row to jail quick config. diff --git a/bastille-init b/bastille-init index 493eb9c..cd0d62d 100755 --- a/bastille-init +++ b/bastille-init @@ -9,7 +9,7 @@ # Debug script #set -x -# Copyright (c) 2019, José Rivera (joserprg@gmail.com). +# Copyright (c) 2019-2020, José Rivera (joserprg@gmail.com). # All rights reserved. # Redistribution and use in source and binary forms, with or without @@ -43,6 +43,7 @@ PATH=/sbin:/bin:/usr/sbin:/usr/bin:/usr/local/sbin:/usr/local/bin CWDIR=$(dirname $(realpath $0)) # Global variables. +CWDIR_TRIM="" PLATFORM=$(uname -m) PRODUCT=$(uname -i) PRDVERSION=$(uname -r | cut -d '-' -f1 | tr -d '.') @@ -76,9 +77,13 @@ GITURL="https://github.com/JRGTH/xigmanas-${APPNAME}-extension/archive/${BRANCH} VERFILE="https://raw.githubusercontent.com/JRGTH/xigmanas-${APPNAME}-extension/${BRANCH}/version" OPT="${1}" -# Required +# Bastille required if [ -f "${BASTILLECONF}" ]; then . /${BASTILLECONF} + # Always enforce ZFS activation below "/mnt/" from the extension. + if echo "${CWDIR}" | grep -q '/mnt/'; then + CWDIR_TRIM=$(echo "${CWDIR}" | sed "s|/mnt/||;s|/${bastille_zfs_prefix}||") + fi fi error_notify() @@ -102,13 +107,13 @@ runtime_config() if [ ! -d ${CWDIR}/backups ]; then mkdir -p ${CWDIR}/backups fi - if [ ! -d ${CWDIR}/conf ]; then + if [ ! -d "${CWDIR}/conf" ]; then mkdir -p ${CWDIR}/conf fi - if [ ! -d ${CWDIR}/log ]; then + if [ ! -d "${CWDIR}/log" ]; then mkdir -p ${CWDIR}/log fi - if [ ! -d ${CWDIR}/locale-bastille ]; then + if [ ! -d "${CWDIR}/locale-bastille" ]; then mkdir -p ${CWDIR}/locale-bastille fi if [ ! -d "${CWDIR}/freebsd-update" ]; then @@ -116,10 +121,12 @@ runtime_config() fi # Check for permissions. - FREEBSD_UPDATE_PERMS=$(stat -f "%Op" ${FREEBSD_UPDATE}/freebsd-update) - if [ "${FREEBSD_UPDATE_PERMS}" != 100555 ]; then - chmod 0555 ${FREEBSD_UPDATE}/freebsd-update - fi + if [ -f "${FREEBSD_UPDATE}/freebsd-update" ]; then + FREEBSD_UPDATE_PERMS=$(stat -f "%Op" ${FREEBSD_UPDATE}/freebsd-update) + if [ "${FREEBSD_UPDATE_PERMS}" != 100555 ]; then + chmod 0555 ${FREEBSD_UPDATE}/freebsd-update + fi + fi } bastille_initial_download() @@ -699,69 +706,75 @@ thickjail_install() zfs_activate() { # Check if ZFS is already configured. - BASTILLE_DIR=$(echo ${CWDIR} | grep -o '[^/]*$') - if zfs list "${bastille_zfs_zpool}/${BASTILLE_DIR}" > /dev/null 2>&1; then - echo "Bastille ZFS is already configured." - exit 0 - else - BASTILLE_DIRS="cache jails logs releases templates" - for dir in ${BASTILLE_DIRS}; do - if [ -d "${CWDIR}/${dir}" ]; then - # Stop if any of the listed dirs already exist. - echo "Bastille has been bootstrapped already, aborting." - exit 0 - fi - done - fi + # Always enforce ZFS activation below "/mnt/" from the extension. + if echo "${bastille_zfs_zpool}" | grep -qw "${CWDIR_TRIM}$"; then - echo "Enabling ZFS on ${PRDNAME} Extension..." - # Confirm before conversion. - while : - do - read -p "Do you really wish to enable ZFS for ${PRDNAME} Extension? [y/N]:" yn - case ${yn} in - [Yy]) break;; - [Nn]) exit 0;; - esac - done - echo "Proceeding..." + BASTILLE_DIR=$(echo "${CWDIR}" | grep -o '[^/]*$') + if [ "${bastille_zfs_prefix}" != "${BASTILLE_DIR}" ]; then + error_notify "Invalid ZFS configuration." + fi + if zfs list "${bastille_zfs_zpool}/${BASTILLE_DIR}" > /dev/null 2>&1; then + echo "Bastille ZFS is already configured." + sysrc -f ${CWDIR}${EXTCONF} ZFS_ACTIVATED="YES" >/dev/null 2>&1 + exit 0 + else + BASTILLE_DIRS="cache jails logs releases templates" + for dir in ${BASTILLE_DIRS}; do + if [ -d "${CWDIR}/${dir}" ]; then + # Stop if any of the listed dirs already exist. + error_notify "Bastille has been bootstrapped already, aborting." + fi + done + fi - if [ "${bastille_zfs_enable}" = "YES" ]; then - if [ ! -z "${bastille_zfs_zpool}" ]; then - if zfs list "${bastille_zfs_zpool}" > /dev/null 2>&1; then - if ! zfs list "${bastille_zfs_zpool}/${BASTILLE_DIR}" > /dev/null 2>&1; then - echo "Renaming existing '${BASTILLE_DIR}' directory" - mv ${CWDIR} ${CWDIR}.old - echo "Creating a new ZFS dataset for '${BASTILLE_DIR}'" - zfs create ${bastille_zfs_options} ${bastille_zfs_zpool}/${bastille_zfs_prefix} - if [ $? -ne 0 ]; then - MSG="Failed to enable ZFS, reverting changes." - echo "${MSG}" - zfs destroy ${bastille_zfs_zpool}/${bastille_zfs_prefix} - mv ${CWDIR}.old ${CWDIR} - logger -t "${SCRIPTNAME}" "${MSG}" - else - echo "Synchronizing '${BASTILLE_DIR}' data on new dataset" - rsync -a ${CWDIR}.old/ ${CWDIR}/ + echo "Enabling ZFS on ${PRDNAME} Extension..." + # Confirm before conversion. + while : + do + read -p "Do you really wish to enable ZFS for ${PRDNAME} Extension? [y/N]:" yn + case ${yn} in + [Yy]) break;; + [Nn]) exit 0;; + esac + done + echo "Proceeding..." + + if [ "${bastille_zfs_enable}" = "YES" ]; then + if [ ! -z "${bastille_zfs_zpool}" ]; then + if zfs list "${bastille_zfs_zpool}" > /dev/null 2>&1; then + if ! zfs list "${bastille_zfs_zpool}/${BASTILLE_DIR}" > /dev/null 2>&1; then + echo "Renaming existing '${BASTILLE_DIR}' directory" + mv ${CWDIR} ${CWDIR}.old + echo "Creating a new ZFS dataset for '${BASTILLE_DIR}'" + zfs create ${bastille_zfs_options} ${bastille_zfs_zpool}/${bastille_zfs_prefix} + if [ $? -ne 0 ]; then + MSG="Failed to enable ZFS, reverting changes." + echo "${MSG}" + mv ${CWDIR}.old ${CWDIR} + logger -t "${SCRIPTNAME}" "${MSG}" + error_notify "${MSG}" + else + echo "Synchronizing '${BASTILLE_DIR}' data on new dataset" + rsync -a ${CWDIR}.old/ ${CWDIR}/ + fi + else + echo "Bastille ZFS is already configured." fi else - if zfs list "${bastille_zfs_zpool}/${BASTILLE_DIR}" > /dev/null 2>&1; then - echo "Bastille ZFS is already configured." - exit 0 - else - error_notify "ERROR: ${bastille_zfs_zpool}/${BASTILLE_DIR} is not a ZFS pool/dataset." - fi + error_notify "ERROR: ${bastille_zfs_zpool} is not a ZFS pool/dataset." fi else - error_notify "ERROR: ${bastille_zfs_zpool} is not a ZFS pool/dataset." + error_notify "Bastille ZPOOL is not set." fi + echo "ZFS Enabled for ${PRDNAME} Extension successfully." else - error_notify "Bastille ZPOOL is not set." + error_notify "Bastille ZFS option is not set." fi - echo "ZFS Enabled for ${PRDNAME} Extension successfully." else - error_notify "Bastille ZFS option is not set." + error_notify "Invalid ZFS configuration." fi + sysrc -f ${CWDIR}${EXTCONF} ZFS_ACTIVATED="YES" >/dev/null 2>&1 + exit 0 } pkg_upgrade() @@ -944,19 +957,23 @@ rc_params() # Check if sane ZFS is enabled in this setup. if [ "${bastille_zfs_enable}" = "YES" ]; then - if [ ! -z "${bastille_zfs_zpool}" ]; then + if [ -n "${bastille_zfs_zpool}" ]; then if zfs list "${bastille_zfs_zpool}" > /dev/null 2>&1; then BASTILLE_DIR=$(echo ${CWDIR} | grep -o '[^/]*$') if zfs list "${bastille_zfs_zpool}/${BASTILLE_DIR}" > /dev/null 2>&1; then sysrc -f ${CWDIR}${EXTCONF} ZFS_SUPPORT="YES" >/dev/null 2>&1 else - sysrc -f ${CWDIR}${EXTCONF} ZFS_SUPPORT="AVA" >/dev/null 2>&1 + if echo "${bastille_zfs_zpool}" | grep -qw "${CWDIR_TRIM}$"; then + sysrc -f ${CWDIR}${EXTCONF} ZFS_SUPPORT="AVA" >/dev/null 2>&1 + else + sysrc -f ${CWDIR}${EXTCONF} ZFS_SUPPORT="ERR" >/dev/null 2>&1 + fi fi else sysrc -f ${CWDIR}${EXTCONF} ZFS_SUPPORT="ERR" >/dev/null 2>&1 fi else - sysrc -f ${CWDIR}${EXTCONF} ZFS_SUPPORT="NO" >/dev/null 2>&1 + sysrc -f ${CWDIR}${EXTCONF} ZFS_SUPPORT="ERR" >/dev/null 2>&1 fi else sysrc -f ${CWDIR}${EXTCONF} ZFS_SUPPORT="NO" >/dev/null 2>&1 diff --git a/gui/bastille_manager-lib.inc b/gui/bastille_manager-lib.inc index 7d0b3bf..befea12 100755 --- a/gui/bastille_manager-lib.inc +++ b/gui/bastille_manager-lib.inc @@ -2,7 +2,7 @@ /* bastille_manager-lib.inc - Copyright (c) 2019 José Rivera (joserprg@gmail.com). + Copyright (c) 2019-2020 José Rivera (joserprg@gmail.com). All rights reserved. Redistribution and use in source and binary forms, with or without @@ -43,22 +43,24 @@ require_once 'system.inc'; $application = "Bastille Manager"; $restore_name = "restore"; $confdir = "/var/etc/bastille_conf"; -$cwdir = exec("/usr/bin/grep 'INSTALL_DIR=' {$confdir}/conf/bastille_config | /usr/bin/cut -d'\"' -f2"); +$cwdir = exec("/usr/bin/grep 'INSTALL_DIR=' $confdir/conf/bastille_config | /usr/bin/cut -d'\"' -f2"); $rootfolder = $cwdir; -$configfile = "{$rootfolder}/conf/bastille_config"; -$versionfile = "{$rootfolder}/version"; +$configfile = "$rootfolder/conf/bastille_config"; +$versionfile = "$rootfolder/version"; $date = strftime('%c'); -$logfile = "{$rootfolder}/log/bastille_ext.log"; -$logevent = "{$rootfolder}/log/bastille_last_event.log"; -$backup_path = exec("/bin/cat {$configfile} | /usr/bin/grep 'BACKUP_DIR=' | /usr/bin/cut -d'\"' -f2"); -$bastille_config = "{$rootfolder}/conf/bastille_config"; -$config_path = exec("/bin/cat {$configfile} | /usr/bin/grep 'BASTILLE_CONFIG=' | /usr/bin/cut -d'\"' -f2"); -$default_distfiles = exec("/bin/cat {$config_path} | /usr/bin/grep 'bastille_bootstrap_archives=' | /usr/bin/cut -d'\"' -f2"); +$logfile = "$rootfolder/log/bastille_ext.log"; +$logevent = "$rootfolder/log/bastille_last_event.log"; +$backup_path = exec("/usr/bin/grep 'BACKUP_DIR=' $configfile | /usr/bin/cut -d'\"' -f2"); +$bastille_config = "$rootfolder/conf/bastille_config"; +$config_path = exec("/usr/bin/grep 'BASTILLE_CONFIG=' $configfile | /usr/bin/cut -d'\"' -f2"); +$default_distfiles = exec("/usr/bin/grep 'bastille_bootstrap_archives=' $config_path | /usr/bin/cut -d'\"' -f2"); $jail_dir = "{$rootfolder}/jails"; $image_dir = "ext/bastille/images"; $options_support = exec("/usr/local/bin/bastille create | grep -wo '\[option\]'"); $reldir = "{$rootfolder}/releases"; -$zfs_support = exec("/bin/cat {$configfile} | /usr/bin/grep 'ZFS_SUPPORT=' | /usr/bin/cut -d'\"' -f2"); +//$zfs_already = exec("/sbin/zfs list | /usr/bin/grep -w $rootfolder/bastille"); +$zfs_support = exec("/usr/bin/grep 'ZFS_SUPPORT=' $configfile | /usr/bin/cut -d'\"' -f2"); +$zfs_activated = exec("/usr/bin/grep 'ZFS_ACTIVATED=' $configfile | /usr/bin/cut -d'\"' -f2"); // Ensure the root directory is configured. if ($rootfolder == "") @@ -78,6 +80,32 @@ function is_dir_empty($reldir) { return (count(scandir($reldir)) == 2); } +// Initial install banner +function initial_install_banner() { + // Never display this if bastille is already bootstraped/activated. + global $rootfolder; + global $zfs_activated; + $is_activated = ""; + $is_bootstrapped = ""; + + // Check activation + if ($zfs_activated == "YES"): + return $is_activated = "YES"; + elseif ($zfs_activated == "NO"): + return $is_activated = "NO"; + else: + // Check for bootstrap directories. + exec("/bin/echo ' cache jails logs releases templates ' | /usr/bin/tr -s ' ' '\n'", $bastille_dirs); + array_shift($bastille_dirs); + foreach($bastille_dirs as $dir): + if(is_dir("$rootfolder/$dir")): + return $is_bootstrapped = "YES"; + break; + endif; + endforeach; + endif; +} + // Check for sane ZFS settings. function get_state_zfs() { global $zfs_support; diff --git a/gui/bastille_manager_config.php b/gui/bastille_manager_config.php index 03261a0..8696fb0 100644 --- a/gui/bastille_manager_config.php +++ b/gui/bastille_manager_config.php @@ -48,7 +48,21 @@ $pgtitle = array(gtext("Extensions"), gtext("Bastille"), gtext("Configuration")) $wSpace = " "; $wSpaceEqual = " = "; -$paramNameSize = 30; //length of parameter name input field, default for parameter value input field is '80' +$paramNameSize = 30; //length of parameter name input field, default for parameter value input field is '80' + +if(!initial_install_banner()): + $errormsg = gtext('Bastille Initial Configuration.') + . ' ' + . '' + . gtext('Please check and configure the following ZFS options: BASTILLE_ZFS_ENABLE and BASTILLE_ZFS_ZPOOL.') + .'' + . gtext('Where BASTILLE_ZFS_ENABLE can be set to "YES", and BASTILLE_ZFS_ZPOOL can be set to "tank" or even "tank/dataset1/dataset2" accordingly.') + .'' + . '' + . gtext('After either configuring or skip this ZFS option, please visit this link to Enable/Disable ZFS Support on Bastille.') + . ''; + $prerequisites_ok = false; +endif; function htmlInput($name, $title, $value="", $size=80) { $result = ""; @@ -145,6 +159,7 @@ bindtextdomain("xigmanas", $textdomain_bastille);
| ";
if (!empty($input_errors)) print_input_errors($input_errors);
diff --git a/gui/bastille_manager_gui.php b/gui/bastille_manager_gui.php
index 995bede..fa8fc52 100644
--- a/gui/bastille_manager_gui.php
+++ b/gui/bastille_manager_gui.php
@@ -2,7 +2,7 @@
/*
bastille_manager_gui.php
- Copyright (c) 2019 José Rivera (joserprg@gmail.com).
+ Copyright (c) 2019-2020 José Rivera (joserprg@gmail.com).
All rights reserved.
Portions of XigmaNAS® (https://www.xigmanas.com).
@@ -75,6 +75,15 @@ $img_path = [
$jls_list = get_jail_infos();
$sphere_array = $jls_list;
+if(!initial_install_banner()):
+ $errormsg = gtext('Bastille Initial Configuration.')
+ . ' '
+ . ''
+ . gtext('Please check and configure ZFS support option first.')
+ . '';
+ $prerequisites_ok = false;
+endif;
+
if($_POST):
if(isset($_POST['apply']) && $_POST['apply']):
$ret = array('output' => [], 'retval' => 0);
diff --git a/gui/bastille_manager_maintenance.php b/gui/bastille_manager_maintenance.php
index ceed1ad..64bdf7a 100644
--- a/gui/bastille_manager_maintenance.php
+++ b/gui/bastille_manager_maintenance.php
@@ -2,7 +2,7 @@
/*
bastille_manager_maintenance.php
- Copyright (c) 2019 José Rivera (joserprg@gmail.com).
+ Copyright (c) 2019-2020 José Rivera (joserprg@gmail.com).
All rights reserved.
Copyright (c) 2016 Andreas Schmidhuber
@@ -43,6 +43,17 @@ require_once("bastille_manager-lib.inc");
$pgtitle = array(gtext("Extensions"), "Bastille", "Maintenance");
+if(!initial_install_banner()):
+ $errormsg = gtext('Bastille Initial Configuration.')
+ . ' '
+ . ''
+ . gtext('Please check and configure ZFS support option first.')
+ . ''
+ . ''
+ . gtext('Or click Activate to save current configuration regardless.');
+ $prerequisites_ok = false;
+endif;
+
// For legacy product versions.
$return_val = mwexec("/bin/cat /etc/prd.version | cut -d'.' -f1 | /usr/bin/grep '10'", true);
if ($return_val == 0) {
@@ -61,6 +72,7 @@ $prdname = "bastille";
$tarballversion = "/usr/local/bin/bastille";
if ($_POST) {
+ global $zfs_activated;
if(isset($_POST['upgrade']) && $_POST['upgrade']):
$cmd = sprintf('%1$s/bastille-init -u > %2$s',$rootfolder,$logevent);
$return_val = 0;
@@ -147,6 +159,44 @@ if ($_POST) {
$input_errors[] = gtext("Failed to save extension settings.");
exec("echo '{$date}: {$application}: Failed to save extension settings' >> {$logfile}");
}
+ // ZFS activation support.
+ if ($_POST['zfs_activate']):
+ $zfs_status = get_state_zfs();
+ if($zfs_status == "Available but not enabled" || $zfs_status == "Enabled"):
+ if(!$zfs_activated):
+ $cmd = sprintf('/bin/echo Y | %1$s/bastille-init -Z > %2$s',$rootfolder,$logevent);
+ $return_val = 0;
+ $output = [];
+ exec($cmd,$output,$return_val);
+ if($return_val == 0):
+ ob_start();
+ include("{$logevent}");
+ $ausgabe = ob_get_contents();
+ ob_end_clean();
+ $savemsg .= str_replace("\n", " ", $ausgabe)." "; + exec("/usr/sbin/sysrc -f {$configfile} ZFS_ACTIVATED=\"YES\""); + else: + $input_errors[] = gtext('An error has occurred during ZFS activation process.'); + $cmd = sprintf('echo %s: %s An error has occurred during ZFS activation process. >> %s',$date,$application,$logfile); + exec($cmd); + endif; + endif; + else: + $input_errors[] = gtext("Cannot activate ZFS with either invalid or disabled configurations."); + endif; + else: + $zfs_status = get_state_zfs(); + if($zfs_status == "Invalid ZFS configuration"): + $input_errors[] = gtext("Cannot skip ZFS activation with an invalid configuration."); + elseif($zfs_status == "Enabled"): + exec("/usr/sbin/sysrc -f {$configfile} ZFS_ACTIVATED=\"YES\""); + elseif(!$zfs_activated): + exec("/usr/sbin/sysrc -f {$configfile} ZFS_ACTIVATED=\"NO\""); + $savemsg .= gtext("ZFS activation option has been skipped."); + endif; + endif; + # Run bastille-init to update config. + exec("bastille-init"); } if (isset($_POST['restore']) && $_POST['restore']) { @@ -231,20 +281,6 @@ $(document).ready(function(){ //--> |