docker-nextcloudclient/start.sh

87 lines
2.3 KiB
Bash
Raw Normal View History

2023-11-09 15:27:05 +00:00
#!/bin/bash
2021-04-28 12:25:11 +00:00
USER_NAME=${USER_NAME:-nextcloudclient}
2021-04-28 13:05:56 +00:00
USER_GROUP=${USER_GROUP:-nextcloudgroup}
2021-04-28 12:25:11 +00:00
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}
2021-05-04 15:13:05 +00:00
NEXTCLOUD_SLEEP=${NEXTCLOUD_SLEEP:-30}
2021-04-28 12:25:11 +00:00
2021-04-28 13:05:56 +00:00
# check if group already exists
2023-11-09 15:17:01 +00:00
GRP_NAME=$(getent group "${USER_GID}" )
2021-04-28 13:05:56 +00:00
if [ "${GRP_NAME}" ] ; then
2023-11-09 15:17:01 +00:00
USER_GROUP=$( echo "${GRP_NAME}" | sed 's/\:.*//' )
2021-04-28 13:05:56 +00:00
else
# if not, we create the group
2023-11-09 15:17:01 +00:00
addgroup -g "${USER_GID}" "${USER_GROUP}"
2021-04-28 13:05:56 +00:00
fi
# check if user already exists
2023-11-09 15:17:01 +00:00
USR_NAME=$(getent passwd "${USER_UID}" )
2021-04-28 13:05:56 +00:00
if [ "${USR_NAME}" ] ; then
2023-11-09 15:17:01 +00:00
USER_NAME=$( echo "${USR_NAME}" | sed 's/\:.*//' )
2021-04-28 13:05:56 +00:00
else
# if not, we create the user
2023-11-09 15:17:01 +00:00
adduser -s /bin/false -D -H -G "${USER_GROUP}" -u "${USER_UID}" "${USER_NAME}"
2021-04-28 13:05:56 +00:00
fi
2021-04-28 12:25:11 +00:00
# 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
2023-11-09 15:17:01 +00:00
chown -R "${USER_UID}":"${USER_GID}" "${NEXTCLOUD_DIR}"
2021-04-28 12:25:11 +00:00
fi
2023-11-09 15:27:05 +00:00
PARAMS=()
2021-04-28 12:25:11 +00:00
if [ "${NEXTCLOUD_FORCE_TRUST}" = "1" ] ; then
2023-11-09 15:27:05 +00:00
PARAMS+="--trust"
2021-04-28 12:25:11 +00:00
fi
if [ ! "${NEXTCLOUD_HTTPPROXY}" = "" ] ; then
2023-11-09 15:27:05 +00:00
PARAMS+="--httpproxy"
PARAMS+="${NEXTCLOUD_HTTPPROXY}"
2021-04-28 12:25:11 +00:00
fi
if [ ! "${NEXTCLOUD_UPLIMIT}" = "" ] ; then
2023-11-09 15:27:05 +00:00
PARAMS+="--uplimit"
PARAMS+="${NEXTCLOUD_UPLIMIT}"
2021-04-28 12:25:11 +00:00
fi
if [ ! "${NEXTCLOUD_DOWNLIMIT}" = "" ] ; then
2023-11-09 15:27:05 +00:00
PARAMS+="--downlimit"
PARAMS+="${NEXTCLOUD_DOWNLIMIT}"
2021-04-28 12:25:11 +00:00
fi
if [ ! "${NEXTCLOUD_EXCLUDEFILE}" = "" ] ; then
if [ -r "${NEXTCLOUD_EXCLUDEFILE}" ] ; then
2023-11-09 15:27:05 +00:00
PARAMS+="--exclude"
PARAMS+="${NEXTCLOUD_EXCLUDEFILE}"
2021-04-28 12:25:11 +00:00
fi
fi
if [ ! "${NEXTCLOUD_UNSYNCFILE}" = "" ] ; then
if [ -r "${NEXTCLOUD_UNSYNCFILE}" ] ; then
2023-11-09 15:27:05 +00:00
PARAMS+="--unsyncedfolders"
PARAMS+="'${NEXTCLOUD_UNSYNCFILE}'"
2021-04-28 12:25:11 +00:00
fi
fi
2021-05-04 15:03:29 +00:00
if [ "${NEXTCLOUD_SILENT}" = "1" ] ; then
2023-11-09 15:27:05 +00:00
PARAMS+="--silent"
2021-05-04 15:03:29 +00:00
fi
2021-04-28 12:25:11 +00:00
2023-11-09 15:27:05 +00:00
PARAMS+="--non-interactive"
PARAMS+="-u"
PARAMS+="${NEXTCLOUD_USERNAME}"
PARAMS+="-p"
PARAMS+="${NEXTCLOUD_PASSWORD}"
PARAMS+="${NEXTCLOUD_DIR}"
PARAMS+="${NEXTCLOUD_URL}"
2021-04-28 12:25:11 +00:00
# main loop
while true; do
2023-11-09 15:27:05 +00:00
/bin/su -s /bin/sh "${USER_NAME}" -c "/usr/bin/nextcloudcmd ${PARAMS[@]}"
2023-11-09 15:17:01 +00:00
sleep "${NEXTCLOUD_SLEEP}"
2021-04-28 12:25:11 +00:00
done