2018-04-25 20:57:57 -05:00
|
|
|
#!/bin/bash
|
|
|
|
|
2022-02-11 21:00:24 -06:00
|
|
|
# shellcheck source=start-utils
|
|
|
|
. "${SCRIPTS:-/}start-utils"
|
2020-03-06 16:52:17 +01:00
|
|
|
|
2022-04-14 11:41:43 -05:00
|
|
|
# The Dockerfile ENVs take precedence here, but defaulting for testing consistency
|
2022-04-11 18:00:16 -05:00
|
|
|
: "${UID:=1000}"
|
|
|
|
: "${GID:=1000}"
|
|
|
|
|
2024-01-19 01:27:58 +01:00
|
|
|
umask "${UMASK:=0002}"
|
2018-09-27 10:27:50 +03:00
|
|
|
|
2023-11-25 18:30:18 -06: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-07 20:05:09 -05:00
|
|
|
|
2022-02-11 21:00:24 -06:00
|
|
|
if ! isTrue "${SKIP_SUDO:-false}" && [ "$(id -u)" = 0 ]; then
|
2020-01-17 08:27:11 -06:00
|
|
|
runAsUser=minecraft
|
|
|
|
runAsGroup=minecraft
|
|
|
|
|
|
|
|
if [[ -v UID ]]; then
|
|
|
|
if [[ $UID != 0 ]]; then
|
|
|
|
if [[ $UID != $(id -u minecraft) ]]; then
|
2020-03-06 16:52:17 +01:00
|
|
|
log "Changing uid of minecraft to $UID"
|
2020-01-17 08:27:11 -06:00
|
|
|
usermod -u $UID minecraft
|
|
|
|
fi
|
|
|
|
else
|
|
|
|
runAsUser=root
|
|
|
|
fi
|
2018-04-25 20:57:57 -05:00
|
|
|
fi
|
2020-01-17 08:27:11 -06:00
|
|
|
|
2018-07-30 21:49:43 -05:00
|
|
|
if [[ -v GID ]]; then
|
2020-01-17 08:27:11 -06:00
|
|
|
if [[ $GID != 0 ]]; then
|
|
|
|
if [[ $GID != $(id -g minecraft) ]]; then
|
2020-03-06 16:52:17 +01:00
|
|
|
log "Changing gid of minecraft to $GID"
|
2022-02-11 21:00:24 -06:00
|
|
|
groupmod -o -g "$GID" minecraft
|
2020-01-17 08:27:11 -06:00
|
|
|
fi
|
|
|
|
else
|
|
|
|
runAsGroup=root
|
|
|
|
fi
|
2018-07-30 21:49:43 -05:00
|
|
|
fi
|
2018-08-18 16:56:45 -05:00
|
|
|
|
2022-02-11 21:00:24 -06:00
|
|
|
if [[ $(stat -c "%u" /data) != "$UID" ]]; then
|
2020-03-06 16:52:17 +01:00
|
|
|
log "Changing ownership of /data to $UID ..."
|
2020-01-17 08:27:11 -06:00
|
|
|
chown -R ${runAsUser}:${runAsGroup} /data
|
2018-08-18 16:56:45 -05:00
|
|
|
fi
|
|
|
|
|
2019-11-26 21:34:56 -06:00
|
|
|
if [[ ${SKIP_NSSWITCH_CONF^^} != TRUE ]]; then
|
|
|
|
echo 'hosts: files dns' > /etc/nsswitch.conf
|
|
|
|
fi
|
|
|
|
|
2022-02-11 21:00:24 -06: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-30 21:49:43 -05:00
|
|
|
else
|
2022-02-11 21:00:24 -06:00
|
|
|
exec "${SCRIPTS:-/}start-configuration" "$@"
|
2018-04-25 20:57:57 -05:00
|
|
|
fi
|