chore: refactor and merge DevOps scripts (setup.sh and update.sh)
This commit is contained in:
@@ -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 "========================================="
|
||||
|
||||
@@ -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 "========================================="
|
||||
@@ -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
@@ -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 "======================================"
|
||||
Reference in New Issue
Block a user