installto.sh 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  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. $target_dir = unslashify($_SERVER['argv'][1]);
  24. if (empty($target_dir) || !is_dir(realpath($target_dir)))
  25. rcube::raise_error("Invalid target: not a directory\nUsage: installto.sh <TARGET>", false, true);
  26. // read version from iniset.php
  27. $iniset = @file_get_contents($target_dir . '/program/include/iniset.php');
  28. if (!preg_match('/define\(.RCMAIL_VERSION.,\s*.([0-9.]+[a-z-]*)/', $iniset, $m))
  29. rcube::raise_error("No valid Roundcube installation found at $target_dir", false, true);
  30. $oldversion = $m[1];
  31. if (version_compare(version_parse($oldversion), version_parse(RCMAIL_VERSION), '>='))
  32. rcube::raise_error("Installation at target location is up-to-date!", false, true);
  33. echo "Upgrading from $oldversion. Do you want to continue? (y/N)\n";
  34. $input = trim(fgets(STDIN));
  35. if (strtolower($input) == 'y') {
  36. echo "Copying files to target location...";
  37. // Save a copy of original .htaccess file (#1490623)
  38. if (file_exists("$target_dir/.htaccess")) {
  39. $htaccess_copied = copy("$target_dir/.htaccess", "$target_dir/.htaccess.orig");
  40. }
  41. $dirs = array('program','installer','bin','SQL','plugins','skins');
  42. if (is_dir(INSTALL_PATH . 'vendor') && !is_file(INSTALL_PATH . 'composer.json')) {
  43. $dirs[] = 'vendor';
  44. }
  45. foreach ($dirs as $dir) {
  46. // @FIXME: should we use --delete for all directories?
  47. $delete = in_array($dir, array('program', 'installer')) ? '--delete ' : '';
  48. $command = "rsync -aC --out-format \"%n\" " . $delete . INSTALL_PATH . "$dir/* $target_dir/$dir/";
  49. if (!system($command, $ret) || $ret > 0) {
  50. rcube::raise_error("Failed to execute command: $command", false, true);
  51. }
  52. }
  53. foreach (array('index.php','.htaccess','config/defaults.inc.php','composer.json-dist','CHANGELOG','README.md','UPGRADING','LICENSE','INSTALL') as $file) {
  54. $command = "rsync -a --out-format \"%n\" " . INSTALL_PATH . "$file $target_dir/$file";
  55. if (file_exists(INSTALL_PATH . $file) && (!system($command, $ret) || $ret > 0)) {
  56. rcube::raise_error("Failed to execute command: $command", false, true);
  57. }
  58. }
  59. // remove old (<1.0) .htaccess file
  60. @unlink("$target_dir/program/.htaccess");
  61. echo "done.";
  62. // Inform the user about .htaccess change
  63. if (!empty($htaccess_copied)) {
  64. if (file_get_contents("$target_dir/.htaccess") != file_get_contents("$target_dir/.htaccess.orig")) {
  65. echo "\n!! Old .htaccess file saved as .htaccess.orig !!";
  66. }
  67. else {
  68. @unlink("$target_dir/.htaccess.orig");
  69. }
  70. }
  71. echo "\n\n";
  72. if (is_dir("$target_dir/skins/default")) {
  73. echo "Removing old default skin...";
  74. system("rm -rf $target_dir/skins/default $target_dir/plugins/jqueryui/themes/default");
  75. foreach (glob(INSTALL_PATH . "plugins/*/skins") as $plugin_skin_dir) {
  76. $plugin_skin_dir = preg_replace('!^.*' . INSTALL_PATH . '!', '', $plugin_skin_dir);
  77. if (is_dir("$target_dir/$plugin_skin_dir/classic"))
  78. system("rm -rf $target_dir/$plugin_skin_dir/default");
  79. }
  80. echo "done.\n\n";
  81. }
  82. echo "Running update script at target...\n";
  83. system("cd $target_dir && php bin/update.sh --version=$oldversion");
  84. echo "All done.\n";
  85. }
  86. else {
  87. echo "Update cancelled. See ya!\n";
  88. }
  89. ?>