#!/bin/sh
set -eu
cd /app
DATA=/app/data
mkdir -p "$DATA/repos" "$DATA/fossil-home" "$DATA/logs" "$DATA/skin-cache"
# 绑定到宿主机 ./data 时,目录属主常与容器进程不一致,导致 fossil init / sqlite 写失败。
# 启动时对齐属主,并把数据目录放宽为可写(含已有仓库文件)。
if [ "$(id -u)" = "0" ]; then
if [ -z "${PUID:-}" ] || [ -z "${PGID:-}" ]; then
PUID=$(stat -c %u "$DATA")
PGID=$(stat -c %g "$DATA")
fi
chown -R "${PUID}:${PGID}" "$DATA"
chmod -R u+rwX,g+rwX "$DATA"
if [ "$PUID" != "0" ] && command -v setpriv >/dev/null 2>&1; then
exec setpriv --reuid="$PUID" --regid="$PGID" --clear-groups -- /app/docker-entrypoint.sh
fi
fi
umask 0002
PA=""
for d in /app/_build/default/lib/*/ebin; do
if [ -d "$d" ]; then
PA="$PA -pa $d"
fi
done
# shellcheck disable=SC2086
exec erl -noshell -config /app/config/sys.config $PA \
-eval 'application:ensure_all_started(lamina).'