-
Notifications
You must be signed in to change notification settings - Fork 11
/
docker-entrypoint.sh
executable file
·72 lines (52 loc) · 2.57 KB
/
docker-entrypoint.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
#!/bin/sh
# Copyright © 2021, PhotoStructure Inc.
# BY RUNNING THIS SOFTWARE YOU AGREE TO ALL THE TERMS OF THIS LICENSE:
# <https://photostructure.com/eula>
# See <https://photostructure.com/server> for instructions and
# <https://forum.photostructure.com/> for support.
# Propagate ctrl-c while we're still in this script:
trap 'exit 130' INT
# Tell PhotoStructure that we're running in a docker container:
export PS_IS_DOCKER="1"
# Tell node to run in production:
export NODE_ENV="production"
# Node was already installed into /usr/local/bin:
export PATH="${PATH}:/usr/local/bin:/ps/app:/ps/app/bin"
# Prior to v1.0, PhotoStructure for Docker defaulted to running as root. To
# prevent upgrades from failing due to permission issues, let's default the UID
# and GID to match the current owner of the system settings.toml file.
# This default value will be overridden if UID, GID, PUID, or PGID are set.
# If the file is missing, we default to 1000 for both the UID and GID, which are
# the default ids given to the first non-system user (at least in Ubuntu and
# Fedora).
DEFAULT_UID=$(stat -c %u /ps/config/settings.toml 2>/dev/null || echo 1000)
DEFAULT_GID=$(stat -c %g /ps/config/settings.toml 2>/dev/null || echo 1000)
# Accept either UID or PUID:
export UID=${UID:-${PUID:-${DEFAULT_UID}}}
# Accept either GID or PGID:
export GID=${GID:-${PGID:-${DEFAULT_GID}}}
# Accept UMASK:
umask "${UMASK:-0022}"
if [ -x "$PS_RUN_AT_STARTUP" ] ; then
"$PS_RUN_AT_STARTUP"
fi
# Let the user shell into the container:
if [ "$*" = "sh" ] || [ "$*" = "dash" ] || [ "$*" = "bash" ]; then
exec "$*"
elif [ "$UID" = "0" ] || [ "$(id --real --user)" != "0" ]; then
# They either want to run as root, or started docker with --user, so we
# shouldn't do any usermod/groupmod/su shenanigans.
# We `exec` to replace the current shell so nothing is between tini and node:
exec /usr/local/bin/node /ps/app/photostructure "$@"
else
# Change the node user and group to match UID/GID.
# (we don't care about "usermod: no changes"):
usermod --non-unique --uid "$UID" node >/dev/null
groupmod --non-unique --gid "$GID" node
# Always make sure the settings, opened-by, and models directories are
# read/writable by node:
chown --silent --recursive node:node /ps/library/.photostructure/settings.toml /ps/library/.photostructure/opened-by /ps/library/.photostructure/models
# Start photostructure as the user "node" instead of root.
# We `exec` to replace the current shell so nothing is between tini and node:
exec su --preserve-environment node --command "/usr/local/bin/node /ps/app/photostructure $*"
fi