From c06908e080e6c7febd54a7e271df4eabee278a7d Mon Sep 17 00:00:00 2001 From: kb01guy Date: Sun, 19 Mar 2023 23:59:28 +0100 Subject: [PATCH] Added Setup-Scripts, Generative-Scripts, Demo-Proj --- mc-java/.env | 10 ++++ mc-java/docker-compose.yml | 11 ++++ mc-java/mc-java.service | 19 +++++++ mc-java/start.ps1 | 1 + mc-java/start.sh | 0 servertool.sh | 112 +++++++++++++++++++++++++++++++++++++ setup-tools-noroot.ps1 | 48 ++++++++++++++++ setup-tools-noroot.sh | 27 +++++++++ setup-tools.sh | 44 +++++++++++++++ 9 files changed, 272 insertions(+) create mode 100644 mc-java/.env create mode 100644 mc-java/docker-compose.yml create mode 100644 mc-java/mc-java.service create mode 100644 mc-java/start.ps1 create mode 100644 mc-java/start.sh create mode 100644 servertool.sh create mode 100644 setup-tools-noroot.ps1 create mode 100644 setup-tools-noroot.sh create mode 100644 setup-tools.sh diff --git a/mc-java/.env b/mc-java/.env new file mode 100644 index 0000000..207650f --- /dev/null +++ b/mc-java/.env @@ -0,0 +1,10 @@ +# Global Vars +TYPE="SPIGOT" +VERSION="1.19" +EULA="TRUE" +ONLINE_MODE="FALSE" +# Docker Vars +JVM_XX_OPTS="-XX:MaxRAMPercentage=75" +# Host Vars +JVM_HOST_OPTS="-Xmx768M -Xms512M -jar spigot.jar nogui" +JAVA_PATH="$JAVA_HOME" \ No newline at end of file diff --git a/mc-java/docker-compose.yml b/mc-java/docker-compose.yml new file mode 100644 index 0000000..17c8ca6 --- /dev/null +++ b/mc-java/docker-compose.yml @@ -0,0 +1,11 @@ +version: '3.8' + +services: + mc-java: + image: itzg/minecraft-server + hostname: mc-java + env_file: .env + #ports: + # - "24454:24454" + volumes: + - ./server:/data \ No newline at end of file diff --git a/mc-java/mc-java.service b/mc-java/mc-java.service new file mode 100644 index 0000000..12be5a5 --- /dev/null +++ b/mc-java/mc-java.service @@ -0,0 +1,19 @@ +[Unit] +Description=Minecraft Server +After=network.target + +[Service] +User=minecraft +Nice=1 +KillMode=none +SuccessExitStatus=0 1 +ProtectHome=true +ProtectSystem=full +PrivateDevices=true +NoNewPrivileges=true +WorkingDirectory=/m/project/kb-one-game-minecraft/mc-java/server +ExecStart=/usr/bin/java -Xmx768M -Xms512M -jar spigot.jar nogui +ExecStop=/m/project/kb-one-game-minecraft/.tools/mcrcon/mcrcon -H 127.0.0.1 -P 25575 -p strong-password stop + +[Install] +WantedBy=multi-user.target \ No newline at end of file diff --git a/mc-java/start.ps1 b/mc-java/start.ps1 new file mode 100644 index 0000000..f413528 --- /dev/null +++ b/mc-java/start.ps1 @@ -0,0 +1 @@ +java -jar template-server/spigot.jar \ No newline at end of file diff --git a/mc-java/start.sh b/mc-java/start.sh new file mode 100644 index 0000000..e69de29 diff --git a/servertool.sh b/servertool.sh new file mode 100644 index 0000000..1c251ab --- /dev/null +++ b/servertool.sh @@ -0,0 +1,112 @@ +#/bin/bash + +# How to Execute this Multi-Purpose script: +# ----------------------------------------- +# execute this Script in a Linux Console or Windows Powershell with: +# bash servertool + +# fill script variables +BASEDIR=$(pwd) +COMMAND=$1; +shift +CONFIG=("$@") + +# Help function prints information about usage of this script. +function print_help { + echo -e " +Welcome to the All in one Minecraft Server Tool +----------------------------------------------- +Usage: servertool [command] [configuration] +COMMAND\tDESCRIPTION\t\t\tEXAMPLE +setup \tInteractive Setup +create \tCreates new configuration \tservertool create test + +-----------------------------------------------"; +# echo -e "start \tStarts configuration"; +# echo -e "stop \tStops running configuration"; +# echo -e "status \tShows Information about configuration"; +# echo -e "remove \tRemoves configuration"; +} + +function list_server { + echo -e "You have currently configured following Servers: " + for i in $(ls -d */); do + echo ${i%%/}; + done +} + +function create_info { + echo -e "$1" +} + +# Creates a new Server Configuration +function create_server { + local name=$1; # any string-value, please no stupid characters + local type=$2; # spigot, paper, bungeecord, waterfall, velocity, etc... + echo -e "Creating Server $name running $type" + echo -e "${#my_array[@]}" + if [ -z "${#my_array[@]}" ]; then + echo "Print create command Help" + elif [ -d "$name" ]; then + echo -e "Server $name allready exists!" + else +# mkdir "$name" +# mkdir "$name/server" + echo -e "version: '3.8' + +services: + $name: + image: itzg/minecraft-server + hostname: $name + environment: + TYPE: \"$type\" + EULA: \"$eula\" + JVM_XX_OPTS: \"-XX:MaxRAMPercentage=75\" + ONLINE_MODE: \"$online\" + SPIGET_RESOURCES: \"70616,7688,73997,34315,51856,16708,92546,28140,80677\" + volumes: + - ./mc-survival:/data" + fi +} + +# Select Command +if [[ -z "$COMMAND" || "$COMMAND" = "help" || "$COMMAND" = "--help" || "$COMMAND" = "-h" ]]; then + print_help +elif [ "$COMMAND" = "create" ]; then + echo "Creating Server"; + create_server $CONFIG; +elif [ "$COMMAND" = "create" ]; then + list_server; +else + print_help +fi +#if ("$COMMAND"=="" || "$COMMAND"=="help" || "$COMMAND"=="--help" || "$COMMAND"=="-h"); then +# print_help; +#fi; + + + + + +# Enable job control +set -m + +while false : +do + read -t 10 -p "input> " input + [[ $input == finish ]] && break + + # set SIGINT to default action + trap - SIGINT + + # Run the command in background + bash -c "$input" & + + # Set our signal mask to ignore SIGINT + trap "" SIGINT + + # Move the command back-into foreground + fg %- + +done + diff --git a/setup-tools-noroot.ps1 b/setup-tools-noroot.ps1 new file mode 100644 index 0000000..10c8b34 --- /dev/null +++ b/setup-tools-noroot.ps1 @@ -0,0 +1,48 @@ +$basedir=(Get-Location) + +# Create File Structure +if (!(Test-Path ".tools/buildtools")){New-Item ".tools/buildtools" -ItemType Directory | Out-Null; Write-Host ("Created Directory .tools/buildtools")} +if (!(Test-Path ".tools/mcrcon" )){New-Item ".tools/mcrcon" -ItemType Directory | Out-Null; Write-Host ("Created Directory .tools/mcrcon" )} +if (!(Test-Path ".tools/nssm" )){New-Item ".tools/nssm" -ItemType Directory | Out-Null; Write-Host ("Created Directory .tools/nssm" )} +if (!(Test-Path ".tools/java" )){New-Item ".tools/java" -ItemType Directory | Out-Null; Write-Host ("Created Directory .tools/java" )} + +# Setup mcrcon +Set-Location $basedir/.tools/mcrcon/ +$release = (Invoke-RestMethod -Uri "https://api.github.com/repos/Tiiffi/mcrcon/releases/latest") +$download = ($release.assets.Where({$_.name -like "*windows*x86-64*"},"First",1)) +if (!((Test-Path $download.name -PathType Leaf) -and (Test-Path "mcrcon.exe" -PathType Leaf))){ + Write-Output ("Downloading mcrcon Version '" + $release.tag_name + "' in '" + (Get-Location) + "'.") + Remove-Item "mcrcon-*-windows-x86-64.zip" + Invoke-WebRequest -Uri $download.browser_download_url -OutFile $download.name + Expand-Archive $download.name . +} else { Write-Output ("Download skipped, mcrcon Version '" + $release.tag_name + "' is allready downloaded.") } + +# Setup BuildTools +Set-Location $basedir/.tools/buildtools +if (!(Test-Path "BuildTools.jar" -PathType Leaf) -or (((get-date)-(get-item "BuildTools.jar").LastWriteTime) -gt (new-timespan -hours 2))){ + Write-Output ("Downloading Build Tools in '" + (Get-Location) + "'.") + Remove-Item "BuildTools.jar" + Invoke-WebRequest -Uri https://hub.spigotmc.org/jenkins/job/BuildTools/lastSuccessfulBuild/artifact/target/BuildTools.jar -OutFile BuildTools.jar +} else { Write-Output ("Download skipped, File .tools/buildtools/BuildTools.jar is newer than 2h.") } + +# Setup NSSM https://nssm.cc/builds +Set-Location $basedir/.tools/nssm +$release = (Invoke-WebRequest -Uri https://nssm.cc/builds).Links.Where({$_.href -like "*ci/nssm*"},"First",1) +$archive_name = $release.href.SubString(4,22) +if (!((Test-Path ($archive_name+".zip") -PathType Leaf) -and (Test-Path "win64/nssm.exe" -PathType Leaf))){ + Write-Output ("Downloading NSSM Version '"+$archive_name.SubString(5,8)+"' in '" + (Get-Location) + "'.") + Remove-Item -Recurse * + Invoke-WebRequest -Uri ("https://nssm.cc"+$release.href) -OutFile ($archive_name+".zip") + Expand-Archive ($archive_name+".zip") . + Move-Item ($archive_name+"\*") . + Remove-Item $archive_name +} else { Write-Output ("Download skipped, NSSM Version '"+$archive_name.SubString(5,8)+"' is allready downloaded.") } + + + + + + +# --------------------------------- +# Go Back to Script-Location +Set-Location $basedir \ No newline at end of file diff --git a/setup-tools-noroot.sh b/setup-tools-noroot.sh new file mode 100644 index 0000000..b2d7835 --- /dev/null +++ b/setup-tools-noroot.sh @@ -0,0 +1,27 @@ +#!/bin/bash + +BASEDIR=$(pwd) + +# Helper +get_latest_release() { # Source: https://gist.github.com/lukechilds/a83e1d7127b78fef38c2914c4ececc3c + curl --silent "https://api.github.com/repos/$1/releases/latest" | # Get latest release from GitHub api + grep '"tag_name":' | # Get tag line + sed -E 's/.*"([^"]+)".*/\1/' # Pluck JSON value +} + +# Create File Structure +mkdir -p ${BASEDIR}/.tools/buildtools && \ +mkdir -p ${BASEDIR}/.tools/mcrcon && \ +mkdir -p ${BASEDIR}/.tools/java + +# Setup mcrcon +cd ${BASEDIR}/.tools/mcrcon/ && \ +LATEST=$(get_latest_release Tiiffi/mcrcon) && \ +ARCHIVE_NAME="mcrcon-${LATEST[@]/v/}-linux-x86-64.tar.gz" && \ +curl -L -o ${ARCHIVE_NAME} https://github.com/Tiiffi/mcrcon/releases/download/${LATEST}/${ARCHIVE_NAME} && \ +tar xfz ${ARCHIVE_NAME} +#chmod +x mcrcon #Needed? + +# Setup BuildTools +cd ${BASEDIR}/.tools/buildtools && \ +curl -L -o BuildTools.jar https://hub.spigotmc.org/jenkins/job/BuildTools/lastSuccessfulBuild/artifact/target/BuildTools.jar diff --git a/setup-tools.sh b/setup-tools.sh new file mode 100644 index 0000000..a8d720d --- /dev/null +++ b/setup-tools.sh @@ -0,0 +1,44 @@ +#!/bin/bash + +BASEDIR=$(pwd) + +# Helper +get_latest_release() { # Source: https://gist.github.com/lukechilds/a83e1d7127b78fef38c2914c4ececc3c + curl --silent "https://api.github.com/repos/$1/releases/latest" | # Get latest release from GitHub api + grep '"tag_name":' | # Get tag line + sed -E 's/.*"([^"]+)".*/\1/' # Pluck JSON value +} + +# Install Essentials +#sudo apt-get update +#sudo apt-get -yq install git build-essential gnupg curl + +# Open JDK install Zulu: Package-Manager apt +#sudo apt-key adv \ +# --keyserver hkp://keyserver.ubuntu.com:80 \ +# --recv-keys 0xB1998361219BD9C9 +#sudo apt-get update +#sudo apt-get install zulu16-jdk + +# Open JDK install Zulu: Direct Download +#curl -O https://cdn.azul.com/zulu/bin/zulu-repo_1.0.0-2_all.deb +#sudo apt-get install ./zulu-repo_1.0.0-2_all.deb + +# Open JDK install Zulu: Portable +#curl -o jdk17.tar.gz https://cdn.azul.com/zulu/bin/zulu17.40.19-ca-jdk17.0.6-linux_x64.tar.gz +#tar xfz jdk17.tar.gz + + +# Create File Structure +mkdir -p ${BASEDIR}/.tools/buildtools && \ +mkdir -p ${BASEDIR}/.tools/java && \ + +# Setup mcrcon +LATEST=$(get_latest_release Tiiffi/mcrcon) +curl -o ${BASEDIR}/tools/mcrcon/mcrcon https://github.com/Tiiffi/mcrcon/releases/download/${LATEST}/mcrcon-${LATEST[@]/v/}-windows-x86-64.zip +cd ${BASEDIR}/tools && git clone https://github.com/Tiiffi/mcrcon.git \ +&& cd ${BASEDIR}/tools/mcrcon && gcc -std=gnu11 -pedantic -Wall -Wextra -O2 -s -o mcrcon mcrcon.c + +# Setup Spigot +cd ${BASEDIR}/tools/buildtools && curl -o BuildTools.jar https://hub.spigotmc.org/jenkins/job/BuildTools/lastSuccessfulBuild/artifact/target/BuildTools.jar \ +&& java -jar BuildTools.jar --rev 1.17