#!/bin/bash set -e # Configuration SERVICE_NAME="swag" SERVICE_DIR="/home/citadel/services/$SERVICE_NAME" DATA_DIR="/home/citadel/data/$SERVICE_NAME" # Colors for output RED='\033[0;31m' GREEN='\033[0;32m' YELLOW='\033[1;33m' NC='\033[0m' # No Color log_info() { echo -e "${GREEN}[INFO]${NC} $1" } log_warn() { echo -e "${YELLOW}[WARN]${NC} $1" } log_error() { echo -e "${RED}[ERROR]${NC} $1" } # Create necessary directories log_info "Creating directories..." mkdir -p "$SERVICE_DIR" mkdir -p "$DATA_DIR" # Set correct ownership log_info "Setting directory ownership..." sudo chown -R $(id -u):$(id -g) "$SERVICE_DIR" "$DATA_DIR" # Check if Docker network exists if ! docker network ls | grep -q "services"; then log_warn "Docker network 'services' not found. Creating..." docker network create services fi # Navigate to service directory cd "$SERVICE_DIR" # Check if .env file exists if [ ! -f ".env" ]; then log_error ".env file not found in $SERVICE_DIR" log_info "Please create the .env file with required variables" exit 1 fi # Update .env with current user IDs log_info "Updating .env with current user IDs..." sed -i "s/^PUID=.*/PUID=$(id -u)/" .env sed -i "s/^PGID=.*/PGID=$(id -g)/" .env # Check if OVH credentials are configured if [ ! -f "$DATA_DIR/dns-conf/ovh.ini" ]; then log_warn "OVH DNS credentials not found at $DATA_DIR/dns-conf/ovh.ini" log_info "Remember to configure OVH API credentials after first start" fi # Start the service log_info "Starting SWAG service..." docker-compose up -d # Check if service is running sleep 5 if docker-compose ps | grep -q "Up"; then log_info "SWAG service started successfully" log_info "Check logs with: docker-compose logs -f" else log_error "SWAG service failed to start" log_info "Check logs with: docker-compose logs" exit 1 fi