Mercurial > hg > rc1
comparison bin/installto.sh @ 0:1e000243b222
vanilla 1.3.3 distro, I hope
author | Charlie Root |
---|---|
date | Thu, 04 Jan 2018 15:50:29 -0500 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:1e000243b222 |
---|---|
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 | |
22 define('INSTALL_PATH', realpath(__DIR__ . '/..') . '/' ); | |
23 | |
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 } | |
29 | |
30 $target_dir = unslashify($_SERVER['argv'][1]); | |
31 | |
32 if (empty($target_dir) || !is_dir(realpath($target_dir))) | |
33 rcube::raise_error("Invalid target: not a directory\nUsage: installto.sh <TARGET>", false, true); | |
34 | |
35 // read version from iniset.php | |
36 $iniset = @file_get_contents($target_dir . '/program/include/iniset.php'); | |
37 if (!preg_match('/define\(.RCMAIL_VERSION.,\s*.([0-9.]+[a-z-]*)/', $iniset, $m)) | |
38 rcube::raise_error("No valid Roundcube installation found at $target_dir", false, true); | |
39 | |
40 $oldversion = $m[1]; | |
41 | |
42 if (version_compare(version_parse($oldversion), version_parse(RCMAIL_VERSION), '>=')) | |
43 rcube::raise_error("Installation at target location is up-to-date!", false, true); | |
44 | |
45 echo "Upgrading from $oldversion. Do you want to continue? (y/N)\n"; | |
46 $input = trim(fgets(STDIN)); | |
47 | |
48 if (strtolower($input) == 'y') { | |
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 | |
56 $dirs = array('program','installer','bin','SQL','plugins','skins'); | |
57 if (is_dir(INSTALL_PATH . 'vendor') && !is_file("$target_dir/composer.json")) { | |
58 $dirs[] = 'vendor'; | |
59 } | |
60 foreach ($dirs as $dir) { | |
61 // @FIXME: should we use --delete for all directories? | |
62 $delete = in_array($dir, array('program', 'installer', 'vendor')) ? '--delete ' : ''; | |
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); | |
66 } | |
67 } | |
68 foreach (array('index.php','.htaccess','config/defaults.inc.php','composer.json-dist','jsdeps.json','CHANGELOG','README.md','UPGRADING','LICENSE','INSTALL') as $file) { | |
69 $command = "rsync -a --out-format=%n " . INSTALL_PATH . "$file $target_dir/$file"; | |
70 if (file_exists(INSTALL_PATH . $file) && (system($command, $ret) === false || $ret > 0)) { | |
71 rcube::raise_error("Failed to execute command: $command", false, true); | |
72 } | |
73 } | |
74 | |
75 // remove old (<1.0) .htaccess file | |
76 @unlink("$target_dir/program/.htaccess"); | |
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"; | |
90 | |
91 if (is_dir("$target_dir/skins/default")) { | |
92 echo "Removing old default skin..."; | |
93 system("rm -rf $target_dir/skins/default $target_dir/plugins/jqueryui/themes/default"); | |
94 foreach (glob(INSTALL_PATH . "plugins/*/skins") as $plugin_skin_dir) { | |
95 $plugin_skin_dir = preg_replace('!^.*' . INSTALL_PATH . '!', '', $plugin_skin_dir); | |
96 if (is_dir("$target_dir/$plugin_skin_dir/classic")) | |
97 system("rm -rf $target_dir/$plugin_skin_dir/default"); | |
98 } | |
99 echo "done.\n\n"; | |
100 } | |
101 | |
102 // check if js-deps are up-to-date | |
103 if (file_exists("$target_dir/jsdeps.json") && file_exists("$target_dir/bin/install-jsdeps.sh")) { | |
104 $jsdeps = json_decode(file_get_contents("$target_dir/jsdeps.json")); | |
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 } | |
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"; | |
120 } | |
121 else { | |
122 echo "Update cancelled. See ya!\n"; | |
123 } | |
124 | |
125 ?> |