#!/bin/bash set -x NEOFORGE_VERSION=21.1.219 SERVER_VERSION=5.5 cd /data if ! [[ "$EULA" = "false" ]]; then echo "eula=true" > eula.txt else echo "You must accept the EULA to install." exit 99 fi if ! [[ -f "Server-Files-$SERVER_VERSION.zip" ]]; then rm -fr config defaultconfigs kubejs mods packmenu Server-Files-* neoforge* curl -Lo "Server-Files-$SERVER_VERSION.zip" \ -A "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/122.0.0.0 Safari/537.36" \ -H "Referer: https://www.curseforge.com/minecraft/modpacks/all-the-mods-10/files" \ "https://mediafilez.forgecdn.net/files/7558/5734/ServerFiles-$SERVER_VERSION.zip" || exit 9 unzip -u -o "Server-Files-$SERVER_VERSION.zip" -d /data DIR_TEST="ServerFiles-$SERVER_VERSION" if [[ $(find . -type d -maxdepth 1 | wc -l) -gt 1 ]]; then cd "${DIR_TEST}" find . -type d -exec chmod 777 {} + mv -f * /data cd /data rm -fr "$DIR_TEST" fi curl -Lo neoforge-${NEOFORGE_VERSION}-installer.jar https://api.mohistmc.com/project/youer/1.21.1/builds/543/download fi if [[ -n "$JVM_OPTS" ]]; then sed -i '/-Xm[s,x]/d' user_jvm_args.txt for j in ${JVM_OPTS}; do echo "$j" >> user_jvm_args.txt; done fi # Initialize whitelist.json if not present if [[ ! -f whitelist.json ]]; then echo "[]" > whitelist.json fi IFS=',' read -ra USERS <<< "$WHITELIST_USERS" for raw_username in "${USERS[@]}"; do username=$(echo "$raw_username" | xargs) if [[ -z "$username" ]] || ! [[ "$username" =~ ^[a-zA-Z0-9_]{3,16}$ ]]; then echo "Whitelist: Invalid or empty username: '$username'. Skipping..." continue fi UUID=$(curl -s "https://playerdb.co/api/player/minecraft/$username" | jq -r '.data.player.id') if [[ "$UUID" != "null" ]]; then if jq -e ".[] | select(.uuid == \"$UUID\" and .name == \"$username\")" whitelist.json > /dev/null; then echo "Whitelist: $username ($UUID) is already whitelisted. Skipping..." else echo "Whitelist: Adding $username ($UUID) to whitelist." jq ". += [{\"uuid\": \"$UUID\", \"name\": \"$username\"}]" whitelist.json > tmp.json && mv tmp.json whitelist.json fi else echo "Whitelist: Failed to fetch UUID for $username." fi done # Initialize ops.json if not present if [[ ! -f ops.json ]]; then echo "[]" > ops.json fi IFS=',' read -ra OPS <<< "$OP_USERS" for raw_username in "${OPS[@]}"; do username=$(echo "$raw_username" | xargs) if [[ -z "$username" ]] || ! [[ "$username" =~ ^[a-zA-Z0-9_]{3,16}$ ]]; then echo "Ops: Invalid or empty username: '$username'. Skipping..." continue fi UUID=$(curl -s "https://playerdb.co/api/player/minecraft/$username" | jq -r '.data.player.id') if [[ "$UUID" != "null" ]]; then if jq -e ".[] | select(.uuid == \"$UUID\" and .name == \"$username\")" ops.json > /dev/null; then echo "Ops: $username ($UUID) is already an operator. Skipping..." else echo "Ops: Adding $username ($UUID) as operator." jq ". += [{\"uuid\": \"$UUID\", \"name\": \"$username\", \"level\": 4, \"bypassesPlayerLimit\": false}]" ops.json > tmp.json && mv tmp.json ops.json fi else echo "Ops: Failed to fetch UUID for $username." fi done # Run installer if server hasn't been installed yet if [[ ! -f "server.jar" ]] || [[ ! -f "run.sh" ]]; then echo "Running NeoForge installer..." java -jar neoforge-${NEOFORGE_VERSION}-installer.jar nogui || exit 1 fi # Apply server.properties overrides (create defaults if missing) if [[ ! -f server.properties ]]; then cat > server.properties << 'EOF' server-port=25565 online-mode=true white-list=false broadcast-rcon-to-ops=true enable-rcon=false rcon.port=25575 rcon.password= max-players=20 allow-flight=false motd=A Minecraft Server EOF fi sed -i 's/server-port.*/server-port=25565/g' server.properties if [[ -n "$MOTD" ]]; then sed -i "s/^motd=.*/motd=$MOTD/" server.properties fi if [[ -n "$ENABLE_WHITELIST" ]]; then sed -i "s/white-list=.*/white-list=$ENABLE_WHITELIST/" server.properties fi if [[ -n "$ALLOW_FLIGHT" ]]; then sed -i "s/allow-flight=.*/allow-flight=$ALLOW_FLIGHT/" server.properties fi if [[ -n "$MAX_PLAYERS" ]]; then sed -i "s/max-players=.*/max-players=$MAX_PLAYERS/" server.properties fi if [[ -n "$ONLINE_MODE" ]]; then sed -i "s/online-mode=.*/online-mode=$ONLINE_MODE/" server.properties fi if [[ -n "$RCON_PASSWORD" ]]; then sed -i "s/enable-rcon=.*/enable-rcon=true/" server.properties sed -i "s/rcon.password=.*/rcon.password=$RCON_PASSWORD/" server.properties sed -i "s/rcon.port=.*/rcon.port=${RCON_PORT:-25575}/" server.properties fi # Start fulfillment daemon in background (only if SHOP_API_URL and RCON_PASSWORD are set) if [[ -n "$SHOP_API_URL" ]] && [[ -n "$SHOP_API_KEY" ]] && [[ -n "$RCON_PASSWORD" ]]; then echo "Starting fulfillment daemon..." python3 /fulfillment.py >> /data/logs/fulfillment.log 2>&1 & else echo "Fulfillment daemon disabled (SHOP_API_URL, SHOP_API_KEY, or RCON_PASSWORD not set)" fi echo "Starting server..." exec ./run.sh nogui