]> git.donarmstrong.com Git - roundcube.git/blob - bin/update.sh
Imported Upstream version 0.2.1
[roundcube.git] / bin / update.sh
1 #!/usr/bin/env php
2 <?php
3 if (php_sapi_name() != 'cli') {
4     die('Not on the "shell" (php-cli).');
5 }
6 define('INSTALL_PATH', realpath(dirname(__FILE__) . '/..') . '/' );
7
8 require_once INSTALL_PATH . 'program/include/iniset.php';
9 require_once INSTALL_PATH . 'installer/rcube_install.php';
10
11 $RCI = rcube_install::get_instance();
12 $RCI->load_config();
13
14 if ($RCI->configured) {
15   if ($messages = $RCI->check_config()) {
16     $err = 0;
17
18     // list missing config options
19     if (is_array($messages['missing'])) {
20       echo "WARNING: Missing config options:\n";
21       echo "(These config options should be present in the current configuration)\n";
22
23       foreach ($messages['missing'] as $msg) {
24         echo "- '" . $msg['prop'] . ($msg['name'] ? "': " . $msg['name'] : "'") . "\n";
25         $err++;
26       }
27       echo "\n";
28     }
29
30     // list old/replaced config options
31     if (is_array($messages['replaced'])) {
32       echo "WARNING: Replaced config options:\n";
33       echo "(These config options have been replaced or renamed)\n";
34
35       foreach ($messages['replaced'] as $msg) {
36         echo "- '" . $msg['prop'] . "' was replaced by '" . $msg['replacement'] . "'\n";
37         $err++;
38       }
39       echo "\n";
40     }
41
42     // list obsolete config options (just a notice)
43     if (is_array($messages['obsolete'])) {
44       echo "NOTICE: Obsolete config options:\n";
45       echo "(You still have some obsolete or inexistent properties set. This isn't a problem but should be noticed)\n";
46
47       foreach ($messages['obsolete'] as $msg) {
48         echo "- '" . $msg['prop'] . ($msg['name'] ? "': " . $msg['name'] : "'") . "\n";
49         $err++;
50       }
51       echo "\n";
52     }
53
54     // ask user to update config files
55     if ($err) {
56       echo "Do you want me to fix your local configuration? (y/N)\n";
57       $input = trim(fgets(STDIN));
58
59       // positive: let's merge the local config with the defaults
60       if (strtolower($input) == 'y') {
61         $copy1 = $copy2 = $write1 = $write2 = false;
62         
63         // backup current config
64         echo ". backing up the current config files...\n";
65         $copy1 = copy(RCMAIL_CONFIG_DIR . '/main.inc.php', RCMAIL_CONFIG_DIR . '/main.old.php');
66         $copy2 = copy(RCMAIL_CONFIG_DIR . '/db.inc.php', RCMAIL_CONFIG_DIR . '/db.old.php');
67         
68         if ($copy1 && $copy2) {
69           $RCI->merge_config();
70         
71           echo ". writing " . RCMAIL_CONFIG_DIR . "/main.inc.php...\n";
72           $write1 = file_put_contents(RCMAIL_CONFIG_DIR . '/main.inc.php', $RCI->create_config('main', true));
73           echo ". writing " . RCMAIL_CONFIG_DIR . "/main.db.php...\n";
74           $write2 = file_put_contents(RCMAIL_CONFIG_DIR . '/db.inc.php', $RCI->create_config('db', true));
75         }
76         
77         // Success!
78         if ($write1 && $write2) {
79           echo "Done.\n";
80           echo "Your configuration files are now up-tp-date!\n";
81         }
82         else {
83           echo "Failed to write config files!\n";
84           echo "Grant write privileges to the current user or update the files manually according to the above messages.\n";
85         }
86       }
87       else {
88         echo "Please update your config files manually according to the above messages.\n";
89       }
90     }
91
92     // check dependencies based on the current configuration
93     if (is_array($messages['dependencies'])) {
94       echo "WARNING: Dependency check failed!\n";
95       echo "(Some of your configuration settings require other options to be configured or additional PHP modules to be installed)\n";
96
97       foreach ($messages['dependencies'] as $msg) {
98         echo "- " . $msg['prop'] . ': ' . $msg['explain'] . "\n";
99       }
100       echo "Please fix your config files and run this script again!\n";
101       echo "See ya.\n";
102     }
103
104   }
105   else {
106     echo "This instance of RoundCube is up-to-date.\n";
107     echo "Have fun!\n";
108   }
109 }
110 else {
111   echo "This instance of RoundCube is not yet configured!\n";
112   echo "Open http://url-to-roundcube/installer/ in your browser and follow the instuctions.\n";
113 }
114
115 echo "\n";
116
117 ?>