Skip to content

Commit

Permalink
version picker
Browse files Browse the repository at this point in the history
  • Loading branch information
AntonUden committed Apr 1, 2024
1 parent 8735525 commit d9af7a4
Show file tree
Hide file tree
Showing 6 changed files with 141 additions and 14 deletions.
45 changes: 45 additions & 0 deletions dependency-reduced-pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>net.novauniverse</groupId>
<artifactId>TournamentSystemCEInstaller</artifactId>
<version>2.0.0-SNAPSHOT</version>
<build>
<sourceDirectory>src</sourceDirectory>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.1</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
<plugin>
<artifactId>maven-shade-plugin</artifactId>
<version>3.2.4</version>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<artifactId>maven-jar-plugin</artifactId>
<version>3.1.0</version>
<configuration>
<archive>
<manifest>
<addClasspath>true</addClasspath>
<classpathPrefix>src/</classpathPrefix>
<mainClass>net.novauniverse.tournamentsystem.installer.TournamentInstaller</mainClass>
</manifest>
</archive>
</configuration>
</plugin>
</plugins>
</build>
</project>
11 changes: 10 additions & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>net.novauniverse</groupId>
<artifactId>TournamentSystemCEInstaller</artifactId>
<version>1.0.0-SNAPSHOT</version>
<version>2.0.0-SNAPSHOT</version>
<build>
<sourceDirectory>src</sourceDirectory>
<plugins>
Expand Down Expand Up @@ -49,4 +49,13 @@
</plugin>
</plugins>
</build>

<dependencies>
<dependency>
<groupId>org.json</groupId>
<artifactId>json</artifactId>
<version>20240303</version>
<scope>compile</scope>
</dependency>
</dependencies>
</project>
9 changes: 5 additions & 4 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,17 @@ The install script only supports debian based distros!

On linux use the following steps to download the tournament system
* Navigate into the folder you want the files to be located in
* `wget https://cdn.novauniverse.net/tournament_system_ce/install.sh`
* `chmod +x install.sh`
* `./install.sh`
* Run `wget https://cdn.novauniverse.net/tournament_system_ce/install.sh`
* Run `chmod +x install.sh`
* Run `./install.sh`
To start and stop the tournament user `docker compose up` and `docker compose down`. The tournament will automatically start one the install script is finished

