2018-12-04 01:59:03 +01:00
|
|
|
#!/bin/bash -eu
|
|
|
|
|
2021-11-22 21:08:04 +01:00
|
|
|
set +H -euo pipefail
|
2018-12-04 01:59:03 +01:00
|
|
|
|
2019-07-10 21:10:34 +02:00
|
|
|
: ${ONEDRIVE_UID:=$(stat /onedrive/data -c '%u')}
|
|
|
|
: ${ONEDRIVE_GID:=$(stat /onedrive/data -c '%g')}
|
2018-12-04 01:59:03 +01:00
|
|
|
|
|
|
|
# Create new group using target GID
|
2020-04-22 05:23:15 +02:00
|
|
|
if ! odgroup="$(getent group "$ONEDRIVE_GID")"; then
|
2018-12-04 01:59:03 +01:00
|
|
|
odgroup='onedrive'
|
2020-04-22 05:23:15 +02:00
|
|
|
groupadd "${odgroup}" -g "$ONEDRIVE_GID"
|
2019-06-09 04:27:00 +02:00
|
|
|
else
|
|
|
|
odgroup=${odgroup%%:*}
|
2018-12-04 01:59:03 +01:00
|
|
|
fi
|
|
|
|
|
|
|
|
# Create new user using target UID
|
2020-04-22 05:23:15 +02:00
|
|
|
if ! oduser="$(getent passwd "$ONEDRIVE_UID")"; then
|
2018-12-04 01:59:03 +01:00
|
|
|
oduser='onedrive'
|
2020-04-22 05:23:15 +02:00
|
|
|
useradd -m "${oduser}" -u "$ONEDRIVE_UID" -g "$ONEDRIVE_GID"
|
2018-12-04 01:59:03 +01:00
|
|
|
else
|
|
|
|
oduser="${oduser%%:*}"
|
|
|
|
usermod -g "${odgroup}" "${oduser}"
|
2019-09-23 22:13:28 +02:00
|
|
|
grep -qv root <( groups "${oduser}" ) || { echo 'ROOT level privileges prohibited!'; exit 1; }
|
2018-12-04 01:59:03 +01:00
|
|
|
fi
|
|
|
|
|
|
|
|
chown "${oduser}:${odgroup}" /onedrive/ /onedrive/conf
|
2019-02-24 07:20:50 +01:00
|
|
|
|
|
|
|
# Default parameters
|
2019-09-09 05:44:07 +02:00
|
|
|
ARGS=(--monitor --confdir /onedrive/conf --syncdir /onedrive/data)
|
2021-11-22 21:08:04 +01:00
|
|
|
echo "Base Args: ${ARGS}"
|
2019-09-09 05:44:07 +02:00
|
|
|
|
2019-09-23 22:13:28 +02:00
|
|
|
# Make Verbose output optional, based on an environment variable
|
|
|
|
if [ "${ONEDRIVE_VERBOSE:=0}" == "1" ]; then
|
2019-09-09 05:44:07 +02:00
|
|
|
echo "# We are being verbose"
|
2021-11-22 21:08:04 +01:00
|
|
|
echo "# Adding --verbose"
|
2019-09-09 05:44:07 +02:00
|
|
|
ARGS=(--verbose ${ARGS[@]})
|
|
|
|
fi
|
2019-02-24 07:20:50 +01:00
|
|
|
|
2019-09-23 22:13:28 +02:00
|
|
|
# Tell client to perform debug output, based on an environment variable
|
|
|
|
if [ "${ONEDRIVE_DEBUG:=0}" == "1" ]; then
|
|
|
|
echo "# We are performing debug output"
|
2021-11-22 21:08:04 +01:00
|
|
|
echo "# Adding --verbose --verbose"
|
2019-09-23 22:13:28 +02:00
|
|
|
ARGS=(--verbose --verbose ${ARGS[@]})
|
|
|
|
fi
|
|
|
|
|
2020-10-16 22:11:00 +02:00
|
|
|
# Tell client to perform HTTPS debug output, based on an environment variable
|
|
|
|
if [ "${ONEDRIVE_DEBUG_HTTPS:=0}" == "1" ]; then
|
|
|
|
echo "# We are performing HTTPS debug output"
|
2021-11-22 21:08:04 +01:00
|
|
|
echo "# Adding --debug-https"
|
2020-10-16 22:11:00 +02:00
|
|
|
ARGS=(--debug-https ${ARGS[@]})
|
|
|
|
fi
|
|
|
|
|
2019-09-23 22:13:28 +02:00
|
|
|
# Tell client to perform a resync based on environment variable
|
|
|
|
if [ "${ONEDRIVE_RESYNC:=0}" == "1" ]; then
|
|
|
|
echo "# We are performing a --resync"
|
2022-01-27 22:58:38 +01:00
|
|
|
echo "# Adding --resync --resync-auth"
|
|
|
|
ARGS=(--resync --resync-auth ${ARGS[@]})
|
2019-09-23 22:13:28 +02:00
|
|
|
fi
|
|
|
|
|
2020-10-26 19:49:25 +01:00
|
|
|
# Tell client to sync in download-only mode based on environment variable
|
|
|
|
if [ "${ONEDRIVE_DOWNLOADONLY:=0}" == "1" ]; then
|
|
|
|
echo "# We are synchronizing in download-only mode"
|
2021-11-22 21:08:04 +01:00
|
|
|
echo "# Adding --download-only"
|
2020-10-26 19:49:25 +01:00
|
|
|
ARGS=(--download-only ${ARGS[@]})
|
|
|
|
fi
|
|
|
|
|
2020-12-20 21:06:18 +01:00
|
|
|
# Tell client to logout based on environment variable
|
|
|
|
if [ "${ONEDRIVE_LOGOUT:=0}" == "1" ]; then
|
|
|
|
echo "# We are logging out to perform a reauthentication"
|
2021-11-22 21:08:04 +01:00
|
|
|
echo "# Adding --logout"
|
2020-12-20 21:06:18 +01:00
|
|
|
ARGS=(--logout ${ARGS[@]})
|
|
|
|
fi
|
|
|
|
|
2021-11-22 21:08:04 +01:00
|
|
|
# Tell client to utilize auth files at the provided locations based on environment variable
|
|
|
|
if [ -n "${ONEDRIVE_AUTHFILES:=""}" ]; then
|
|
|
|
echo "# We are using auth files to perform authentication"
|
|
|
|
echo "# Adding --auth-files ARG"
|
|
|
|
ARGS=(--auth-files ${ONEDRIVE_AUTHFILES} ${ARGS[@]})
|
|
|
|
fi
|
|
|
|
|
|
|
|
# Tell client to utilize provided auth reponse based on environment variable
|
|
|
|
if [ -n "${ONEDRIVE_AUTHRESPONSE:=""}" ]; then
|
|
|
|
echo "# We are providing the auth response directly to perform authentication"
|
|
|
|
echo "# Adding --auth-response ARG"
|
|
|
|
ARGS=(--auth-response \"${ONEDRIVE_AUTHRESPONSE}\" ${ARGS[@]})
|
|
|
|
fi
|
2020-12-20 21:06:18 +01:00
|
|
|
|
2019-02-24 07:20:50 +01:00
|
|
|
if [ ${#} -gt 0 ]; then
|
|
|
|
ARGS=("${@}")
|
|
|
|
fi
|
|
|
|
|
2021-11-22 21:08:04 +01:00
|
|
|
echo "# Launching onedrive"
|
2019-02-24 07:20:50 +01:00
|
|
|
exec gosu "${oduser}" /usr/local/bin/onedrive "${ARGS[@]}"
|