2018-04-26 01:57:57 +00:00
|
|
|
#!/bin/bash
|
|
|
|
|
2022-02-12 03:00:24 +00:00
|
|
|
# shellcheck source=start-utils
|
|
|
|
. "${SCRIPTS:-/}start-utils"
|
2020-03-06 15:52:17 +00:00
|
|
|
|
2022-04-14 16:41:43 +00:00
|
|
|
# The Dockerfile ENVs take precedence here, but defaulting for testing consistency
|
2022-04-11 23:00:16 +00:00
|
|
|
: "${UID:=1000}"
|
|
|
|
: "${GID:=1000}"
|
|
|
|
|
2024-01-19 00:27:58 +00:00
|
|
|
umask "${UMASK:=0002}"
|
2018-09-27 07:27:50 +00:00
|
|
|
|
2023-11-26 00:30:18 +00:00
|
|
|
# Remove from previous run and do this as elevated user since file used to be created before demoting
|
|
|
|
rm -f "$HOME/.rcon-cli.env"
|
2023-04-08 01:05:09 +00:00
|
|
|
|
2022-02-12 03:00:24 +00:00
|
|
|
if ! isTrue "${SKIP_SUDO:-false}" && [ "$(id -u)" = 0 ]; then
|
2020-01-17 14:27:11 +00:00
|
|
|
runAsUser=minecraft
|
|
|
|
runAsGroup=minecraft
|
|
|
|
|
|
|
|
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"
|
2020-01-17 14:27:11 +00:00
|
|
|
usermod -u $UID minecraft
|
|
|
|
fi
|
|
|
|
else
|
|
|
|
runAsUser=root
|
|
|
|
fi
|
2018-04-26 01:57:57 +00:00
|
|
|
fi
|
2020-01-17 14:27:11 +00:00
|
|
|
|
2018-07-31 02:49:43 +00:00
|
|
|
if [[ -v GID ]]; then
|
2020-01-17 14:27:11 +00:00
|
|
|
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"
|
2022-02-12 03:00:24 +00:00
|
|
|
groupmod -o -g "$GID" minecraft
|
2020-01-17 14:27:11 +00:00
|
|
|
fi
|
|
|
|
else
|
|
|
|
runAsGroup=root
|
|
|
|
fi
|
2018-07-31 02:49:43 +00:00
|
|
|
fi
|
2018-08-18 21:56:45 +00:00
|
|
|
|
2022-02-12 03:00:24 +00:00
|
|
|
if [[ $(stat -c "%u" /data) != "$UID" ]]; then
|
2020-03-06 15:52:17 +00:00
|
|
|
log "Changing ownership of /data to $UID ..."
|
2020-01-17 14:27:11 +00:00
|
|
|
chown -R ${runAsUser}:${runAsGroup} /data
|
2018-08-18 21:56:45 +00:00
|
|
|
fi
|
|
|
|
|
2019-11-27 03:34:56 +00:00
|
|
|
if [[ ${SKIP_NSSWITCH_CONF^^} != TRUE ]]; then
|
|
|
|
echo 'hosts: files dns' > /etc/nsswitch.conf
|
|
|
|
fi
|
|
|
|
|
2022-02-12 03:00:24 +00:00
|
|
|
distro=$(getDistro)
|
|
|
|
if [[ $distro == alpine ]]; then
|
|
|
|
exec su-exec ${runAsUser}:${runAsGroup} "${SCRIPTS:-/}start-configuration" "$@"
|
|
|
|
else
|
|
|
|
exec gosu ${runAsUser}:${runAsGroup} "${SCRIPTS:-/}start-configuration" "$@"
|
|
|
|
fi
|
2018-07-31 02:49:43 +00:00
|
|
|
else
|
2022-02-12 03:00:24 +00:00
|
|
|
exec "${SCRIPTS:-/}start-configuration" "$@"
|
2018-04-26 01:57:57 +00:00
|
|
|
fi
|