Skip to content

Instantly share code, notes, and snippets.

@rafirh
Last active December 4, 2025 15:41
Show Gist options
  • Select an option

  • Save rafirh/c95a17cfc7ce30695c14c35027a1f4df to your computer and use it in GitHub Desktop.

Select an option

Save rafirh/c95a17cfc7ce30695c14c35027a1f4df to your computer and use it in GitHub Desktop.
#!/bin/bash
clear
echo "=== AUTO INSTALL SATU PETA ==="
set -euo pipefail
# --- INPUT DOMAIN ---
read -p "Masukkan domain (tanpa https://): " DOMAIN
# --- INPUT GITLAB USERNAME & TOKEN ---
echo "=== AUTH GITLAB ==="
read -p "GitLab Username (email/username): " GIT_USER
read -s -p "Token/Password GitLab (hidden): " GIT_TOKEN
echo ""
# --- CEK ROOT ---
if [ "$EUID" -ne 0 ]; then
echo "❌ Harus menjalankan script sebagai ROOT !!"
exit
fi
# --- INSTALL DEPENDENCIES ---
echo ">>> Install nginx"
apt update -y
apt install git nginx -y
ufw allow 'Nginx Full'
# --- CLONE REPO WITH CREDENTIAL FILE ---
echo ">>> Clone repository menggunakan token dengan aman"
REPOS=(
"https://gitlab.com/profile-image/projects/jawa-timur/satu-peta/satu-peta-backend.git"
"https://gitlab.com/profile-image/projects/jawa-timur/satu-peta/satu-peta-frontend.git"
)
# create temporary credential file
CRED_FILE="$(mktemp --tmpdir gitlab-cred-XXXXXX)"
chmod 600 "$CRED_FILE"
HOST="gitlab.com"
printf "https://%s:%s@%s\n" "$GIT_USER" "$GIT_TOKEN" "$HOST" > "$CRED_FILE"
for REPO_URL in "${REPOS[@]}"; do
REPO_NAME=$(basename "$REPO_URL" .git)
echo "πŸ”Ή Clone: $REPO_NAME"
if [ -d "$REPO_NAME" ]; then
echo "⚠️ Folder '$REPO_NAME' sudah ada β€” lewati."
continue
fi
git -c credential.helper="store --file=$CRED_FILE" clone "$REPO_URL" || {
echo "❌ Gagal clone: $REPO_URL"
}
done
# Hapus credential file setelah clone
if command -v shred >/dev/null 2>&1; then
shred -u "$CRED_FILE" || rm -f "$CRED_FILE"
else
rm -f "$CRED_FILE"
fi
# --- SETUP BACKEND ---
echo ">>> Setup Backend"
cd satu-peta-backend || exit
cp .env.example .env
sed -i "s|APP_URL=.*|APP_URL=https://$DOMAIN|g" .env
docker compose up -d
# --- SETUP FRONTEND ---
echo ">>> Setup Frontend"
cd ../satu-peta-frontend || exit
cp env.prod.example .env.local
sed -i "s|NEXT_PUBLIC_API_URL=.*|NEXT_PUBLIC_API_URL=https://$DOMAIN/api|g" .env.local
sed -i "s|AUTH_URL=.*|AUTH_URL=https://$DOMAIN|g" .env.local
sed -i "s|NEXTAUTH_URL=.*|NEXTAUTH_URL=https://$DOMAIN|g" .env.local
sed -i "s|NEXT_PUBLIC_SITE_URL=.*|NEXT_PUBLIC_SITE_URL=https://$DOMAIN|g" .env.local
sed -i "s|AUTH_SECRET=.*|AUTH_SECRET=$(openssl rand -hex 32)|g" .env.local
sed -i "s|NEXTAUTH_SECRET=.*|NEXTAUTH_SECRET=$(openssl rand -hex 32)|g" .env.local
docker compose up -d
# --- SETUP NGINX ---
echo ">>> Setup Nginx"
cat > /etc/nginx/sites-available/satupeta.conf <<EOF
server {
listen 80;
server_name $DOMAIN;
location / {
proxy_pass http://localhost:4000;
proxy_set_header Host \$host;
proxy_set_header X-Real-IP \$remote_addr;
proxy_redirect off;
}
location /api/ {
proxy_pass http://localhost:5000/;
proxy_set_header Host \$host;
proxy_set_header X-Real-IP \$remote_addr;
proxy_redirect off;
}
}
EOF
ln -s /etc/nginx/sites-available/satupeta.conf /etc/nginx/sites-enabled/satupeta.conf 2>/dev/null
nginx -t && systemctl reload nginx
echo "πŸŽ‰ === SETUP BERES ==="
echo "🌍 Akses situs di: https://$DOMAIN"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment