Du kannst nicht mehr als 25 Themen auswählen Themen müssen mit entweder einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.

update.sh 10KB

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