[mc] Check writability of /data before chown'ing it

For #104
This commit is contained in:
Geoff Bourne 2016-09-06 21:36:54 -05:00
parent f7523eef4e
commit 76d4fd1bbc
2 changed files with 12 additions and 10 deletions

View File

@ -19,7 +19,8 @@ RUN useradd -s /bin/false --uid 1000 minecraft \
&& mkdir /config \
&& mkdir /mods \
&& mkdir /plugins \
&& chown minecraft:minecraft /data /config /mods /plugins
&& mkdir /home/minecraft \
&& chown minecraft:minecraft /data /config /mods /plugins /home/minecraft
EXPOSE 25565 25575

View File

@ -4,16 +4,17 @@ set -e
usermod --uid $UID minecraft
groupmod --gid $GID minecraft
chown -R minecraft:minecraft /data /start-minecraft /home/minecraft
chmod -R g+wX /data /start-minecraft
fix_ownership() {
dir=$1
if ! sudo -u minecraft test -w $dir; then
echo "Correcting writability of $dir ..."
chown -R minecraft:minecraft $dir
chmod -R u+w $dir
fi
}
while lsof -- /start-minecraft; do
echo -n "."
sleep 1
done
mkdir -p /home/minecraft
chown minecraft: /home/minecraft
fix_ownership /data
fix_ownership /home/minecraft
echo "Switching to user 'minecraft'"
exec sudo -E -u minecraft /start-minecraft "$@"