resolved path issues and added op file generation

This commit is contained in:
Patrick Kuhs 2025-02-08 15:58:17 +01:00
parent 2dc0974957
commit f51c269431
2 changed files with 38 additions and 25 deletions

View File

@ -6,7 +6,7 @@ services:
container_name: YOUR_CONTAINER_NAME
restart: always
volumes:
- "YOUR_SERVER_LOCATION":/server:z
- "YOUR_SERVER_LOCATION":/home/server/instance:z
ports:
- "YOUR_PORT:25565"
environment:

View File

@ -1,12 +1,10 @@
#!/bin/bash
# Enter server directory
cd /home/server/instance
SERVER_DIR=/home/server/instance
cd $SERVER_DIR
# Set nullstrings back to 'latest'
: ${MINECRAFT_VERSION:='latest'}
# Lowercase these to avoid 404 errors on wget
MINECRAFT_VERSION="${MINECRAFT_VERSION,,}"
PROJECT="paper"
@ -32,11 +30,9 @@ JAVA_OPTS=" -XX:+UseG1GC -XX:+ParallelRefProcEnabled \
-Daikars.new.flags=true \
-Dusing.aikars.flags=https://mcflags.emc.gs"
# Get version information and build download URL and jar name
URL='https://papermc.io/api/v2/projects/paper'
if [[ $MINECRAFT_VERSION == latest ]]
then
# Get the latest MC version
MINECRAFT_VERSION=$(curl -s https://api.papermc.io/v2/projects/${PROJECT} | \
jq -r '.versions[-1]')
fi
@ -44,43 +40,40 @@ fi
LATEST_BUILD=$(curl -s https://api.papermc.io/v2/projects/${PROJECT}/versions/${MINECRAFT_VERSION}/builds | \
jq -r '.builds | map(select(.channel == "default") | .build) | .[-1]')
# update server.jar to latest stable
if [ "$LATEST_BUILD" != "null" ]; then
JAR_NAME=${PROJECT}-${MINECRAFT_VERSION}-${LATEST_BUILD}.jar
PAPERMC_URL="https://api.papermc.io/v2/projects/${PROJECT}/versions/${MINECRAFT_VERSION}/builds/${LATEST_BUILD}/downloads/${JAR_NAME}"
rm -f *.jar
# Download the latest Paper version
curl -o server.jar $PAPERMC_URL
curl -o $SERVER_DIR/server.jar $PAPERMC_URL
echo "Download completed"
else
echo "No stable build for version $MINECRAFT_VERSION found :("
fi
# Update eula.txt with current setting
echo "eula=${EULA:-false}" > eula.txt
# Add RAM options to Java options if necessary
if [[ -n $SERVER_MEMORY ]]
then
JAVA_OPTS="-Xms${SERVER_MEMORY} -Xmx${SERVER_MEMORY} $JAVA_OPTS"
fi
# prepare server properties
SERVER_PROPERTIES=$SERVER_DIR/server.properties
SERVER_WHITELIST=$SERVER_DIR/whitelist.json
SERVER_OPLIST=$SERVER_DIR/ops.json
WHITELIST_PREP=$SERVER_DIR/whitelist.prep
OPLIST_PREP=$SERVER_DIR/op.prep
SERVER_PROPERTIES=/server/server.properties
if [ -f /server/server.properties ]; then
if [ -f $SERVER_PROPERTIES ]; then
mv $SERVER_PROPERTIES $SERVER_PROPERTIES.bkp
rm $SERVER_PROPERTIES
touch $SERVER_PROPERTIES
fi
if [ -f /server/whitelist.prep ]; then
echo -n "[" > /server/whitelist.json
cat /server/whitelist.prep | while read u
if [ -f $WHITELIST_PREP ]; then
echo -n "[" > $SERVER_WHITELIST
cat $WHITELIST_PREP | while read u
do
echo "Adding $u to whitelist"
@ -95,15 +88,35 @@ if [ -f /server/whitelist.prep ]; then
fi
# write to whitelist.json
echo -n "{\"uuid\": \"$uuid\",\"name\": \"$u\"}" >> /server/whitelist.json;
echo -n "{\"uuid\": \"$uuid\",\"name\": \"$u\"}" >> $SERVER_WHITELIST;
done
echo "]" >> /server/whitelist.json
sed --in-place -e 's/}{/}, {/g' /server/whitelist.json
echo "]" >> $SERVER_WHITELIST
sed --in-place -e 's/}{/}, {/g' $SERVER_WHITELIST
fi
if [ -f /server/op.prep ]; then
echo "true"
if [ -f $OPLIST_PREP ]; then
echo -n "[" > $SERVER_OPLIST
cat $OPLIST_PREP | while read u
do
echo "Adding $u to whitelist"
# get uuid of user
uuid=$(curl -s https://api.mojang.com/users/profiles/minecraft/$u | jq -r '.id')
uuid=$(echo "${uuid:0:8}-${uuid:8:4}-${uuid:12:4}-${uuid:16:4}-${uuid:20:12}")
if [[ $uuid == "null" ]]; then
echo "User $u not found. Skipping."
continue
fi
# write to whitelist.json
echo -n "{\"uuid\": \"$uuid\",\"name\": \"$u\",\"level\": 4,\"bypassesPlayerLimit\": false}" >> $SERVER_OPLIST;
done
echo "]" >> $SERVER_OPLIST
sed --in-place -e 's/}{/}, {/g' $SERVER_OPLIST
fi
if [[ -n $WHITELIST ]]; then