--- install.php	2007-04-13 10:56:57.000000000 +0200
+++ install.php	2007-05-05 10:39:43.000000000 +0200
@@ -24,6 +24,14 @@ function install_main() {
   // Ensure correct page headers are sent (e.g. caching)
   drupal_page_header();
 
+  // Finalizing steps can do redirects and redirect to install.php?install_finalized=1
+  // to ensure installation is not triggered again.
+  if (isset($_GET['install_finalized'])) {
+    install_complete(NULL);
+    exit;
+  }
+
+
   // Check existing settings.php.
   $verify = install_verify_settings();
 
@@ -95,8 +103,11 @@ function install_main() {
     drupal_set_message(st('All necessary changes to %file have been made. It has been set to read-only for security.', array('%file' => $settings_file)));
   }
 
+  // Finalize installation. Anything, including redirects can happen here.
+  // Make sure that if you use redirect, you set $_GET['install_finalized'] to true.
+  $profile_message = install_finalize($profile);
   // Show end page.
-  install_complete($profile);
+  install_complete($profile_message);
 }
 
 /**
@@ -544,11 +555,9 @@ function install_missing_modules_error($
 }
 
 /**
- * Page displayed when the installation is complete. Called from install.php.
+ * Finalize installation, call profile final function if it exists.
  */
-function install_complete($profile) {
-  global $base_url;
-  $output = '';
+function install_finalize($profile) {
   // Store install profile for later use.
   variable_set('install_profile', $profile);
 
@@ -557,20 +566,33 @@ function install_complete($profile) {
   drupal_bootstrap(DRUPAL_BOOTSTRAP_FULL);
   $_SESSION['messages'] = $messages;
 
-  // Build final page.
-  drupal_maintenance_theme();
-  install_task_list();
-  drupal_set_title(st('@drupal installation complete', array('@drupal' => drupal_install_profile_name())));
-  $output .= '<p>'. st('Congratulations, @drupal has been successfully installed.', array('@drupal' => drupal_install_profile_name())) .'</p>';
-
   // Show profile finalization info.
   $function = $profile .'_profile_final';
   if (function_exists($function)) {
     // More steps required
     $profile_message = $function();
   }
+  return $profile_message;
+}
+/**
+ * Page displayed when the installation is complete. Called from install.php.
+ */
+function install_complete($profile_message = NULL) {
+  global $base_url;
+  $output = '';
+
+  // Bootstrap newly installed Drupal.
+  drupal_bootstrap(DRUPAL_BOOTSTRAP_FULL);
 
+  // Rebuild all menus. Nothing should change now.
   menu_rebuild();
+  
+  // Build final page.
+  drupal_maintenance_theme();
+  install_task_list();
+  drupal_set_title(st('@drupal installation complete', array('@drupal' => drupal_install_profile_name())));
+  $output .= '<p>'. st('Congratulations, @drupal has been successfully installed.', array('@drupal' => drupal_install_profile_name())) .'</p>';
+
   // If the profile returned a welcome message, use that instead of default.
   if (isset($profile_message)) {
     $output .= $profile_message;
