comparison 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
comparison
equal deleted inserted replaced
7:65fd7d441cf1 8:bf99236cc5cd
16 | to a new version | 16 | to a new version |
17 +-----------------------------------------------------------------------+ 17 +-----------------------------------------------------------------------+
18 | Author: Thomas Bruederli <roundcube@gmail.com> | 18 | Author: Thomas Bruederli <roundcube@gmail.com> |
19 +-----------------------------------------------------------------------+ 19 +-----------------------------------------------------------------------+
20 */ 20 */
21 if ($_SERVER['RCMAIL_CONFIG_DIR']) {
22 define('RCMAIL_CONFIG_DIR', $_SERVER['RCMAIL_CONFIG_DIR']);
23 }
24
25 if ($_SERVER['DEBIAN_PKG']) {
26 define('DEBIAN_PKG', TRUE);
27 }
28 21
29 define('INSTALL_PATH', realpath(__DIR__ . '/..') . '/' ); 22 define('INSTALL_PATH', realpath(__DIR__ . '/..') . '/' );
30 23
31 require_once INSTALL_PATH . 'program/include/clisetup.php'; 24 require_once INSTALL_PATH . 'program/include/clisetup.php';
32 25
33 // get arguments 26 // get arguments
34 $opts = rcube_utils::get_opt(array('v' => 'version', 'y' => 'accept')); 27 $opts = rcube_utils::get_opt(array('v' => 'version', 'y' => 'accept:bool'));
35 28
36 // ask user if no version is specified 29 // ask user if no version is specified
37 if (!$opts['version']) { 30 if (!$opts['version']) {
38 echo "What version are you upgrading from? Type '?' if you don't know.\n"; 31 echo "What version are you upgrading from? Type '?' if you don't know.\n";
39 if (($input = trim(fgets(STDIN))) && preg_match('/^[0-9.]+[a-z-]*$/', $input)) 32 if (($input = trim(fgets(STDIN))) && preg_match('/^[0-9.]+[a-z-]*$/', $input))
91 84
92 // positive: let's merge the local config with the defaults 85 // positive: let's merge the local config with the defaults
93 if ($opts['accept'] || strtolower($input) == 'y') { 86 if ($opts['accept'] || strtolower($input) == 'y') {
94 $error = $written = false; 87 $error = $written = false;
95 88
96 if (!DEBIAN_PKG) { 89 // backup current config
97 // backup current config 90 echo ". backing up the current config file(s)...\n";
98 echo ". backing up the current config file(s)...\n"; 91
99 92 foreach (array('config', 'main', 'db') as $file) {
100 foreach (array('config', 'main', 'db') as $file) { 93 if (file_exists(RCMAIL_CONFIG_DIR . '/' . $file . '.inc.php')) {
101 if (file_exists(RCMAIL_CONFIG_DIR . '/' . $file . '.inc.php')) { 94 if (!copy(RCMAIL_CONFIG_DIR . '/' . $file . '.inc.php', RCMAIL_CONFIG_DIR . '/' . $file . '.old.php')) {
102 if (!copy(RCMAIL_CONFIG_DIR . '/' . $file . '.inc.php', RCMAIL_CONFIG_DIR . '/' . $file . '.old.php')) { 95 $error = true;
103 $error = true;
104 }
105 } 96 }
106 } 97 }
107 } 98 }
108 99
109 if (!$error) { 100 if (!$error) {
110 $RCI->merge_config(); 101 $RCI->merge_config();
111 if (DEBIAN_PKG) { 102 echo ". writing " . RCMAIL_CONFIG_DIR . "/config.inc.php...\n";
112 echo ". writing " . RCMAIL_CONFIG_DIR . "/config.inc.php.dpkg-new...\n";
113 } else {
114 echo ". writing " . RCMAIL_CONFIG_DIR . "/config.inc.php...\n";
115 }
116 $written = $RCI->save_configfile($RCI->create_config()); 103 $written = $RCI->save_configfile($RCI->create_config());
117 } 104 }
118 105
119 // Success! 106 // Success!
120 if ($written) { 107 if ($written) {
125 echo "But you still need to add the following missing options:\n"; 112 echo "But you still need to add the following missing options:\n";
126 foreach ($messages['missing'] as $msg) 113 foreach ($messages['missing'] as $msg)
127 echo "- '" . $msg['prop'] . ($msg['name'] ? "': " . $msg['name'] : "'") . "\n"; 114 echo "- '" . $msg['prop'] . ($msg['name'] ? "': " . $msg['name'] : "'") . "\n";
128 } 115 }
129 116
130 if (!DEBIAN_PKG) { 117 if ($RCI->legacy_config) {
131 if ($RCI->legacy_config) { 118 foreach (array('main', 'db') as $file) {
132 foreach (array('main', 'db') as $file) { 119 @unlink(RCMAIL_CONFIG_DIR . '/' . $file . '.inc.php');
133 @unlink(RCMAIL_CONFIG_DIR . '/' . $file . '.inc.php');
134 }
135 } 120 }
136 } 121 }
137 } 122 }
138 else { 123 else {
139 echo "Failed to write config file(s)!\n"; 124 echo "Failed to write config file(s)!\n";
166 if ($RCI->check_mime_extensions()) { 151 if ($RCI->check_mime_extensions()) {
167 echo "WARNING: Mimetype to file extension mapping doesn't work properly!\n"; 152 echo "WARNING: Mimetype to file extension mapping doesn't work properly!\n";
168 echo "Please check the 'mime_types' config option and run this script again.\n"; 153 echo "Please check the 'mime_types' config option and run this script again.\n";
169 } 154 }
170 155
171 if (!DEBIAN_PKG) { 156 // check database schema
172 // check database schema 157 if ($RCI->config['db_dsnw']) {
173 if ($RCI->config['db_dsnw']) { 158 echo "Executing database schema update.\n";
174 echo "Executing database schema update.\n"; 159 $success = rcmail_utils::db_update(INSTALL_PATH . 'SQL', 'roundcube', $opts['version'],
175 system("php " . INSTALL_PATH . "bin/updatedb.sh --package=roundcube --version=" . $opts['version'] 160 array('errors' => true));
176 . " --dir=" . INSTALL_PATH . "SQL", $res);
177
178 $success = !$res;
179 }
180 } 161 }
181 162
182 // update composer dependencies 163 // update composer dependencies
183 if (is_file(INSTALL_PATH . 'composer.json') && is_readable(INSTALL_PATH . 'composer.json-dist')) { 164 if (is_file(INSTALL_PATH . 'composer.json') && is_readable(INSTALL_PATH . 'composer.json-dist')) {
184 $composer_data = json_decode(file_get_contents(INSTALL_PATH . 'composer.json'), true); 165 $composer_data = json_decode(file_get_contents(INSTALL_PATH . 'composer.json'), true);
186 $comsposer_json = null; 167 $comsposer_json = null;
187 168
188 // update the require section with the new dependencies 169 // update the require section with the new dependencies
189 if (is_array($composer_data['require']) && is_array($composer_template['require'])) { 170 if (is_array($composer_data['require']) && is_array($composer_template['require'])) {
190 $composer_data['require'] = array_merge($composer_data['require'], $composer_template['require']); 171 $composer_data['require'] = array_merge($composer_data['require'], $composer_template['require']);
191 /* TO BE ADDED LATER 172
192 $old_packages = array(); 173 // remove obsolete packages
193 for ($old_packages as $pkg) { 174 $old_packages = array(
194 if (array_key_exists($composer_data['require'], $pkg)) { 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'])) {
195 unset($composer_data['require'][$pkg]); 187 unset($composer_data['require'][$pkg]);
196 } 188 }
197 } 189 }
198 */
199 } 190 }
200 191
201 // update the repositories section with the new dependencies 192 // update the repositories section with the new dependencies
202 if (is_array($composer_template['repositories'])) { 193 if (is_array($composer_template['repositories'])) {
203 if (!is_array($composer_data['repositories'])) { 194 if (!is_array($composer_data['repositories'])) {
207 foreach ($composer_template['repositories'] as $repo) { 198 foreach ($composer_template['repositories'] as $repo) {
208 $rkey = $repo['type'] . preg_replace('/^https?:/', '', $repo['url']) . $repo['package']['name']; 199 $rkey = $repo['type'] . preg_replace('/^https?:/', '', $repo['url']) . $repo['package']['name'];
209 $existing = false; 200 $existing = false;
210 foreach ($composer_data['repositories'] as $k => $_repo) { 201 foreach ($composer_data['repositories'] as $k => $_repo) {
211 if ($rkey == $_repo['type'] . preg_replace('/^https?:/', '', $_repo['url']) . $_repo['package']['name']) { 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);
212 $existing = true; 206 $existing = true;
213 break; 207 break;
214 } 208 }
215 // remove old repos 209 // remove old repos
216 else if (strpos($_repo['url'], 'git://git.kolab.org') === 0) { 210 else if (strpos($_repo['url'], 'git://git.kolab.org') === 0) {
217 unset($composer_data['repositories'][$k]); 211 unset($composer_data['repositories'][$k]);
212 }
213 else if ($_repo['type'] == 'package' && $_repo['package']['name'] == 'Net_SMTP') {
214 unset($composer_data['repositories'][$k]);
218 } 215 }
219 } 216 }
220 if (!$existing) { 217 if (!$existing) {
221 $composer_data['repositories'][] = $repo; 218 $composer_data['repositories'][] = $repo;
222 } 219 }
260 echo "NOTE: Update dependencies by running `php composer.phar update --no-dev`\n"; 257 echo "NOTE: Update dependencies by running `php composer.phar update --no-dev`\n";
261 } 258 }
262 259
263 // index contacts for fulltext searching 260 // index contacts for fulltext searching
264 if ($opts['version'] && version_compare(version_parse($opts['version']), '0.6.0', '<')) { 261 if ($opts['version'] && version_compare(version_parse($opts['version']), '0.6.0', '<')) {
265 system("php " . INSTALL_PATH . 'bin/indexcontacts.sh'); 262 rcmail_utils::indexcontacts();
266 } 263 }
267 264
268 if ($success) { 265 if ($success) {
269 echo "This instance of Roundcube is up-to-date.\n"; 266 echo "This instance of Roundcube is up-to-date.\n";
270 echo "Have fun!\n"; 267 echo "Have fun!\n";