refactor: storage path in config.yaml only — deploy script no longer prompts

This commit is contained in:
Claus Lohmar 2026-08-06 14:23:56 +01:00
parent aba58cf1a0
commit d867e3b976
2 changed files with 9 additions and 39 deletions

View file

@ -7,7 +7,7 @@ server:
viewer_port: ":8090" viewer_port: ":8090"
storage: storage:
recordings_path: "" recordings_path: "/home/master/nvr_data"
retention_days: 7 retention_days: 7
cleanup_interval_mins: 60 cleanup_interval_mins: 60

View file

@ -159,33 +159,8 @@ log "Local time: $(date)"
TZ=$(timedatectl show --property=Timezone --value 2>/dev/null || cat /etc/timezone 2>/dev/null || echo "unknown") TZ=$(timedatectl show --property=Timezone --value 2>/dev/null || cat /etc/timezone 2>/dev/null || echo "unknown")
log "Timezone: ${TZ}" log "Timezone: ${TZ}"
# ── 1c. Storage path ──
echo ""
log "Step 1c/7: Where should recordings be stored?"
info " This is where video clips and snapshots will be saved."
info " Examples: /mnt/recordings, /home/user/nvr, /media/usb-drive"
info " Or set STORAGE_PATH environment variable to skip the prompt."
echo ""
if [ -n "${STORAGE_PATH}" ]; then
log "Using STORAGE_PATH from environment: ${STORAGE_PATH}"
elif [ -e /dev/tty ]; then
read -p " Storage path [${HOME}/nvr_data]: " STORAGE_PATH </dev/tty
STORAGE_PATH="${STORAGE_PATH:-${HOME}/nvr_data}"
echo "" # newline after prompt
else
STORAGE_PATH="${HOME}/nvr_data"
warn "No terminal available — using default storage: ${STORAGE_PATH}"
fi
# Strip trailing slash.
STORAGE_PATH="${STORAGE_PATH%/}"
info "Creating ${STORAGE_PATH}..."
sudo mkdir -p "${STORAGE_PATH}"
sudo chown "$(whoami):$(id -gn)" "${STORAGE_PATH}"
log "Storage: ${STORAGE_PATH}"
# ── 2. Install Go (portable — no distro packages) ── # ── 2. Install Go (portable — no distro packages) ──
log "Step 2/7: Setting up Go ${GO_VERSION}..." log "Step 2/6: Setting up Go ${GO_VERSION}..."
GO_TAR="go${GO_VERSION}.linux-${GO_ARCH}.tar.gz" GO_TAR="go${GO_VERSION}.linux-${GO_ARCH}.tar.gz"
GO_URL="https://go.dev/dl/${GO_TAR}" GO_URL="https://go.dev/dl/${GO_TAR}"
@ -207,7 +182,7 @@ export GOPATH="$HOME/go"
export GOCACHE="$HOME/.cache/go-build" export GOCACHE="$HOME/.cache/go-build"
# ── 3. Clone or update repository ── # ── 3. Clone or update repository ──
log "Step 4/7: Fetching NextNVR source..." log "Step 4/6: Fetching NextNVR source..."
if [ -d "${DEPLOY_DIR}/.git" ]; then if [ -d "${DEPLOY_DIR}/.git" ]; then
info "Repository exists, pulling latest..." info "Repository exists, pulling latest..."
@ -224,7 +199,7 @@ fi
cd "${DEPLOY_DIR}" cd "${DEPLOY_DIR}"
# ── 4. Build ── # ── 4. Build ──
log "Step 5/7: Building NextNVR binary..." log "Step 5/6: Building NextNVR binary..."
go mod tidy go mod tidy
@ -239,22 +214,17 @@ chmod +x nextnvr
log "Binary built: nextnvr v${VERSION} ($(du -h nextnvr | cut -f1))" log "Binary built: nextnvr v${VERSION} ($(du -h nextnvr | cut -f1))"
# ── 5. Configuration & directories ── # ── 5. Configuration & directories ──
log "Step 6/7: Configuration..." log "Step 6/6: Configuration..."
if [ ! -f "${DEPLOY_DIR}/config.yaml" ]; then if [ ! -f "${DEPLOY_DIR}/config.yaml" ]; then
cp config.yaml "${DEPLOY_DIR}/config.yaml" cp config.yaml "${DEPLOY_DIR}/config.yaml"
log "Default config.yaml created with storage path: ${STORAGE_PATH}" log "Default config.yaml created. Use the web UI to configure cameras and storage."
else else
log "config.yaml already exists — updating storage path to: ${STORAGE_PATH}" log "config.yaml already exists — preserved."
fi fi
# Always inject the chosen storage path into config.
sed -i "s|recordings_path:.*|recordings_path: \"${STORAGE_PATH}\"|" "${DEPLOY_DIR}/config.yaml"
sudo mkdir -p "${STORAGE_PATH}" 2>/dev/null || mkdir -p "${STORAGE_PATH}"
sudo chown "$(whoami):$(id -gn)" "${STORAGE_PATH}" 2>/dev/null || true
# ── 6. Install service ── # ── 6. Install service ──
log "Step 7/7: Service installation..." log "Step 7/6: Service installation..."
RUN_USER="$(whoami)" RUN_USER="$(whoami)"
SERVICE_FILE="/etc/systemd/system/${SERVICE_NAME}.service" SERVICE_FILE="/etc/systemd/system/${SERVICE_NAME}.service"
@ -319,7 +289,7 @@ echo "============================================"
echo "" echo ""
info " Web UI: http://$(hostname -I 2>/dev/null | awk '{print $1}' || echo 'localhost'):8080" info " Web UI: http://$(hostname -I 2>/dev/null | awk '{print $1}' || echo 'localhost'):8080"
info " Config: ${DEPLOY_DIR}/config.yaml" info " Config: ${DEPLOY_DIR}/config.yaml"
info " Storage: /mnt/recordings/" info " Storage: $(grep recordings_path ${DEPLOY_DIR}/config.yaml 2>/dev/null | awk '{print $2}' | tr -d '"')"
echo "" echo ""
if $HAS_SYSTEMD; then if $HAS_SYSTEMD; then
echo " Service:" echo " Service:"