#!/bin/bash set -e echo "======================================" echo " Starting NexusGuard SD-WAN Suite... " echo "======================================" # Auto-create .env if it doesn't exist if [ ! -f .env ]; then echo "[!] .env file not found." if [ -f .env.example ]; then echo "[+] Auto-generating .env from .env.example..." cp .env.example .env # Generate secure random hex keys for JWT and Server Salt # Memastikan sistem aman tanpa campur tangan manual RANDOM_JWT=$(openssl rand -hex 32) RANDOM_SALT=$(openssl rand -hex 32) # Replace the placeholders in the newly created .env file sed -i "s/GantiDenganKunciRahasiaJWTUntukDashboard256Bit/$RANDOM_JWT/g" .env sed -i "s/GantiDenganKunciGaramUntukWireGuard256Bit/$RANDOM_SALT/g" .env echo "[+] Secure random cryptographic keys have been auto-generated!" echo "[!] IMPORTANT: Please review the .env file to change the default database passwords!" else echo "[-] ERROR: .env.example is missing. Cannot generate .env." exit 1 fi else echo "[+] .env file detected." fi # Make sure Docker is available if ! command -v docker-compose &> /dev/null; then echo "[-] ERROR: docker-compose is not installed. Please install Docker first." exit 1 fi echo "[+] Sourcing environment variables to prepare builds..." export $(grep -v '^#' .env | xargs) echo "[+] Rebuilding containers if necessary..." docker-compose build --build-arg VITE_API_BASE_URL=$VITE_API_BASE_URL echo "[+] Bringing up Docker containers..." docker-compose up -d echo "======================================" echo " NexusGuard is successfully running! " echo " Web Dashboard : http://localhost" echo " API Port : ${API_PORT:-8080}" echo "======================================"