87 lines
2.3 KiB
Bash
Executable File
87 lines
2.3 KiB
Bash
Executable File
#!/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_PASSWORD=${NEXTCLOUD_PASSWORD:-password}
|
|
NEXTCLOUD_URL=${NEXTCLOUD_URL:-https://nextcloud.example.com}
|
|
NEXTCLOUD_DIR=${NEXTCLOUD_DIR:-/data}
|
|
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=$( 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
|
|
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=()
|
|
if [ "${NEXTCLOUD_FORCE_TRUST}" = "1" ] ; then
|
|
PARAMS+="--trust"
|
|
fi
|
|
if [ ! "${NEXTCLOUD_HTTPPROXY}" = "" ] ; then
|
|
PARAMS+="--httpproxy"
|
|
PARAMS+="${NEXTCLOUD_HTTPPROXY}"
|
|
fi
|
|
if [ ! "${NEXTCLOUD_UPLIMIT}" = "" ] ; then
|
|
PARAMS+="--uplimit"
|
|
PARAMS+="${NEXTCLOUD_UPLIMIT}"
|
|
fi
|
|
if [ ! "${NEXTCLOUD_DOWNLIMIT}" = "" ] ; then
|
|
PARAMS+="--downlimit"
|
|
PARAMS+="${NEXTCLOUD_DOWNLIMIT}"
|
|
fi
|
|
if [ ! "${NEXTCLOUD_EXCLUDEFILE}" = "" ] ; then
|
|
if [ -r "${NEXTCLOUD_EXCLUDEFILE}" ] ; then
|
|
PARAMS+="--exclude"
|
|
PARAMS+="${NEXTCLOUD_EXCLUDEFILE}"
|
|
fi
|
|
fi
|
|
if [ ! "${NEXTCLOUD_UNSYNCFILE}" = "" ] ; then
|
|
if [ -r "${NEXTCLOUD_UNSYNCFILE}" ] ; then
|
|
PARAMS+="--unsyncedfolders"
|
|
PARAMS+="'${NEXTCLOUD_UNSYNCFILE}'"
|
|
fi
|
|
fi
|
|
if [ "${NEXTCLOUD_SILENT}" = "1" ] ; then
|
|
PARAMS+="--silent"
|
|
fi
|
|
|
|
PARAMS+="--non-interactive"
|
|
PARAMS+="-u"
|
|
PARAMS+="${NEXTCLOUD_USERNAME}"
|
|
PARAMS+="-p"
|
|
PARAMS+="${NEXTCLOUD_PASSWORD}"
|
|
PARAMS+="${NEXTCLOUD_DIR}"
|
|
PARAMS+="${NEXTCLOUD_URL}"
|
|
|
|
# main loop
|
|
while true; do
|
|
/bin/su -s /bin/sh "${USER_NAME}" -c "/usr/bin/nextcloudcmd ${PARAMS[@]}"
|
|
sleep "${NEXTCLOUD_SLEEP}"
|
|
done
|