docker-minecraft-server/scripts/start

65 lines
1.6 KiB
Plaintext
Raw Normal View History

#!/bin/bash
# shellcheck source=start-utils
. "${SCRIPTS:-/}start-utils"
2020-03-06 15:52:17 +00:00
# The Dockerfile ENVs take precedence here, but defaulting for testing consistency
: "${UID:=1000}"
: "${GID:=1000}"
umask 0002
chmod g+w /data
if isTrue "${ENABLE_RCON:-true}" && ! [ -v RCON_PASSWORD ] && ! [ -v RCON_PASSWORD_FILE ]; then
RCON_PASSWORD=$(openssl rand -hex 12)
export RCON_PASSWORD
fi
if ! isTrue "${SKIP_SUDO:-false}" && [ "$(id -u)" = 0 ]; then
runAsUser=minecraft
runAsGroup=minecraft
# For rcon-cli access running via exec, which by default is running as root
echo "password=${RCON_PASSWORD}" > "$HOME/.rcon-cli.env"
if [[ -v UID ]]; then
if [[ $UID != 0 ]]; then
if [[ $UID != $(id -u minecraft) ]]; then
2020-03-06 15:52:17 +00:00
log "Changing uid of minecraft to $UID"
usermod -u $UID minecraft
fi
else
runAsUser=root
fi
fi
if [[ -v GID ]]; then
if [[ $GID != 0 ]]; then
if [[ $GID != $(id -g minecraft) ]]; then
2020-03-06 15:52:17 +00:00
log "Changing gid of minecraft to $GID"
groupmod -o -g "$GID" minecraft
fi
else
runAsGroup=root
fi
fi
if [[ $(stat -c "%u" /data) != "$UID" ]]; then
2020-03-06 15:52:17 +00:00
log "Changing ownership of /data to $UID ..."
chown -R ${runAsUser}:${runAsGroup} /data
fi
2019-11-27 03:34:56 +00:00
if [[ ${SKIP_NSSWITCH_CONF^^} != TRUE ]]; then
echo 'hosts: files dns' > /etc/nsswitch.conf
fi
distro=$(getDistro)
if [[ $distro == alpine ]]; then
exec su-exec ${runAsUser}:${runAsGroup} "${SCRIPTS:-/}start-configuration" "$@"
else
exec gosu ${runAsUser}:${runAsGroup} "${SCRIPTS:-/}start-configuration" "$@"
fi
else
exec "${SCRIPTS:-/}start-configuration" "$@"
fi