Files
Crumb-Core-v.1/native_crumbcore_v1/native-update.sh
2025-12-24 18:26:59 +01:00

192 lines
4.3 KiB
Bash
Executable File
Raw Blame History

This file contains ambiguous Unicode characters

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
#
# Crumbforest Update Script
# Updates code and dependencies without full reinstallation
#
# Run as root or with sudo
#
set -e
# Colors
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
RED='\033[0;31m'
BLUE='\033[0;34m'
NC='\033[0m'
# Configuration
INSTALL_DIR="/opt/crumbforest"
APP_USER="crumbforest"
LOG_DIR="/var/log/crumbforest"
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
PROJECT_ROOT="$(dirname "$SCRIPT_DIR")"
# Functions
print_success() {
echo -e "${GREEN}${NC} $1"
}
print_warning() {
echo -e "${YELLOW}${NC} $1"
}
print_error() {
echo -e "${RED}${NC} $1"
}
print_info() {
echo -e "${BLUE}${NC} $1"
}
check_root() {
if [ "$EUID" -ne 0 ]; then
print_error "Bitte als root ausführen oder sudo verwenden"
exit 1
fi
}
echo "============================================"
echo "🔄 Crumbforest Update"
echo "============================================"
echo ""
check_root
# Step 1: Stop service
echo "=== Step 1: Stop Service ==="
echo ""
if systemctl is-active --quiet crumbforest; then
print_info "Stoppe crumbforest Service..."
systemctl stop crumbforest
print_success "Service gestoppt"
else
print_warning "Service läuft nicht"
fi
echo ""
# Step 2: Backup current installation
echo "=== Step 2: Backup ==="
echo ""
BACKUP_DIR="/var/backups/crumbforest"
mkdir -p "$BACKUP_DIR"
TIMESTAMP=$(date +%Y%m%d_%H%M%S)
BACKUP_FILE="$BACKUP_DIR/app_backup_$TIMESTAMP.tar.gz"
print_info "Erstelle Backup..."
tar -czf "$BACKUP_FILE" -C "$INSTALL_DIR" app/ .env 2>/dev/null || true
print_success "Backup erstellt: $BACKUP_FILE"
echo ""
# Step 3: Update code
echo "=== Step 3: Update Code ==="
echo ""
print_info "Kopiere neuen Code..."
cp -r "$PROJECT_ROOT/app"/* "$INSTALL_DIR/app/"
print_success "Code aktualisiert"
print_info "Aktualisiere Konfiguration..."
if [ -f "$PROJECT_ROOT/crumbforest_config.json" ]; then
cp "$PROJECT_ROOT/crumbforest_config.json" "$INSTALL_DIR/app/"
print_success "Config aktualisiert"
fi
# Update docs if needed
if [ -d "$PROJECT_ROOT/docs_git" ]; then
print_info "Aktualisiere Dokumentation aus docs_git..."
cp -r "$PROJECT_ROOT/docs_git"/* "$INSTALL_DIR/docs/" 2>/dev/null || true
print_success "Docs aktualisiert"
elif [ -d "$PROJECT_ROOT/docs" ]; then
print_info "Aktualisiere Dokumentation aus docs..."
cp -r "$PROJECT_ROOT/docs"/* "$INSTALL_DIR/docs/" 2>/dev/null || true
print_success "Docs aktualisiert"
fi
# Update Crumb Doktor if exists
if [ -f "$PROJECT_ROOT/crumbpages-doktor.sh" ]; then
cp "$PROJECT_ROOT/crumbpages-doktor.sh" "/usr/local/bin/crumb-doktor"
chmod +x "/usr/local/bin/crumb-doktor"
print_success "Crumb Doktor aktualisiert"
fi
echo ""
# Step 4: Update Python dependencies
echo "=== Step 4: Python Dependencies ==="
echo ""
print_info "Aktualisiere Dependencies..."
"$INSTALL_DIR/venv/bin/pip" install --upgrade -r "$PROJECT_ROOT/app/requirements.txt"
print_success "Dependencies aktualisiert"
echo ""
# Step 5: Set permissions
echo "=== Step 5: Permissions ==="
echo ""
print_info "Setze Besitzer..."
chown -R "$APP_USER:$APP_USER" "$INSTALL_DIR/app"
print_success "Permissions gesetzt"
echo ""
# Step 6: Database migrations (if needed)
echo "=== Step 6: Database Migration ==="
echo ""
print_warning "Falls Schema-Änderungen vorhanden sind, bitte manuell migrieren!"
echo ""
# Step 7: Start service
echo "=== Step 7: Start Service ==="
echo ""
print_info "Starte Service..."
systemctl start crumbforest
sleep 2
if systemctl is-active --quiet crumbforest; then
print_success "Service läuft"
else
print_error "Service konnte nicht gestartet werden!"
print_error "Prüfe Logs: journalctl -u crumbforest -n 50"
exit 1
fi
echo ""
# Step 8: Health check
echo "=== Step 8: Health Check ==="
echo ""
sleep 3
if curl -s http://localhost:8000/health | grep -q "ok"; then
print_success "Health Check OK"
else
print_warning "Health Check fehlgeschlagen - prüfe Logs"
fi
echo ""
# Summary
echo "============================================"
echo "✓ Update abgeschlossen!"
echo "============================================"
echo ""
echo "Backup: $BACKUP_FILE"
echo ""
echo "Status prüfen:"
echo " sudo systemctl status crumbforest"
echo " sudo journalctl -u crumbforest -f"
echo ""
echo "Health Check:"
echo " curl http://localhost:8000/health"
echo ""
echo "Wuuuuhuuu! 🦉💚"
echo ""