Repository navigation
Expand file tree
/
Copy pathentrypoint.sh
More file actions
59 lines (50 loc) · 2 KB
/
Copy pathentrypoint.sh
File metadata and controls
59 lines (50 loc) · 2 KB
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
#!/bin/sh
RUNNING_AS_ROOT=false
if [ "$(id -u)" -eq 0 ]; then
RUNNING_AS_ROOT=true
PUID=${PUID:-9011}
PGID=${PGID:-9011}
if ! CURRENT_UID=$(id -u photon 2>/dev/null) || ! CURRENT_GID=$(id -g photon 2>/dev/null); then
echo "ERROR: user 'photon' does not exist in this image, refusing to change file ownership" >&2
exit 1
fi
if [ "$CURRENT_GID" != "$PGID" ]; then
echo "Updating photon group GID from $CURRENT_GID to $PGID"
groupmod -o -g "$PGID" photon
echo "Updating ownership of files from GID $CURRENT_GID to $PGID"
find / -group "$CURRENT_GID" -exec chgrp -h "$PGID" {} \; 2>/dev/null
fi
if [ "$CURRENT_UID" != "$PUID" ]; then
echo "Updating photon user UID from $CURRENT_UID to $PUID"
usermod -o -u "$PUID" photon
echo "Updating ownership of files from UID $CURRENT_UID to $PUID"
find / -user "$CURRENT_UID" -exec chown -h "$PUID" {} \; 2>/dev/null
fi
else
if [ -n "$PUID" ] || [ -n "$PGID" ]; then
echo "WARNING: PUID/PGID are ignored when the container runs as non-root user $(id -u):$(id -g)" >&2
fi
UNWRITABLE=$(find /photon/data ! -writable -print -quit)
if [ -n "$UNWRITABLE" ]; then
echo "ERROR: $UNWRITABLE is not writable by $(id -u):$(id -g)." >&2
echo "Change the ownership of the mounted data directory and its contents to match the container user." >&2
exit 1
fi
fi
if [ -d "/photon/data/photon_data/node_1" ]; then
if [ -d "/photon/data/node_1" ]; then
echo "Removing old index..."
rm -rf /photon/data/node_1
echo "Cleanup complete: removed /photon/data/node_1"
fi
elif [ -d "/photon/data/node_1" ]; then
echo "Migrating data structure..."
mkdir -p /photon/data/photon_data
mv /photon/data/node_1 /photon/data/photon_data/
echo "Migration complete: moved node_1 to /photon/data/photon_data/"
fi
if [ "$RUNNING_AS_ROOT" = true ]; then
chown -R photon:photon /photon
exec gosu photon "$@"
fi
exec "$@"