diff options
author | Renato Botelho <renato@netgate.com> | 2015-11-12 11:14:16 -0200 |
---|---|---|
committer | Renato Botelho <renato@netgate.com> | 2015-11-12 11:14:16 -0200 |
commit | 46903fb95f62c8ab5ada0ca738c3905fde631c27 (patch) | |
tree | 73dc9cfd534a45de6194425a947f55861fae6d8f /src/etc | |
parent | 97ee791fffb53133542f5a9dba7c59528cbb9161 (diff) | |
download | pfsense-46903fb95f62c8ab5ada0ca738c3905fde631c27.zip pfsense-46903fb95f62c8ab5ada0ca738c3905fde631c27.tar.gz |
Reinstall packages from old versions when upgrading to 2.3
Diffstat (limited to 'src/etc')
-rw-r--r-- | src/etc/inc/pkg-utils.inc | 79 | ||||
-rwxr-xr-x | src/etc/rc.bootup | 16 |
2 files changed, 79 insertions, 16 deletions
diff --git a/src/etc/inc/pkg-utils.inc b/src/etc/inc/pkg-utils.inc index 6f7022a..4f82bf2 100644 --- a/src/etc/inc/pkg-utils.inc +++ b/src/etc/inc/pkg-utils.inc @@ -302,15 +302,20 @@ function is_pkg_installed($pkg_name) { } /* Install package, $pkg_name should not contain prefix */ -function pkg_install($pkg_name) { +function pkg_install($pkg_name, $force = false) { global $g; $result = false; pkg_remove_prefix($pkg_name); + $pkg_force = ""; + if ($force) { + $pkg_force = "-f "; + } + pkg_debug("Installing package {$pkg_name}\n"); - if (!is_pkg_installed($pkg_name)) { - $result = pkg_call("install -y " . $g['pkg_prefix'] . $pkg_name); + if ($force || !is_pkg_installed($pkg_name)) { + $result = pkg_call("install -y " . $pkg_force . $g['pkg_prefix'] . $pkg_name); /* Cleanup cacke to free disk space */ pkg_call("clean -y"); } @@ -1012,11 +1017,71 @@ function delete_package_xml($package_name, $when = "post-deinstall") { conf_mount_ro(); } -function pkg_reinstall_all() { - global $g, $config; +/* + * Used during upgrade process or retore backup process, verify all + * packages installed in config.xml and install pkg accordingly + */ +function package_reinstall_all() { + global $g, $config, $static_output, $pkg_interface; - // XXX: implement - return; + if (!isset($config['installedpackages']['package']) || + !is_array($config['installedpackages']['package'])) { + return true; + } + + $upgrade = (file_exists('/conf/needs_package_sync') && platform_booting()); + + /* During boot after upgrade, wait for internet connection */ + if ($upgrade) { + $static_output .= gettext("Waiting for internet connection to update pkg metadata and fini package reinstallation"); + update_output_window($static_output); + while (true) { + if (pkg_update(true)) { + break; + } + $static_output .= '.'; + update_output_window($static_output); + sleep(1); + } + $static_output .= "\n"; + update_output_window($static_output); + } else { + if (!pkg_update()) { + return false; + } + } + + $pkg_info = get_pkg_info(); + + foreach ($config['installedpackages']['package'] 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) { + $found = true; + break; + } + } + + if (!$found) { + if (!function_exists("file_notice")) { + require_once("notices.inc"); + } + + 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']); + } + } + + /* Obsoleted packages were removed, lets reinstall all remaining */ + foreach ($config['installedpackages']['package'] as $package) { + $internal_name = get_package_internal_name($package); + pkg_install($internal_name, true); + } + + return true; } function stop_packages() { diff --git a/src/etc/rc.bootup b/src/etc/rc.bootup index e4a83f1..478e3f5 100755 --- a/src/etc/rc.bootup +++ b/src/etc/rc.bootup @@ -393,16 +393,14 @@ if (file_exists("/sbin/shutdown.old")) { } /* Resync / Reinstall packages if need be */ -if (file_exists('/conf/needs_package_sync')) { - if ($config['installedpackages'] <> '' && is_array($config['installedpackages']['package'])) { - require_once("pkg-utils.inc"); - if ($g['platform'] == $g['product_name'] || $g['platform'] == "nanobsd") { - mark_subsystem_dirty('packagelock'); - pkg_reinstall_all(); - clear_subsystem_dirty('packagelock'); - } +if (file_exists('/conf/needs_package_sync') && + ($g['platform'] == $g['product_name'] || $g['platform'] == "nanobsd")) { + require_once("pkg-utils.inc"); + mark_subsystem_dirty('packagelock'); + if (package_reinstall_all()) { + @unlink('/conf/needs_package_sync'); } - @unlink('/conf/needs_package_sync'); + clear_subsystem_dirty('packagelock'); } /* Give syslogd a kick after everything else has been initialized, otherwise it can occasionally |