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