| 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) 2011, The Roundcube Dev Team | |
|---|
| 9 | | Licensed under the GNU GPL | |
|---|
| 10 | | | |
|---|
| 11 | | PURPOSE: | |
|---|
| 12 | | Update an existing Roundcube installation with files from | |
|---|
| 13 | | this version | |
|---|
| 14 | +-----------------------------------------------------------------------+ |
|---|
| 15 | | Author: Thomas Bruederli <roundcube@gmail.com> | |
|---|
| 16 | +-----------------------------------------------------------------------+ |
|---|
| 17 | |
|---|
| 18 | $Id$ |
|---|
| 19 | |
|---|
| 20 | */ |
|---|
| 21 | |
|---|
| 22 | if (php_sapi_name() != 'cli') { |
|---|
| 23 | die('Not on the "shell" (php-cli).'); |
|---|
| 24 | } |
|---|
| 25 | define('INSTALL_PATH', realpath(dirname(__FILE__) . '/..') . '/' ); |
|---|
| 26 | |
|---|
| 27 | require_once INSTALL_PATH . 'program/include/iniset.php'; |
|---|
| 28 | |
|---|
| 29 | $target_dir = unslashify($_SERVER['argv'][1]); |
|---|
| 30 | |
|---|
| 31 | if (empty($target_dir) || !is_dir(realpath($target_dir))) |
|---|
| 32 | die("Invalid target: not a directory\nUsage: installto.sh <TARGET>\n"); |
|---|
| 33 | |
|---|
| 34 | // read version from iniset.php |
|---|
| 35 | $iniset = @file_get_contents($target_dir . '/program/include/iniset.php'); |
|---|
| 36 | if (!preg_match('/define\(.RCMAIL_VERSION.,\s*.([0-9.]+[a-z-]*)/', $iniset, $m)) |
|---|
| 37 | die("No valid Roundcube installation found at $target_dir\n"); |
|---|
| 38 | |
|---|
| 39 | $oldversion = $m[1]; |
|---|
| 40 | |
|---|
| 41 | if (version_compare($oldversion, RCMAIL_VERSION, '>=')) |
|---|
| 42 | die("Installation at target location is up-to-date!\n"); |
|---|
| 43 | |
|---|
| 44 | echo "Upgrading from $oldversion. Do you want to continue? (y/N)\n"; |
|---|
| 45 | $input = trim(fgets(STDIN)); |
|---|
| 46 | |
|---|
| 47 | if (strtolower($input) == 'y') { |
|---|
| 48 | $err = false; |
|---|
| 49 | echo "Copying files to target location..."; |
|---|
| 50 | foreach (array('program','installer','bin','SQL','plugins','skins/default') as $dir) { |
|---|
| 51 | if (!system("rsync -avuC " . INSTALL_PATH . "$dir/* $target_dir/$dir/")) { |
|---|
| 52 | $err = true; |
|---|
| 53 | break; |
|---|
| 54 | } |
|---|
| 55 | } |
|---|
| 56 | foreach (array('index.php','.htaccess','config/main.inc.php.dist','config/db.inc.php.dist','CHANGELOG','README','UPGRADING') as $file) { |
|---|
| 57 | if (!system("rsync -avu " . INSTALL_PATH . "$file $target_dir/$file")) { |
|---|
| 58 | $err = true; |
|---|
| 59 | break; |
|---|
| 60 | } |
|---|
| 61 | } |
|---|
| 62 | echo "done.\n\n"; |
|---|
| 63 | |
|---|
| 64 | if (!$err) { |
|---|
| 65 | echo "Running update script at target...\n"; |
|---|
| 66 | system("cd $target_dir && bin/update.sh --version=$oldversion"); |
|---|
| 67 | echo "All done.\n"; |
|---|
| 68 | } |
|---|
| 69 | } |
|---|
| 70 | else |
|---|
| 71 | echo "Update cancelled. See ya!\n"; |
|---|
| 72 | |
|---|
| 73 | ?> |
|---|