Mercurial > hg > rc1
comparison bin/update.sh @ 0:1e000243b222
vanilla 1.3.3 distro, I hope
author | Charlie Root |
---|---|
date | Thu, 04 Jan 2018 15:50:29 -0500 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:1e000243b222 |
---|---|
1 #!/usr/bin/env php | |
2 <?php | |
3 /* | |
4 +-----------------------------------------------------------------------+ | |
5 | bin/update.sh | | |
6 | | | |
7 | This file is part of the Roundcube Webmail client | | |
8 | Copyright (C) 2010-2015, The Roundcube Dev Team | | |
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. | | |
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 | |
22 define('INSTALL_PATH', realpath(__DIR__ . '/..') . '/' ); | |
23 | |
24 require_once INSTALL_PATH . 'program/include/clisetup.php'; | |
25 | |
26 // get arguments | |
27 $opts = rcube_utils::get_opt(array('v' => 'version', 'y' => 'accept:bool')); | |
28 | |
29 // ask user if no version is specified | |
30 if (!$opts['version']) { | |
31 echo "What version are you upgrading from? Type '?' if you don't know.\n"; | |
32 if (($input = trim(fgets(STDIN))) && preg_match('/^[0-9.]+[a-z-]*$/', $input)) | |
33 $opts['version'] = $input; | |
34 else | |
35 $opts['version'] = RCMAIL_VERSION; | |
36 } | |
37 | |
38 $RCI = rcmail_install::get_instance(); | |
39 $RCI->load_config(); | |
40 | |
41 if ($RCI->configured) { | |
42 $success = true; | |
43 | |
44 if (($messages = $RCI->check_config()) || $RCI->legacy_config) { | |
45 $success = false; | |
46 $err = 0; | |
47 | |
48 // list old/replaced config options | |
49 if (is_array($messages['replaced'])) { | |
50 echo "WARNING: Replaced config options:\n"; | |
51 echo "(These config options have been replaced or renamed)\n"; | |
52 | |
53 foreach ($messages['replaced'] as $msg) { | |
54 echo "- '" . $msg['prop'] . "' was replaced by '" . $msg['replacement'] . "'\n"; | |
55 $err++; | |
56 } | |
57 echo "\n"; | |
58 } | |
59 | |
60 // list obsolete config options (just a notice) | |
61 if (is_array($messages['obsolete'])) { | |
62 echo "NOTICE: Obsolete config options:\n"; | |
63 echo "(You still have some obsolete or inexistent properties set. This isn't a problem but should be noticed)\n"; | |
64 | |
65 foreach ($messages['obsolete'] as $msg) { | |
66 echo "- '" . $msg['prop'] . ($msg['name'] ? "': " . $msg['name'] : "'") . "\n"; | |
67 $err++; | |
68 } | |
69 echo "\n"; | |
70 } | |
71 | |
72 if (!$err && $RCI->legacy_config) { | |
73 echo "WARNING: Your configuration needs to be migrated!\n"; | |
74 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"; | |
75 $err++; | |
76 } | |
77 | |
78 // ask user to update config files | |
79 if ($err) { | |
80 if (!$opts['accept']) { | |
81 echo "Do you want me to fix your local configuration? (y/N)\n"; | |
82 $input = trim(fgets(STDIN)); | |
83 } | |
84 | |
85 // positive: let's merge the local config with the defaults | |
86 if ($opts['accept'] || strtolower($input) == 'y') { | |
87 $error = $written = false; | |
88 | |
89 // backup current config | |
90 echo ". backing up the current config file(s)...\n"; | |
91 | |
92 foreach (array('config', 'main', 'db') as $file) { | |
93 if (file_exists(RCMAIL_CONFIG_DIR . '/' . $file . '.inc.php')) { | |
94 if (!copy(RCMAIL_CONFIG_DIR . '/' . $file . '.inc.php', RCMAIL_CONFIG_DIR . '/' . $file . '.old.php')) { | |
95 $error = true; | |
96 } | |
97 } | |
98 } | |
99 | |
100 if (!$error) { | |
101 $RCI->merge_config(); | |
102 echo ". writing " . RCMAIL_CONFIG_DIR . "/config.inc.php...\n"; | |
103 $written = $RCI->save_configfile($RCI->create_config()); | |
104 } | |
105 | |
106 // Success! | |
107 if ($written) { | |
108 echo "Done.\n"; | |
109 echo "Your configuration files are now up-to-date!\n"; | |
110 | |
111 if ($messages['missing']) { | |
112 echo "But you still need to add the following missing options:\n"; | |
113 foreach ($messages['missing'] as $msg) | |
114 echo "- '" . $msg['prop'] . ($msg['name'] ? "': " . $msg['name'] : "'") . "\n"; | |
115 } | |
116 | |
117 if ($RCI->legacy_config) { | |
118 foreach (array('main', 'db') as $file) { | |
119 @unlink(RCMAIL_CONFIG_DIR . '/' . $file . '.inc.php'); | |
120 } | |
121 } | |
122 } | |
123 else { | |
124 echo "Failed to write config file(s)!\n"; | |
125 echo "Grant write privileges to the current user or update the files manually according to the above messages.\n"; | |
126 } | |
127 } | |
128 else { | |
129 echo "Please update your config files manually according to the above messages.\n"; | |
130 } | |
131 } | |
132 | |
133 // check dependencies based on the current configuration | |
134 if (is_array($messages['dependencies'])) { | |
135 echo "WARNING: Dependency check failed!\n"; | |
136 echo "(Some of your configuration settings require other options to be configured or additional PHP modules to be installed)\n"; | |
137 | |
138 foreach ($messages['dependencies'] as $msg) { | |
139 echo "- " . $msg['prop'] . ': ' . $msg['explain'] . "\n"; | |
140 } | |
141 echo "Please fix your config files and run this script again!\n"; | |
142 echo "See ya.\n"; | |
143 } | |
144 } | |
145 | |
146 // check file type detection | |
147 if ($RCI->check_mime_detection()) { | |
148 echo "WARNING: File type detection doesn't work properly!\n"; | |
149 echo "Please check the 'mime_magic' config option or the finfo functions of PHP and run this script again.\n"; | |
150 } | |
151 if ($RCI->check_mime_extensions()) { | |
152 echo "WARNING: Mimetype to file extension mapping doesn't work properly!\n"; | |
153 echo "Please check the 'mime_types' config option and run this script again.\n"; | |
154 } | |
155 | |
156 // check database schema | |
157 if ($RCI->config['db_dsnw']) { | |
158 echo "Executing database schema update.\n"; | |
159 $success = rcmail_utils::db_update(INSTALL_PATH . 'SQL', 'roundcube', $opts['version'], | |
160 array('errors' => true)); | |
161 } | |
162 | |
163 // update composer dependencies | |
164 if (is_file(INSTALL_PATH . 'composer.json') && is_readable(INSTALL_PATH . 'composer.json-dist')) { | |
165 $composer_data = json_decode(file_get_contents(INSTALL_PATH . 'composer.json'), true); | |
166 $composer_template = json_decode(file_get_contents(INSTALL_PATH . 'composer.json-dist'), true); | |
167 $comsposer_json = null; | |
168 | |
169 // update the require section with the new dependencies | |
170 if (is_array($composer_data['require']) && is_array($composer_template['require'])) { | |
171 $composer_data['require'] = array_merge($composer_data['require'], $composer_template['require']); | |
172 | |
173 // remove obsolete packages | |
174 $old_packages = array( | |
175 'pear-pear.php.net/net_socket', | |
176 'pear-pear.php.net/auth_sasl', | |
177 'pear-pear.php.net/net_idna2', | |
178 'pear-pear.php.net/mail_mime', | |
179 'pear-pear.php.net/net_smtp', | |
180 'pear-pear.php.net/crypt_gpg', | |
181 'pear-pear.php.net/net_sieve', | |
182 'pear/mail_mime-decode', | |
183 'roundcube/net_sieve', | |
184 ); | |
185 foreach ($old_packages as $pkg) { | |
186 if (array_key_exists($pkg, $composer_data['require'])) { | |
187 unset($composer_data['require'][$pkg]); | |
188 } | |
189 } | |
190 } | |
191 | |
192 // update the repositories section with the new dependencies | |
193 if (is_array($composer_template['repositories'])) { | |
194 if (!is_array($composer_data['repositories'])) { | |
195 $composer_data['repositories'] = array(); | |
196 } | |
197 | |
198 foreach ($composer_template['repositories'] as $repo) { | |
199 $rkey = $repo['type'] . preg_replace('/^https?:/', '', $repo['url']) . $repo['package']['name']; | |
200 $existing = false; | |
201 foreach ($composer_data['repositories'] as $k => $_repo) { | |
202 if ($rkey == $_repo['type'] . preg_replace('/^https?:/', '', $_repo['url']) . $_repo['package']['name']) { | |
203 // switch to https:// | |
204 if (isset($_repo['url']) && strpos($_repo['url'], 'http://') === 0) | |
205 $composer_data['repositories'][$k]['url'] = 'https:' . substr($_repo['url'], 5); | |
206 $existing = true; | |
207 break; | |
208 } | |
209 // remove old repos | |
210 else if (strpos($_repo['url'], 'git://git.kolab.org') === 0) { | |
211 unset($composer_data['repositories'][$k]); | |
212 } | |
213 else if ($_repo['type'] == 'package' && $_repo['package']['name'] == 'Net_SMTP') { | |
214 unset($composer_data['repositories'][$k]); | |
215 } | |
216 } | |
217 if (!$existing) { | |
218 $composer_data['repositories'][] = $repo; | |
219 } | |
220 } | |
221 | |
222 $composer_data['repositories'] = array_values($composer_data['repositories']); | |
223 } | |
224 | |
225 // use the JSON encoder from the Composer package | |
226 if (is_file('composer.phar')) { | |
227 include 'phar://composer.phar/src/Composer/Json/JsonFile.php'; | |
228 $comsposer_json = \Composer\Json\JsonFile::encode($composer_data); | |
229 } | |
230 // PHP 5.4's json_encode() does the job, too | |
231 else if (defined('JSON_PRETTY_PRINT')) { | |
232 $comsposer_json = json_encode($composer_data, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES); | |
233 } | |
234 else { | |
235 $success = false; | |
236 $comsposer_json = null; | |
237 } | |
238 | |
239 // write updated composer.json back to disk | |
240 if ($comsposer_json && is_writeable(INSTALL_PATH . 'composer.json')) { | |
241 $success &= (bool)file_put_contents(INSTALL_PATH . 'composer.json', $comsposer_json); | |
242 } | |
243 else { | |
244 echo "WARNING: unable to update composer.json!\n"; | |
245 echo "Please replace the 'require' section in your composer.json with the following:\n"; | |
246 | |
247 $require_json = ''; | |
248 foreach ($composer_data['require'] as $pkg => $ver) { | |
249 $require_json .= sprintf(' "%s": "%s",'."\n", $pkg, $ver); | |
250 } | |
251 | |
252 echo ' "require": {'."\n"; | |
253 echo rtrim($require_json, ",\n"); | |
254 echo "\n }\n\n"; | |
255 } | |
256 | |
257 echo "NOTE: Update dependencies by running `php composer.phar update --no-dev`\n"; | |
258 } | |
259 | |
260 // index contacts for fulltext searching | |
261 if ($opts['version'] && version_compare(version_parse($opts['version']), '0.6.0', '<')) { | |
262 rcmail_utils::indexcontacts(); | |
263 } | |
264 | |
265 if ($success) { | |
266 echo "This instance of Roundcube is up-to-date.\n"; | |
267 echo "Have fun!\n"; | |
268 } | |
269 } | |
270 else { | |
271 echo "This instance of Roundcube is not yet configured!\n"; | |
272 echo "Open http://url-to-roundcube/installer/ in your browser and follow the instuctions.\n"; | |
273 } | |
274 | |
275 ?> |