- Uninstall all packages on current system before upgrade using
pre_upgrade_command script
- Create a file containing all packages previously installed and
reinstall them on first boot after upgrade
This commit is contained in:
Renato Botelho 2016-04-29 16:00:35 -03:00
parent 3610a08e13
commit c0cb3c7358
2 changed files with 63 additions and 11 deletions

View File

@ -1000,12 +1000,24 @@ function package_reinstall_all() {
$pkg_info = get_pkg_info();
foreach ($config['installedpackages']['package'] as $package) {
if ($upgrade &&
file_exists("{$g['cf_conf_path']}/packages_to_reinstall_after_upgrade.txt")) {
$package_list = file("{$g['cf_conf_path']}/packages_to_reinstall_after_upgrade.txt",
FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES);
unlink_if_exists("{$g['cf_conf_path']}/packages_to_reinstall_after_upgrade.txt");
} else {
$package_list = array();
foreach ($config['installedpackages']['package'] as $package) {
$package_list[] = get_package_internal_name($package);
}
}
foreach ($package_list as $package) {
$found = false;
$internal_name = get_package_internal_name($package);
foreach ($pkg_info as $pkg) {
pkg_remove_prefix($pkg['name']);
if ($pkg['name'] == $internal_name) {
if ($pkg['name'] == $package) {
pkg_install($g['pkg_prefix'] . $package, true);
$found = true;
break;
}
@ -1017,17 +1029,12 @@ function package_reinstall_all() {
}
file_notice(gettext("Package reinstall"),
sprintf(gettext("Package %s does not exist in current %s version and it has been removed."), $package['name'], $g['product_name']));
uninstall_package($package['name']);
sprintf(gettext("Package %s does not exist in current %s version and it has been removed."),
$package, $g['product_name']));
uninstall_package($package);
}
}
/* Obsoleted packages were removed, lets reinstall all remaining */
foreach ($config['installedpackages']['package'] as $package) {
$internal_name = get_package_internal_name($package);
pkg_install($g['pkg_prefix'] . $internal_name, true);
}
return true;
}

View File

@ -12,6 +12,51 @@ echo $PRIOR_VERSION > /tmp/pre_upgrade_version
# De-activate sync on the root slice only. This will not match NanoBSD since it already has sync,noatime
/usr/bin/sed -i '' 's/^\(\/.*[[:space:]]*\/[[:space:]]*ufs[[:space:]]*\)rw,sync\([[:space:]]*[[:digit:]][[:space:]]*[[:digit:]]\)$/\1rw\2/' /etc/fstab
# Uninstall all packages before upgrade to 2.3
PFSENSE_VERSION=$(cat /etc/version)
if echo "$PFSENSE_VERSION" | grep -q '^1.2'; then
UNINSTALL="uninstall_package_from_name"
else
UNINSTALL="uninstall_package"
fi
cat >/tmp/remove_all_packages.php <<EOD
#!/usr/local/bin/php
<?php
require_once("pkg-utils.inc");
global \$pkg_interface;
\$pkg_interface = "console";
if (!isset(\$config['installedpackages']['package'])) {
exit(0);
}
if (!is_array(\$config['installedpackages']['package'])) {
exit(0);
}
\$removed_packages = array();
foreach (\$config['installedpackages']['package'] as \$package) {
if (isset(\$package['internal_name'])) {
\$removed_packages[] = \$package['internal_name'];
} else {
\$removed_packages[] = \$package['name'];
}
//${UNINSTALL}(\$package['name']);
}
@file_put_contents("{\$g['cf_conf_path']}/packages_to_reinstall_after_upgrade.txt", implode("\\n",\$removed_packages));
?>
EOD
/usr/local/bin/php /tmp/remove_all_packages.php
exit
rm -f /tmp/remove_all_packages.php
# Cleanup PBIs
if which pbi_info >/dev/null 2>&1; then
for pbi in $(pbi_info); do