Aleksander Machniak
2013-06-14 461a30d771edd8bc6606f2c92dfde363514b93b1
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                     |
8  | Copyright (C) 2010-2011, 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
929030 28 $opts = rcube_utils::get_opt(array('v' => 'version'));
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
63cf4f 39 if ($opts['version'] && version_compare(version_parse($opts['version']), version_parse(RCMAIL_VERSION), '>='))
e6bb83 40   die("Nothing to be done here. Bye!\n");
T 41
fee8c6 42
T 43 $RCI = rcube_install::get_instance();
44 $RCI->load_config();
45
46 if ($RCI->configured) {
2491c6 47   $success = true;
461a30 48
fee8c6 49   if ($messages = $RCI->check_config()) {
2491c6 50     $success = false;
fee8c6 51     $err = 0;
T 52
53     // list old/replaced config options
54     if (is_array($messages['replaced'])) {
55       echo "WARNING: Replaced config options:\n";
56       echo "(These config options have been replaced or renamed)\n";
57
58       foreach ($messages['replaced'] as $msg) {
cbffc2 59         echo "- '" . $msg['prop'] . "' was replaced by '" . $msg['replacement'] . "'\n";
fee8c6 60         $err++;
T 61       }
62       echo "\n";
63     }
64
65     // list obsolete config options (just a notice)
66     if (is_array($messages['obsolete'])) {
67       echo "NOTICE: Obsolete config options:\n";
68       echo "(You still have some obsolete or inexistent properties set. This isn't a problem but should be noticed)\n";
69
70       foreach ($messages['obsolete'] as $msg) {
cbffc2 71         echo "- '" . $msg['prop'] . ($msg['name'] ? "': " . $msg['name'] : "'") . "\n";
fee8c6 72         $err++;
T 73       }
74       echo "\n";
75     }
76
77     // ask user to update config files
78     if ($err) {
79       echo "Do you want me to fix your local configuration? (y/N)\n";
80       $input = trim(fgets(STDIN));
81
82       // positive: let's merge the local config with the defaults
83       if (strtolower($input) == 'y') {
461a30 84         $error = $writed = false;
AM 85
fee8c6 86         // backup current config
461a30 87         echo ". backing up the current config file(s)...\n";
AM 88
89         foreach (array('config', 'main', 'db') as $file) {
90           if (file_exists(RCMAIL_CONFIG_DIR . '/' . $file . '.inc.php'))
91             if (!copy(RCMAIL_CONFIG_DIR . '/' . $file . '.inc.php', RCMAIL_CONFIG_DIR . '/' . $file . '.old.php')) {
92               $error = true;
93             }
94           }
fee8c6 95         }
461a30 96
AM 97         if (!$error) {
98           $RCI->merge_config();
99           echo ". writing " . RCMAIL_CONFIG_DIR . "/config.inc.php...\n";
100           $writed = file_put_contents(RCMAIL_CONFIG_DIR . '/config.inc.php', $RCI->create_config());
101         }
102
fee8c6 103         // Success!
461a30 104         if ($writed) {
fee8c6 105           echo "Done.\n";
0da902 106           echo "Your configuration files are now up-to-date!\n";
471d55 107
TB 108           if ($messages['missing']) {
109             echo "But you still need to add the following missing options:\n";
110             foreach ($messages['missing'] as $msg)
111               echo "- '" . $msg['prop'] . ($msg['name'] ? "': " . $msg['name'] : "'") . "\n";
112           }
fee8c6 113         }
T 114         else {
461a30 115           echo "Failed to write config file(s)!\n";
fee8c6 116           echo "Grant write privileges to the current user or update the files manually according to the above messages.\n";
T 117         }
118       }
119       else {
7e7431 120         echo "Please update your config files manually according to the above messages.\n";
fee8c6 121       }
T 122     }
123
124     // check dependencies based on the current configuration
125     if (is_array($messages['dependencies'])) {
126       echo "WARNING: Dependency check failed!\n";
127       echo "(Some of your configuration settings require other options to be configured or additional PHP modules to be installed)\n";
128
129       foreach ($messages['dependencies'] as $msg) {
130         echo "- " . $msg['prop'] . ': ' . $msg['explain'] . "\n";
131       }
132       echo "Please fix your config files and run this script again!\n";
133       echo "See ya.\n";
134     }
135   }
2491c6 136
T 137   // check database schema
138   if ($RCI->config['db_dsnw']) {
7e7431 139     echo "Executing database schema update.\n";
e4a6eb 140     system(INSTALL_PATH . "bin/updatedb.sh --package=roundcube --version=" . $opts['version']
7e7431 141       . " --dir=" . INSTALL_PATH . DIRECTORY_SEPARATOR . "SQL", $res);
AM 142
143     $success = !$res;
2491c6 144   }
7e7431 145
faf10e 146   // index contacts for fulltext searching
a07926 147   if (version_compare(version_parse($opts['version']), '0.6.0', '<')) {
faf10e 148     system(INSTALL_PATH . 'bin/indexcontacts.sh');
T 149   }
7e7431 150
2491c6 151   if ($success) {
e019f2 152     echo "This instance of Roundcube is up-to-date.\n";
fee8c6 153     echo "Have fun!\n";
T 154   }
155 }
156 else {
e019f2 157   echo "This instance of Roundcube is not yet configured!\n";
fee8c6 158   echo "Open http://url-to-roundcube/installer/ in your browser and follow the instuctions.\n";
T 159 }
160
d48470 161 ?>