1 6 7 package com.quikj.application.utilities.postinstall; 8 9 import java.io.*; 10 import java.util.*; 11 import java.net.*; 12 import java.sql.*; 13 import com.quikj.server.web.*; 14 15 19 public class TextPostInstaller implements ScreenPrinterInterface 20 { 21 private String os; 22 private ConfigParams installParams = new ConfigParams(); 23 private Locale locale = new Locale("en", "US"); 24 private DataValidator dataValidator = new DataValidator(installParams); 25 private BufferedReader reader = new BufferedReader(new InputStreamReader(System.in)); 26 27 28 public TextPostInstaller() 29 { 30 os = System.getProperty("os.name"); 31 ConfigElement e = new ConfigElement(); 32 e.setParamName("ace-version"); 33 e.setParamValue(HTTPApplicationServer.VERSION); 34 e.setReplacePattern("$$ACE(ACE_VERSION)"); 35 installParams.put(e); 36 } 37 38 public void install() 39 { 40 System.out.println("Welcome to the Ace Operator Post Installation Tool.\n" 41 + "This tool will help you setup Ace Operator as per your requirements.\n" 42 + "Please enter the information below. If you want to change some of the\n" 43 + "information you provided, you will be able to do so after the installer\n" 44 + "collects all the data.\n\n"); 45 46 boolean cont = false; 47 do 48 { 49 processUserInput(); 50 cont = displayUserInput(); 51 } 52 while(cont == false); 53 54 if (performReplace() == false) 55 { 56 System.exit(1); 57 } 58 59 if (os.startsWith("Windows") == false) { 61 System.out.println("\nNext we will run shell scripts to create user accounts\n" 62 + "and initialize permissions."); 63 String error = ScriptExecutor.executeUnixInitScript(installParams.find("ace-home").getParamValue(), 64 this); 65 if (error != null) 66 { 67 System.out.println("***WARNING - initialization failed :" 68 + error); 69 70 System.exit(1); 71 } 72 } 73 74 initDB(); 76 77 if (installParams.save( 79 installParams.find("ace-home").getParamValue(), 80 "install.log") == false) 81 { 82 System.out.println("IO Error writing the installation log"); 83 } 84 85 System.out.println("All done"); 86 System.exit(0); 87 } 88 89 90 private void initDB() 91 { 92 System.out.println("\nNext, we will initialize the Ace database"); 93 String ace_folder = installParams.find("ace-home").getParamValue(); 94 try 97 { 98 boolean skip_db_init = false; 99 DBAccess db = null; 100 101 String answer = collectUserInput("Please make sure that you have started the database and then press the ENTER key", 102 ""); 103 104 while (true) 106 { 107 String password = collectUserInput("Enter the root password for the database, enter 'skip' to skip this step", 108 ""); 109 if (password.equals("skip") == true) 110 { 111 skip_db_init = true; 112 113 System.out.println( "The database has not been initialized. To initialize the database manually, using a standard MYSQL client, " 114 + "run the SQL commands specified in the file " 115 + installParams.find("ace-home").getParamValue() 116 + File.separator 117 + "sql" 118 + File.separator 119 + "init_ace.sql"); 120 break; 121 } 122 123 try 124 { 125 db = new DBAccess("com.mysql.jdbc.Driver", 126 installParams.find("sql-host").getParamValue(), 127 "root", password, "test"); 128 break; 129 } 130 catch (SQLException ex) 131 { 132 System.out.println("Login failed. Please try again. If you are unable to login and you think you have the correct " 133 + "root password, it may be because " 134 + "the database is not setup to accept a JDBC connection. You can bypass this step by skipping the " 135 + "database initialization and initialize it manually as per the instructions in the SYSADMIN manual."); 136 } 137 138 } 139 140 if (skip_db_init == false) 141 { 142 if (db.databaseAlreadyExists() == true) 144 { 145 while (true) 146 { 147 answer = collectUserInput("Ace database already exists, do you want to re-initialize the database? (yes/no)", 148 "", "no"); 149 150 if ((answer.equals("yes") == true) || (answer.equalsIgnoreCase("Y") == true)) 151 { 152 System.out.println("Clearing out the old database..."); 154 String path = ace_folder + File.separator + "sql" + 155 File.separator + "clear_ace.sql"; 156 String error = db.executeSQLStatements(path); 157 if (error != null) 158 { 159 System.out.println("Failed to clear out the old database: " 160 + error); 161 System.exit(1); 162 } 163 System.out.println("Old database cleared"); 164 } 165 else if ((answer.equals("no") == true) || (answer.equalsIgnoreCase("N") == true)) 166 { 167 System.out.println("The database will not be initialized"); 168 return; 169 } 170 else 171 { 172 System.out.println("Please enter 'yes' or 'no'"); 173 continue; 174 } 175 break; 176 } 177 } 178 179 System.out.println("Initializing the database ..."); 180 String path = ace_folder + File.separator + "sql" + 181 File.separator + "init_ace.sql"; 182 String error = db.executeSQLStatements(path); 183 if (error != null) 184 { 185 System.out.println("Failed to initialize the database: " 186 + error); 187 System.exit(1); 188 } 189 190 System.out.println("Database initialized"); 191 } 192 } 193 catch (Exception ex1) 194 { 195 System.out.println("Fatal error connecting to the database. Post installation failed to update database"); 196 System.exit(1); 197 } 198 } 199 200 private void processUserInput() 201 { 202 String license_path = "$ACE_HOME" 203 + File.separator 204 + "data" 205 + File.separator 206 + "global" 207 + File.separator 208 + "www" 209 + File.separator 210 + "aceapp" 211 + File.separator 212 + "license" 213 + File.separator 214 + "index.html"; 215 System.out.println("Please read the license agreements for Ace Operator and other bundled products carefully.\n" 216 + "The license agreements are located in the file " 217 + license_path 218 + " where $ACE_HOME is the location where Ace Operator is installed.\n"); 219 220 do 221 { 222 String accept = collectUserInput("Type \"accept\" to accept the terms of the license, type exit to exit installation? (accept/exit)", 223 "", 224 ""); 225 if (accept.equals("accept") == true) 226 { 227 break; 228 } 229 else if (accept.equals("exit") == true) 230 { 231 System.exit(0); 232 } 233 } 234 while (true); 235 236 System.out.println("First, we need to collect some information on how you plan to run the system.\n" 237 + "Please enter the following information.\n"); 238 239 collectEmbeddedWebServerInfo(); 240 241 collectAceHomeInfo(); 242 243 collectAceHostNameInfo(); 244 245 collectJavaHomeInfo(); 246 247 System.out.println("\nNext, we will setup your database parameters.\n" 248 + "Please enter the following information.\n"); 249 250 collectDBHostInfo(); 251 252 collectDBUserInfo(); 253 254 collectDBPasswordInfo(); 255 256 257 System.out.println("\nNext, we will setup your e-mail parameters.\n" 258 + "Please enter the following information.\n"); 259 260 collectSMTPServerInfo(); 261 262 collectOperatorEmailInfo(); 263 264 collectLoggerEmailInfo(); 265 266 collectContactCenterEmailInfo(); 267 268 } 269 270 271 272 private void collectEmbeddedWebServerInfo() 273 { 274 while (true) 275 { 276 String answer = collectUserInput("Do you want to use the bundled Tomcat web server? (yes/no)", 277 "ace-use-bundled-https", 278 "yes"); 279 boolean ws = false; 280 if ((answer.equals("yes") == true) || 281 (answer.equalsIgnoreCase("y") == true)) 282 { 283 ws = true; 284 } 285 else if ((answer.equals("no") == true) || 286 (answer.equalsIgnoreCase("N") == true)) 287 { 288 ws = false; 289 } 290 else 291 { 292 System.out.println("Invalid entry. You must enter 'yes' or 'no'"); 293 continue; 294 } 295 296 String error = dataValidator.validateEmbeddedWebServer(ws, true); 297 if (error != null) 298 { 299 System.out.println(error); 300 continue; 301 } 302 303 break; 304 } 305 } 306 307 private void collectAceHomeInfo() 308 { 309 String def = DataValidator.findAceHome(os); 310 311 while (true) 312 { 313 String answer = collectUserInput("Enter the directory where you installed Ace Operator", 314 "ace-home", def); 315 316 String error = dataValidator.validateAceHome(answer, true); 317 if (error != null) 318 { 319 System.out.println(error); 320 continue; 321 } 322 323 break; 324 } 325 } 326 327 private void collectAceHostNameInfo() 328 { 329 String def = null; 330 try 331 { 332 InetAddress addr = InetAddress.getLocalHost(); 333 def = addr.getHostName(); 334 } 335 catch (UnknownHostException ex) 336 { 337 ; 338 } 339 340 while (true) 341 { 342 String answer = collectUserInput("Enter the external host name of the system", 343 "ace-host", def); 344 345 String error = dataValidator.validateHostName(answer, true); 346 if (error != null) 347 { 348 System.out.println(error); 349 continue; 350 } 351 352 break; 353 } 354 } 355 356 private void collectJavaHomeInfo() 357 { 358 String def = System.getProperty("java.home"); 359 360 while (true) 361 { 362 String answer = collectUserInput("Enter the directory where Java is installed", 363 "java-home", def); 364 365 String error = dataValidator.validateJavaHome(answer, true); 366 if (error != null) 367 { 368 System.out.println(error); 369 continue; 370 } 371 372 break; 373 } 374 } 375 376 private void collectDBHostInfo() 377 { 378 while (true) 379 { 380 String answer = collectUserInput("Enter the host name of the MySQL server", 381 "sql-host", "localhost"); 382 383 String error = dataValidator.validateDBHostName(answer, true); 384 if (error != null) 385 { 386 System.out.println(error); 387 continue; 388 } 389 390 break; 391 } 392 } 393 394 private void collectDBUserInfo() 395 { 396 while (true) 397 { 398 String answer = collectUserInput("Enter the MySQL user name for the owner of the 'ace' database", 399 "sql-user", "ace"); 400 401 String error = dataValidator.validateDBUser(answer, true); 402 if (error != null) 403 { 404 System.out.println(error); 405 continue; 406 } 407 408 break; 409 } 410 } 411 412 private void collectDBPasswordInfo() 413 { 414 while (true) 415 { 416 String answer = collectUserInput("Enter the MySQL password for the above user", 417 "sql-password"); 418 419 String error = dataValidator.validateDBPassword(answer, answer, true); 420 if (error != null) 421 { 422 System.out.println(error); 423 continue; 424 } 425 426 break; 427 } 428 } 429 430 private void collectSMTPServerInfo() 431 { 432 while (true) 433 { 434 String answer = collectUserInput("Enter the SMTP server name", 435 "smtp-server"); 436 437 String error = dataValidator.validateSMTP(answer, true); 438 if (error != null) 439 { 440 System.out.println(error); 441 continue; 442 } 443 444 break; 445 } 446 } 447 448 private void collectOperatorEmailInfo() 449 { 450 while (true) 451 { 452 String answer = collectUserInput("Enter the e-mail address for the default operator group", 453 "operator-email"); 454 455 String error = dataValidator.validateOperatorEmail(answer, true); 456 if (error != null) 457 { 458 System.out.println(error); 459 continue; 460 } 461 462 break; 463 } 464 } 465 466 private void collectLoggerEmailInfo() 467 { 468 while (true) 469 { 470 String answer = collectUserInput("Enter the e-mail address to which all error messages will be sent", 471 "log-email"); 472 473 String error = dataValidator.validateLogEmail(answer, true); 474 if (error != null) 475 { 476 System.out.println(error); 477 continue; 478 } 479 480 break; 481 } 482 } 483 484 private void collectContactCenterEmailInfo() 485 { 486 while (true) 487 { 488 String answer = collectUserInput("Enter the e-mail address for the default Contact Center group", 489 "oos-email"); 490 491 String error = dataValidator.validateOOSEmail(answer, true); 492 if (error != null) 493 { 494 System.out.println(error); 495 continue; 496 } 497 498 break; 499 } 500 } 501 502 private boolean displayUserInput() 503 { 504 System.out.println("\n\nYou entered the following data\n"); 505 506 System.out.print(installParams.displayEnteredValues()); 507 508 while (true) 509 { 510 String answer = collectUserInput("Do you want to change any of the above information you entered? (yes/no)", 511 "", "no"); 512 513 if ((answer.equals("yes") == true) || 514 (answer.equalsIgnoreCase("y") == true)) 515 { 516 return false; 517 } 518 else if ((answer.equals("no") == true) || 519 (answer.equalsIgnoreCase("N") == true)) 520 { 521 return true; 522 } 523 else 524 { 525 System.out.println("Invalid entry. You must enter 'yes' or 'no'"); 526 continue; 527 } 528 } 529 } 530 531 private String collectUserInput(String prompt, String param, String def) 532 { 533 ConfigElement e = installParams.find(param); 534 System.out.print(prompt + " ["); 535 if (e != null) 536 { 537 System.out.print(e.getParamValue()); 538 } 539 else if (def != null) 540 { 541 System.out.print(def); 542 } 543 544 System.out.print("] : "); 545 System.out.flush(); 546 547 try 548 { 549 String line = reader.readLine().trim(); 550 if (line.length() == 0) 551 { 552 if (e != null) 553 { 554 return e.getParamValue(); 555 } 556 else if (def != null) 557 { 558 return def; 559 } 560 else 561 { 562 return ""; 563 } 564 } 565 else return line; 566 } 567 catch (IOException ex) 568 { 569 System.out.println("A fatal error occured while reading input. Terminating..."); 570 System.exit(1); 571 return null; } 573 } 574 575 private String collectUserInput(String prompt, String param) 576 { 577 return collectUserInput(prompt, param, null); 578 } 579 580 public void print(String message) 581 { 582 System.out.print(message); 583 } 584 585 public void println(String message) 586 { 587 System.out.println(message); 588 } 589 590 private boolean performReplace() 591 { 592 System.out.println("\nWe will now configure the system with the values you entered."); 593 boolean result = installParams.replace(installParams.find("ace-home").getParamValue(), 594 ".orig", this); 595 596 if (result == false) 597 { 598 System.out.println(installParams.getErrorMessage()); 599 return false; 600 } 601 602 System.out.println("\nConfiguration files changed."); 603 return true; 604 } 605 } 606 | Popular Tags |