diff bin/update.sh @ 8:bf99236cc5cd default tip

try to recover from upgrade fail
author Charlie Root
date Sat, 29 Dec 2018 07:07:34 -0500
parents 4681f974d28b
children
line wrap: on
line diff
--- a/bin/update.sh	Sat Dec 29 06:32:49 2018 -0500
+++ b/bin/update.sh	Sat Dec 29 07:07:34 2018 -0500
@@ -18,20 +18,13 @@
  | Author: Thomas Bruederli <roundcube@gmail.com>                        |
  +-----------------------------------------------------------------------+
 */
-if ($_SERVER['RCMAIL_CONFIG_DIR']) {
-  define('RCMAIL_CONFIG_DIR', $_SERVER['RCMAIL_CONFIG_DIR']);
-}
-
-if ($_SERVER['DEBIAN_PKG']) {
-  define('DEBIAN_PKG', TRUE);
-}
 
 define('INSTALL_PATH', realpath(__DIR__ . '/..') . '/' );
 
 require_once INSTALL_PATH . 'program/include/clisetup.php';
 
 // get arguments
-$opts = rcube_utils::get_opt(array('v' => 'version', 'y' => 'accept'));
+$opts = rcube_utils::get_opt(array('v' => 'version', 'y' => 'accept:bool'));
 
 // ask user if no version is specified
 if (!$opts['version']) {
@@ -93,26 +86,20 @@
       if ($opts['accept'] || strtolower($input) == 'y') {
         $error = $written = false;
 
-        if (!DEBIAN_PKG) {
-          // backup current config
-          echo ". backing up the current config file(s)...\n";
+        // backup current config
+        echo ". backing up the current config file(s)...\n";
 
-          foreach (array('config', 'main', 'db') as $file) {
-            if (file_exists(RCMAIL_CONFIG_DIR . '/' . $file . '.inc.php')) {
-              if (!copy(RCMAIL_CONFIG_DIR . '/' . $file . '.inc.php', RCMAIL_CONFIG_DIR . '/' . $file . '.old.php')) {
-                $error = true;
-              }
+        foreach (array('config', 'main', 'db') as $file) {
+          if (file_exists(RCMAIL_CONFIG_DIR . '/' . $file . '.inc.php')) {
+            if (!copy(RCMAIL_CONFIG_DIR . '/' . $file . '.inc.php', RCMAIL_CONFIG_DIR . '/' . $file . '.old.php')) {
+              $error = true;
             }
           }
         }
 
         if (!$error) {
           $RCI->merge_config();
-          if (DEBIAN_PKG) {
-            echo ". writing " . RCMAIL_CONFIG_DIR . "/config.inc.php.dpkg-new...\n";
-          } else {
-            echo ". writing " . RCMAIL_CONFIG_DIR . "/config.inc.php...\n";
-          }
+          echo ". writing " . RCMAIL_CONFIG_DIR . "/config.inc.php...\n";
           $written = $RCI->save_configfile($RCI->create_config());
         }
 
@@ -127,11 +114,9 @@
               echo "- '" . $msg['prop'] . ($msg['name'] ? "': " . $msg['name'] : "'") . "\n";
           }
 
-          if (!DEBIAN_PKG) {
-            if ($RCI->legacy_config) {
-              foreach (array('main', 'db') as $file) {
-                @unlink(RCMAIL_CONFIG_DIR . '/' . $file . '.inc.php');
-              }
+          if ($RCI->legacy_config) {
+            foreach (array('main', 'db') as $file) {
+              @unlink(RCMAIL_CONFIG_DIR . '/' . $file . '.inc.php');
             }
           }
         }
@@ -168,15 +153,11 @@
     echo "Please check the 'mime_types' config option and run this script again.\n";
   }
 
-  if (!DEBIAN_PKG) {
-    // check database schema
-    if ($RCI->config['db_dsnw']) {
-      echo "Executing database schema update.\n";
-      system("php " . INSTALL_PATH . "bin/updatedb.sh --package=roundcube --version=" . $opts['version']
-        . " --dir=" . INSTALL_PATH . "SQL", $res);
-
-      $success = !$res;
-    }
+  // check database schema
+  if ($RCI->config['db_dsnw']) {
+    echo "Executing database schema update.\n";
+    $success = rcmail_utils::db_update(INSTALL_PATH . 'SQL', 'roundcube', $opts['version'],
+        array('errors' => true));
   }
 
   // update composer dependencies
@@ -188,14 +169,24 @@
     // update the require section with the new dependencies
     if (is_array($composer_data['require']) && is_array($composer_template['require'])) {
       $composer_data['require'] = array_merge($composer_data['require'], $composer_template['require']);
-      /* TO BE ADDED LATER
-      $old_packages = array();
-      for ($old_packages as $pkg) {
-        if (array_key_exists($composer_data['require'], $pkg)) {
+
+      // remove obsolete packages
+      $old_packages = array(
+        'pear-pear.php.net/net_socket',
+        'pear-pear.php.net/auth_sasl',
+        'pear-pear.php.net/net_idna2',
+        'pear-pear.php.net/mail_mime',
+        'pear-pear.php.net/net_smtp',
+        'pear-pear.php.net/crypt_gpg',
+        'pear-pear.php.net/net_sieve',
+        'pear/mail_mime-decode',
+        'roundcube/net_sieve',
+      );
+      foreach ($old_packages as $pkg) {
+        if (array_key_exists($pkg, $composer_data['require'])) {
           unset($composer_data['require'][$pkg]);
         }
       }
-      */
     }
 
     // update the repositories section with the new dependencies
@@ -209,12 +200,18 @@
         $existing = false;
         foreach ($composer_data['repositories'] as $k =>  $_repo) {
           if ($rkey == $_repo['type'] . preg_replace('/^https?:/', '', $_repo['url']) . $_repo['package']['name']) {
+            // switch to https://
+            if (isset($_repo['url']) && strpos($_repo['url'], 'http://') === 0)
+              $composer_data['repositories'][$k]['url'] = 'https:' . substr($_repo['url'], 5);
             $existing = true;
             break;
           }
           // remove old repos
           else if (strpos($_repo['url'], 'git://git.kolab.org') === 0) {
-              unset($composer_data['repositories'][$k]);
+            unset($composer_data['repositories'][$k]);
+          }
+          else if ($_repo['type'] == 'package' && $_repo['package']['name'] == 'Net_SMTP') {
+            unset($composer_data['repositories'][$k]);
           }
         }
         if (!$existing) {
@@ -262,7 +259,7 @@
 
   // index contacts for fulltext searching
   if ($opts['version'] && version_compare(version_parse($opts['version']), '0.6.0', '<')) {
-    system("php " . INSTALL_PATH . 'bin/indexcontacts.sh');
+    rcmail_utils::indexcontacts();
   }
 
   if ($success) {