2021-01-15 15:02:06 +01:00
|
|
|
#!/usr/bin/env bash
|
|
|
|
|
2021-09-29 09:01:57 +02:00
|
|
|
if [[ $(id -u) == "0" ]]; then
|
2021-09-28 18:51:23 +02:00
|
|
|
echo "development base image started as root"
|
2021-09-29 09:01:57 +02:00
|
|
|
|
|
|
|
if [ -e /root/.init ]; then
|
|
|
|
echo "initialized"
|
|
|
|
elif [[ ${PHOTOPRISM_INIT} ]]; then
|
|
|
|
for target in $PHOTOPRISM_INIT; do
|
|
|
|
echo "init ${target}..."
|
|
|
|
make -f /root/Makefile "${target}"
|
|
|
|
done
|
|
|
|
echo 1 >/root/.init
|
|
|
|
fi
|
2021-09-28 18:51:23 +02:00
|
|
|
else
|
|
|
|
echo "development base image started as uid $(id -u)"
|
2021-01-15 15:02:06 +01:00
|
|
|
fi
|
|
|
|
|
2021-09-28 18:51:23 +02:00
|
|
|
re='^[0-9]+$'
|
|
|
|
|
|
|
|
# Legacy umask env variable in use?
|
|
|
|
if [[ -z ${PHOTOPRISM_UMASK} ]] && [[ ${UMASK} =~ $re ]]; then
|
|
|
|
PHOTOPRISM_UMASK=${UMASK}
|
|
|
|
echo "WARNING: UMASK without PHOTOPRISM_ prefix is deprecated, use PHOTOPRISM_UMASK: \"${PHOTOPRISM_UMASK}\" instead"
|
|
|
|
fi
|
2021-01-15 15:02:06 +01:00
|
|
|
|
2021-09-28 18:51:23 +02:00
|
|
|
# Set file permission mask
|
|
|
|
if [[ ${PHOTOPRISM_UMASK} =~ $re ]]; then
|
|
|
|
echo "umask ${PHOTOPRISM_UMASK}"
|
|
|
|
umask "${PHOTOPRISM_UMASK}"
|
|
|
|
fi
|
2021-02-05 17:39:48 +01:00
|
|
|
|
2021-09-28 18:51:23 +02:00
|
|
|
# Script runs as root?
|
2021-09-29 09:01:57 +02:00
|
|
|
if [[ $(id -u) == "0" ]]; then
|
2021-09-28 18:51:23 +02:00
|
|
|
# Legacy user ID env variable in use?
|
|
|
|
if [[ -z ${PHOTOPRISM_UID} ]] && [[ ${UID} =~ $re ]] && [[ ${UID} != "0" ]]; then
|
|
|
|
PHOTOPRISM_UID=${UID}
|
|
|
|
echo "WARNING: UID without PHOTOPRISM_ prefix is deprecated, use PHOTOPRISM_UID: \"${PHOTOPRISM_UID}\" instead"
|
2021-02-05 17:39:48 +01:00
|
|
|
fi
|
|
|
|
|
2021-09-28 18:51:23 +02:00
|
|
|
# Legacy group ID env variable in use?
|
|
|
|
if [[ -z ${PHOTOPRISM_GID} ]] && [[ ${GID} =~ $re ]] && [[ ${GID} != "0" ]]; then
|
|
|
|
PHOTOPRISM_GID=${GID}
|
|
|
|
echo "WARNING: GID without PHOTOPRISM_ prefix is deprecated, use PHOTOPRISM_GID: \"${PHOTOPRISM_GID}\" instead"
|
|
|
|
fi
|
2021-02-05 17:39:48 +01:00
|
|
|
|
2021-09-28 18:51:23 +02:00
|
|
|
# User and group ID set?
|
|
|
|
if [[ ${PHOTOPRISM_UID} =~ $re ]] && [[ ${PHOTOPRISM_UID} != "0" ]] && [[ ${PHOTOPRISM_GID} =~ $re ]] && [[ ${PHOTOPRISM_GID} != "0" ]]; then
|
|
|
|
groupadd -g "${PHOTOPRISM_GID}" "group_${PHOTOPRISM_GID}" 2>/dev/null
|
|
|
|
useradd -o -u "${PHOTOPRISM_UID}" -g "${PHOTOPRISM_GID}" -d /photoprism "user_${PHOTOPRISM_UID}" 2>/dev/null
|
|
|
|
usermod -g "${PHOTOPRISM_GID}" "user_${PHOTOPRISM_UID}" 2>/dev/null
|
2021-02-05 17:39:48 +01:00
|
|
|
|
2021-09-29 09:01:57 +02:00
|
|
|
if [[ -z ${PHOTOPRISM_DISABLE_CHOWN} ]]; then
|
2021-09-28 18:51:23 +02:00
|
|
|
echo "set PHOTOPRISM_DISABLE_CHOWN: \"true\" to disable storage permission updates"
|
|
|
|
echo "updating storage permissions..."
|
|
|
|
chown -Rf "${PHOTOPRISM_UID}:${PHOTOPRISM_GID}" /photoprism /var/lib/photoprism /tmp/photoprism /go
|
|
|
|
fi
|
2021-02-05 17:39:48 +01:00
|
|
|
|
2021-09-28 18:51:23 +02:00
|
|
|
echo "running as uid ${PHOTOPRISM_UID}:${PHOTOPRISM_GID}"
|
|
|
|
echo "${@}"
|
|
|
|
|
|
|
|
gosu "${PHOTOPRISM_UID}:${PHOTOPRISM_GID}" "$@" &
|
|
|
|
elif [[ ${PHOTOPRISM_UID} =~ $re ]] && [[ ${PHOTOPRISM_UID} != "0" ]]; then
|
|
|
|
# User ID only
|
|
|
|
useradd -o -u "${PHOTOPRISM_UID}" -g 1000 -d /photoprism "user_${PHOTOPRISM_UID}" 2>/dev/null
|
|
|
|
usermod -g 1000 "user_${PHOTOPRISM_UID}" 2>/dev/null
|
|
|
|
|
2021-09-29 09:01:57 +02:00
|
|
|
if [[ -z ${PHOTOPRISM_DISABLE_CHOWN} ]]; then
|
2021-09-28 18:51:23 +02:00
|
|
|
echo "set PHOTOPRISM_DISABLE_CHOWN: \"true\" to disable storage permission updates"
|
|
|
|
echo "updating storage permissions..."
|
|
|
|
chown -Rf "${PHOTOPRISM_UID}" /photoprism /var/lib/photoprism /tmp/photoprism /go
|
|
|
|
fi
|
2021-02-05 17:39:48 +01:00
|
|
|
|
2021-09-28 18:51:23 +02:00
|
|
|
echo "running as uid ${PHOTOPRISM_UID}"
|
|
|
|
echo "${@}"
|
|
|
|
|
|
|
|
gosu "${PHOTOPRISM_UID}" "$@" &
|
|
|
|
else
|
|
|
|
# Run as root
|
|
|
|
echo "running as root"
|
|
|
|
echo "${@}"
|
|
|
|
|
|
|
|
"$@" &
|
|
|
|
fi
|
2021-01-15 15:02:06 +01:00
|
|
|
else
|
2021-09-28 18:51:23 +02:00
|
|
|
# Running as user
|
2021-02-22 21:09:50 +01:00
|
|
|
echo "running as uid $(id -u)"
|
|
|
|
echo "${@}"
|
2021-02-05 17:39:48 +01:00
|
|
|
|
2021-01-15 15:02:06 +01:00
|
|
|
"$@" &
|
|
|
|
fi
|
|
|
|
|
|
|
|
PID=$!
|
|
|
|
|
|
|
|
trap "kill $PID" INT TERM
|
2021-09-29 09:01:57 +02:00
|
|
|
wait
|