mirror of
https://github.com/JRGTH/xigmanas-bastille-extension.git
synced 2025-12-12 01:39:50 +01:00
Display container release version, ability to upgrade/downgrade container base
This commit is contained in:
@@ -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.
|
||||
|
||||
@@ -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;;
|
||||
|
||||
@@ -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']):
|
||||
|
||||
@@ -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.')
|
||||
. ' '
|
||||
|
||||
@@ -241,6 +241,7 @@ $document->render();
|
||||
<col style="width:5%">
|
||||
<col style="width:10%">
|
||||
<col style="width:10%">
|
||||
<col style="width:10%">
|
||||
<col style="width:5%">
|
||||
<col style="width:25%">
|
||||
<col style="width:5%">
|
||||
@@ -251,13 +252,14 @@ $document->render();
|
||||
<thead>
|
||||
<?php
|
||||
html_separator2();
|
||||
html_titleline2(gettext('Overview'), 10);
|
||||
html_titleline2(gettext('Overview'), 11);
|
||||
?>
|
||||
<tr>
|
||||
<th class="lhelc"><?=gtext('Select');?></th>
|
||||
<th class="lhell"><?=gtext('JID');?></th>
|
||||
<th class="lhell"><?=gtext('IPv4 Address');?></th>
|
||||
<th class="lhell"><?=gtext('Hostname');?></th>
|
||||
<th class="lhell"><?=gtext('Release');?></th>
|
||||
<th class="lhell"><?=gtext('Interface');?></th>
|
||||
<th class="lhell"><?=gtext('Path');?></th>
|
||||
<th class="lhell"><?=gtext('Boot');?></th>
|
||||
@@ -290,6 +292,7 @@ $document->render();
|
||||
<td class="lcell"><?=htmlspecialchars($sphere_record['id']);?> </td>
|
||||
<td class="lcell"><?=htmlspecialchars($sphere_record['ip']);?> </td>
|
||||
<td class="lcell"><?=htmlspecialchars($sphere_record['name']);?> </td>
|
||||
<td class="lcell"><?=htmlspecialchars($sphere_record['rel']);?> </td>
|
||||
<td class="lcell"><?=htmlspecialchars($sphere_record['nic']);?> </td>
|
||||
<td class="lcell"><?=htmlspecialchars($sphere_record['path']);?> </td>
|
||||
<td class="lcell"><img src="<?=$sphere_record['boot'];?>"></td>
|
||||
@@ -331,7 +334,7 @@ $document->render();
|
||||
</tbody>
|
||||
<tfoot>
|
||||
<tr>
|
||||
<td class="lcenl" colspan="9"></td>
|
||||
<td class="lcenl" colspan="10"></td>
|
||||
<td class="lceadd">
|
||||
<a href="bastille_manager_add.php"><img src="<?=$img_path['add'];?>" title="<?=$gt_record_add;?>" border="0" alt="<?=$gt_record_add;?>" class="spin oneemhigh"/></a>
|
||||
</td>
|
||||
|
||||
@@ -205,8 +205,10 @@ $document->render();
|
||||
</colgroup>
|
||||
<thead>
|
||||
<?php
|
||||
if (!is_dir_empty($reldir)):
|
||||
html_titleline2(gettext('FreeBSD Base Release Installed'));
|
||||
if (is_dir($reldir)):
|
||||
if (!is_dir_empty($reldir)):
|
||||
html_titleline2(gettext('FreeBSD Base Release Installed'));
|
||||
endif;
|
||||
endif;
|
||||
foreach ($sphere_array as $sphere_record):
|
||||
if (file_exists("{$reldir}/{$sphere_record['relname']}/root/.profile")):
|
||||
|
||||
@@ -128,6 +128,34 @@ 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("Base release change disabled for thick containers.");
|
||||
else:
|
||||
$cmd = ("/usr/local/sbin/bastille-init --osrelease {$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("echo '{$date}: {$application}: Container base release changed to {$new_release} on {$item} successfully' >> {$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();
|
||||
</thead>
|
||||
<tbody>
|
||||
<?php
|
||||
$b_action = $l_release;
|
||||
#$current_release = exec("/usr/sbin/jexec {$pconfig['jailname']} freebsd-version 2>/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);
|
||||
?>
|
||||
</tbody>
|
||||
|
||||
Reference in New Issue
Block a user