#!/usr/bin/env bash
# 原始 manifest / 二进制 / deb 等系统安装件 -> /srv/mirror/installers
set -uo pipefail
OUT=/srv/mirror/installers
mkdir -p "$OUT"; cd "$OUT"

dl(){ # url out
  echo "[dl] $2"
  if ! curl -fL --retry 5 --retry-delay 2 -C - -o "$2" "$1"; then
    case "$1" in
      https://github.com/*|https://raw.githubusercontent.com/*)
        echo "   direct failed -> ghproxy"
        curl -fL --retry 5 -C - -o "$2" "https://ghproxy.net/$1" || echo "   FAILED: $2";;
      *) echo "   FAILED: $2";;
    esac
  fi
}

# --- K8s 平台 manifest ---
dl https://raw.githubusercontent.com/projectcalico/calico/v3.28.0/manifests/calico.yaml calico-v3.28.0.yaml
dl https://raw.githubusercontent.com/metallb/metallb/v0.14.8/config/manifests/metallb-native.yaml metallb-native-v0.14.8.yaml
dl https://raw.githubusercontent.com/rancher/local-path-provisioner/v0.0.30/deploy/local-path-storage.yaml local-path-storage-v0.0.30.yaml
dl https://github.com/argoproj/argo-rollouts/releases/download/v1.7.2/install.yaml argo-rollouts-install-v1.7.2.yaml
dl https://github.com/argoproj/argo-rollouts/releases/download/v1.7.2/kubectl-argo-rollouts-linux-amd64 kubectl-argo-rollouts-linux-amd64-v1.7.2

# --- 二进制 ---
dl https://get.helm.sh/helm-v3.16.2-linux-amd64.tar.gz helm-v3.16.2-linux-amd64.tar.gz

# --- NVIDIA ---
dl https://developer.download.nvidia.com/compute/cuda/repos/ubuntu2204/x86_64/cuda-keyring_1.1-1_all.deb cuda-keyring_1.1-1_all.deb
NCT=https://nvidia.github.io/libnvidia-container/stable/deb/amd64
for p in \
  libnvidia-container1_1.16.2-1_amd64.deb \
  libnvidia-container-tools_1.16.2-1_amd64.deb \
  nvidia-container-toolkit-base_1.16.2-1_amd64.deb \
  nvidia-container-toolkit_1.16.2-1_amd64.deb ; do
  dl "$NCT/$p" "$p"
done

# --- Grafana DCGM 看板 12239 ---
dl "https://grafana.com/api/dashboards/12239/revisions/latest/download" grafana-dashboard-dcgm-12239.json

echo "=== installers done ==="
ls -lh "$OUT"
