Files
appstore/apps/1panel/v2/scripts/init.sh
T
okxlin 6377f8bd02 Fix 1Panel configurable base directory
Mount the selected host data directory at the same container path and pass it through BASE_DIR, matching the current moelin/1panel entrypoint contract. Normalize legacy relative DATA_PATH values before install or upgrade and preserve existing data locations.
2026-07-16 18:26:22 +08:00

27 lines
873 B
Bash
Executable File

#!/bin/bash
set -e
ROOT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
ENV_FILE="${ENV_FILE:-$ROOT_DIR/.env}"
DATA_PATH="$(sed -n 's/^DATA_PATH=//p' "$ENV_FILE" | tail -n 1)"
if [[ "$DATA_PATH" == \"*\" ]] || [[ "$DATA_PATH" == \'*\' ]]; then
DATA_PATH="${DATA_PATH:1:${#DATA_PATH}-2}"
fi
DATA_PATH="${DATA_PATH:-/opt/1panel-data}"
if [[ "$DATA_PATH" != /* ]]; then
DATA_PATH="$(realpath -m -- "$ROOT_DIR/$DATA_PATH")"
fi
if [[ "$DATA_PATH" != /* ]] || [[ "$DATA_PATH" =~ [[:space:]:] ]]; then
echo "DATA_PATH must be an absolute path using common path characters" >&2
exit 1
fi
mkdir -p -- "$DATA_PATH"
DATA_PATH_ESCAPED="$(printf '%s' "$DATA_PATH" | sed 's/[|&\\]/\\&/g')"
if grep -q '^DATA_PATH=' "$ENV_FILE"; then
sed -i "s|^DATA_PATH=.*$|DATA_PATH=${DATA_PATH_ESCAPED}|" "$ENV_FILE"
else
printf '\nDATA_PATH=%s\n' "$DATA_PATH" >> "$ENV_FILE"
fi