Add experimental auto install support, rewrite user/group logic

This commit is contained in:
Robin 2021-12-20 17:47:48 +01:00
parent a24ecbd1b4
commit 7a89953e24
3 changed files with 74 additions and 24 deletions

View File

@ -1,23 +1,41 @@
#!/bin/sh #!/bin/sh
if [ -n "$(getent passwd "$WWW_DATA_UID")" ]
then
USERNAME=$(getent passwd "$WWW_DATA_UID" | cut -d: -f1)
echo "Deleting user $USERNAME which already uses UID $WWW_DATA_UID"
deluser "$USERNAME"
fi
if [ -n "$(getent group "$WWW_DATA_GID")" ] if [ -n "$(getent group "$WWW_DATA_GID")" ]
then then
GROUPNAME=$(getent passwd "$WWW_DATA_GID" | cut -d: -f1) GROUPNAME=$(getent passwd "$WWW_DATA_GID" | cut -d: -f1)
echo "Deleting group $GROUPNAME which already uses GID $WWW_DATA_GID" echo "Deleting group $GROUPNAME which already uses GID $WWW_DATA_GID"
delgroup "$GROUPNAME" groupdel "$GROUPNAME"
else
echo "GID $WWW_DATA_GID not in use"
fi fi
# for some reason, a www-data group exists by default but a www-data user doesn't if [ -n "$(getent passwd "$WWW_DATA_UID")" ]
echo "Adding www-data user with UID $WWW_DATA_UID and setting www-data GID to $WWW_DATA_GID" then
groupmod -g "$WWW_DATA_GID" www-data USERNAME=$(getent passwd "$WWW_DATA_UID" | cut -d: -f1)
adduser -D -G www-data -u "$WWW_DATA_UID" www-data echo "Deleting user $USERNAME which already uses UID $WWW_DATA_UID"
userdel "$USERNAME"
else
echo "UID $WWW_DATA_UID not in use"
fi
if [ -n "$(getent group www-data)" ]
then
echo "Modifying existing www-data group, setting GID to $WWW_DATA_GID"
groupmod -g "$WWW_DATA_GID" www-data
else
echo "Adding www-data group with GID $WWW_DATA_GID"
groupadd -g "$WWW_DATA_GID" www-data
fi
if [ -n "$(getent passwd www-data)" ]
then
echo "Modifying existing www-data user, setting GID to $WWW_DATA_GID"
usermod -g "$WWW_DATA_GID" www-data
else
echo "Adding www-data user with UID $WWW_DATA_UID and GID $WWW_DATA_GID"
getent passwd 1000
useradd -u "$WWW_DATA_UID" -g "$WWW_DATA_GID" www-data
fi
cat > /etc/nginx/php.conf << EOL cat > /etc/nginx/php.conf << EOL
upstream php-handler { upstream php-handler {

View File

@ -25,7 +25,7 @@ RUN { \
ADD entrypoint.sh / ADD entrypoint.sh /
ARG VERSION=v2.0.0-pr12 ARG VERSION=v2
ENV VERSION=${VERSION} ENV VERSION=${VERSION}
# Used by website to know if it runs using our docker images for statistics # Used by website to know if it runs using our docker images for statistics

View File

@ -1,23 +1,42 @@
#!/bin/sh #!/bin/sh
set -e set -e
if [ -n "$(getent passwd "$WWW_DATA_UID")" ]
then
USERNAME=$(getent passwd "$WWW_DATA_UID" | cut -d: -f1)
echo "Deleting user $USERNAME which already uses UID $WWW_DATA_UID"
deluser "$USERNAME"
fi
if [ -n "$(getent group "$WWW_DATA_GID")" ] if [ -n "$(getent group "$WWW_DATA_GID")" ]
then then
GROUPNAME=$(getent passwd "$WWW_DATA_GID" | cut -d: -f1) GROUPNAME=$(getent passwd "$WWW_DATA_GID" | cut -d: -f1)
echo "Deleting group $GROUPNAME which already uses GID $WWW_DATA_GID" echo "Deleting group $GROUPNAME which already uses GID $WWW_DATA_GID"
delgroup "$GROUPNAME" groupdel "$GROUPNAME"
else
echo "GID $WWW_DATA_GID not in use"
fi fi
echo "Setting www-data uid:gid to $WWW_DATA_UID:$WWW_DATA_GID" if [ -n "$(getent passwd "$WWW_DATA_UID")" ]
usermod -u "$WWW_DATA_UID" www-data then
groupmod -g "$WWW_DATA_GID" www-data USERNAME=$(getent passwd "$WWW_DATA_UID" | cut -d: -f1)
echo "Deleting user $USERNAME which already uses UID $WWW_DATA_UID"
userdel "$USERNAME"
else
echo "UID $WWW_DATA_UID not in use"
fi
if [ -n "$(getent group www-data)" ]
then
echo "Modifying existing www-data group, setting GID to $WWW_DATA_GID"
groupmod -g "$WWW_DATA_GID" www-data
else
echo "Adding www-data group with GID $WWW_DATA_GID"
groupadd -g "$WWW_DATA_GID" www-data
fi
if [ -n "$(getent passwd www-data)" ]
then
echo "Modifying existing www-data user, setting GID to $WWW_DATA_GID"
usermod -g "$WWW_DATA_GID" www-data
else
echo "Adding www-data user with UID $WWW_DATA_UID and GID $WWW_DATA_GID"
getent passwd 1000
useradd -u "$WWW_DATA_UID" -g "$WWW_DATA_GID" www-data
fi
if [ -n "$(ls -A /data 2>/dev/null)" ] if [ -n "$(ls -A /data 2>/dev/null)" ]
then then
@ -54,4 +73,17 @@ else
echo "Done!" echo "Done!"
fi fi
if [ -n "$NAMELESS_AUTO_INSTALL" ]
then
cd /data
if [ -f core/config.php ]; then
echo "core/config.php exists, not running installer."
else
echo "Going to run installer, first waiting 10 seconds for the database to start"
sleep 10
echo "Running installer..."
php -f cli_install.php -- --iSwearIKnowWhatImDoing
fi
fi
exec php-fpm exec php-fpm