#!/usr/bin/env bash

if [[ -n "${DEBUG:-}" ]]; then
    set -eux
else
    set -euo pipefail
fi

BASE_URL="https://gist.asfd.cn/jetsung/gendocs/raw/HEAD"

download_files() {
  curl -fsSL -O "${BASE_URL}/deploy.sh"
  chmod +x deploy.sh

  curl -fsSL -o README.md "${BASE_URL}/DOCS.md"

  curl -fsSL -O "${BASE_URL}/config.example.toml"

  curl -fsSL -O "${BASE_URL}/.gitignore"

  curl -fsSL --create-dirs -o ".github/workflows/docs.yml" "${BASE_URL}/docs.yml"
}

main() {
  download_files

  if [[ ! -f CNAME ]]; then
    echo "" > CNAME
  fi  
}

main "$@"