### Windows
Before downloading make sure you have docker installed https://www.docker.com/get-started/
* Download the installer from the releases page https://github.com/NovaUniverse/TournamentSystemCEInstaller/releases/
* Put the installer jar in a the folder you want the tournament to be installed to
* Open cmd and navigate into the folder
* Run `java -jar TournamentSystemInstaller.jar`
* Run `java -jar TournamentSystemInstaller.jar <Version>` Replace &lt;version&gt; with the version you want to run. [Available versions can be found here](https://novauniverse.s3.amazonaws.com/tournamentsystem/ce/versions.json)
To start and stop the tournament use start.bat and stop.bat

# Logging in to the admin ui
Expand All @@ -29,3 +29,4 @@ If this is the first time running the tournament system you will have to configu
* If you want to run the tournament in offline mode change OFFLINE_MODE to true in the .env file
* If you move the folder containing the tournament system you need to edit the .env file and change the DATA_DIRECTORY folder
* If you want to change the MySQL password you need to first change it in phpMyAdmin then in the .env file
* While testing we sometimes ran into an issue where it fails to update the map database. To resolve this restart the docker container on windows by running `stop.bat` then `start.bat` or on linux `docker compose down` then `docker compose up`
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,17 @@
import java.io.IOException;
import java.io.InputStreamReader;

import org.json.JSONArray;

import net.novauniverse.tournamentsystem.installer.config.InstallerConfig;
import net.novauniverse.tournamentsystem.installer.utils.DockerUtils;
import net.novauniverse.tournamentsystem.installer.utils.DownloadUtils;
import net.novauniverse.tournamentsystem.installer.utils.FileUtils;
import net.novauniverse.tournamentsystem.installer.utils.HttpUtils;
import net.novauniverse.tournamentsystem.installer.utils.RandomUtils;

public class TournamentInstaller implements Runnable {
public class TournamentInstaller {
public static void main(String[] args) {
new TournamentInstaller().run();
}

@Override
public void run() {
System.out.println("Checking requirements...");
if (!DockerUtils.isDockerInstalled()) {
System.err.println("Docker is not installed on this system. Please install it from https://www.docker.com/get-started/");
Expand All @@ -29,11 +27,50 @@ public void run() {
System.exit(1);
}

System.out.println("Fetching version list...");
JSONArray versions = null;
try {
String versionDataString = HttpUtils.get(InstallerConfig.VERSION_MANIFEST_URL);
if (versionDataString == null) {
System.exit(1);
}
versions = new JSONArray(versionDataString);
} catch (Exception e) {
e.printStackTrace();
System.err.println("An error occued while fetching version info");
System.exit(1);
}

String[] versionStringArray = new String[versions.length()];
for (int i = 0; i < versions.length(); i++) {
versionStringArray[i] = versions.getString(i);
}

if (args.length == 0) {
System.err.println("Please provide what version you want to download. Valid versions are: " + String.join(", ", versionStringArray));
System.exit(1);
}

String selectedVersion = args[0];
boolean isValid = false;
for (int i = 0; i < versions.length(); i++) {
if (selectedVersion.equals(versions.get(i))) {
isValid = true;
break;
}
}

if (!isValid) {
System.err.println("Invalid version: " + selectedVersion + ". Valid ones are: " + String.join(", ", versionStringArray));
System.exit(1);
}

File dockerFile = new File("docker-compose.yml");
String versionUrl = InstallerConfig.DOCKER_COMPOSE_URL.replace("%version%", selectedVersion);
if (!dockerFile.exists()) {
System.out.println("Trying to download docker-conpose.yml from " + InstallerConfig.DOCKER_COMPOSE_URL);
System.out.println("Trying to download docker-conpose.yml from " + versionUrl);
try {
DownloadUtils.downloadFile(InstallerConfig.DOCKER_COMPOSE_URL, dockerFile.getAbsolutePath());
DownloadUtils.downloadFile(versionUrl, dockerFile.getAbsolutePath());
} catch (Exception e) {
e.printStackTrace();
System.err.println("Download failed");
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package net.novauniverse.tournamentsystem.installer.config;

public class InstallerConfig {
public static final String DOCKER_COMPOSE_URL = "https://novauniverse.s3.amazonaws.com/tournamentsystem/ce/docker-compose.yml";
public static final String VERSION_MANIFEST_URL = "https://novauniverse.s3.amazonaws.com/tournamentsystem/ce/versions.json";

public static final String DOCKER_COMPOSE_URL = "https://novauniverse.s3.amazonaws.com/tournamentsystem/ce/prod/%version%/docker-compose.yml";
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package net.novauniverse.tournamentsystem.installer.utils;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.URL;

public class HttpUtils {
public static String get(String urlString) {
StringBuilder response = new StringBuilder();
try {
URL url = new URL(urlString);
HttpURLConnection connection = (HttpURLConnection) url.openConnection();
connection.setRequestMethod("GET");
int responseCode = connection.getResponseCode();
if (responseCode == HttpURLConnection.HTTP_OK) {
BufferedReader in = new BufferedReader(new InputStreamReader(connection.getInputStream()));
String inputLine;
while ((inputLine = in.readLine()) != null) {
response.append(inputLine);
}
in.close();
} else {
System.out.println("Error: " + responseCode);
return null;
}
} catch (IOException e) {
e.printStackTrace();
}
return response.toString();
}
}

0 comments on commit d9af7a4

Please sign in to comment.