From c78c9ced21924806b6578e8c0e1bf782c2f35ffe Mon Sep 17 00:00:00 2001 From: Franco Fichtner Date: Mon, 10 Oct 2016 08:34:22 +0200 Subject: [PATCH] config: weave new migrations into convert_config(); closes #1156 --- +POST_INSTALL | 3 --- src/etc/inc/config.lib.inc | 45 +++++++++++++++++++---------------- src/etc/rc.bootup | 2 +- src/etc/rc.configure_firmware | 1 + 4 files changed, 27 insertions(+), 24 deletions(-) diff --git a/+POST_INSTALL b/+POST_INSTALL index 75f3aaeae..a72f34137 100644 --- a/+POST_INSTALL +++ b/+POST_INSTALL @@ -38,9 +38,6 @@ fi echo "Flush Phalcon volt templates" rm -f /usr/local/opnsense/mvc/app/cache/*.php -echo "Execute model migrations" -/usr/local/opnsense/mvc/script/run_migrations.php - echo "Reloading GUI configuration" /usr/local/etc/rc.php_ini_setup if pgrep -q php-cgi; then diff --git a/src/etc/inc/config.lib.inc b/src/etc/inc/config.lib.inc index 340b5a11b..8b05874b7 100644 --- a/src/etc/inc/config.lib.inc +++ b/src/etc/inc/config.lib.inc @@ -40,12 +40,11 @@ $g = array( "dhcpd_chroot_path" => "/var/dhcpd", "unbound_chroot_path" => "/var/unbound", "product_name" => "OPNsense", - "product_website" => "https://opnsense.org", + "product_website" => "https://opnsense.org/", "product_email" => "project@opnsense.org", "product_copyright_owner" => "Deciso B.V.", "product_copyright_years" => "2014-2016", "product_copyright_url" => "https://www.deciso.com/", - "latest_config" => "11.2", ); require_once("xmlparse.inc"); @@ -118,39 +117,45 @@ function parse_config() * null ******/ /* convert configuration, if necessary */ -function convert_config() +function convert_config($verbose = false) { - global $config, $g; + global $config; + + /* hardcode this, legacy migration path is now disabled */ + $latest_config = '11.2'; if (!isset($config['revision'])) { /* force a revision tag for proper handling in config history */ write_config('Factory configuration', false); } - if ($config['version'] == $g['latest_config']) { - /* already at latest version */ - return; + if ($config['version'] !== $latest_config) { + $prev_version = $config['version']; + /* Loop and run upgrade_VER_to_VER() until we're at current version */ + while ($config['version'] < $latest_config) { + $cur = $config['version'] * 10; + $next = $cur + 1; + $migration_function = sprintf('upgrade_%03d_to_%03d', $cur, $next); + if (function_exists($migration_function)) { + $migration_function(); + } + $config['version'] = sprintf('%.1f', $next / 10); } - // Save off config version - $prev_version = $config['version']; - /* Loop and run upgrade_VER_to_VER() until we're at current version */ - while ($config['version'] < $g['latest_config']) { - $cur = $config['version'] * 10; - $next = $cur + 1; - $migration_function = sprintf('upgrade_%03d_to_%03d', $cur, $next); - if (function_exists($migration_function)) { - $migration_function(); + if ($prev_version != $config['version']) { + write_config(sprintf('Upgraded config version level from %s to %s', $prev_version, $config['version'])); } - $config['version'] = sprintf('%.1f', $next / 10); } - if ($prev_version != $config['version']) { - write_config(sprintf('Upgraded config version level from %s to %s', $prev_version, $config['version'])); + /* chain the new migration into this function call */ + $mvc_migration = '/usr/local/opnsense/mvc/script/run_migrations.php'; + if ($verbose) { + passthru($mvc_migration); + } else { + mwexecf($mvc_migraton); } } - /****f* config/write_config * NAME * write_config - Backup and write the firewall configuration. diff --git a/src/etc/rc.bootup b/src/etc/rc.bootup index c3c7fe226..76ccc33e4 100755 --- a/src/etc/rc.bootup +++ b/src/etc/rc.bootup @@ -96,7 +96,7 @@ if ($setup_installer) { echo "Loading configuration..."; global $config; $config = parse_config(); -convert_config(); +convert_config(true); echo "done.\n"; /* diff --git a/src/etc/rc.configure_firmware b/src/etc/rc.configure_firmware index d4e5caf6e..59bc89781 100755 --- a/src/etc/rc.configure_firmware +++ b/src/etc/rc.configure_firmware @@ -37,3 +37,4 @@ require_once 'system.inc'; system_firmware_configure(); system_console_configure(); +convert_config(true);