commit | author | age
|
d48470
|
1 |
#!/usr/bin/env php |
fee8c6
|
2 |
<?php |
d48470
|
3 |
if (php_sapi_name() != 'cli') { |
T |
4 |
die('Not on the "shell" (php-cli).'); |
|
5 |
} |
fee8c6
|
6 |
define('INSTALL_PATH', realpath(dirname(__FILE__) . '/..') . '/' ); |
T |
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) { |
2491c6
|
15 |
$success = true; |
T |
16 |
|
fee8c6
|
17 |
if ($messages = $RCI->check_config()) { |
2491c6
|
18 |
$success = false; |
fee8c6
|
19 |
$err = 0; |
T |
20 |
|
|
21 |
// list missing config options |
|
22 |
if (is_array($messages['missing'])) { |
|
23 |
echo "WARNING: Missing config options:\n"; |
|
24 |
echo "(These config options should be present in the current configuration)\n"; |
|
25 |
|
|
26 |
foreach ($messages['missing'] as $msg) { |
cbffc2
|
27 |
echo "- '" . $msg['prop'] . ($msg['name'] ? "': " . $msg['name'] : "'") . "\n"; |
fee8c6
|
28 |
$err++; |
T |
29 |
} |
|
30 |
echo "\n"; |
|
31 |
} |
|
32 |
|
|
33 |
// list old/replaced config options |
|
34 |
if (is_array($messages['replaced'])) { |
|
35 |
echo "WARNING: Replaced config options:\n"; |
|
36 |
echo "(These config options have been replaced or renamed)\n"; |
|
37 |
|
|
38 |
foreach ($messages['replaced'] as $msg) { |
cbffc2
|
39 |
echo "- '" . $msg['prop'] . "' was replaced by '" . $msg['replacement'] . "'\n"; |
fee8c6
|
40 |
$err++; |
T |
41 |
} |
|
42 |
echo "\n"; |
|
43 |
} |
|
44 |
|
|
45 |
// list obsolete config options (just a notice) |
|
46 |
if (is_array($messages['obsolete'])) { |
|
47 |
echo "NOTICE: Obsolete config options:\n"; |
|
48 |
echo "(You still have some obsolete or inexistent properties set. This isn't a problem but should be noticed)\n"; |
|
49 |
|
|
50 |
foreach ($messages['obsolete'] as $msg) { |
cbffc2
|
51 |
echo "- '" . $msg['prop'] . ($msg['name'] ? "': " . $msg['name'] : "'") . "\n"; |
fee8c6
|
52 |
$err++; |
T |
53 |
} |
|
54 |
echo "\n"; |
|
55 |
} |
|
56 |
|
|
57 |
// ask user to update config files |
|
58 |
if ($err) { |
|
59 |
echo "Do you want me to fix your local configuration? (y/N)\n"; |
|
60 |
$input = trim(fgets(STDIN)); |
|
61 |
|
|
62 |
// positive: let's merge the local config with the defaults |
|
63 |
if (strtolower($input) == 'y') { |
|
64 |
$copy1 = $copy2 = $write1 = $write2 = false; |
|
65 |
|
|
66 |
// backup current config |
|
67 |
echo ". backing up the current config files...\n"; |
|
68 |
$copy1 = copy(RCMAIL_CONFIG_DIR . '/main.inc.php', RCMAIL_CONFIG_DIR . '/main.old.php'); |
|
69 |
$copy2 = copy(RCMAIL_CONFIG_DIR . '/db.inc.php', RCMAIL_CONFIG_DIR . '/db.old.php'); |
|
70 |
|
|
71 |
if ($copy1 && $copy2) { |
|
72 |
$RCI->merge_config(); |
|
73 |
|
|
74 |
echo ". writing " . RCMAIL_CONFIG_DIR . "/main.inc.php...\n"; |
|
75 |
$write1 = file_put_contents(RCMAIL_CONFIG_DIR . '/main.inc.php', $RCI->create_config('main', true)); |
|
76 |
echo ". writing " . RCMAIL_CONFIG_DIR . "/main.db.php...\n"; |
|
77 |
$write2 = file_put_contents(RCMAIL_CONFIG_DIR . '/db.inc.php', $RCI->create_config('db', true)); |
|
78 |
} |
|
79 |
|
|
80 |
// Success! |
|
81 |
if ($write1 && $write2) { |
|
82 |
echo "Done.\n"; |
db1a87
|
83 |
echo "Your configuration files are now up-to-date!\n"; |
fee8c6
|
84 |
} |
T |
85 |
else { |
|
86 |
echo "Failed to write config files!\n"; |
|
87 |
echo "Grant write privileges to the current user or update the files manually according to the above messages.\n"; |
|
88 |
} |
|
89 |
} |
|
90 |
else { |
|
91 |
echo "Please update your config files manually according to the above messages.\n"; |
|
92 |
} |
|
93 |
} |
|
94 |
|
|
95 |
// check dependencies based on the current configuration |
|
96 |
if (is_array($messages['dependencies'])) { |
|
97 |
echo "WARNING: Dependency check failed!\n"; |
|
98 |
echo "(Some of your configuration settings require other options to be configured or additional PHP modules to be installed)\n"; |
|
99 |
|
|
100 |
foreach ($messages['dependencies'] as $msg) { |
|
101 |
echo "- " . $msg['prop'] . ': ' . $msg['explain'] . "\n"; |
|
102 |
} |
|
103 |
echo "Please fix your config files and run this script again!\n"; |
|
104 |
echo "See ya.\n"; |
|
105 |
} |
|
106 |
} |
2491c6
|
107 |
|
T |
108 |
// check database schema |
|
109 |
if ($RCI->config['db_dsnw']) { |
|
110 |
$DB = new rcube_mdb2($RCI->config['db_dsnw'], '', false); |
|
111 |
$DB->db_connect('w'); |
|
112 |
if ($db_error_msg = $DB->is_error()) { |
|
113 |
echo "Error connecting to database: $db_error_msg\n"; |
|
114 |
$success = false; |
|
115 |
} |
|
116 |
else if ($RCI->db_schema_check($DB, false)) { |
27a96a
|
117 |
$db_map = array('pgsql' => 'postgres', 'mysqli' => 'mysql', 'sqlsrv' => 'mssql'); |
A |
118 |
$updatefile = INSTALL_PATH . 'SQL/' . (isset($db_map[$DB->db_provider]) ? $db_map[$DB->db_provider] : $DB->db_provider) . '.update.sql'; |
2491c6
|
119 |
echo "WARNING: Database schema needs to be updated!\n"; |
T |
120 |
echo "Open $updatefile and execute all queries that are superscribed with the currently installed version number\n"; |
|
121 |
$success = false; |
|
122 |
} |
|
123 |
} |
|
124 |
|
|
125 |
|
|
126 |
if ($success) { |
e019f2
|
127 |
echo "This instance of Roundcube is up-to-date.\n"; |
fee8c6
|
128 |
echo "Have fun!\n"; |
T |
129 |
} |
|
130 |
} |
|
131 |
else { |
e019f2
|
132 |
echo "This instance of Roundcube is not yet configured!\n"; |
fee8c6
|
133 |
echo "Open http://url-to-roundcube/installer/ in your browser and follow the instuctions.\n"; |
T |
134 |
} |
|
135 |
|
|
136 |
echo "\n"; |
|
137 |
|
d48470
|
138 |
?> |