#!/bin/bash # Landvex Site Manager — Eget verktyg för att hantera webbplatser # Användning: ./site-manager.sh [kommando] [parametrar] set -e SITES=("quixzoom" "landvex") S3_BUCKETS=("s3://quixzoom-landing-prod" "s3://landvex-prod") CF_DISTRIBUTIONS=("EE30B9WM5ZYM7" "E2M3J95HLUR89H") WORKSPACE="/opt/amos/public" color_red='\033[0;31m' color_green='\033[0;32m' color_yellow='\033[1;33m' color_nc='\033[0m' log() { echo -e "${color_green}[$(date +%H:%M:%S)]${color_nc} $1"; } warn() { echo -e "${color_yellow}[$(date +%H:%M:%S)] WARNING:${color_nc} $1"; } error() { echo -e "${color_red}[$(date +%H:%M:%S)] ERROR:${color_nc} $1"; exit 1; } show_help() { cat << 'EOF' Landvex Site Manager — Kommandon: sync [site] Synka lokala filer till S3 + invalidera CloudFront sync-all Synka alla sajter check [site] Kolla skillnader mellan lokal och S3 status Visa status för alla sajter fix-contrast [site] Fixa kontrastproblem automatiskt fix-mobile [site] Fixa mobilanpassning automatiskt add-terms [file] [n] Lägg till n termer i glossary från fil validate [site] Validera HTML, CSS, kontrast backup [site] Skapa backup av S3-bucket restore [site] [date] Återställ från backup Exempel: ./site-manager.sh sync landvex ./site-manager.sh fix-mobile quixzoom ./site-manager.sh add-terms nya-termer.txt 20 EOF } sync_site() { local site=$1 local idx=-1 for i in "${!SITES[@]}"; do if [[ "${SITES[$i]}" == "$site" ]]; then idx=$i; break; fi done [[ $idx -eq -1 ]] && error "Okänd sajt: $site" log "Synkar $site..." aws s3 sync "${WORKSPACE}/${site}/" "${S3_BUCKETS[$idx]}" --delete log "Invaliderar CloudFront..." aws cloudfront create-invalidation \ --distribution-id "${CF_DISTRIBUTIONS[$idx]}" \ --paths "/*" \ --query 'Invalidation.Id' --output text log "$site synkad och invaliderad!" } sync_all() { for site in "${SITES[@]}"; do sync_site "$site" done } check_diff() { local site=$1 local idx=-1 for i in "${!SITES[@]}"; do if [[ "${SITES[$i]}" == "$site" ]]; then idx=$i; break; fi done [[ $idx -eq -1 ]] && error "Okänd sajt: $site" log "Kollar skillnader för $site..." aws s3 sync "${WORKSPACE}/${site}/" "${S3_BUCKETS[$idx]}" --dry-run } show_status() { log "=== SAJTSTATUS ===" for i in "${!SITES[@]}"; do local site=${SITES[$i]} local local_files=$(find "${WORKSPACE}/${site}" -type f | wc -l) local s3_files=$(aws s3 ls "${S3_BUCKETS[$i]}" --recursive | wc -l) log "$site: $local_files lokala filer, $s3_files filer på S3" done } fix_contrast() { local site=$1 log "Fixar kontrast för $site..." find "${WORKSPACE}/${site}" -name "*.html" -exec sed -i \ -e 's/#f0f0f0/#1a1a1a/g' \ -e 's/#e0e0e0/#2a2a2a/g' \ -e 's/#cccccc/#333333/g' \ {} + log "Kontrast fixad! Glöm inte att synka." } fix_mobile() { local site=$1 log "Fixar mobilanpassning för $site..." # Lägg till mobil-CSS om det saknas find "${WORKSPACE}/${site}" -name "*.html" | while read -r file; do if ! grep -q "@media.*max-width.*640" "$file"; then sed -i '/<\/style>/i\ @media (max-width: 640px) {\ .hero h1 { font-size: 2rem !important; }\ .hero p { font-size: 1rem !important; }\ .card { padding: 1.5rem !important; }\ .grid { grid-template-columns: 1fr !important; }\ .btn { padding: 0.75rem 1.5rem !important; font-size: 1rem !important; }\ }' "$file" fi done log "Mobilanpassning fixad! Glöm inte att synka." } add_terms() { local file=$1 local n=${2:-10} [[ ! -f "$file" ]] && error "Fil finns inte: $file" log "Lägger till $n termer från $file..." local glossary="${WORKSPACE}/quixzoom/glossary.html" local count=0 while IFS='|' read -r term short long category && [[ $count -lt $n ]]; do [[ -z "$term" ]] && continue # Skapa term-card HTML local html="
$short
$long