Aleksander Machniak
2016-05-22 77b5d7ee304a688a2eb115ce04b460b43c0dd700
commit | author | age
e6bb83 1 #!/usr/bin/env php
T 2 <?php
3 /*
4  +-----------------------------------------------------------------------+
5  | bin/installto.sh                                                      |
6  |                                                                       |
7  | This file is part of the Roundcube Webmail client                     |
0c137f 8  | Copyright (C) 2014, The Roundcube Dev Team                            |
7fe381 9  |                                                                       |
T 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.                     |
e6bb83 13  |                                                                       |
T 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
0ea079 22 define('INSTALL_PATH', realpath(__DIR__ . '/..') . '/' );
e6bb83 23
6cc3f5 24 require_once INSTALL_PATH . 'program/include/clisetup.php';
e6bb83 25
T 26 $target_dir = unslashify($_SERVER['argv'][1]);
27
28 if (empty($target_dir) || !is_dir(realpath($target_dir)))
f23ef1 29   rcube::raise_error("Invalid target: not a directory\nUsage: installto.sh <TARGET>", false, true);
e6bb83 30
T 31 // read version from iniset.php
32 $iniset = @file_get_contents($target_dir . '/program/include/iniset.php');
33 if (!preg_match('/define\(.RCMAIL_VERSION.,\s*.([0-9.]+[a-z-]*)/', $iniset, $m))
f23ef1 34   rcube::raise_error("No valid Roundcube installation found at $target_dir", false, true);
e6bb83 35
T 36 $oldversion = $m[1];
37
a07926 38 if (version_compare(version_parse($oldversion), version_parse(RCMAIL_VERSION), '>='))
f23ef1 39   rcube::raise_error("Installation at target location is up-to-date!", false, true);
e6bb83 40
T 41 echo "Upgrading from $oldversion. Do you want to continue? (y/N)\n";
42 $input = trim(fgets(STDIN));
43
44 if (strtolower($input) == 'y') {
45   $err = false;
46   echo "Copying files to target location...";
e0481f 47
AM 48   // Save a copy of original .htaccess file (#1490623)
49   if (file_exists("$target_dir/.htaccess")) {
50     $htaccess_copied = copy("$target_dir/.htaccess", "$target_dir/.htaccess.orig");
51   }
52
bd51db 53   $dirs = array('program','installer','bin','SQL','plugins','skins');
TB 54   if (is_dir(INSTALL_PATH . 'vendor') && !is_file(INSTALL_PATH . 'composer.json')) {
55     $dirs[] = 'vendor';
56   }
57   foreach ($dirs as $dir) {
373b11 58     if (!system("rsync -avC " . INSTALL_PATH . "$dir/* $target_dir/$dir/")) {
e6bb83 59       $err = true;
T 60       break;
61     }
62   }
dba43e 63   foreach (array('index.php','.htaccess','config/defaults.inc.php','composer.json-dist','CHANGELOG','README.md','UPGRADING','LICENSE','INSTALL') as $file) {
373b11 64     if (!system("rsync -av " . INSTALL_PATH . "$file $target_dir/$file")) {
e6bb83 65       $err = true;
T 66       break;
67     }
68   }
e0481f 69
14b8b4 70   // remove old (<1.0) .htaccess file
AM 71   @unlink("$target_dir/program/.htaccess");
e0481f 72   echo "done.";
AM 73
74   // Inform the user about .htaccess change
75   if (!empty($htaccess_copied)) {
76     if (file_get_contents("$target_dir/.htaccess") != file_get_contents("$target_dir/.htaccess.orig")) {
77       echo "\n!! Old .htaccess file saved as .htaccess.orig !!";
78     }
79     else {
80       @unlink("$target_dir/.htaccess.orig");
81     }
82   }
83
84   echo "\n\n";
471d55 85
TB 86   if (is_dir("$target_dir/skins/default")) {
87       echo "Removing old default skin...";
a025cd 88       system("rm -rf $target_dir/skins/default $target_dir/plugins/jqueryui/themes/default");
471d55 89       foreach (glob(INSTALL_PATH . "plugins/*/skins") as $plugin_skin_dir) {
TB 90           $plugin_skin_dir = preg_replace('!^.*' . INSTALL_PATH . '!', '', $plugin_skin_dir);
a025cd 91           if (is_dir("$target_dir/$plugin_skin_dir/classic"))
TB 92             system("rm -rf $target_dir/$plugin_skin_dir/default");
471d55 93       }
TB 94       echo "done.\n\n";
95   }
96
e6bb83 97   if (!$err) {
T 98     echo "Running update script at target...\n";
f5007e 99     system("cd $target_dir && php bin/update.sh --version=$oldversion");
e6bb83 100     echo "All done.\n";
T 101   }
102 }
103 else
104   echo "Update cancelled. See ya!\n";
105
106 ?>