2015-01-01 15:10:41 +00:00
|
|
|
#!/bin/bash
|
2014-11-01 20:20:52 +00:00
|
|
|
|
2015-01-01 16:01:15 +00:00
|
|
|
if [ ! -e /data/eula.txt ]; then
|
|
|
|
if [ "$EULA" != "" ]; then
|
|
|
|
echo "# Generated via Docker on $(date)" > eula.txt
|
|
|
|
echo "eula=$EULA" >> eula.txt
|
|
|
|
else
|
|
|
|
echo ""
|
|
|
|
echo "Please accept the Minecraft EULA at"
|
|
|
|
echo " https://account.mojang.com/documents/minecraft_eula"
|
|
|
|
echo "by adding the following immediately after 'docker run':"
|
|
|
|
echo " -e EULA=TRUE"
|
|
|
|
echo ""
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
|
2015-03-05 01:15:36 +00:00
|
|
|
echo "Checking version information."
|
2015-12-22 06:47:42 +00:00
|
|
|
case "X$VERSION" in
|
|
|
|
X|XLATEST|Xlatest)
|
2015-03-05 00:47:54 +00:00
|
|
|
VANILLA_VERSION=`wget -O - https://s3.amazonaws.com/Minecraft.Download/versions/versions.json | jsawk -n 'out(this.latest.release)'`
|
|
|
|
;;
|
2015-12-22 06:47:42 +00:00
|
|
|
XSNAPSHOT|Xsnapshot)
|
2015-03-05 00:47:54 +00:00
|
|
|
VANILLA_VERSION=`wget -O - https://s3.amazonaws.com/Minecraft.Download/versions/versions.json | jsawk -n 'out(this.latest.snapshot)'`
|
2015-03-05 04:21:52 +00:00
|
|
|
;;
|
2015-12-22 06:47:42 +00:00
|
|
|
X[1-9]*)
|
2015-03-05 04:21:52 +00:00
|
|
|
VANILLA_VERSION=$VERSION
|
2015-03-05 00:47:54 +00:00
|
|
|
;;
|
2015-12-22 06:47:42 +00:00
|
|
|
*)
|
|
|
|
VANILLA_VERSION=`wget -O - https://s3.amazonaws.com/Minecraft.Download/versions/versions.json | jsawk -n 'out(this.latest.release)'`
|
|
|
|
;;
|
2015-03-05 00:47:54 +00:00
|
|
|
esac
|
|
|
|
|
2015-03-05 01:17:20 +00:00
|
|
|
cd /data
|
2014-11-01 20:20:52 +00:00
|
|
|
|
2015-03-05 01:15:36 +00:00
|
|
|
echo "Checking minecraft / forge type information."
|
2015-12-22 06:47:42 +00:00
|
|
|
case "$TYPE" in
|
2015-03-04 23:55:57 +00:00
|
|
|
VANILLA)
|
2015-03-05 00:47:54 +00:00
|
|
|
SERVER="minecraft_server.$VANILLA_VERSION.jar"
|
2015-03-04 23:55:57 +00:00
|
|
|
|
|
|
|
if [ ! -e $SERVER ]; then
|
|
|
|
echo "Downloading $SERVER ..."
|
|
|
|
wget -q https://s3.amazonaws.com/Minecraft.Download/versions/$VANILLA_VERSION/$SERVER
|
|
|
|
fi
|
|
|
|
;;
|
|
|
|
|
|
|
|
FORGE)
|
2015-03-05 04:21:52 +00:00
|
|
|
# norm := the official Minecraft version as Forge is tracking it. dropped the third part starting with 1.8
|
|
|
|
case $VANILLA_VERSION in
|
|
|
|
1.7.*)
|
|
|
|
norm=$VANILLA_VERSION
|
|
|
|
;;
|
|
|
|
|
|
|
|
*)
|
2015-12-22 06:47:42 +00:00
|
|
|
norm=`echo "$VANILLA_VERSION" | sed 's/^\([0-9]\+\.[0-9]\+\).*/\1/'`
|
2015-03-05 04:21:52 +00:00
|
|
|
;;
|
|
|
|
esac
|
|
|
|
|
2015-05-11 20:45:23 +00:00
|
|
|
echo "Checking Forge version information."
|
|
|
|
case $FORGEVERSION in
|
|
|
|
RECOMMENDED)
|
|
|
|
FORGE_VERSION=`wget -O - http://files.minecraftforge.net/maven/net/minecraftforge/forge/promotions_slim.json | jsawk -n "out(this.promos['$norm-recommended'])"`
|
|
|
|
;;
|
2015-11-29 04:11:01 +00:00
|
|
|
|
2015-05-11 20:45:23 +00:00
|
|
|
*)
|
|
|
|
FORGE_VERSION=$FORGEVERSION
|
|
|
|
;;
|
|
|
|
esac
|
2015-03-05 04:21:52 +00:00
|
|
|
|
2015-06-13 06:51:07 +00:00
|
|
|
# URL format changed for 1.7.10 from 10.13.2.1300
|
|
|
|
sorted=$((echo $FORGE_VERSION; echo 10.13.2.1300) | sort -V | head -1)
|
|
|
|
if [[ $norm == '1.7.10' && $sorted == '10.13.2.1300' ]]; then
|
|
|
|
# if $FORGEVERSION >= 10.13.2.1300
|
|
|
|
normForgeVersion="$norm-$FORGE_VERSION-$norm"
|
|
|
|
else
|
|
|
|
normForgeVersion="$norm-$FORGE_VERSION"
|
|
|
|
fi
|
|
|
|
|
2015-03-05 04:21:52 +00:00
|
|
|
FORGE_INSTALLER="forge-$normForgeVersion-installer.jar"
|
|
|
|
SERVER="forge-$normForgeVersion-universal.jar"
|
2015-03-04 23:55:57 +00:00
|
|
|
|
2015-12-22 06:47:42 +00:00
|
|
|
if [ ! -e "$SERVER" ]; then
|
2015-03-05 01:15:36 +00:00
|
|
|
echo "Downloading $FORGE_INSTALLER ..."
|
2015-03-05 04:21:52 +00:00
|
|
|
wget -q http://files.minecraftforge.net/maven/net/minecraftforge/forge/$normForgeVersion/$FORGE_INSTALLER
|
2015-03-05 01:15:36 +00:00
|
|
|
echo "Installing $SERVER"
|
2015-03-05 04:21:52 +00:00
|
|
|
java -jar $FORGE_INSTALLER --installServer
|
2015-03-04 23:55:57 +00:00
|
|
|
fi
|
|
|
|
;;
|
2015-03-05 04:21:52 +00:00
|
|
|
|
2015-03-04 23:55:57 +00:00
|
|
|
esac
|
2014-11-01 20:20:52 +00:00
|
|
|
|
2015-12-19 02:32:29 +00:00
|
|
|
# If supplied with a URL for a world, download it and unpack
|
|
|
|
case "X$WORLD" in
|
2015-12-22 06:47:42 +00:00
|
|
|
X[Hh][Tt][Tt][Pp]*[Zz][iI][pP])
|
2015-12-19 08:48:09 +00:00
|
|
|
echo "Downloading world via HTTP"
|
2015-12-22 07:39:53 +00:00
|
|
|
echo "$WORLD"
|
2015-12-19 08:50:44 +00:00
|
|
|
wget -q -O - "$WORLD" > /data/world.zip
|
2015-12-19 08:48:09 +00:00
|
|
|
echo "Unzipping word"
|
|
|
|
unzip -q /data/world.zip
|
|
|
|
rm -f /data/world.zip
|
|
|
|
if [ ! -d /data/world ]; then
|
2015-12-22 07:39:53 +00:00
|
|
|
echo World directory not found
|
2015-12-19 08:48:09 +00:00
|
|
|
for i in /data/*/level.dat; do
|
2015-12-19 08:50:44 +00:00
|
|
|
if [ -f "$i" ]; then
|
|
|
|
d=`dirname "$i"`
|
2015-12-22 07:39:53 +00:00
|
|
|
echo Renaming world directory from $d
|
2015-12-19 08:50:44 +00:00
|
|
|
mv -f "$d" /data/world
|
2015-12-19 08:48:09 +00:00
|
|
|
fi
|
|
|
|
done
|
|
|
|
fi
|
2015-12-19 02:32:29 +00:00
|
|
|
;;
|
2015-12-22 06:47:42 +00:00
|
|
|
*)
|
|
|
|
echo "Invalid URL given for world: Must be HTTP or HTTPS and a ZIP file"
|
|
|
|
;;
|
2015-12-19 02:32:29 +00:00
|
|
|
esac
|
|
|
|
|
2014-11-01 20:20:52 +00:00
|
|
|
if [ ! -e server.properties ]; then
|
|
|
|
cp /tmp/server.properties .
|
|
|
|
|
2015-11-29 04:11:01 +00:00
|
|
|
if [ -n "$WHITELIST" ]; then
|
|
|
|
sed -i "/whitelist\s*=/ c whitelist=true" /data/server.properties
|
2015-11-29 05:02:43 +00:00
|
|
|
sed -i "/white-list\s*=/ c white-list=true" /data/server.properties
|
2015-11-29 04:11:01 +00:00
|
|
|
fi
|
|
|
|
|
2015-01-01 16:01:15 +00:00
|
|
|
if [ -n "$MOTD" ]; then
|
|
|
|
sed -i "/motd\s*=/ c motd=$MOTD" /data/server.properties
|
|
|
|
fi
|
2015-01-01 15:10:41 +00:00
|
|
|
|
2015-01-01 16:01:15 +00:00
|
|
|
if [ -n "$LEVEL" ]; then
|
|
|
|
sed -i "/level-name\s*=/ c level-name=$LEVEL" /data/server.properties
|
|
|
|
fi
|
2015-01-01 15:10:41 +00:00
|
|
|
|
2015-01-01 16:01:15 +00:00
|
|
|
if [ -n "$SEED" ]; then
|
|
|
|
sed -i "/level-seed\s*=/ c level-seed=$SEED" /data/server.properties
|
|
|
|
fi
|
2015-01-01 15:10:41 +00:00
|
|
|
|
2015-03-29 18:39:25 +00:00
|
|
|
if [ -n "$PVP" ]; then
|
|
|
|
sed -i "/pvp\s*=/ c pvp=$PVP" /data/server.properties
|
|
|
|
fi
|
|
|
|
|
2015-10-03 12:05:01 +00:00
|
|
|
if [ -n "$LEVEL_TYPE" ]; then
|
|
|
|
# normalize to uppercase
|
|
|
|
LEVEL_TYPE=${LEVEL_TYPE^^}
|
|
|
|
# check for valid values and only then set
|
|
|
|
case $LEVEL_TYPE in
|
|
|
|
DEFAULT|FLAT|LARGEBIOMES|AMPLIFIED|CUSTOMIZED)
|
|
|
|
sed -i "/level-type\s*=/ c level-type=$LEVEL_TYPE" /data/server.properties
|
|
|
|
;;
|
|
|
|
*)
|
|
|
|
echo "Invalid LEVEL_TYPE: $LEVEL_TYPE"
|
|
|
|
exit 1
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
fi
|
|
|
|
|
|
|
|
if [ -n "$GENERATOR_SETTINGS" ]; then
|
|
|
|
sed -i "/generator-settings\s*=/ c generator-settings=$GENERATOR_SETTINGS" /data/server.properties
|
|
|
|
fi
|
|
|
|
|
2015-06-10 18:13:36 +00:00
|
|
|
if [ -n "$DIFFICULTY" ]; then
|
|
|
|
case $DIFFICULTY in
|
2015-12-22 06:47:42 +00:00
|
|
|
peaceful|0)
|
2015-06-10 18:13:36 +00:00
|
|
|
DIFFICULTY=0
|
|
|
|
;;
|
2015-12-22 06:47:42 +00:00
|
|
|
easy|1)
|
2015-06-10 18:13:36 +00:00
|
|
|
DIFFICULTY=1
|
|
|
|
;;
|
2015-12-22 06:47:42 +00:00
|
|
|
normal|2)
|
2015-06-10 18:13:36 +00:00
|
|
|
DIFFICULTY=2
|
|
|
|
;;
|
2015-12-22 06:47:42 +00:00
|
|
|
hard|3)
|
2015-06-10 18:13:36 +00:00
|
|
|
DIFFICULTY=3
|
|
|
|
;;
|
|
|
|
*)
|
2015-06-10 18:14:31 +00:00
|
|
|
echo "DIFFICULTY must be peaceful, easy, normal, or hard."
|
2015-06-10 18:13:36 +00:00
|
|
|
exit 1
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
sed -i "/difficulty\s*=/ c difficulty=$DIFFICULTY" /data/server.properties
|
|
|
|
fi
|
|
|
|
|
2015-01-01 16:01:15 +00:00
|
|
|
if [ -n "$MODE" ]; then
|
|
|
|
case ${MODE,,?} in
|
|
|
|
0|1|2|3)
|
|
|
|
;;
|
|
|
|
s*)
|
|
|
|
MODE=0
|
|
|
|
;;
|
|
|
|
c*)
|
|
|
|
MODE=1
|
|
|
|
;;
|
2015-12-22 06:47:42 +00:00
|
|
|
a*)
|
|
|
|
MODE=2
|
|
|
|
;;
|
|
|
|
s*)
|
|
|
|
MODE=3
|
|
|
|
;;
|
2015-01-01 16:01:15 +00:00
|
|
|
*)
|
|
|
|
echo "ERROR: Invalid game mode: $MODE"
|
|
|
|
exit 1
|
|
|
|
;;
|
|
|
|
esac
|
2015-03-04 23:55:57 +00:00
|
|
|
|
2015-01-01 16:01:15 +00:00
|
|
|
sed -i "/gamemode\s*=/ c gamemode=$MODE" /data/server.properties
|
|
|
|
fi
|
2015-01-01 15:10:41 +00:00
|
|
|
fi
|
|
|
|
|
2015-01-01 16:01:15 +00:00
|
|
|
|
|
|
|
if [ -n "$OPS" -a ! -e ops.txt.converted ]; then
|
2014-11-01 20:20:52 +00:00
|
|
|
echo $OPS | awk -v RS=, '{print}' >> ops.txt
|
|
|
|
fi
|
2015-01-01 16:01:15 +00:00
|
|
|
|
2015-11-29 04:11:01 +00:00
|
|
|
if [ -n "$WHITELIST" -a ! -e white-list.txt.converted ]; then
|
|
|
|
echo $WHITELIST | awk -v RS=, '{print}' >> white-list.txt
|
|
|
|
fi
|
|
|
|
|
2015-01-01 16:01:15 +00:00
|
|
|
if [ -n "$ICON" -a ! -e server-icon.png ]; then
|
2014-11-09 16:27:05 +00:00
|
|
|
echo "Using server icon from $ICON..."
|
|
|
|
# Not sure what it is yet...call it "img"
|
|
|
|
wget -q -O /tmp/icon.img $ICON
|
|
|
|
specs=$(identify /tmp/icon.img | awk '{print $2,$3}')
|
|
|
|
if [ "$specs" = "PNG 64x64" ]; then
|
|
|
|
mv /tmp/icon.img /data/server-icon.png
|
|
|
|
else
|
|
|
|
echo "Converting image to 64x64 PNG..."
|
|
|
|
convert /tmp/icon.img -resize 64x64! /data/server-icon.png
|
|
|
|
fi
|
|
|
|
fi
|
2014-11-01 20:20:52 +00:00
|
|
|
|
2015-12-19 08:48:09 +00:00
|
|
|
# Make sure files exist to avoid errors
|
|
|
|
if [ ! -e banned-players.json ]; then
|
|
|
|
echo '' > banned-players.json
|
|
|
|
fi
|
2015-12-22 07:39:53 +00:00
|
|
|
if [ ! -e banned-ips.json ]; then
|
|
|
|
echo '' > banned-ips.json
|
2015-12-19 08:48:09 +00:00
|
|
|
fi
|
|
|
|
|
2015-12-19 02:32:29 +00:00
|
|
|
# If any modules have been provided, copy them over
|
|
|
|
[ -d /data/mods ] || mkdir /data/mods
|
|
|
|
for m in /mods/*.jar
|
|
|
|
do
|
|
|
|
if [ -f "$m" ]; then
|
2015-12-19 08:50:44 +00:00
|
|
|
echo Copying mod `basename "$m"`
|
|
|
|
cp -f "$m" /data/mods
|
2015-12-19 02:32:29 +00:00
|
|
|
fi
|
|
|
|
done
|
|
|
|
[ -d /data/config ] || mkdir /data/config
|
|
|
|
for c in /config/*
|
|
|
|
do
|
|
|
|
if [ -f "$c" ]; then
|
2015-12-19 08:50:44 +00:00
|
|
|
echo Copying configuration `basename "$c"`
|
|
|
|
cp -rf "$c" /data/config
|
2015-12-19 02:32:29 +00:00
|
|
|
fi
|
|
|
|
done
|
|
|
|
|
2016-01-06 20:55:45 +00:00
|
|
|
# If we have a bootstrap.txt file... feed that in to the server stdin
|
|
|
|
if [ -f /data/bootstrap.txt ];
|
2016-01-01 22:03:04 +00:00
|
|
|
then
|
2016-01-06 20:55:45 +00:00
|
|
|
exec java $JVM_OPTS -jar $SERVER < /data/bootstrap.txt
|
2016-01-01 22:03:04 +00:00
|
|
|
else
|
|
|
|
exec java $JVM_OPTS -jar $SERVER
|
|
|
|
fi
|