#!/bin/bash

## Copyright (C) 2012 - 2025 ENCRYPTED SUPPORT LLC <adrelanos@whonix.org>
## See the file COPYING for copying conditions.

set -x
set -o errexit
set -o nounset
set -o pipefail
set -o errtrace
shopt -s inherit_errexit
shopt -s shift_verbose

init_variables() {
  #derivative_version="17"
  derivative_version="18"

  qubes_release_list=()
  ## NOTE: Do not add 'R' prefix, for example, do not write 'R4.2'.
  #qubes_release_list+=("4.2")
  qubes_release_list+=("4.3")

  template_list=()
  template_list+=("kicksecure-${derivative_version}")
  template_list+=("whonix-gateway-${derivative_version}")
  template_list+=("whonix-workstation-${derivative_version}")

  template_oneline_string="${template_list[*]}"
}

git_tag_pushed_sanity_test() {
  local repo_path

  ## XXX: hardcoded path
  for repo_path in \
      "$HOME/derivative-maker/qubes/qubes-template-kicksecure" \
      "$HOME/derivative-maker/qubes/qubes-template-whonix" ; do
    cd -- "${repo_path}"
    git switch master
    dm-quickgittagsign
    dm-push
  done
}

init_variables
git_tag_pushed_sanity_test

## XXX: hardcoded path
cd -- "$HOME/sourcesother/qubes-builder"

for qubes_release_item in "${qubes_release_list[@]}"; do
  cmd_list=(
    env
    REPO_PROXY=''
    make
    RELEASE="$qubes_release_item"
    DISTS_VM="$template_oneline_string"
    template-github
  )

  "${cmd_list[@]}"
done

for template_item in "${template_list[@]}"; do
  realpath -- "build-logs/template-github-$template_item.log"
done
