#!/bin/bash

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

set -x
set -e

true "INFO: Currently running script: $BASH_SOURCE $@"

dist_build_internal_run="true"

MYDIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
cd "$MYDIR"

## XXX: hardcoded path
source "$HOME/derivative-maker/help-steps/pre"
source "$HOME/derivative-maker/help-steps/colors"
source "$HOME/derivative-maker/help-steps/variables"

if [ "$(id -u)" = "0" ]; then
   true "ERROR: Do not run this as root!"
   exit 1
fi

if [ ! "$build_upload_noninteractive" = "true" ]; then
   true "${cyan}INFO $BASH_SOURCE: Please press enter to continue canary github.${reset}"
   read temp
fi

## XXX: hardcoded git repositories
pushd ~/sourcesown/canary/
git push github-kicksecure master
git push github-whonix master
git push adrelanos master
popd

## XXX: hardcoded project domain names
for upload_location in root@whonix.org root@kicksecure.com ; do

   if [ ! "$build_upload_noninteractive" = "true" ]; then
      true "${cyan}INFO $BASH_SOURCE: Please press enter to continue canary --dry-run.${reset}"
      read temp
   fi

   true "${cyan}INFO $BASH_SOURCE: Test only. Running rsync with --dry-run...${reset}"
   rsync \
      --dry-run \
      $rsync_opts \
      --recursive \
      --rsh ssh \
      "$binary_build_folder_dist/canary/canary.txt.asc" \
      "$binary_build_folder_dist/canary/canary.txt" \
      "$binary_build_folder_dist/canary/canary.txt.clearsign.asc" \
      "$binary_build_folder_dist/canary/canary.txt.sig" \
      "$binary_build_folder_dist/canary/canary.txt.embed.sig" \
      "${upload_location}:/var/rsync/developer-meta-files/canary"

   if [ ! "$build_upload_noninteractive" = "true" ]; then
      true "${cyan}INFO $BASH_SOURCE: Please press enter to continue canary.${reset}"
      read temp
   fi

   true "${cyan}INFO $BASH_SOURCE: Uploading canary...${reset}"
   rsync \
      $rsync_opts \
      --recursive \
      --rsh ssh \
      "$binary_build_folder_dist/canary/canary.txt.asc" \
      "$binary_build_folder_dist/canary/canary.txt" \
      "$binary_build_folder_dist/canary/canary.txt.clearsign.asc" \
      "$binary_build_folder_dist/canary/canary.txt.sig" \
      "$binary_build_folder_dist/canary/canary.txt.embed.sig" \
      "${upload_location}:/var/rsync/developer-meta-files/canary"

done
