feat: setup.sh asks for storage path, creates directory, injects into config

This commit is contained in:
Claus Lohmar 2026-08-06 13:53:58 +01:00
parent 7a4c97e760
commit b5dcbe9c56

View file

@ -143,8 +143,24 @@ log "Local time: $(date)"
TZ=$(timedatectl show --property=Timezone --value 2>/dev/null || cat /etc/timezone 2>/dev/null || echo "unknown")
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"
echo ""
read -p " Storage path [/mnt/recordings]: " STORAGE_PATH
STORAGE_PATH="${STORAGE_PATH:-/mnt/recordings}"
# 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) ──
log "Step 2/6: Setting up Go ${GO_VERSION}..."
log "Step 2/7: Setting up Go ${GO_VERSION}..."
GO_TAR="go${GO_VERSION}.linux-${GO_ARCH}.tar.gz"
GO_URL="https://go.dev/dl/${GO_TAR}"
@ -166,7 +182,7 @@ export GOPATH="$HOME/go"
export GOCACHE="$HOME/.cache/go-build"
# ── 3. Clone or update repository ──
log "Step 3/6: Fetching NextNVR source..."
log "Step 4/7: Fetching NextNVR source..."
if [ -d "${DEPLOY_DIR}/.git" ]; then
info "Repository exists, pulling latest..."
@ -183,7 +199,7 @@ fi
cd "${DEPLOY_DIR}"
# ── 4. Build ──
log "Step 4/6: Building NextNVR binary..."
log "Step 5/7: Building NextNVR binary..."
go mod tidy
@ -198,21 +214,23 @@ chmod +x nextnvr
log "Binary built: nextnvr v${VERSION} ($(du -h nextnvr | cut -f1))"
# ── 5. Configuration & directories ──
log "Step 5/6: Configuration..."
log "Step 6/7: Configuration..."
if [ ! -f "${DEPLOY_DIR}/config.yaml" ]; then
cp config.yaml "${DEPLOY_DIR}/config.yaml"
log "Default config.yaml created."
# Inject the user's storage path into the config.
sed -i "s|recordings_path:.*|recordings_path: \"${STORAGE_PATH}\"|" "${DEPLOY_DIR}/config.yaml"
log "Default config.yaml created with storage path: ${STORAGE_PATH}"
info "Edit it to match your cameras: nano ${DEPLOY_DIR}/config.yaml"
else
log "config.yaml already exists — preserved."
fi
sudo mkdir -p /mnt/recordings 2>/dev/null || mkdir -p /mnt/recordings
sudo chown "$(whoami):$(id -gn)" /mnt/recordings 2>/dev/null || true
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 ──
log "Step 6/6: Service installation..."
log "Step 7/7: Service installation..."
RUN_USER="$(whoami)"
SERVICE_FILE="/etc/systemd/system/${SERVICE_NAME}.service"