Welcome to mirror list, hosted at ThFree Co, Russian Federation.

installto.sh « bin - github.com/roundcube/roundcubemail.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 0cb8f09d68929252e1a7327be6267966d4f6b286 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
#!/usr/bin/env php
<?php
/*
 +-----------------------------------------------------------------------+
 | This file is part of the Roundcube Webmail client                     |
 |                                                                       |
 | Copyright (C) The Roundcube Dev Team                                  |
 |                                                                       |
 | Licensed under the GNU General Public License version 3 or            |
 | any later version with exceptions for skins & plugins.                |
 | See the README file for a full license statement.                     |
 |                                                                       |
 | PURPOSE:                                                              |
 |   Update an existing Roundcube installation with files from           |
 |   this version                                                        |
 +-----------------------------------------------------------------------+
 | Author: Thomas Bruederli <roundcube@gmail.com>                        |
 +-----------------------------------------------------------------------+
*/

define('INSTALL_PATH', realpath(__DIR__ . '/..') . '/' );

require_once INSTALL_PATH . 'program/include/clisetup.php';

if (!function_exists('system')) {
    rcube::raise_error("PHP system() function is required. Check disable_functions in php.ini.", false, true);
}

$target_dir = unslashify(end($_SERVER['argv']));
$accept = in_array('-y', $_SERVER['argv']) ? 'y' : null;

if (empty($target_dir) || !is_dir(realpath($target_dir))) {
    rcube::raise_error("Invalid target: not a directory\nUsage: installto.sh [-y] <TARGET>", false, true);
}

// read version from iniset.php
$iniset = @file_get_contents($target_dir . '/program/include/iniset.php');
if (!preg_match('/define\(.RCMAIL_VERSION.,\s*.([0-9.]+[a-z0-9-]*)/', $iniset, $m)) {
    rcube::raise_error("No valid Roundcube installation found at $target_dir", false, true);
}

$oldversion = $m[1];

if (version_compare(version_parse($oldversion), version_parse(RCMAIL_VERSION), '>')) {
    rcube::raise_error("Target installation already in version $oldversion.", false, true);
}

if (version_compare(version_parse($oldversion), version_parse(RCMAIL_VERSION), '==')) {
    echo "Target installation already in version $oldversion. Do you want to update again? (y/N)\n";
}
else {
    echo "Upgrading from $oldversion. Do you want to continue? (y/N)\n";
}

$input = $accept ?: trim(fgets(STDIN));

if (strtolower($input) == 'y') {
    echo "Copying files to target location...";

    $adds = [];
    $dirs = ['bin','SQL','plugins','skins','program','public_html'];

    if (is_dir(INSTALL_PATH . 'vendor') && !is_file("$target_dir/composer.json")) {
        $dirs[] = 'vendor';
    }
    if (file_exists("$target_dir/installer")) {
        $dirs[] = 'installer';
    }

    foreach ($dirs as $dir) {
        // @FIXME: should we use --delete for all directories?
        $delete  = in_array($dir, ['program', 'vendor', 'installer']) ? '--delete ' : '';
        $command = "rsync -aC --out-format=%n " . $delete . INSTALL_PATH . "$dir/ $target_dir/$dir/";

        if (system($command, $ret) === false || $ret > 0) {
            rcube::raise_error("Failed to execute command: $command", false, true);
        }
    }

    foreach (['index.php','config/defaults.inc.php','composer.json-dist','jsdeps.json','CHANGELOG.md','README.md','UPGRADING','LICENSE','INSTALL'] as $file) {
        $command = "rsync -a --out-format=%n " . INSTALL_PATH . "$file $target_dir/$file";

        if (file_exists(INSTALL_PATH . $file) && (system($command, $ret) === false || $ret > 0)) {
            rcube::raise_error("Failed to execute command: $command", false, true);
        }
    }

    // Copy .htaccess or .user.ini if needed
    foreach (['.htaccess','.user.ini'] as $file) {
        if (file_exists(INSTALL_PATH . $file)) {
            if (!file_exists("$target_dir/$file") || file_get_contents(INSTALL_PATH . $file) != file_get_contents("$target_dir/$file")) {
                if (copy(INSTALL_PATH . $file, "$target_dir/$file.new")) {
                    echo "$file.new\n";
                    $adds[] = "NOTICE: New $file file saved as $file.new.";
                }
            }
        }
    }

    // remove old (<1.0) .htaccess file
    @unlink("$target_dir/program/.htaccess");
    echo "done.\n\n";

    if (is_dir("$target_dir/skins/default")) {
        echo "Removing old default skin...";
        system("rm -rf $target_dir/skins/default $target_dir/plugins/jqueryui/themes/default");
        foreach (glob(INSTALL_PATH . "plugins/*/skins") as $plugin_skin_dir) {
            $plugin_skin_dir = preg_replace('!^.*' . INSTALL_PATH . '!', '', $plugin_skin_dir);
            if (is_dir("$target_dir/$plugin_skin_dir/classic")) {
                system("rm -rf $target_dir/$plugin_skin_dir/default");
            }
        }
        echo "done.\n\n";
    }

    // Warn about situation when using "complete" package to update "custom" installation (#7087)
    // Note: "Complete" package do not include jsdeps.json nor install-jsdeps.sh
    if (file_exists("$target_dir/jsdeps.json") && !file_exists(INSTALL_PATH . "jsdeps.json")) {
        $adds[] = "WARNING: JavaScript dependencies update skipped. New jsdeps.json file not found.";
    }
    // check if js-deps are up-to-date
    else if (file_exists("$target_dir/jsdeps.json") && file_exists("$target_dir/bin/install-jsdeps.sh")) {
        $jsdeps    = json_decode(file_get_contents("$target_dir/jsdeps.json"));
        $package   = $jsdeps->dependencies[0];
        $dest_file = $target_dir . '/' . $package->dest;

        if (!file_exists($dest_file) || sha1_file($dest_file) !== $package->sha1) {
            echo "Installing JavaScript dependencies...";
            system("cd $target_dir && bin/install-jsdeps.sh");
            echo "done.\n\n";
        }
    }

    if (file_exists("$target_dir/installer")) {
        $adds[] = "NOTICE: The 'installer' directory still exists. You should remove it after the upgrade.";
    }

    if (!empty($adds)) {
        echo implode("\n", $adds) . "\n\n";
    }

    echo "Running update script at target...\n";
    system("cd $target_dir && php bin/update.sh --version=$oldversion" . ($accept ? ' -y' : ''));
    echo "All done.\n";
}
else {
    echo "Update cancelled. See ya!\n";
}