2022-07-23 13:16:10 +02:00
|
|
|
#!/usr/bin/env bash
|
2020-10-20 12:47:04 +02:00
|
|
|
|
2022-03-01 13:55:05 +01:00
|
|
|
# regular expressions
|
|
|
|
re='^[0-9]+$'
|
|
|
|
|
|
|
|
# set env defaults
|
2022-03-11 09:05:42 +01:00
|
|
|
export PHOTOPRISM_ARCH=${PHOTOPRISM_ARCH:-arch}
|
2022-03-01 13:55:05 +01:00
|
|
|
export DOCKER_ENV=${DOCKER_ENV:-unknown}
|
|
|
|
export DOCKER_TAG=${DOCKER_TAG:-unknown}
|
2022-03-23 08:33:44 +01:00
|
|
|
export PATH="/usr/local/sbin:/usr/sbin:/sbin:/usr/local/bin:/usr/bin:/bin:/scripts"
|
2022-03-01 13:55:05 +01:00
|
|
|
|
|
|
|
# detect environment
|
|
|
|
case $DOCKER_ENV in
|
|
|
|
prod)
|
2022-09-17 20:06:34 +02:00
|
|
|
export PATH="/usr/local/sbin:/usr/sbin:/sbin:/usr/local/bin:/usr/bin:/bin:/scripts:/opt/photoprism/bin";
|
2022-03-17 10:14:08 +01:00
|
|
|
INIT_SCRIPT="/scripts/entrypoint-init.sh";
|
2022-03-01 13:55:05 +01:00
|
|
|
;;
|
|
|
|
|
|
|
|
develop)
|
2022-09-17 20:06:34 +02:00
|
|
|
export PATH="/usr/local/sbin:/usr/sbin:/sbin:/usr/local/go/bin:/go/bin:/usr/local/bin:/usr/bin:/bin:/scripts";
|
2022-08-28 14:55:48 +02:00
|
|
|
INIT_SCRIPT="/scripts/entrypoint-init.sh";
|
2022-03-01 13:55:05 +01:00
|
|
|
;;
|
|
|
|
|
|
|
|
*)
|
2022-03-17 10:14:08 +01:00
|
|
|
echo "entrypoint: unknown environment $DOCKER_ENV";
|
2022-03-16 19:09:53 +01:00
|
|
|
INIT_SCRIPT=""
|
2022-03-01 13:55:05 +01:00
|
|
|
;;
|
|
|
|
esac
|
|
|
|
|
|
|
|
# normalize user and group ID environment variables
|
|
|
|
if [[ -z ${PHOTOPRISM_UID} ]]; then
|
|
|
|
if [[ ${UID} =~ $re ]] && [[ ${UID} != "0" ]]; then
|
|
|
|
export PHOTOPRISM_UID=${UID}
|
|
|
|
elif [[ ${PUID} =~ $re ]] && [[ ${PUID} != "0" ]]; then
|
|
|
|
export PHOTOPRISM_UID=${PUID}
|
|
|
|
fi
|
|
|
|
if [[ -z ${PHOTOPRISM_GID} ]]; then
|
|
|
|
if [[ ${GID} =~ $re ]] && [[ ${GID} != "0" ]]; then
|
|
|
|
export PHOTOPRISM_GID=${GID}
|
|
|
|
elif [[ ${PGID} =~ $re ]] && [[ ${PGID} != "0" ]]; then
|
|
|
|
export PHOTOPRISM_GID=${PGID}
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
|
|
|
|
# initialize container packages and permissions
|
2022-03-16 19:09:53 +01:00
|
|
|
if [[ ${INIT_SCRIPT} ]] && [[ -f "${INIT_SCRIPT}" ]]; then
|
|
|
|
if [[ $(/usr/bin/id -u) == "0" ]]; then
|
2022-03-17 10:14:08 +01:00
|
|
|
echo "started $DOCKER_TAG as root ($PHOTOPRISM_ARCH-$DOCKER_ENV)"
|
2022-04-18 14:14:32 +02:00
|
|
|
/bin/bash -c "${INIT_SCRIPT}"
|
2022-03-01 13:55:05 +01:00
|
|
|
else
|
2022-03-17 10:14:08 +01:00
|
|
|
echo "started $DOCKER_TAG as uid $(/usr/bin/id -u) ($PHOTOPRISM_ARCH-$DOCKER_ENV)"
|
2022-03-16 19:09:53 +01:00
|
|
|
/usr/bin/sudo -E "${INIT_SCRIPT}"
|
2021-09-29 09:01:57 +02:00
|
|
|
fi
|
2022-02-20 12:23:06 +01:00
|
|
|
else
|
2022-03-17 10:14:08 +01:00
|
|
|
echo "started $DOCKER_TAG as uid $(/usr/bin/id -u) without init script ($PHOTOPRISM_ARCH-$DOCKER_ENV)"
|
|
|
|
fi
|
|
|
|
|
|
|
|
# display documentation info and link
|
|
|
|
if [[ $DOCKER_ENV == "prod" ]]; then
|
|
|
|
echo "Problems? Our Troubleshooting Checklists help you quickly diagnose and solve them:";
|
|
|
|
echo "https://docs.photoprism.app/getting-started/troubleshooting/";
|
2020-10-20 12:47:04 +02:00
|
|
|
fi
|
|
|
|
|
2022-03-01 13:55:05 +01:00
|
|
|
# set explicit home directory
|
2022-03-11 09:05:42 +01:00
|
|
|
export HOME="/photoprism"
|
2021-02-05 17:39:48 +01:00
|
|
|
|
2022-02-20 12:23:06 +01:00
|
|
|
# check for alternate umask variable
|
|
|
|
if [[ -z ${PHOTOPRISM_UMASK} ]] && [[ ${UMASK} =~ $re ]] && [[ ${#UMASK} == 4 ]]; then
|
2022-03-01 13:55:05 +01:00
|
|
|
export PHOTOPRISM_UMASK=${UMASK}
|
2021-09-28 18:51:23 +02:00
|
|
|
fi
|
2021-02-05 17:39:48 +01:00
|
|
|
|
2022-02-20 12:23:06 +01:00
|
|
|
# set file-creation mode (umask)
|
|
|
|
if [[ ${PHOTOPRISM_UMASK} =~ $re ]] && [[ ${#PHOTOPRISM_UMASK} == 4 ]]; then
|
2021-09-28 18:51:23 +02:00
|
|
|
umask "${PHOTOPRISM_UMASK}"
|
2022-02-20 12:23:06 +01:00
|
|
|
else
|
|
|
|
umask 0002
|
2021-09-28 18:51:23 +02:00
|
|
|
fi
|
2021-02-05 17:39:48 +01:00
|
|
|
|
2022-03-11 09:05:42 +01:00
|
|
|
# display additional container info for troubleshooting
|
2022-03-17 10:14:08 +01:00
|
|
|
echo "file umask....: \"$(umask)\" ($(umask -S))"
|
|
|
|
echo "home directory: ${HOME}"
|
|
|
|
echo "assets path...: ${PHOTOPRISM_ASSETS_PATH:-default}"
|
|
|
|
echo "storage path..: ${PHOTOPRISM_STORAGE_PATH:-default}"
|
|
|
|
echo "config path...: ${PHOTOPRISM_CONFIG_PATH:-default}"
|
|
|
|
echo "cache path....: ${PHOTOPRISM_CACHE_PATH:-default}"
|
|
|
|
echo "backup path...: ${PHOTOPRISM_BACKUP_PATH:-default}"
|
|
|
|
echo "import path...: ${PHOTOPRISM_IMPORT_PATH:-default}"
|
|
|
|
echo "originals path: ${PHOTOPRISM_ORIGINALS_PATH:-default}"
|
2022-02-20 14:02:13 +01:00
|
|
|
|
2022-03-01 13:55:05 +01:00
|
|
|
# change to another user and group on request
|
2022-03-16 19:09:53 +01:00
|
|
|
if [[ ${INIT_SCRIPT} ]] && [[ $(/usr/bin/id -u) == "0" ]] && [[ ${PHOTOPRISM_UID} =~ $re ]] && [[ ${PHOTOPRISM_UID} != "0" ]]; then
|
2022-02-20 14:23:24 +01:00
|
|
|
# check uid and gid env variables
|
2022-03-01 13:55:05 +01:00
|
|
|
if [[ ${PHOTOPRISM_GID} =~ $re ]] && [[ ${PHOTOPRISM_GID} != "0" ]]; then
|
2022-02-20 14:02:13 +01:00
|
|
|
echo "switching to uid ${PHOTOPRISM_UID}:${PHOTOPRISM_GID}"
|
2021-09-28 18:51:23 +02:00
|
|
|
echo "${@}"
|
2022-02-19 19:54:49 +01:00
|
|
|
|
2022-03-01 13:55:05 +01:00
|
|
|
# run command as uid:gid
|
2022-09-22 10:04:49 +02:00
|
|
|
([[ ${DOCKER_ENV} != "prod" ]] || /usr/bin/setpriv --reuid "${PHOTOPRISM_UID}" --regid "${PHOTOPRISM_GID}" --init-groups --inh-caps -all "/scripts/audit.sh") \
|
|
|
|
&& /usr/bin/setpriv --reuid "${PHOTOPRISM_UID}" --regid "${PHOTOPRISM_GID}" --init-groups --inh-caps -all "$@" &
|
2021-09-28 18:51:23 +02:00
|
|
|
else
|
2022-03-01 13:55:05 +01:00
|
|
|
echo "switching to uid ${PHOTOPRISM_UID}"
|
2021-09-28 18:51:23 +02:00
|
|
|
echo "${@}"
|
2022-02-19 19:54:49 +01:00
|
|
|
|
2022-03-01 13:55:05 +01:00
|
|
|
# run command as uid
|
2022-09-22 10:04:49 +02:00
|
|
|
([[ ${DOCKER_ENV} != "prod" ]] || /usr/bin/setpriv --reuid "${PHOTOPRISM_UID}" --regid "$(/usr/bin/id -g "${PHOTOPRISM_UID}")" --init-groups --inh-caps -all "/scripts/audit.sh") \
|
|
|
|
&& /usr/bin/setpriv --reuid "${PHOTOPRISM_UID}" --regid "$(/usr/bin/id -g "${PHOTOPRISM_UID}")" --init-groups --inh-caps -all "$@" &
|
2021-09-28 18:51:23 +02:00
|
|
|
fi
|
2020-10-20 12:47:04 +02:00
|
|
|
else
|
2021-02-22 21:09:50 +01:00
|
|
|
echo "running as uid $(id -u)"
|
|
|
|
echo "${@}"
|
2022-02-19 19:54:49 +01:00
|
|
|
|
2022-03-01 13:55:05 +01:00
|
|
|
# run command
|
2022-03-11 09:05:42 +01:00
|
|
|
([[ ${DOCKER_ENV} != "prod" ]] || "/scripts/audit.sh") \
|
|
|
|
&& "$@" &
|
2020-10-20 12:47:04 +02:00
|
|
|
fi
|
|
|
|
|
|
|
|
PID=$!
|
|
|
|
|
|
|
|
trap "kill $PID" INT TERM
|
2021-09-29 09:01:57 +02:00
|
|
|
wait
|