2022-07-23 13:16:10 +02:00
|
|
|
#!/usr/bin/env bash
|
2022-03-01 13:55:05 +01:00
|
|
|
|
|
|
|
# INITIALIZES CONTAINER PACKAGES AND PERMISSIONS
|
2022-08-01 15:40:16 +02:00
|
|
|
export PATH="/usr/local/sbin:/usr/sbin:/sbin:/usr/local/bin:/usr/bin:/bin:/scripts"
|
2022-03-01 13:55:05 +01:00
|
|
|
|
|
|
|
# abort if not executed as root
|
2022-03-23 08:16:01 +01:00
|
|
|
if [[ $(id -u) != "0" ]]; then
|
2022-03-01 13:55:05 +01:00
|
|
|
echo "Usage: run ${0##*/} as root" 1>&2
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
|
|
|
# regular expressions
|
|
|
|
re='^[0-9]+$'
|
|
|
|
|
|
|
|
# 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-11 09:05:42 +01:00
|
|
|
INIT_SCRIPTS="/scripts"
|
2022-08-01 15:40:16 +02:00
|
|
|
CHOWN_DIRS=("/photoprism/storage")
|
|
|
|
CHMOD_DIRS=("/photoprism/storage")
|
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/bin:/usr/bin:/bin:/scripts:/usr/local/go/bin:/go/bin:/opt/photoprism/bin";
|
2022-08-28 15:21:13 +02:00
|
|
|
INIT_SCRIPTS="/scripts"
|
2022-04-18 14:14:32 +02:00
|
|
|
CHOWN_DIRS=("/photoprism" "/opt/photoprism" "/go" "/tmp/photoprism")
|
|
|
|
CHMOD_DIRS=("/opt/photoprism" "/tmp/photoprism")
|
2022-03-01 13:55:05 +01:00
|
|
|
;;
|
|
|
|
|
|
|
|
*)
|
2022-03-17 10:14:08 +01:00
|
|
|
echo "init: unsupported environment $DOCKER_ENV";
|
2022-03-01 13:55:05 +01:00
|
|
|
exit
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
|
|
|
|
if [[ ${PHOTOPRISM_UID} =~ $re ]] && [[ ${PHOTOPRISM_UID} != "0" ]]; then
|
|
|
|
if [[ ${PHOTOPRISM_GID} =~ $re ]] && [[ ${PHOTOPRISM_GID} != "0" ]]; then
|
2022-03-17 10:14:08 +01:00
|
|
|
CHOWN="${PHOTOPRISM_UID}:${PHOTOPRISM_GID}"
|
2022-03-01 13:55:05 +01:00
|
|
|
else
|
2022-03-17 10:14:08 +01:00
|
|
|
CHOWN="${PHOTOPRISM_UID}"
|
|
|
|
fi
|
2022-03-01 13:55:05 +01:00
|
|
|
|
2022-04-18 14:14:32 +02:00
|
|
|
if [[ -z ${PHOTOPRISM_DISABLE_CHOWN} ]] || [[ ${PHOTOPRISM_DISABLE_CHOWN} == "false" ]]; then
|
2022-03-17 10:14:08 +01:00
|
|
|
echo "init: updating filesystem permissions"
|
2022-04-18 14:14:32 +02:00
|
|
|
echo "PHOTOPRISM_DISABLE_CHOWN=\"true\" disables permission updates"
|
2022-04-18 15:49:30 +02:00
|
|
|
chown --preserve-root --silent -R "${CHOWN}" "${CHOWN_DIRS[@]}"
|
|
|
|
chmod --preserve-root --silent -R u+rwX "${CHMOD_DIRS[@]}"
|
2022-03-17 10:14:08 +01:00
|
|
|
fi
|
2022-03-01 13:55:05 +01:00
|
|
|
fi
|
|
|
|
|
|
|
|
# do nothing if PHOTOPRISM_INIT was not set
|
|
|
|
if [[ -z ${PHOTOPRISM_INIT} ]]; then
|
|
|
|
exit
|
|
|
|
fi
|
|
|
|
|
2022-03-11 09:05:42 +01:00
|
|
|
INIT_LOCK="/scripts/.init-lock"
|
2022-03-01 13:55:05 +01:00
|
|
|
|
2022-03-16 19:09:53 +01:00
|
|
|
# execute targets via /usr/bin/make
|
2022-03-01 13:55:05 +01:00
|
|
|
if [[ ! -e ${INIT_LOCK} ]]; then
|
|
|
|
for INIT_TARGET in $PHOTOPRISM_INIT; do
|
2022-03-17 10:14:08 +01:00
|
|
|
echo "init: $INIT_TARGET"
|
2022-03-23 08:16:01 +01:00
|
|
|
make -C "$INIT_SCRIPTS" "$INIT_TARGET"
|
2022-03-01 13:55:05 +01:00
|
|
|
done
|
|
|
|
|
|
|
|
echo 1 >${INIT_LOCK}
|
|
|
|
fi
|