File size: 850 Bytes
3dd217d | 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 | #!/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 "$@"
|