add more variables

This commit is contained in:
Fl3xm3ist3r 2024-12-07 13:17:24 +01:00
parent 1d6fca2d53
commit 121b7667f5
3 changed files with 50 additions and 16 deletions

View file

@ -4,8 +4,8 @@ FROM openjdk:21-buster
LABEL version="1.27.0"
RUN apt-get update && apt-get install -y curl unzip && \
adduser --uid 99 --gid 100 --home /data --disabled-password minecraft
RUN apt-get update && apt-get install -y curl unzip jq && \
adduser --uid 99 --gid 100 --home /data --disabled-password minecraft
COPY launch.sh /launch.sh
RUN chmod +x /launch.sh

View file

@ -33,18 +33,13 @@ As the end user, you are repsonsible for accepting the EULA from Mojang to run t
## Options
These environment variables can be set at run time to override their defaults.
These environment variables can be set to override their defaults.
* JVM_OPTS "-Xms2048m -Xmx4096m"
* MOTD "All the Mods 10-1.27.0 Server Powered by Docker"
* LEVEL world
### Adding Minecraft Operators
Set the enviroment variable `OPS` with a comma separated list of players.
example:
`OPS="OpPlayer1,OpPlayer2"`
* ENABLE_WHITELIST "true" or "false"
* WHITELIST_USERS "TestUserName1, TestUserName2"
* OP_USERS "TestUserName1, TestUserName2"
## Troubleshooting

View file

@ -34,12 +34,51 @@ fi
if [[ -n "$MOTD" ]]; then
sed -i "s/motd\s*=/ c motd=$MOTD" /data/server.properties
fi
if [[ -n "$OPS" ]]; then
echo $OPS | awk -v RS=, '{print}' > ops.txt
fi
if [[ -n "$ALLOWLIST" ]]; then
echo $ALLOWLIST | awk -v RS=, '{print}' > white-list.txt
if [[ -n "$ENABLE_WHITELIST" ]]; then
sed -i "s/white-list=.*/white-list=$ENABLE_WHITELIST/" /data/server.properties
fi
[[ ! -f whitelist.json ]] && echo "[]" > whitelist.json
IFS=',' read -ra USERS <<< "$WHITELIST_USERS"
for raw_username in "${USERS[@]}"; do
username=$(echo "$raw_username" | xargs)
if [[ ! "$username" =~ ^[a-zA-Z0-9_]{3,16}$ ]]; then
echo "Whitelist: Invalid username: '$username'. Skipping..."
continue
fi
UUID=$(curl -s "https://api.mojang.com/users/profiles/minecraft/$username" | jq -r '.id')
if [[ "$UUID" != "null" ]]; then
if jq -e ".[] | select(.uuid == \"$UUID\")" whitelist.json > /dev/null; then
echo "Whitelist: $username ($UUID) is already whitelisted."
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
[[ ! -f ops.json ]] && echo "[]" > ops.json
IFS=',' read -ra OPS <<< "$OP_USERS"
for raw_username in "${OPS[@]}"; do
username=$(echo "$raw_username" | xargs)
if [[ ! "$username" =~ ^[a-zA-Z0-9_]{3,16}$ ]]; then
echo "Ops: Invalid username: '$username'. Skipping..."
continue
fi
UUID=$(curl -s "https://api.mojang.com/users/profiles/minecraft/$username" | jq -r '.id')
if [[ "$UUID" != "null" ]]; then
if jq -e ".[] | select(.uuid == \"$UUID\")" ops.json > /dev/null; then
echo "Ops: $username ($UUID) is already an operator."
else
echo "Ops: Adding $username ($UUID) as operator."
jq ". += [{\"uuid\": \"$UUID\", \"name\": \"$username\", \"level\": 4}]" ops.json > tmp.json && mv tmp.json ops.json
fi
else
echo "Ops: Failed to fetch UUID for $username."
fi
done
sed -i 's/server-port.*/server-port=25565/g' server.properties
chmod 755 run.sh