|
@@ -18,7 +18,10 @@
|
|
*/
|
|
*/
|
|
package com.l2jserver.cli.command.database;
|
|
package com.l2jserver.cli.command.database;
|
|
|
|
|
|
|
|
+import static com.l2jserver.cli.model.DatabaseInstallType.FULL;
|
|
|
|
+
|
|
import java.io.File;
|
|
import java.io.File;
|
|
|
|
+import java.util.Scanner;
|
|
|
|
|
|
import org.aeonbits.owner.Mutable;
|
|
import org.aeonbits.owner.Mutable;
|
|
|
|
|
|
@@ -29,46 +32,46 @@ import com.l2jserver.cli.dao.GameServerDatabaseDAO;
|
|
import com.l2jserver.cli.dao.LoginServerDatabaseDAO;
|
|
import com.l2jserver.cli.dao.LoginServerDatabaseDAO;
|
|
import com.l2jserver.cli.model.DatabaseInstallType;
|
|
import com.l2jserver.cli.model.DatabaseInstallType;
|
|
import com.l2jserver.cli.model.ServerType;
|
|
import com.l2jserver.cli.model.ServerType;
|
|
|
|
+import com.l2jserver.cli.util.CloseShieldInputStreamReader;
|
|
|
|
|
|
import picocli.CommandLine.Command;
|
|
import picocli.CommandLine.Command;
|
|
import picocli.CommandLine.Option;
|
|
import picocli.CommandLine.Option;
|
|
|
|
|
|
/**
|
|
/**
|
|
* Database install command.
|
|
* Database install command.
|
|
- *
|
|
|
|
* @author Zoey76
|
|
* @author Zoey76
|
|
* @version 1.0.2
|
|
* @version 1.0.2
|
|
*/
|
|
*/
|
|
@Command(name = "install")
|
|
@Command(name = "install")
|
|
public class DatabaseInstallCommand extends AbstractCommand {
|
|
public class DatabaseInstallCommand extends AbstractCommand {
|
|
-
|
|
|
|
|
|
+
|
|
@Option(names = "-sql", required = true, description = "SQL Files location")
|
|
@Option(names = "-sql", required = true, description = "SQL Files location")
|
|
private String path;
|
|
private String path;
|
|
-
|
|
|
|
|
|
+
|
|
@Option(names = "-url", description = "Database URL")
|
|
@Option(names = "-url", description = "Database URL")
|
|
private String url;
|
|
private String url;
|
|
-
|
|
|
|
|
|
+
|
|
@Option(names = "-db", description = "Database Name")
|
|
@Option(names = "-db", description = "Database Name")
|
|
private String name;
|
|
private String name;
|
|
-
|
|
|
|
|
|
+
|
|
@Option(names = "-u", description = "Database User")
|
|
@Option(names = "-u", description = "Database User")
|
|
private String user;
|
|
private String user;
|
|
-
|
|
|
|
|
|
+
|
|
@Option(names = "-p", description = "Database Password")
|
|
@Option(names = "-p", description = "Database Password")
|
|
private String password;
|
|
private String password;
|
|
-
|
|
|
|
|
|
+
|
|
@Option(names = "-m", required = true, description = "Database installation mode")
|
|
@Option(names = "-m", required = true, description = "Database installation mode")
|
|
private DatabaseInstallType mode;
|
|
private DatabaseInstallType mode;
|
|
-
|
|
|
|
|
|
+
|
|
@Option(names = "-t", required = true, description = "Server Type")
|
|
@Option(names = "-t", required = true, description = "Server Type")
|
|
private ServerType serverType;
|
|
private ServerType serverType;
|
|
-
|
|
|
|
|
|
+
|
|
@Option(names = "-c", description = "Custom Tables")
|
|
@Option(names = "-c", description = "Custom Tables")
|
|
private boolean customs;
|
|
private boolean customs;
|
|
-
|
|
|
|
|
|
+
|
|
@Option(names = "-mods", description = "Mods Tables")
|
|
@Option(names = "-mods", description = "Mods Tables")
|
|
private boolean mods;
|
|
private boolean mods;
|
|
-
|
|
|
|
|
|
+
|
|
@Override
|
|
@Override
|
|
public void run() {
|
|
public void run() {
|
|
// Validate files exists
|
|
// Validate files exists
|
|
@@ -77,57 +80,67 @@ public class DatabaseInstallCommand extends AbstractCommand {
|
|
System.err.println("The path does not exist!");
|
|
System.err.println("The path does not exist!");
|
|
return;
|
|
return;
|
|
}
|
|
}
|
|
-
|
|
|
|
|
|
+
|
|
final AbstractDatabaseDAO databaseDAO = databaseDAO();
|
|
final AbstractDatabaseDAO databaseDAO = databaseDAO();
|
|
-
|
|
|
|
- if (mode == DatabaseInstallType.FULL) {
|
|
|
|
- databaseDAO.createDatabase();
|
|
|
|
|
|
+
|
|
|
|
+ try {
|
|
|
|
+ if (mode == FULL) {
|
|
|
|
+ databaseDAO.createDatabase();
|
|
|
|
+ }
|
|
|
|
+ } catch (Exception ex) {
|
|
|
|
+ System.out.print("Seems database already exists, do you want to continue installing? (y/N): ");
|
|
|
|
+ try (var reader = new Scanner(new CloseShieldInputStreamReader(System.in))) {
|
|
|
|
+ final var input = reader.next();
|
|
|
|
+ if (!"y".equalsIgnoreCase(input) && !"yes".equalsIgnoreCase(input)) {
|
|
|
|
+ return;
|
|
|
|
+ }
|
|
|
|
+ }
|
|
}
|
|
}
|
|
-
|
|
|
|
|
|
+
|
|
databaseDAO.createDump();
|
|
databaseDAO.createDump();
|
|
-
|
|
|
|
|
|
+
|
|
databaseDAO.updates(mode, sqlPath);
|
|
databaseDAO.updates(mode, sqlPath);
|
|
-
|
|
|
|
|
|
+
|
|
databaseDAO.basic(sqlPath);
|
|
databaseDAO.basic(sqlPath);
|
|
-
|
|
|
|
|
|
+
|
|
if (customs) {
|
|
if (customs) {
|
|
databaseDAO.custom(sqlPath);
|
|
databaseDAO.custom(sqlPath);
|
|
}
|
|
}
|
|
-
|
|
|
|
|
|
+
|
|
if (mods) {
|
|
if (mods) {
|
|
databaseDAO.mods(sqlPath);
|
|
databaseDAO.mods(sqlPath);
|
|
}
|
|
}
|
|
-
|
|
|
|
|
|
+
|
|
System.out.println("Database installation complete.");
|
|
System.out.println("Database installation complete.");
|
|
}
|
|
}
|
|
-
|
|
|
|
|
|
+
|
|
private AbstractDatabaseDAO databaseDAO() {
|
|
private AbstractDatabaseDAO databaseDAO() {
|
|
switch (serverType) {
|
|
switch (serverType) {
|
|
- case GAME: {
|
|
|
|
- overrideConfigs(Configuration.gameServer());
|
|
|
|
- return new GameServerDatabaseDAO();
|
|
|
|
- }
|
|
|
|
- default:
|
|
|
|
- case LOGIN: {
|
|
|
|
- overrideConfigs(Configuration.loginServer());
|
|
|
|
- return new LoginServerDatabaseDAO();
|
|
|
|
- }
|
|
|
|
|
|
+ case GAME: {
|
|
|
|
+ overrideConfigs(Configuration.gameServer());
|
|
|
|
+ return new GameServerDatabaseDAO();
|
|
|
|
+ }
|
|
|
|
+ default:
|
|
|
|
+ case LOGIN: {
|
|
|
|
+ overrideConfigs(Configuration.loginServer());
|
|
|
|
+ return new LoginServerDatabaseDAO();
|
|
|
|
+ }
|
|
}
|
|
}
|
|
}
|
|
}
|
|
-
|
|
|
|
|
|
+
|
|
private void overrideConfigs(Mutable databaseConfiguration) {
|
|
private void overrideConfigs(Mutable databaseConfiguration) {
|
|
if (url != null) {
|
|
if (url != null) {
|
|
databaseConfiguration.setProperty("DatabaseURL", url);
|
|
databaseConfiguration.setProperty("DatabaseURL", url);
|
|
}
|
|
}
|
|
-
|
|
|
|
|
|
+
|
|
if (user != null) {
|
|
if (user != null) {
|
|
databaseConfiguration.setProperty("DatabaseUser", user);
|
|
databaseConfiguration.setProperty("DatabaseUser", user);
|
|
}
|
|
}
|
|
-
|
|
|
|
|
|
+
|
|
if (password != null) {
|
|
if (password != null) {
|
|
databaseConfiguration.setProperty("DatabasePassword", password);
|
|
databaseConfiguration.setProperty("DatabasePassword", password);
|
|
}
|
|
}
|
|
-
|
|
|
|
|
|
+
|
|
if (name != null) {
|
|
if (name != null) {
|
|
databaseConfiguration.setProperty("DatabaseName", name);
|
|
databaseConfiguration.setProperty("DatabaseName", name);
|
|
}
|
|
}
|