fix for existing user/group
continuous-integration/drone/push Build is passing Details
continuous-integration/drone/tag Build is passing Details

This commit is contained in:
Paolo Asperti 2021-04-28 15:05:56 +02:00
parent 25c8afed3f
commit d8fa38b097
Signed by: paspo
GPG Key ID: 06D46905D19D5182
1 changed files with 18 additions and 4 deletions

View File

@ -1,7 +1,7 @@
#!/bin/sh
USER_NAME=${USER_NAME:-nextcloudclient}
USER_GRP=${USER_NAME}
USER_GROUP=${USER_GROUP:-nextcloudgroup}
USER_UID=${USER_UID:-1000}
USER_GID=${USER_GID:-1000}
NEXTCLOUD_USERNAME=${NEXTCLOUD_USERNAME:-username}
@ -10,9 +10,23 @@ NEXTCLOUD_URL=${NEXTCLOUD_URL:-https://nextcloud.example.com}
NEXTCLOUD_DIR=${NEXTCLOUD_DIR:-/data}
NEXTCLOUD_DIR_CHOWN=${NEXTCLOUD_DIR_CHOWN:-1}
# create the user/group
addgroup -g ${USER_GID} ${USER_GRP}
adduser -s /bin/false -D -H -G ${USER_GRP} -u ${USER_UID} ${USER_NAME}
# check if group already exists
GRP_NAME=$(getent group ${USER_GID} )
if [ "${GRP_NAME}" ] ; then
USER_GROUP=$( echo ${GRP_NAME} | sed 's/\:.*//' )
else
# if not, we create the group
addgroup -g ${USER_GID} ${USER_GROUP}
fi
# check if user already exists
USR_NAME=$(getent passwd ${USER_UID} )
if [ "${USR_NAME}" ] ; then
USER_NAME=$( echo ${USR_NAME} | sed 's/\:.*//' )
else
# if not, we create the user
adduser -s /bin/false -D -H -G ${USER_GROUP} -u ${USER_UID} ${USER_NAME}
fi
# create dir if not exists (it should exist if you mapped it outside the container)
if [ ! -d "${NEXTCLOUD_DIR}" ] ; then