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
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 "========================================="