00001 <?php
00002
00019
00020
00021
00022 require(dirname(__FILE__) . '/includes/cliTool.inc.php');
00023
00024 import('install.Install');
00025 import('install.form.InstallForm');
00026 import('site.Version');
00027 import('site.VersionCheck');
00028
00029 class installTool extends CommandLineTool {
00030
00032 var $params;
00033
00038 function installTool($argv = array()) {
00039 parent::CommandLineTool($argv);
00040 }
00041
00045 function usage() {
00046 echo "Install tool\n"
00047 . "Usage: {$this->scriptName}\n";
00048 }
00049
00053 function execute() {
00054 if ($this->readParams()) {
00055 $this->install();
00056 }
00057 }
00058
00062 function install() {
00063 $installer = &new Install($this->params);
00064 $installer->setLogger($this);
00065
00066 if ($installer->execute()) {
00067 if (count($installer->getNotes()) > 0) {
00068 printf("\nRelease Notes\n");
00069 printf("----------------------------------------\n");
00070 foreach ($installer->getNotes() as $note) {
00071 printf("%s\n\n", $note);
00072 }
00073 }
00074
00075 if (!$installer->wroteConfig()) {
00076 printf("\nNew config.inc.php:\n");
00077 printf("----------------------------------------\n");
00078 echo $installer->getConfigContents();
00079 printf("----------------------------------------\n");
00080 }
00081
00082 if ($this->params['manualInstall']) {
00083 if (count($installer->getSQL()) > 0) {
00084 printf("\nSQL\n");
00085 printf("----------------------------------------\n");
00086 foreach ($installer->getSQL() as $sql) {
00087 printf("%s\n\n", $sql);
00088 }
00089 }
00090
00091 } else {
00092 $newVersion = &$installer->getNewVersion();
00093 printf("Successfully installed version %s\n", $newVersion->getVersionString());
00094 }
00095
00096 } else {
00097 printf("ERROR: Installation failed: %s\n", $installer->getErrorString());
00098 }
00099 }
00100
00106 function readParams() {
00107 printf("%s\n", Locale::translate('installer.ojsInstallation'));
00108
00109 $installForm = &new InstallForm();
00110
00111
00112 $this->printTitle('installer.localeSettings');
00113 $this->readParamOptions('locale', 'locale.primary', $installForm->supportedLocales, 'en_US');
00114 $this->readParamOptions('additionalLocales', 'installer.additionalLocales', $installForm->supportedLocales, '', true);
00115 $this->readParamOptions('clientCharset', 'installer.clientCharset', $installForm->supportedClientCharsets, 'utf-8');
00116 $this->readParamOptions('connectionCharset', 'installer.connectionCharset', $installForm->supportedConnectionCharsets, '');
00117 $this->readParamOptions('databaseCharset', 'installer.databaseCharset', $installForm->supportedDatabaseCharsets, '');
00118
00119
00120 $this->printTitle('installer.fileSettings');
00121 $this->readParam('filesDir', 'installer.filesDir');
00122 $this->readParamBoolean('skipFilesDir', 'installer.skipFilesDir');
00123
00124
00125 $this->printTitle('installer.securitySettings');
00126 $this->readParamOptions('encryption', 'installer.encryption', $installForm->supportedEncryptionAlgorithms, 'md5');
00127
00128
00129 $this->printTitle('installer.administratorAccount');
00130 $this->readParam('adminUsername', 'user.username');
00131 @`/bin/stty -echo`;
00132 $this->readParam('adminPassword', 'user.password');
00133 printf("\n");
00134 do {
00135 $this->readParam('adminPassword2', 'user.register.repeatPassword');
00136 printf("\n");
00137 } while ($this->params['adminPassword'] != $this->params['adminPassword2']);
00138 @`/bin/stty echo`;
00139 $this->readParam('adminEmail', 'user.email');
00140
00141
00142 $this->printTitle('installer.databaseSettings');
00143 $this->readParamOptions('databaseDriver', 'installer.databaseDriver', $installForm->checkDBDrivers());
00144 $this->readParam('databaseHost', 'installer.databaseHost', '');
00145 $this->readParam('databaseUsername', 'installer.databaseUsername', '');
00146 $this->readParam('databasePassword', 'installer.databasePassword', '');
00147 $this->readParam('databaseName', 'installer.databaseName');
00148 $this->readParamBoolean('createDatabase', 'installer.createDatabase', 'Y');
00149
00150
00151 $this->printTitle('installer.miscSettings');
00152 $this->readParam('oaiRepositoryId', 'installer.oaiRepositoryId');
00153 $this->readParamBoolean('manualInstall', 'installer.manualInstall');
00154
00155 printf("\n*** ");
00156 $this->readParamBoolean('install', 'installer.installOJS');
00157
00158 return $this->params['install'];
00159 }
00160
00165 function printTitle($title) {
00166 printf("\n%s\n%s\n%s\n", str_repeat('-', 80), Locale::translate($title), str_repeat('-', 80));
00167 }
00168
00173 function readInput() {
00174 $value = trim(fgets(STDIN));
00175 if ($value === false || feof(STDIN)) {
00176 printf("\n");
00177 exit(0);
00178 }
00179 return $value;
00180 }
00181
00188 function readParam($name, $prompt, $defaultValue = null) {
00189 do {
00190 if (isset($defaultValue)) {
00191 printf("%s (%s): ", Locale::translate($prompt), $defaultValue !== '' ? $defaultValue : Locale::translate('common.none'));
00192 } else {
00193 printf("%s: ", Locale::translate($prompt));
00194 }
00195
00196 $value = $this->readInput();
00197
00198 if ($value === '' && isset($defaultValue)) {
00199 $value = $defaultValue;
00200 }
00201 } while ($value === '' && $defaultValue !== '');
00202 $this->params[$name] = $value;
00203 }
00204
00211 function readParamBoolean($name, $prompt, $default = 'N') {
00212 if ($default == 'N') {
00213 printf("%s [y/N] ", Locale::translate($prompt));
00214 $value = $this->readInput();
00215 $this->params[$name] = (int)(strtolower(substr(trim($value), 0, 1)) == 'y');
00216 } else {
00217 printf("%s [Y/n] ", Locale::translate($prompt));
00218 $value = $this->readInput();
00219 $this->params[$name] = (int)(strtolower(substr(trim($value), 0, 1)) != 'n');
00220 }
00221 }
00222
00230 function readParamOptions($name, $prompt, $options, $defaultValue = null, $allowMultiple = false) {
00231 do {
00232 printf("%s\n", Locale::translate($prompt));
00233 foreach ($options as $k => $v) {
00234 printf(" %-10s %s\n", '[' . $k . ']', $v);
00235 }
00236 if ($allowMultiple) {
00237 printf(" (%s)\n", Locale::translate('installer.form.separateMultiple'));
00238 }
00239 if (isset($defaultValue)) {
00240 printf("%s (%s): ", Locale::translate('common.select'), $defaultValue !== '' ? $defaultValue : Locale::translate('common.none'));
00241 } else {
00242 printf("%s: ", Locale::translate('common.select'));
00243 }
00244
00245 $value = $this->readInput();
00246
00247 if ($value === '' && isset($defaultValue)) {
00248 $value = $defaultValue;
00249 }
00250
00251 $values = array();
00252 if ($value !== '') {
00253 if ($allowMultiple) {
00254 $values = ($value === '' ? array() : preg_split('/\s*,\s*/', $value));
00255 } else {
00256 $values = array($value);
00257 }
00258 foreach ($values as $k) {
00259 if (!isset($options[$k])) {
00260 $value = '';
00261 break;
00262 }
00263 }
00264 }
00265 } while ($value === '' && $defaultValue !== '');
00266
00267 if ($allowMultiple) {
00268 $this->params[$name] = $values;
00269 } else {
00270 $this->params[$name] = $value;
00271 }
00272 }
00273
00278 function log($message) {
00279 printf("[%s]\n", $message);
00280 }
00281
00282 }
00283
00284 $tool = &new installTool(isset($argv) ? $argv : array());
00285 $tool->execute();
00286 ?>