bmc_hub/updateto.sh
Christian 25168108d6 feat(sag): Initialize case management module with CRUD operations, relations, and tags
- Added backend API routes for case management including listing, creating, updating, and deleting cases.
- Implemented relations and tags functionality for cases.
- Created frontend views for displaying case lists and details with filtering options.
- Added database migration scripts to set up necessary tables and indexes.
- Included HTML templates for case listing and detail views with responsive design.
- Configured module metadata in module.json for integration.
2026-01-29 23:07:33 +01:00

158 lines
4.7 KiB
Bash
Raw Permalink Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#!/bin/bash
# BMC Hub Production Deployment Script
# Usage: ./updateto.sh v1.3.15
set -e # Exit on any error
VERSION=$1
# This production deployment is designed for ROOTLESS Podman.
# Running with sudo will use a different Podman storage (rootful) and can make it look
# like "data disappeared" because volumes/networks are separate.
if [ "${EUID:-$(id -u)}" -eq 0 ]; then
echo "❌ Fejl: Kør ikke dette script som root (sudo)."
echo " Brug i stedet: sudo -iu bmcadmin && cd /srv/podman/bmc_hub_v1.0 && ./updateto.sh $VERSION"
exit 1
fi
PODMAN_COMPOSE_FILE="docker-compose.prod.yml"
if [ -z "$VERSION" ]; then
echo "❌ Fejl: Ingen version angivet"
echo "Usage: ./updateto.sh v1.3.15"
exit 1
fi
# SAFETY CHECK: Verify we're on production server
CURRENT_IP=$(hostname -I | awk '{print $1}' 2>/dev/null || echo "unknown")
CURRENT_DIR=$(pwd)
if [[ "$CURRENT_IP" != "172.16.31.183" ]] && [[ "$CURRENT_DIR" != "/srv/podman/bmc_hub_v1.0" ]]; then
echo "⚠️ ADVARSEL: Dette script skal kun køres på PRODUCTION serveren!"
echo " Forventet IP: 172.16.31.183"
echo " Forventet mappe: /srv/podman/bmc_hub_v1.0"
echo " Nuværende IP: $CURRENT_IP"
echo " Nuværende mappe: $CURRENT_DIR"
echo ""
read -p "Er du SIKKER på du vil fortsætte? (skriv 'JA' for at fortsætte): " CONFIRM
if [ "$CONFIRM" != "JA" ]; then
echo "❌ Deployment afbrudt"
exit 1
fi
fi
echo "🚀 Deploying BMC Hub version: $VERSION"
echo "================================"
# Check if .env exists
if [ ! -f ".env" ]; then
echo "❌ Fejl: .env fil ikke fundet"
exit 1
fi
if [ ! -f "$PODMAN_COMPOSE_FILE" ]; then
echo "❌ Fejl: $PODMAN_COMPOSE_FILE ikke fundet i $(pwd)"
echo " Kør fra /srv/podman/bmc_hub_v1.0"
exit 1
fi
# Load environment variables (DB credentials)
set -a
source .env
set +a
# Update RELEASE_VERSION in .env
echo "📝 Opdaterer .env med version $VERSION..."
if grep -q "^RELEASE_VERSION=" .env; then
# Replace existing line
sed -i.bak "s/^RELEASE_VERSION=.*/RELEASE_VERSION=$VERSION/" .env
else
# Add if missing
echo "RELEASE_VERSION=$VERSION" >> .env
fi
echo "✅ .env opdateret"
# Stop containers
echo ""
echo "⏹️ Stopper containere..."
podman-compose -f "$PODMAN_COMPOSE_FILE" down
# Pull/rebuild with new version
echo ""
echo "🔨 Bygger nyt image med version $VERSION..."
podman-compose -f "$PODMAN_COMPOSE_FILE" up -d --build
# Sync migrations from container to host
echo ""
echo "📁 Syncer migrations fra container til host..."
if podman cp bmc-hub-api-prod:/app/migrations ./migrations_temp 2>/dev/null; then
rm -rf ./migrations
mv ./migrations_temp ./migrations
chmod -R 755 ./migrations
echo "✅ Migrations synced"
else
echo "⚠️ Warning: Could not sync migrations (container might not be ready yet)"
fi
# Wait a bit for startup
echo ""
echo "⏳ Venter på container startup..."
sleep 5
# Database migrations
echo ""
echo "🧱 Database migrationer"
echo " NOTE: Scriptet kører ikke længere en hardcoded enkelt-migration automatisk."
echo " Brug migrations-UI'en i BMC Hub, eller sæt RUN_MIGRATIONS=true for at køre alle .sql i /docker-entrypoint-initdb.d/ i sorteret rækkefølge."
if [ "${RUN_MIGRATIONS:-false}" = "true" ]; then
if [ -z "$POSTGRES_USER" ] || [ -z "$POSTGRES_DB" ]; then
echo "❌ Fejl: POSTGRES_USER/POSTGRES_DB mangler i .env"
exit 1
fi
for i in {1..30}; do
if podman exec bmc-hub-postgres-prod pg_isready -U "$POSTGRES_USER" >/dev/null 2>&1; then
break
fi
echo "⏳ Venter på postgres... ($i/30)"
sleep 2
done
echo "📄 Kører alle migrations fra /docker-entrypoint-initdb.d (sorteret)..."
podman exec bmc-hub-postgres-prod sh -lc "ls -1 /docker-entrypoint-initdb.d/*.sql 2>/dev/null | sort" \
| while read -r file; do
[ -z "$file" ] && continue
echo "➡️ $file"
podman exec -i bmc-hub-postgres-prod psql -v ON_ERROR_STOP=1 -U "$POSTGRES_USER" -d "$POSTGRES_DB" -f "$file"
done
echo "✅ Migrations kørt"
else
echo " RUN_MIGRATIONS=false (default)"
fi
# Show logs
echo ""
echo "📋 Logs fra startup:"
echo "================================"
podman logs --tail 50 bmc-hub-api-prod
echo ""
echo "✅ Deployment fuldført!"
echo ""
echo "🔍 Tjek status med:"
echo " podman-compose -f $PODMAN_COMPOSE_FILE ps"
echo " podman logs -f bmc-hub-api-prod"
echo ""
echo "🌐 Test health endpoint:"
echo " curl http://localhost:8000/health"
echo ""
echo "📊 Sync kunder fra e-conomic:"
echo " curl -X POST http://localhost:8000/api/v1/system/sync/economic"
echo ""
echo "🔗 Link vTiger til kunder:"
echo " curl -X POST http://localhost:8000/api/v1/system/sync/vtiger"