File make-vendor.sh of Package ghostty

#!/usr/bin/env bash
set -euo pipefail

# Run from inside an extracted ghostty source dir (ghostty-1.2.3/)
# It will create vendor/ with all remote tarballs and then vendor.tar.zst.

need() { command -v "$1" >/dev/null 2>&1 || { echo "Missing: $1" >&2; exit 1; }; }
need rg
need curl
need tar
need zstd

VENDOR_DIR="${VENDOR_DIR:-vendor}"
mkdir -p "$VENDOR_DIR"

# Find all .zon files that may contain dependency URLs
mapfile -t ZON_FILES < <(find . -type f -name '*.zon' -print | sort)

# Extract URLs from .zon files
mapfile -t URLS < <(
  rg -No --no-filename '\.url\s*=\s*"https?://[^"]+"' "${ZON_FILES[@]}" \
  | sed -E 's@^.*"([^"]+)"$@\1@' \
  | sort -u
)

if [[ ${#URLS[@]} -eq 0 ]]; then
  echo "No URLs found in *.zon files. Nothing to vendor."
  exit 0
fi

ALLOW_MISSING="${ALLOW_MISSING:-0}"
FAILED=()

echo "Found ${#URLS[@]} URLs. Downloading into ${VENDOR_DIR}/ ..."

for url in "${URLS[@]}"; do
  base="$(basename "${url}")"
  out="${VENDOR_DIR}/${base}"

  if [[ -s "$out" ]]; then
    echo "  [skip] $base"
    continue
  fi

  echo "  [get ] $url"
  if curl -fL --retry 5 --retry-delay 1 --connect-timeout 10 --max-time 300 \
      -o "${out}.part" "$url"; then
    mv "${out}.part" "$out"
  else
    echo "  [warn] failed to download $url" >&2
    rm -f "${out}.part"
    FAILED+=("$url")
  fi
done

if [[ ${#FAILED[@]} -gt 0 ]]; then
  echo "Missing ${#FAILED[@]} URLs:" >&2
  printf '  - %s\n' "${FAILED[@]}" >&2
  if [[ "$ALLOW_MISSING" != "1" ]]; then
    exit 1
  fi
fi

echo "Creating vendor.tar.zst ..."
tar --sort=name --owner=0 --group=0 --numeric-owner \
  -I 'zstd -19 -T0' -cf vendor.tar.zst "$VENDOR_DIR"

echo "Done: vendor.tar.zst"
openSUSE Build Service is sponsored by