Repository navigation
Expand file tree
/
Copy pathdocker-entrypoint.sh
More file actions
executable file
·47 lines (40 loc) · 1.71 KB
/
Copy pathdocker-entrypoint.sh
File metadata and controls
executable file
·47 lines (40 loc) · 1.71 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
#!/bin/sh
# Ensure bind-mounted chains-config is writable by appuser, then drop privileges.
# FakeMySQL LOCAL INFILE captures are persisted under:
# chains-config/cache/fake-server-files/
# Empty host mounts (./chains-config created as root:root) otherwise yield
# AccessDeniedException and appear as "cannot read files" in the UI.
set -eu
APP_USER="${CHAINS_APP_USER:-appuser}"
APP_GROUP="${CHAINS_APP_GROUP:-appgroup}"
CONFIG_DIR="${CHAINS_CONFIG_DIR:-/chains/chains-config}"
ensure_dir_writable_by_app() {
dir="$1"
mkdir -p "$dir"
if ! runuser -u "$APP_USER" -- test -w "$dir" 2>/dev/null; then
chown "$APP_USER:$APP_GROUP" "$dir" || true
fi
}
if [ "$(id -u)" = "0" ]; then
mkdir -p "$CONFIG_DIR"
# Host bind mounts often create the volume root as root:root (mode 755).
# Chown the directory inode (not a recursive tree walk) so appuser can create
# cache/plugin/preset children without rewriting user plugin contents.
if ! runuser -u "$APP_USER" -- test -w "$CONFIG_DIR" 2>/dev/null; then
chown "$APP_USER:$APP_GROUP" "$CONFIG_DIR" || true
fi
ensure_dir_writable_by_app "$CONFIG_DIR/cache"
ensure_dir_writable_by_app "$CONFIG_DIR/cache/fake-server-files"
ensure_dir_writable_by_app "$CONFIG_DIR/plugins"
ensure_dir_writable_by_app "$CONFIG_DIR/presets"
ensure_dir_writable_by_app "$CONFIG_DIR/plugin-data"
# Previous root-owned captures under cache/ would still be unreadable; reclaim cache only.
if [ -d "$CONFIG_DIR/cache" ]; then
chown -R "$APP_USER:$APP_GROUP" "$CONFIG_DIR/cache" 2>/dev/null || true
fi
if command -v setpriv >/dev/null 2>&1; then
exec setpriv --reuid="$APP_USER" --regid="$APP_GROUP" --init-groups -- "$@"
fi
exec runuser -u "$APP_USER" -- "$@"
fi
exec "$@"