From 4a8a5245e78cb15125ed065bdad0b53e63c178a7 Mon Sep 17 00:00:00 2001 From: datadunia Date: Sat, 16 May 2026 03:02:48 +0700 Subject: [PATCH] chore: refactor and merge DevOps scripts (setup.sh and update.sh) --- setup.sh | 44 +++++++++++++++++++------------------------- update.sh | 41 +++++++++++++++++++++++++++++++++++++++++ update_repo.sh | 40 ---------------------------------------- upgrade.sh | 34 ---------------------------------- 4 files changed, 60 insertions(+), 99 deletions(-) create mode 100644 update.sh delete mode 100755 update_repo.sh delete mode 100755 upgrade.sh diff --git a/setup.sh b/setup.sh index 422a5e3..b02ed0d 100755 --- a/setup.sh +++ b/setup.sh @@ -1,53 +1,47 @@ #!/bin/bash set -e -echo "======================================" -echo " Starting NexusGuard SD-WAN Suite... " -echo "======================================" +echo "=========================================" +echo " NexusGuard SD-WAN: INITIAL SETUP " +echo "=========================================" -# Auto-create .env if it doesn't exist +# 1. Environment File Generation 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 + # Generate secure random hex keys 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!" + echo "[+] Secure cryptographic keys have been auto-generated!" else echo "[-] ERROR: .env.example is missing. Cannot generate .env." exit 1 fi else - echo "[+] .env file detected." + echo "[+] .env file already exists. Skipping environment generation." 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." + echo "[-] ERROR: docker-compose is not installed. Please install Docker and Docker-Compose 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:${WEB_PORT:-80}" -echo " API Port : ${API_PORT:-8080}" -echo "======================================" +echo "" +echo "=========================================" +echo " Setup complete! Next Steps: " +echo " 1. Open and review the '.env' file. " +echo " Make sure to change DB_PASSWORD, " +echo " API_PORT, and VITE_API_BASE_URL. " +echo " " +echo " 2. Run './update.sh' to download the " +echo " latest code, build, and start the " +echo " system. " +echo "=========================================" diff --git a/update.sh b/update.sh new file mode 100644 index 0000000..6c300a6 --- /dev/null +++ b/update.sh @@ -0,0 +1,41 @@ +#!/bin/bash +set -e + +echo "=========================================" +echo " NexusGuard SD-WAN: SYSTEM UPDATE " +echo "=========================================" + +# 1. Pastikan file env ada +if [ ! -f .env ]; then + echo "[-] ERROR: .env file not found. Please run ./setup.sh first to initialize configuration." + exit 1 +fi + +# 2. Update Code dari Git (Main & Submodules) +echo "[+] Pulling latest source code from repository..." +git pull origin main || echo "[!] Git pull for main repo skipped or failed, continuing..." + +echo "[+] Syncing and updating submodules..." +git submodule update --init --recursive --remote || echo "[!] Git submodule update skipped or failed." + +# 3. Source variabel dari .env untuk dimasukkan ke build process (contoh: VITE_API_BASE_URL) +echo "[+] Sourcing environment variables from root .env..." +export $(grep -v '^#' .env | xargs) + +# 4. Rebuild Images & Restart Containers +echo "[+] Rebuilding Docker images (injecting new environment variables)..." +# Menggunakan --build-arg untuk memastikan Vue/Vite membaca domain API baru +docker-compose build --build-arg VITE_API_BASE_URL=$VITE_API_BASE_URL + +echo "[+] Restarting containers..." +docker-compose up -d + +# 5. Cleanup +echo "[+] Cleaning up unused dangling images to free up space..." +docker image prune -f + +echo "=========================================" +echo " Update & Deployment complete! " +echo " Dashboard : http://localhost:${WEB_PORT:-80}" +echo " API Port : ${API_PORT:-8080}" +echo "=========================================" diff --git a/update_repo.sh b/update_repo.sh deleted file mode 100755 index 2ff8637..0000000 --- a/update_repo.sh +++ /dev/null @@ -1,40 +0,0 @@ -#!/bin/bash -set -e - -echo "======================================" -echo " Updating NexusGuard Repository " -echo "======================================" - -# Step 1: Docker down -echo "[+] Stopping Docker containers..." -docker-compose down --remove-orphans -echo "[+] Docker containers stopped." - -# Step 2: Git pull main repo -echo "[+] Pulling latest main repo..." -git pull - -# Step 3: Update submodules -echo "[+] Updating submodules..." -git submodule update --init --recursive - -# Step 4: Pull latest on each submodule -for sub in apps/server-core apps/device-agent apps/dashboard-ui; do - if [ -d "$sub" ]; then - echo "[+] Updating $sub..." - cd "$sub" - git checkout main 2>/dev/null || git checkout master 2>/dev/null || true - git pull - cd - > /dev/null - fi -done - -# Step 5: Re-check submodule pointers -git submodule update --remote --merge 2>/dev/null || true - -echo "======================================" -echo " Repository updated! " -echo " Docker is stopped. " -echo " Run ./setup.sh or ./upgrade.sh " -echo " to start the services. " -echo "======================================" diff --git a/upgrade.sh b/upgrade.sh deleted file mode 100755 index f6d8f5f..0000000 --- a/upgrade.sh +++ /dev/null @@ -1,34 +0,0 @@ -#!/bin/bash -set -e - -echo "======================================" -echo " Upgrading NexusGuard SD-WAN Suite... " -echo "======================================" - -# Pastikan file env ada -if [ ! -f .env ]; then - echo "[-] ERROR: .env file not found. Please run ./setup.sh first." - exit 1 -fi - -echo "[+] Pulling latest source code from repository..." -git pull origin main || echo "[!] Git pull skipped or failed, continuing..." - -echo "[+] Sourcing environment variables from root .env..." -export $(grep -v '^#' .env | xargs) - -echo "[+] Rebuilding Docker images (injecting new environment variables)..." -# Menggunakan --build-arg untuk memastikan Vue/Vite membaca domain API baru -docker-compose build --build-arg VITE_API_BASE_URL=$VITE_API_BASE_URL - -echo "[+] Restarting containers..." -docker-compose up -d - -echo "[+] Cleaning up unused dangling images to free up space..." -docker image prune -f - -echo "======================================" -echo " Upgrade & Rebuild complete! " -echo " Dashboard : http://localhost:${WEB_PORT:-80}" -echo " API Port : ${API_PORT:-8080}" -echo "======================================"