#!/bin/bash

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

set -x
set -e

git_tag_nearest="$(git describe --always --abbrev=0)"

## TODO: qubes-template-kicksecure qubes-template-whonix

for repo in github-derivative-maker github-kicksecure github-whonix adrelanos ; do
   if git remote get-url "$repo" &>/dev/null ; then
      if git rev-parse --verify main &>/dev/null ; then
         git verify-commit main
         git push "$repo" main &
         pid_list+=" $!"
      fi
      if git rev-parse --verify master &>/dev/null ; then
         git verify-commit master
         git push "$repo" master &
         pid_list+=" $!"
      fi
      ## TODO: Debian 14 / forky
      if git rev-parse --verify trixie &>/dev/null ; then
         git verify-commit trixie
         git push "$repo" trixie &
         pid_list+=" $!"
      fi
      if [ ! "$git_tag_nearest" = "" ]; then
         git verify-tag "$git_tag_nearest"
         git push "$repo" "$git_tag_nearest" &
         pid_list+=" $!"
      fi
   fi
done

wait -- $pid_list

true "$0: OK"
