Aleksander Machniak
2016-05-06 acf633c73bc8df9a5036bc52d7568f4213ab73c7
commit | author | age
d48470 1 #!/usr/bin/env php
fee8c6 2 <?php
e6bb83 3 /*
T 4  +-----------------------------------------------------------------------+
5  | bin/update.sh                                                         |
6  |                                                                       |
7  | This file is part of the Roundcube Webmail client                     |
447fc6 8  | Copyright (C) 2010-2013, The Roundcube Dev Team                       |
7fe381 9  |                                                                       |
T 10  | Licensed under the GNU General Public License version 3 or            |
11  | any later version with exceptions for skins & plugins.                |
12  | See the README file for a full license statement.                     |
e6bb83 13  |                                                                       |
T 14  | PURPOSE:                                                              |
15  |   Check local configuration and database schema after upgrading       |
16  |   to a new version                                                    |
17  +-----------------------------------------------------------------------+
18  | Author: Thomas Bruederli <roundcube@gmail.com>                        |
19  +-----------------------------------------------------------------------+
20 */
21
fee8c6 22 define('INSTALL_PATH', realpath(dirname(__FILE__) . '/..') . '/' );
T 23
e6bb83 24 require_once INSTALL_PATH . 'program/include/clisetup.php';
fee8c6 25 require_once INSTALL_PATH . 'installer/rcube_install.php';
e6bb83 26
T 27 // get arguments
447fc6 28 $opts = rcube_utils::get_opt(array('v' => 'version', 'y' => 'accept'));
e6bb83 29
T 30 // ask user if no version is specified
31 if (!$opts['version']) {
32   echo "What version are you upgrading from? Type '?' if you don't know.\n";
33   if (($input = trim(fgets(STDIN))) && preg_match('/^[0-9.]+[a-z-]*$/', $input))
34     $opts['version'] = $input;
63cf4f 35   else
AM 36     $opts['version'] = RCMAIL_VERSION;
e6bb83 37 }
T 38
fee8c6 39 $RCI = rcube_install::get_instance();
T 40 $RCI->load_config();
41
42 if ($RCI->configured) {
2491c6 43   $success = true;
461a30 44
9bacb2 45   if (($messages = $RCI->check_config()) || $RCI->legacy_config) {
2491c6 46     $success = false;
fee8c6 47     $err = 0;
T 48
49     // list old/replaced config options
50     if (is_array($messages['replaced'])) {
51       echo "WARNING: Replaced config options:\n";
52       echo "(These config options have been replaced or renamed)\n";
53
54       foreach ($messages['replaced'] as $msg) {
cbffc2 55         echo "- '" . $msg['prop'] . "' was replaced by '" . $msg['replacement'] . "'\n";
fee8c6 56         $err++;
T 57       }
58       echo "\n";
59     }
60
61     // list obsolete config options (just a notice)
62     if (is_array($messages['obsolete'])) {
63       echo "NOTICE: Obsolete config options:\n";
64       echo "(You still have some obsolete or inexistent properties set. This isn't a problem but should be noticed)\n";
65
66       foreach ($messages['obsolete'] as $msg) {
cbffc2 67         echo "- '" . $msg['prop'] . ($msg['name'] ? "': " . $msg['name'] : "'") . "\n";
fee8c6 68         $err++;
T 69       }
70       echo "\n";
71     }
72
9bacb2 73     if (!$err && $RCI->legacy_config) {
TB 74       echo "WARNING: Your configuration needs to be migrated!\n";
75       echo "We changed the configuration files structure and your two config files main.inc.php and db.inc.php have to be merged into one single file.\n";
76       $err++;
77     }
78
fee8c6 79     // ask user to update config files
T 80     if ($err) {
447fc6 81       if (!$opts['accept']) {
TB 82         echo "Do you want me to fix your local configuration? (y/N)\n";
83         $input = trim(fgets(STDIN));
84       }
fee8c6 85
T 86       // positive: let's merge the local config with the defaults
447fc6 87       if ($opts['accept'] || strtolower($input) == 'y') {
9bacb2 88         $error = $written = false;
461a30 89
fee8c6 90         // backup current config
461a30 91         echo ". backing up the current config file(s)...\n";
AM 92
93         foreach (array('config', 'main', 'db') as $file) {
9bacb2 94           if (file_exists(RCMAIL_CONFIG_DIR . '/' . $file . '.inc.php')) {
461a30 95             if (!copy(RCMAIL_CONFIG_DIR . '/' . $file . '.inc.php', RCMAIL_CONFIG_DIR . '/' . $file . '.old.php')) {
AM 96               $error = true;
97             }
98           }
fee8c6 99         }
461a30 100
AM 101         if (!$error) {
102           $RCI->merge_config();
103           echo ". writing " . RCMAIL_CONFIG_DIR . "/config.inc.php...\n";
fd6b19 104           $written = $RCI->save_configfile($RCI->create_config());
461a30 105         }
AM 106
fee8c6 107         // Success!
9bacb2 108         if ($written) {
fee8c6 109           echo "Done.\n";
0da902 110           echo "Your configuration files are now up-to-date!\n";
471d55 111
TB 112           if ($messages['missing']) {
113             echo "But you still need to add the following missing options:\n";
114             foreach ($messages['missing'] as $msg)
115               echo "- '" . $msg['prop'] . ($msg['name'] ? "': " . $msg['name'] : "'") . "\n";
116           }
9bacb2 117
TB 118           if ($RCI->legacy_config) {
119             foreach (array('main', 'db') as $file) {
120               @unlink(RCMAIL_CONFIG_DIR . '/' . $file . '.inc.php');
121             }
122           }
fee8c6 123         }
T 124         else {
461a30 125           echo "Failed to write config file(s)!\n";
fee8c6 126           echo "Grant write privileges to the current user or update the files manually according to the above messages.\n";
T 127         }
128       }
129       else {
7e7431 130         echo "Please update your config files manually according to the above messages.\n";
fee8c6 131       }
T 132     }
133
134     // check dependencies based on the current configuration
135     if (is_array($messages['dependencies'])) {
136       echo "WARNING: Dependency check failed!\n";
137       echo "(Some of your configuration settings require other options to be configured or additional PHP modules to be installed)\n";
138
139       foreach ($messages['dependencies'] as $msg) {
140         echo "- " . $msg['prop'] . ': ' . $msg['explain'] . "\n";
141       }
142       echo "Please fix your config files and run this script again!\n";
143       echo "See ya.\n";
144     }
145   }
2491c6 146
8f49e4 147   // check file type detection
TB 148   if ($RCI->check_mime_detection()) {
149     echo "WARNING: File type detection doesn't work properly!\n";
8c32f8 150     echo "Please check the 'mime_magic' config option or the finfo functions of PHP and run this script again.\n";
8f49e4 151   }
TB 152   if ($RCI->check_mime_extensions()) {
153     echo "WARNING: Mimetype to file extension mapping doesn't work properly!\n";
154     echo "Please check the 'mime_types' config option and run this script again.\n";
155   }
156
2491c6 157   // check database schema
T 158   if ($RCI->config['db_dsnw']) {
7e7431 159     echo "Executing database schema update.\n";
f5007e 160     system("php " . INSTALL_PATH . "bin/updatedb.sh --package=roundcube --version=" . $opts['version']
7e7431 161       . " --dir=" . INSTALL_PATH . DIRECTORY_SEPARATOR . "SQL", $res);
AM 162
163     $success = !$res;
2491c6 164   }
7e7431 165
faf10e 166   // index contacts for fulltext searching
447fc6 167   if ($opts['version'] && version_compare(version_parse($opts['version']), '0.6.0', '<')) {
f5007e 168     system("php " . INSTALL_PATH . 'bin/indexcontacts.sh');
faf10e 169   }
7e7431 170
2491c6 171   if ($success) {
e019f2 172     echo "This instance of Roundcube is up-to-date.\n";
fee8c6 173     echo "Have fun!\n";
T 174   }
175 }
176 else {
e019f2 177   echo "This instance of Roundcube is not yet configured!\n";
fee8c6 178   echo "Open http://url-to-roundcube/installer/ in your browser and follow the instuctions.\n";
T 179 }
180
d48470 181 ?>