#!/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