splitted entrypoint
All checks were successful
continuous-integration/drone/tag Build is passing

This commit is contained in:
Paolo Asperti 2023-11-09 18:05:53 +01:00
parent 5ae52fa449
commit 49d431dc58
Signed by: paspo
GPG Key ID: 06D46905D19D5182
3 changed files with 44 additions and 40 deletions

View File

@ -22,6 +22,6 @@ ENV \
NEXTCLOUD_SILENT= \ NEXTCLOUD_SILENT= \
NEXTCLOUD_SLEEP=30 NEXTCLOUD_SLEEP=30
COPY start.sh /start.sh COPY entrypoint.sh start.sh /
ENTRYPOINT ["/bin/bash", "/start.sh"] ENTRYPOINT ["/bin/bash", "/entrypoint.sh"]

41
entrypoint.sh Executable file
View File

@ -0,0 +1,41 @@
#!/bin/bash
USER_NAME=${USER_NAME:-nextcloudclient}
USER_GROUP=${USER_GROUP:-nextcloudgroup}
USER_UID=${USER_UID:-1000}
USER_GID=${USER_GID:-1000}
NEXTCLOUD_SLEEP=${NEXTCLOUD_SLEEP:-30}
# check if group already exists
GRP_NAME=$(getent group "${USER_GID}" )
if [ "${GRP_NAME}" ] ; then
USER_GROUP="${GRP_NAME//:*/}"
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="${USR_NAME//:*/}"
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
mkdir -p "${NEXTCLOUD_DIR}"
fi
# replace data directory permissions
if [ "${NEXTCLOUD_DIR_CHOWN}" = "1" ] ; then
chown -R "${USER_UID}":"${USER_GID}" "${NEXTCLOUD_DIR}"
fi
# main loop
while true; do
/bin/su -s /bin/sh -c "/start.sh" "${USER_NAME}"
sleep "${NEXTCLOUD_SLEEP}"
done

View File

@ -1,43 +1,10 @@
#!/bin/bash #!/bin/bash
USER_NAME=${USER_NAME:-nextcloudclient}
USER_GROUP=${USER_GROUP:-nextcloudgroup}
USER_UID=${USER_UID:-1000}
USER_GID=${USER_GID:-1000}
NEXTCLOUD_USERNAME=${NEXTCLOUD_USERNAME:-username} NEXTCLOUD_USERNAME=${NEXTCLOUD_USERNAME:-username}
NEXTCLOUD_PASSWORD=${NEXTCLOUD_PASSWORD:-password} NEXTCLOUD_PASSWORD=${NEXTCLOUD_PASSWORD:-password}
NEXTCLOUD_URL=${NEXTCLOUD_URL:-https://nextcloud.example.com} NEXTCLOUD_URL=${NEXTCLOUD_URL:-https://nextcloud.example.com}
NEXTCLOUD_DIR=${NEXTCLOUD_DIR:-/data} NEXTCLOUD_DIR=${NEXTCLOUD_DIR:-/data}
NEXTCLOUD_DIR_CHOWN=${NEXTCLOUD_DIR_CHOWN:-1} NEXTCLOUD_DIR_CHOWN=${NEXTCLOUD_DIR_CHOWN:-1}
NEXTCLOUD_SLEEP=${NEXTCLOUD_SLEEP:-30}
# check if group already exists
GRP_NAME=$(getent group "${USER_GID}" )
if [ "${GRP_NAME}" ] ; then
USER_GROUP="${GRP_NAME//:*/}"
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="${USR_NAME//:*/}"
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
mkdir -p "${NEXTCLOUD_DIR}"
fi
# replace data directory permissions
if [ "${NEXTCLOUD_DIR_CHOWN}" = "1" ] ; then
chown -R "${USER_UID}":"${USER_GID}" "${NEXTCLOUD_DIR}"
fi
PARAMS=() PARAMS=()
if [ "${NEXTCLOUD_FORCE_TRUST}" = "1" ] ; then if [ "${NEXTCLOUD_FORCE_TRUST}" = "1" ] ; then
@ -79,8 +46,4 @@ PARAMS+=("${NEXTCLOUD_PASSWORD}")
PARAMS+=("${NEXTCLOUD_DIR}") PARAMS+=("${NEXTCLOUD_DIR}")
PARAMS+=("${NEXTCLOUD_URL}") PARAMS+=("${NEXTCLOUD_URL}")
# main loop /usr/bin/nextcloudcmd "${PARAMS[@]}"
while true; do
/bin/su -s /bin/sh "${USER_NAME}" -- /usr/bin/nextcloudcmd "${PARAMS[@]}"
sleep "${NEXTCLOUD_SLEEP}"
done