#!/usr/bin/env bash

fileName="fabric-1.21.1.jar"
memory=8192
configPath="./config"
serverConfigDir="server-properties"
packwizPath="http://nginxwebdav:32080/ferdinland/modpacks/server/smp/"

# Install git if it's not installed
export git=$(which git)
if [ -z $git ]
then
	eco installing git...
	echo | sudo -S apt install git
else
	echo git is already installed
fi

# Update config directory
(cd "$configPath" && git pull)

# Copy server-properties
cp --force "$configPath"/"$serverConfigDir"/server.properties ./server.properties
# Copy server-icon.png
cp --force "$configPath"/"$serverConfigDir"/server.properties ./server-icon.png

java -jar packwiz-installer-bootstrap.jar -g -s server https://"$packwizPath"/pack.toml

declare -i memory

java -Xms"$memory"M -Xmx"$memory"M -XX:+UnlockExperimentalVMOptions -XX:+UnlockDiagnosticVMOptions -XX:+AlwaysActAsServerClassMachine -XX:+AlwaysPreTouch -XX:+DisableExplicitGC -XX:+UseNUMA -XX:NmethodSweepActivity=1 -XX:ReservedCodeCacheSize=400M -XX:NonNMethodCodeHeapSize=12M -XX:ProfiledCodeHeapSize=194M -XX:NonProfiledCodeHeapSize=194M -XX:-DontCompileHugeMethods -XX:MaxNodeLimit=240000 -XX:NodeLimitFudgeFactor=8000 -XX:+UseVectorCmov -XX:+PerfDisableSharedMem -XX:+UseFastUnorderedTimeStamps -XX:+UseCriticalJavaThreadPriority -XX:ThreadPriorityPolicy=1 -XX:AllocatePrefetchStyle=3 -XX:+UseZGC -XX:AllocatePrefetchStyle=1 -XX:-ZProactive -jar "$fileName" --nogui
