chore: refactor and merge DevOps scripts (setup.sh and update.sh)

This commit is contained in:
datadunia
2026-05-16 03:02:48 +07:00
parent f9ab85e001
commit 4a8a5245e7
4 changed files with 60 additions and 99 deletions
+19 -25
View File
@@ -1,53 +1,47 @@
#!/bin/bash #!/bin/bash
set -e set -e
echo "======================================" echo "========================================="
echo " Starting NexusGuard SD-WAN Suite... " echo " NexusGuard SD-WAN: INITIAL SETUP "
echo "======================================" echo "========================================="
# Auto-create .env if it doesn't exist # 1. Environment File Generation
if [ ! -f .env ]; then if [ ! -f .env ]; then
echo "[!] .env file not found." echo "[!] .env file not found."
if [ -f .env.example ]; then if [ -f .env.example ]; then
echo "[+] Auto-generating .env from .env.example..." echo "[+] Auto-generating .env from .env.example..."
cp .env.example .env cp .env.example .env
# Generate secure random hex keys for JWT and Server Salt # Generate secure random hex keys
# Memastikan sistem aman tanpa campur tangan manual
RANDOM_JWT=$(openssl rand -hex 32) RANDOM_JWT=$(openssl rand -hex 32)
RANDOM_SALT=$(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/GantiDenganKunciRahasiaJWTUntukDashboard256Bit/$RANDOM_JWT/g" .env
sed -i "s/GantiDenganKunciGaramUntukWireGuard256Bit/$RANDOM_SALT/g" .env sed -i "s/GantiDenganKunciGaramUntukWireGuard256Bit/$RANDOM_SALT/g" .env
echo "[+] Secure random cryptographic keys have been auto-generated!" echo "[+] Secure cryptographic keys have been auto-generated!"
echo "[!] IMPORTANT: Please review the .env file to change the default database passwords!"
else else
echo "[-] ERROR: .env.example is missing. Cannot generate .env." echo "[-] ERROR: .env.example is missing. Cannot generate .env."
exit 1 exit 1
fi fi
else else
echo "[+] .env file detected." echo "[+] .env file already exists. Skipping environment generation."
fi fi
# Make sure Docker is available # Make sure Docker is available
if ! command -v docker-compose &> /dev/null; then 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 exit 1
fi fi
echo "[+] Sourcing environment variables to prepare builds..." echo ""
export $(grep -v '^#' .env | xargs) echo "========================================="
echo " Setup complete! Next Steps: "
echo "[+] Rebuilding containers if necessary..." echo " 1. Open and review the '.env' file. "
docker-compose build --build-arg VITE_API_BASE_URL=$VITE_API_BASE_URL echo " Make sure to change DB_PASSWORD, "
echo " API_PORT, and VITE_API_BASE_URL. "
echo "[+] Bringing up Docker containers..." echo " "
docker-compose up -d echo " 2. Run './update.sh' to download the "
echo " latest code, build, and start the "
echo "======================================" echo " system. "
echo " NexusGuard is successfully running! " echo "========================================="
echo " Web Dashboard : http://localhost:${WEB_PORT:-80}"
echo " API Port : ${API_PORT:-8080}"
echo "======================================"
+41
View File
@@ -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 "========================================="
-40
View File
@@ -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 "======================================"
-34
View File
@@ -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 "======================================"