#!/bin/bash # NextNVR v0.1.0 — Deployment Script # Clones the repository and deploys to /opt/nextnvr set -e GIT_URL="https://git.lohmar.co.uk/cclohmar/NextNVR.git" DEPLOY_DIR="/opt/nextnvr" SERVICE_NAME="nextnvr" GO_BIN="/home/master/.local/go/bin/go" FFMPEG_BIN="ffmpeg" echo "=== NextNVR Deployment ===" echo "Target: ${DEPLOY_DIR}" echo "Git: ${GIT_URL}" # 1. Install system dependencies if missing. if ! command -v ffmpeg &>/dev/null; then echo "Installing ffmpeg..." sudo apt-get update -qq sudo apt-get install -y -qq ffmpeg fi # 2. Clone or pull repository. if [ -d "${DEPLOY_DIR}" ]; then echo "Repository exists, pulling latest..." cd "${DEPLOY_DIR}" git pull origin main else echo "Cloning repository..." sudo mkdir -p "${DEPLOY_DIR}" sudo chown master:master "${DEPLOY_DIR}" git clone "${GIT_URL}" "${DEPLOY_DIR}" cd "${DEPLOY_DIR}" fi # 3. Build the Go binary with embedded static files. echo "Building NextNVR binary..." export PATH=$HOME/.local/go/bin:$PATH export GOPATH=$HOME/go go mod tidy CGO_ENABLED=0 go build -ldflags="-s -w -X main.Version=$(cat VERSION) -X main.BuildTime=$(date -u +%Y-%m-%dT%H:%M:%SZ)" -o nextnvr . # 4. Copy config if not present. if [ ! -f "${DEPLOY_DIR}/config.yaml" ]; then cp config.yaml "${DEPLOY_DIR}/config.yaml" echo "Default config.yaml created." fi # 5. Set permissions. sudo chown -R master:master "${DEPLOY_DIR}" chmod +x "${DEPLOY_DIR}/nextnvr" # 6. Install systemd service. SERVICE_FILE="/etc/systemd/system/${SERVICE_NAME}.service" if [ ! -f "${SERVICE_FILE}" ]; then echo "Creating systemd service..." sudo tee "${SERVICE_FILE}" > /dev/null <