c2a / entrypoint.sh
xuanwoai's picture
Upload 2 files
3dd217d verified
Raw
History Blame Contribute Delete
850 Bytes
#!/bin/sh
set -eu
PERSIST_ROOT="${PERSIST_ROOT:-/data}"
APP_DATA_DIR="${PERSIST_ROOT}/app-data"
PERSIST_CONFIG="${PERSIST_ROOT}/config.json"
DEFAULT_CONFIG="/app/config.default.json"
mkdir -p "$APP_DATA_DIR"
if [ ! -f "$PERSIST_CONFIG" ]; then
if [ -f "$DEFAULT_CONFIG" ]; then
cp "$DEFAULT_CONFIG" "$PERSIST_CONFIG"
else
printf '{}\n' > "$PERSIST_CONFIG"
fi
fi
link_path() {
target="$1"
link="$2"
if [ -L "$link" ]; then
current="$(readlink "$link" || true)"
if [ "$current" = "$target" ]; then
return
fi
rm "$link"
elif [ -e "$link" ]; then
backup="${link}.image-default"
if [ ! -e "$backup" ]; then
mv "$link" "$backup"
else
rm -rf "$link"
fi
fi
ln -s "$target" "$link"
}
link_path "$APP_DATA_DIR" /app/data
link_path "$PERSIST_CONFIG" /app/config.json
exec "$@"