comparison bin/installto.sh @ 8:bf99236cc5cd

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
3 /* 3 /*
4 +-----------------------------------------------------------------------+ 4 +-----------------------------------------------------------------------+
5 | bin/installto.sh | 5 | bin/installto.sh |
6 | | 6 | |
7 | This file is part of the Roundcube Webmail client | 7 | This file is part of the Roundcube Webmail client |
8 | Copyright (C) 2014, The Roundcube Dev Team | 8 | Copyright (C) 2014-2016, The Roundcube Dev Team |
9 | | 9 | |
10 | Licensed under the GNU General Public License version 3 or | 10 | Licensed under the GNU General Public License version 3 or |
11 | any later version with exceptions for skins & plugins. | 11 | any later version with exceptions for skins & plugins. |
12 | See the README file for a full license statement. | 12 | See the README file for a full license statement. |
13 | | 13 | |
20 */ 20 */
21 21
22 define('INSTALL_PATH', realpath(__DIR__ . '/..') . '/' ); 22 define('INSTALL_PATH', realpath(__DIR__ . '/..') . '/' );
23 23
24 require_once INSTALL_PATH . 'program/include/clisetup.php'; 24 require_once INSTALL_PATH . 'program/include/clisetup.php';
25
26 if (!function_exists('system')) {
27 rcube::raise_error("PHP system() function is required. Check disable_functions in php.ini.", false, true);
28 }
25 29
26 $target_dir = unslashify($_SERVER['argv'][1]); 30 $target_dir = unslashify($_SERVER['argv'][1]);
27 31
28 if (empty($target_dir) || !is_dir(realpath($target_dir))) 32 if (empty($target_dir) || !is_dir(realpath($target_dir)))
29 rcube::raise_error("Invalid target: not a directory\nUsage: installto.sh <TARGET>", false, true); 33 rcube::raise_error("Invalid target: not a directory\nUsage: installto.sh <TARGET>", false, true);
40 44
41 echo "Upgrading from $oldversion. Do you want to continue? (y/N)\n"; 45 echo "Upgrading from $oldversion. Do you want to continue? (y/N)\n";
42 $input = trim(fgets(STDIN)); 46 $input = trim(fgets(STDIN));
43 47
44 if (strtolower($input) == 'y') { 48 if (strtolower($input) == 'y') {
45 $err = false;
46 echo "Copying files to target location..."; 49 echo "Copying files to target location...";
50
51 // Save a copy of original .htaccess file (#1490623)
52 if (file_exists("$target_dir/.htaccess")) {
53 $htaccess_copied = copy("$target_dir/.htaccess", "$target_dir/.htaccess.orig");
54 }
55
47 $dirs = array('program','installer','bin','SQL','plugins','skins'); 56 $dirs = array('program','installer','bin','SQL','plugins','skins');
48 if (is_dir(INSTALL_PATH . 'vendor') && !is_file(INSTALL_PATH . 'composer.json')) { 57 if (is_dir(INSTALL_PATH . 'vendor') && !is_file("$target_dir/composer.json")) {
49 $dirs[] = 'vendor'; 58 $dirs[] = 'vendor';
50 } 59 }
51 foreach ($dirs as $dir) { 60 foreach ($dirs as $dir) {
52 if (!system("rsync -avC " . INSTALL_PATH . "$dir/* $target_dir/$dir/")) { 61 // @FIXME: should we use --delete for all directories?
53 $err = true; 62 $delete = in_array($dir, array('program', 'installer', 'vendor')) ? '--delete ' : '';
54 break; 63 $command = "rsync -aC --out-format=%n " . $delete . INSTALL_PATH . "$dir/ $target_dir/$dir/";
64 if (system($command, $ret) === false || $ret > 0) {
65 rcube::raise_error("Failed to execute command: $command", false, true);
55 } 66 }
56 } 67 }
57 foreach (array('index.php','.htaccess','config/defaults.inc.php','composer.json-dist','CHANGELOG','README.md','UPGRADING','LICENSE','INSTALL') as $file) { 68 foreach (array('index.php','.htaccess','config/defaults.inc.php','composer.json-dist','jsdeps.json','CHANGELOG','README.md','UPGRADING','LICENSE','INSTALL') as $file) {
58 if (!system("rsync -av " . INSTALL_PATH . "$file $target_dir/$file")) { 69 $command = "rsync -a --out-format=%n " . INSTALL_PATH . "$file $target_dir/$file";
59 $err = true; 70 if (file_exists(INSTALL_PATH . $file) && (system($command, $ret) === false || $ret > 0)) {
60 break; 71 rcube::raise_error("Failed to execute command: $command", false, true);
61 } 72 }
62 } 73 }
74
63 // remove old (<1.0) .htaccess file 75 // remove old (<1.0) .htaccess file
64 @unlink("$target_dir/program/.htaccess"); 76 @unlink("$target_dir/program/.htaccess");
65 echo "done.\n\n"; 77 echo "done.";
78
79 // Inform the user about .htaccess change
80 if (!empty($htaccess_copied)) {
81 if (file_get_contents("$target_dir/.htaccess") != file_get_contents("$target_dir/.htaccess.orig")) {
82 echo "\n!! Old .htaccess file saved as .htaccess.orig !!";
83 }
84 else {
85 @unlink("$target_dir/.htaccess.orig");
86 }
87 }
88
89 echo "\n\n";
66 90
67 if (is_dir("$target_dir/skins/default")) { 91 if (is_dir("$target_dir/skins/default")) {
68 echo "Removing old default skin..."; 92 echo "Removing old default skin...";
69 system("rm -rf $target_dir/skins/default $target_dir/plugins/jqueryui/themes/default"); 93 system("rm -rf $target_dir/skins/default $target_dir/plugins/jqueryui/themes/default");
70 foreach (glob(INSTALL_PATH . "plugins/*/skins") as $plugin_skin_dir) { 94 foreach (glob(INSTALL_PATH . "plugins/*/skins") as $plugin_skin_dir) {
73 system("rm -rf $target_dir/$plugin_skin_dir/default"); 97 system("rm -rf $target_dir/$plugin_skin_dir/default");
74 } 98 }
75 echo "done.\n\n"; 99 echo "done.\n\n";
76 } 100 }
77 101
78 if (!$err) { 102 // check if js-deps are up-to-date
79 echo "Running update script at target...\n"; 103 if (file_exists("$target_dir/jsdeps.json") && file_exists("$target_dir/bin/install-jsdeps.sh")) {
80 system("cd $target_dir && php bin/update.sh --version=$oldversion"); 104 $jsdeps = json_decode(file_get_contents("$target_dir/jsdeps.json"));
81 echo "All done.\n"; 105 $package = $jsdeps->dependencies[0];
106 $dest_file = $target_dir . '/' . $package->dest;
107 if (!file_exists($dest_file) || sha1_file($dest_file) !== $package->sha1) {
108 echo "Installing JavaScript dependencies...";
109 system("cd $target_dir && bin/install-jsdeps.sh");
110 echo "done.\n\n";
111 }
82 } 112 }
113 else {
114 echo "JavaScript dependencies installation skipped...\n";
115 }
116
117 echo "Running update script at target...\n";
118 system("cd $target_dir && php bin/update.sh --version=$oldversion");
119 echo "All done.\n";
83 } 120 }
84 else 121 else {
85 echo "Update cancelled. See ya!\n"; 122 echo "Update cancelled. See ya!\n";
123 }
86 124
87 ?> 125 ?>