#!/usr/bin/env bash
# Connected staging host only; refreshes the pinned distribution assets.
set -euo pipefail
BASE=$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")/.." && pwd)
cd "$BASE"
mkdir -p downloads bin images
release=https://github.com/gitleaks/gitleaks/releases/download/v8.30.0
curl -fL --retry 3 "$release/gitleaks_8.30.0_linux_x64.tar.gz" -o downloads/gitleaks_8.30.0_linux_x64.tar.gz
curl -fL --retry 3 "$release/gitleaks_8.30.0_checksums.txt" -o downloads/gitleaks_8.30.0_checksums.txt
(
    cd downloads
    grep ' gitleaks_8.30.0_linux_x64.tar.gz$' gitleaks_8.30.0_checksums.txt | sha256sum -c -
)
tar --no-same-owner -xzf downloads/gitleaks_8.30.0_linux_x64.tar.gz -C bin
skopeo copy --override-os linux --override-arch amd64 \
    docker://docker.io/gitea/gitea@sha256:dfc61e347c8b582df918f4556401bf2cecdfbdb56c5282ae9488dd76fca3e41c \
    "docker-archive:$BASE/images/gitea-1.22-linux-amd64.tar:docker.io/gitea/gitea:1.22"
echo 'Downloads complete. Review assets, then run scripts/package.sh.'
