mirror of
https://github.com/itzg/docker-minecraft-server.git
synced 2026-05-23 20:25:25 +00:00
mc: remove the need for entrypoint script to run as root
This commit is contained in:
+90
-18
@@ -1,23 +1,95 @@
|
||||
#!/bin/sh
|
||||
#!/bin/bash
|
||||
|
||||
set -e
|
||||
# Since Alpine doesn't have a usermod command we have to directly manipulate the passwd/group files :(
|
||||
sed -i "/^minecraft/s/:1000:1000:/:${UID}:${GID}:/" /etc/passwd
|
||||
sed -i "/^minecraft/s/:1000:/:${GID}:/" /etc/group
|
||||
shopt -s nullglob
|
||||
|
||||
if [ "$SKIP_OWNERSHIP_FIX" != "TRUE" ]; then
|
||||
fix_ownership() {
|
||||
dir=$1
|
||||
if ! su-exec minecraft test -w $dir; then
|
||||
echo "Correcting writability of $dir ..."
|
||||
chown -R minecraft:minecraft $dir
|
||||
chmod -R u+w $dir
|
||||
#umask 002
|
||||
export HOME=/data
|
||||
|
||||
if [ ! -e /data/eula.txt ]; then
|
||||
if [ "$EULA" != "" ]; then
|
||||
echo "# Generated via Docker on $(date)" > eula.txt
|
||||
echo "eula=$EULA" >> eula.txt
|
||||
if [ $? != 0 ]; then
|
||||
echo "ERROR: unable to write eula to /data. Please make sure attached directory is writable by uid=${UID}"
|
||||
exit 2
|
||||
fi
|
||||
}
|
||||
|
||||
fix_ownership /data
|
||||
fix_ownership /home/minecraft
|
||||
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
|
||||
|
||||
echo "Switching to user 'minecraft'"
|
||||
su-exec minecraft /start-configuration $@
|
||||
if ! touch /data/.verify_access; then
|
||||
echo "ERROR: /data doesn't seem to be writable. Please make sure attached directory is writable by uid=${UID} "
|
||||
exit 2
|
||||
fi
|
||||
|
||||
if [[ $PROXY ]]; then
|
||||
export http_proxy="$PROXY"
|
||||
export https_proxy="$PROXY"
|
||||
echo "INFO: Giving proxy time to startup..."
|
||||
sleep 5
|
||||
fi
|
||||
|
||||
export SERVER_PROPERTIES=/data/server.properties
|
||||
export FTB_DIR=/data/FeedTheBeast
|
||||
export VERSIONS_JSON=https://launchermeta.mojang.com/mc/game/version_manifest.json
|
||||
|
||||
echo "Checking version information."
|
||||
case "X$VERSION" in
|
||||
X|XLATEST|Xlatest)
|
||||
export VANILLA_VERSION=`curl -fsSL $VERSIONS_JSON | jq -r '.latest.release'`
|
||||
;;
|
||||
XSNAPSHOT|Xsnapshot)
|
||||
export VANILLA_VERSION=`curl -fsSL $VERSIONS_JSON | jq -r '.latest.snapshot'`
|
||||
;;
|
||||
X[1-9]*)
|
||||
export VANILLA_VERSION=$VERSION
|
||||
;;
|
||||
*)
|
||||
export VANILLA_VERSION=`curl -fsSL $VERSIONS_JSON | jq -r '.latest.release'`
|
||||
;;
|
||||
esac
|
||||
|
||||
cd /data
|
||||
|
||||
export ORIGINAL_TYPE=${TYPE}
|
||||
|
||||
echo "Checking type information."
|
||||
case "$TYPE" in
|
||||
*BUKKIT|*bukkit|SPIGOT|spigot)
|
||||
exec /start-deployBukkitSpigot $@
|
||||
;;
|
||||
|
||||
PAPER|paper)
|
||||
exec /start-deployPaper $@
|
||||
;;
|
||||
|
||||
FORGE|forge)
|
||||
exec /start-deployForge $@
|
||||
;;
|
||||
|
||||
FTB|ftb)
|
||||
exec /start-deployFTB $@
|
||||
;;
|
||||
|
||||
VANILLA|vanilla)
|
||||
exec /start-deployVanilla $@
|
||||
;;
|
||||
|
||||
SPONGEVANILLA|spongevanilla)
|
||||
exec /start-deploySpongeVanilla $@
|
||||
;;
|
||||
|
||||
*)
|
||||
echo "Invalid type: '$TYPE'"
|
||||
echo "Must be: VANILLA, FORGE, BUKKIT, SPIGOT, PAPER, FTB, SPONGEVANILLA"
|
||||
exit 1
|
||||
;;
|
||||
|
||||
esac
|
||||
|
||||
Reference in New Issue
Block a user