You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

installto.sh 5.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. #!/usr/bin/env php
  2. <?php
  3. /*
  4. +-----------------------------------------------------------------------+
  5. | bin/installto.sh |
  6. | |
  7. | This file is part of the Roundcube Webmail client |
  8. | Copyright (C) 2014-2016, 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. | Update an existing Roundcube installation with files from |
  16. | this 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. if (!function_exists('system')) {
  24. rcube::raise_error("PHP system() function is required. Check disable_functions in php.ini.", false, true);
  25. }
  26. $target_dir = unslashify($_SERVER['argv'][1]);
  27. if (empty($target_dir) || !is_dir(realpath($target_dir)))
  28. rcube::raise_error("Invalid target: not a directory\nUsage: installto.sh <TARGET>", false, true);
  29. // read version from iniset.php
  30. $iniset = @file_get_contents($target_dir . '/program/include/iniset.php');
  31. if (!preg_match('/define\(.RCMAIL_VERSION.,\s*.([0-9.]+[a-z-]*)/', $iniset, $m))
  32. rcube::raise_error("No valid Roundcube installation found at $target_dir", false, true);
  33. $oldversion = $m[1];
  34. if (version_compare(version_parse($oldversion), version_parse(RCMAIL_VERSION), '>='))
  35. rcube::raise_error("Installation at target location is up-to-date!", false, true);
  36. echo "Upgrading from $oldversion. Do you want to continue? (y/N)\n";
  37. $input = trim(fgets(STDIN));
  38. if (strtolower($input) == 'y') {
  39. echo "Copying files to target location...";
  40. // Save a copy of original .htaccess file (#1490623)
  41. if (file_exists("$target_dir/.htaccess")) {
  42. $htaccess_copied = copy("$target_dir/.htaccess", "$target_dir/.htaccess.orig");
  43. }
  44. $dirs = array('program','installer','bin','SQL','plugins','skins');
  45. if (is_dir(INSTALL_PATH . 'vendor') && !is_file("$target_dir/composer.json")) {
  46. $dirs[] = 'vendor';
  47. }
  48. foreach ($dirs as $dir) {
  49. // @FIXME: should we use --delete for all directories?
  50. $delete = in_array($dir, array('program', 'installer', 'vendor')) ? '--delete ' : '';
  51. $command = "rsync -aC --out-format=%n " . $delete . INSTALL_PATH . "$dir/ $target_dir/$dir/";
  52. if (system($command, $ret) === false || $ret > 0) {
  53. rcube::raise_error("Failed to execute command: $command", false, true);
  54. }
  55. }
  56. foreach (array('index.php','.htaccess','config/defaults.inc.php','composer.json-dist','jsdeps.json','CHANGELOG','README.md','UPGRADING','LICENSE','INSTALL') as $file) {
  57. $command = "rsync -a --out-format=%n " . INSTALL_PATH . "$file $target_dir/$file";
  58. if (file_exists(INSTALL_PATH . $file) && (system($command, $ret) === false || $ret > 0)) {
  59. rcube::raise_error("Failed to execute command: $command", false, true);
  60. }
  61. }
  62. // remove old (<1.0) .htaccess file
  63. @unlink("$target_dir/program/.htaccess");
  64. echo "done.";
  65. // Inform the user about .htaccess change
  66. if (!empty($htaccess_copied)) {
  67. if (file_get_contents("$target_dir/.htaccess") != file_get_contents("$target_dir/.htaccess.orig")) {
  68. echo "\n!! Old .htaccess file saved as .htaccess.orig !!";
  69. }
  70. else {
  71. @unlink("$target_dir/.htaccess.orig");
  72. }
  73. }
  74. echo "\n\n";
  75. if (is_dir("$target_dir/skins/default")) {
  76. echo "Removing old default skin...";
  77. system("rm -rf $target_dir/skins/default $target_dir/plugins/jqueryui/themes/default");
  78. foreach (glob(INSTALL_PATH . "plugins/*/skins") as $plugin_skin_dir) {
  79. $plugin_skin_dir = preg_replace('!^.*' . INSTALL_PATH . '!', '', $plugin_skin_dir);
  80. if (is_dir("$target_dir/$plugin_skin_dir/classic"))
  81. system("rm -rf $target_dir/$plugin_skin_dir/default");
  82. }
  83. echo "done.\n\n";
  84. }
  85. // check if js-deps are up-to-date
  86. if (file_exists("$target_dir/jsdeps.json") && file_exists("$target_dir/bin/install-jsdeps.sh")) {
  87. $jsdeps = json_decode(file_get_contents("$target_dir/jsdeps.json"));
  88. $package = $jsdeps->dependencies[0];
  89. $dest_file = $target_dir . '/' . $package->dest;
  90. if (!file_exists($dest_file) || sha1_file($dest_file) !== $package->sha1) {
  91. echo "Installing JavaScript dependencies...";
  92. system("cd $target_dir && bin/install-jsdeps.sh");
  93. echo "done.\n\n";
  94. }
  95. }
  96. else {
  97. echo "JavaScript dependencies installation skipped...\n";
  98. }
  99. echo "Running update script at target...\n";
  100. system("cd $target_dir && php bin/update.sh --version=$oldversion");
  101. echo "All done.\n";
  102. }
  103. else {
  104. echo "Update cancelled. See ya!\n";
  105. }
  106. ?>