Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100755 189 lines (157 sloc) 7.143 kb
d484704 @till * let's not discriminate unix :) (= generalized paths)
till authored
1 #!/usr/bin/env php
fee8c6c @thomascube First version of the commandline update script
thomascube authored
2 <?php
e6bb836 @thomascube Create interactive update script with improved DB schema check; udate…
thomascube authored
3 /*
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 |
7fe3811 @thomascube Changed license to GNU GPLv3+ with exceptions for skins and plugins
thomascube authored
9 | |
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. |
e6bb836 @thomascube Create interactive update script with improved DB schema check; udate…
thomascube authored
13 | |
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
fee8c6c @thomascube First version of the commandline update script
thomascube authored
22 define('INSTALL_PATH', realpath(dirname(__FILE__) . '/..') . '/' );
23
e6bb836 @thomascube Create interactive update script with improved DB schema check; udate…
thomascube authored
24 require_once INSTALL_PATH . 'program/include/clisetup.php';
fee8c6c @thomascube First version of the commandline update script
thomascube authored
25 require_once INSTALL_PATH . 'installer/rcube_install.php';
26
e6bb836 @thomascube Create interactive update script with improved DB schema check; udate…
thomascube authored
27 // get arguments
28 $opts = get_opt(array('v' => 'version'));
29
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;
35 }
36
37 if ($opts['version'] && version_compare($opts['version'], RCMAIL_VERSION, '>'))
38 die("Nothing to be done here. Bye!\n");
39
40
fee8c6c @thomascube First version of the commandline update script
thomascube authored
41 $RCI = rcube_install::get_instance();
42 $RCI->load_config();
43
44 if ($RCI->configured) {
2491c62 @thomascube Add minimal database schema check to installer and update script
thomascube authored
45 $success = true;
46
fee8c6c @thomascube First version of the commandline update script
thomascube authored
47 if ($messages = $RCI->check_config()) {
2491c62 @thomascube Add minimal database schema check to installer and update script
thomascube authored
48 $success = false;
fee8c6c @thomascube First version of the commandline update script
thomascube authored
49 $err = 0;
50
51 // list missing config options
52 if (is_array($messages['missing'])) {
53 echo "WARNING: Missing config options:\n";
54 echo "(These config options should be present in the current configuration)\n";
55
56 foreach ($messages['missing'] as $msg) {
cbffc2f @thomascube Let update script handle the replacement of 'multiple_identities' by …
thomascube authored
57 echo "- '" . $msg['prop'] . ($msg['name'] ? "': " . $msg['name'] : "'") . "\n";
fee8c6c @thomascube First version of the commandline update script
thomascube authored
58 $err++;
59 }
60 echo "\n";
61 }
62
63 // list old/replaced config options
64 if (is_array($messages['replaced'])) {
65 echo "WARNING: Replaced config options:\n";
66 echo "(These config options have been replaced or renamed)\n";
67
68 foreach ($messages['replaced'] as $msg) {
cbffc2f @thomascube Let update script handle the replacement of 'multiple_identities' by …
thomascube authored
69 echo "- '" . $msg['prop'] . "' was replaced by '" . $msg['replacement'] . "'\n";
fee8c6c @thomascube First version of the commandline update script
thomascube authored
70 $err++;
71 }
72 echo "\n";
73 }
74
75 // list obsolete config options (just a notice)
76 if (is_array($messages['obsolete'])) {
77 echo "NOTICE: Obsolete config options:\n";
78 echo "(You still have some obsolete or inexistent properties set. This isn't a problem but should be noticed)\n";
79
80 foreach ($messages['obsolete'] as $msg) {
cbffc2f @thomascube Let update script handle the replacement of 'multiple_identities' by …
thomascube authored
81 echo "- '" . $msg['prop'] . ($msg['name'] ? "': " . $msg['name'] : "'") . "\n";
fee8c6c @thomascube First version of the commandline update script
thomascube authored
82 $err++;
83 }
84 echo "\n";
85 }
86
87 // ask user to update config files
88 if ($err) {
89 echo "Do you want me to fix your local configuration? (y/N)\n";
90 $input = trim(fgets(STDIN));
91
92 // positive: let's merge the local config with the defaults
93 if (strtolower($input) == 'y') {
94 $copy1 = $copy2 = $write1 = $write2 = false;
95
96 // backup current config
97 echo ". backing up the current config files...\n";
98 $copy1 = copy(RCMAIL_CONFIG_DIR . '/main.inc.php', RCMAIL_CONFIG_DIR . '/main.old.php');
99 $copy2 = copy(RCMAIL_CONFIG_DIR . '/db.inc.php', RCMAIL_CONFIG_DIR . '/db.old.php');
100
101 if ($copy1 && $copy2) {
102 $RCI->merge_config();
103
104 echo ". writing " . RCMAIL_CONFIG_DIR . "/main.inc.php...\n";
105 $write1 = file_put_contents(RCMAIL_CONFIG_DIR . '/main.inc.php', $RCI->create_config('main', true));
106 echo ". writing " . RCMAIL_CONFIG_DIR . "/main.db.php...\n";
107 $write2 = file_put_contents(RCMAIL_CONFIG_DIR . '/db.inc.php', $RCI->create_config('db', true));
108 }
109
110 // Success!
111 if ($write1 && $write2) {
112 echo "Done.\n";
0da9021 @alecpl - Fix typo
alecpl authored
113 echo "Your configuration files are now up-to-date!\n";
471d559 @thomascube Update installto/update script to remove old default skins and copy a…
thomascube authored
114
115 if ($messages['missing']) {
116 echo "But you still need to add the following missing options:\n";
117 foreach ($messages['missing'] as $msg)
118 echo "- '" . $msg['prop'] . ($msg['name'] ? "': " . $msg['name'] : "'") . "\n";
119 }
fee8c6c @thomascube First version of the commandline update script
thomascube authored
120 }
121 else {
122 echo "Failed to write config files!\n";
123 echo "Grant write privileges to the current user or update the files manually according to the above messages.\n";
124 }
125 }
126 else {
e6bb836 @thomascube Create interactive update script with improved DB schema check; udate…
thomascube authored
127 echo "Please update your config files manually according to the above messages.\n\n";
fee8c6c @thomascube First version of the commandline update script
thomascube authored
128 }
129 }
130
131 // check dependencies based on the current configuration
132 if (is_array($messages['dependencies'])) {
133 echo "WARNING: Dependency check failed!\n";
134 echo "(Some of your configuration settings require other options to be configured or additional PHP modules to be installed)\n";
135
136 foreach ($messages['dependencies'] as $msg) {
137 echo "- " . $msg['prop'] . ': ' . $msg['explain'] . "\n";
138 }
139 echo "Please fix your config files and run this script again!\n";
140 echo "See ya.\n";
141 }
2491c62 @thomascube Add minimal database schema check to installer and update script
thomascube authored
142 }
fee8c6c @thomascube First version of the commandline update script
thomascube authored
143
2491c62 @thomascube Add minimal database schema check to installer and update script
thomascube authored
144 // check database schema
145 if ($RCI->config['db_dsnw']) {
91f2271 @alecpl Replace rcube_mdb2 with rcube_db
alecpl authored
146 $DB = rcube_db::factory($RCI->config['db_dsnw'], '', false);
2491c62 @thomascube Add minimal database schema check to installer and update script
thomascube authored
147 $DB->db_connect('w');
148 if ($db_error_msg = $DB->is_error()) {
149 echo "Error connecting to database: $db_error_msg\n";
150 $success = false;
151 }
e6bb836 @thomascube Create interactive update script with improved DB schema check; udate…
thomascube authored
152 else if ($err = $RCI->db_schema_check($DB, false)) {
153 $updatefile = INSTALL_PATH . 'SQL/' . (isset($RCI->db_map[$DB->db_provider]) ? $RCI->db_map[$DB->db_provider] : $DB->db_provider) . '.update.sql';
2491c62 @thomascube Add minimal database schema check to installer and update script
thomascube authored
154 echo "WARNING: Database schema needs to be updated!\n";
e6bb836 @thomascube Create interactive update script with improved DB schema check; udate…
thomascube authored
155 echo join("\n", $err) . "\n\n";
2491c62 @thomascube Add minimal database schema check to installer and update script
thomascube authored
156 $success = false;
e6bb836 @thomascube Create interactive update script with improved DB schema check; udate…
thomascube authored
157
158 if ($opts['version']) {
159 echo "Do you want to run the update queries to get the schmea fixed? (y/N)\n";
160 $input = trim(fgets(STDIN));
161 if (strtolower($input) == 'y') {
162 $success = $RCI->update_db($DB, $opts['version']);
163 }
164 }
165
166 if (!$success)
167 echo "Open $updatefile and execute all queries below the comment with the currently installed version number.\n";
2491c62 @thomascube Add minimal database schema check to installer and update script
thomascube authored
168 }
fee8c6c @thomascube First version of the commandline update script
thomascube authored
169 }
2491c62 @thomascube Add minimal database schema check to installer and update script
thomascube authored
170
faf10e8 @thomascube Fix automatic db updates; trigger contact indexing after upgrade
thomascube authored
171 // index contacts for fulltext searching
172 if (version_compare($opts['version'], '0.6', '<')) {
173 system(INSTALL_PATH . 'bin/indexcontacts.sh');
174 }
2491c62 @thomascube Add minimal database schema check to installer and update script
thomascube authored
175
176 if ($success) {
e019f2d @alecpl - s/RoundCube/Roundcube/
alecpl authored
177 echo "This instance of Roundcube is up-to-date.\n";
fee8c6c @thomascube First version of the commandline update script
thomascube authored
178 echo "Have fun!\n";
179 }
180 }
181 else {
e019f2d @alecpl - s/RoundCube/Roundcube/
alecpl authored
182 echo "This instance of Roundcube is not yet configured!\n";
fee8c6c @thomascube First version of the commandline update script
thomascube authored
183 echo "Open http://url-to-roundcube/installer/ in your browser and follow the instuctions.\n";
184 }
185
186 echo "\n";
187
d484704 @till * let's not discriminate unix :) (= generalized paths)
till authored
188 ?>
Something went wrong with that request. Please try again.