mirror of
https://github.com/abraunegg/onedrive
synced 2024-06-08 00:42:13 +02:00
5d7e4532ef
* This allows for the use of the `--auth-files` switch in the docker environment. Co-authored-by: abraunegg <alex.braunegg@gmail.com>
94 lines
2.9 KiB
Bash
Executable file
94 lines
2.9 KiB
Bash
Executable file
#!/bin/bash -eu
|
|
|
|
set +H -euo pipefail
|
|
|
|
: ${ONEDRIVE_UID:=$(stat /onedrive/data -c '%u')}
|
|
: ${ONEDRIVE_GID:=$(stat /onedrive/data -c '%g')}
|
|
|
|
# Create new group using target GID
|
|
if ! odgroup="$(getent group "$ONEDRIVE_GID")"; then
|
|
odgroup='onedrive'
|
|
groupadd "${odgroup}" -g "$ONEDRIVE_GID"
|
|
else
|
|
odgroup=${odgroup%%:*}
|
|
fi
|
|
|
|
# Create new user using target UID
|
|
if ! oduser="$(getent passwd "$ONEDRIVE_UID")"; then
|
|
oduser='onedrive'
|
|
useradd -m "${oduser}" -u "$ONEDRIVE_UID" -g "$ONEDRIVE_GID"
|
|
else
|
|
oduser="${oduser%%:*}"
|
|
usermod -g "${odgroup}" "${oduser}"
|
|
grep -qv root <( groups "${oduser}" ) || { echo 'ROOT level privileges prohibited!'; exit 1; }
|
|
fi
|
|
|
|
chown "${oduser}:${odgroup}" /onedrive/ /onedrive/conf
|
|
|
|
# Default parameters
|
|
ARGS=(--monitor --confdir /onedrive/conf --syncdir /onedrive/data)
|
|
echo "Base Args: ${ARGS}"
|
|
|
|
# Make Verbose output optional, based on an environment variable
|
|
if [ "${ONEDRIVE_VERBOSE:=0}" == "1" ]; then
|
|
echo "# We are being verbose"
|
|
echo "# Adding --verbose"
|
|
ARGS=(--verbose ${ARGS[@]})
|
|
fi
|
|
|
|
# Tell client to perform debug output, based on an environment variable
|
|
if [ "${ONEDRIVE_DEBUG:=0}" == "1" ]; then
|
|
echo "# We are performing debug output"
|
|
echo "# Adding --verbose --verbose"
|
|
ARGS=(--verbose --verbose ${ARGS[@]})
|
|
fi
|
|
|
|
# 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"
|
|
echo "# Adding --debug-https"
|
|
ARGS=(--debug-https ${ARGS[@]})
|
|
fi
|
|
|
|
# Tell client to perform a resync based on environment variable
|
|
if [ "${ONEDRIVE_RESYNC:=0}" == "1" ]; then
|
|
echo "# We are performing a --resync"
|
|
echo "# Adding --resync"
|
|
ARGS=(--resync ${ARGS[@]})
|
|
fi
|
|
|
|
# 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"
|
|
echo "# Adding --download-only"
|
|
ARGS=(--download-only ${ARGS[@]})
|
|
fi
|
|
|
|
# Tell client to logout based on environment variable
|
|
if [ "${ONEDRIVE_LOGOUT:=0}" == "1" ]; then
|
|
echo "# We are logging out to perform a reauthentication"
|
|
echo "# Adding --logout"
|
|
ARGS=(--logout ${ARGS[@]})
|
|
fi
|
|
|
|
# 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
|
|
|
|
if [ ${#} -gt 0 ]; then
|
|
ARGS=("${@}")
|
|
fi
|
|
|
|
echo "# Launching onedrive"
|
|
exec gosu "${oduser}" /usr/local/bin/onedrive "${ARGS[@]}"
|