#!/usr/bin/env bash
# install-argocd.sh
# Argo CD — Continuously sync Kubernetes cluster state from a Git repository.
# Target: Ubuntu / Debian. Safe to re-run.
# Source guide: devops-hub/tools/argocd.html

set -euo pipefail

if [[ $EUID -eq 0 ]]; then
  echo "Run this as a regular sudo-capable user, not root." >&2
  exit 1
fi

echo "==> Download the CLI binary"
curl -sSL -o argocd https://github.com/argoproj/argo-cd/releases/latest/download/argocd-linux-amd64

echo "==> Make it executable and move it onto PATH"
chmod +x argocd
sudo mv argocd /usr/local/bin/

echo "==> Install the server into a cluster"
kubectl create namespace argocd
kubectl apply -n argocd -f https://raw.githubusercontent.com/argoproj/argo-cd/stable/manifests/install.yaml

echo "==> Verify"
argocd version --client

echo "==> Done. Argo CD installation finished."
