#!/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

## amd64 chroot already existing for version check
## SC2037: shellcheck cannot statically tell that the trailing glob
##   resolves to a command, so it mistakes the line for an attempt
##   to assign a command's output - it is in fact the bash VAR=value
##   command-prefix form.
## SC2211: glob as command name, see comment above.
# shellcheck disable=SC2037,SC2211
make_cross_build_platform_list="arm64" ~/derivative-maker/build-steps.d/*_cowbuilder-setup --allow-untagged true --allow-uncommitted true --flavor source --target root

# shellcheck disable=SC2037,SC2211
make_cross_build_platform_list="amd64 arm64" ~/derivative-maker/build-steps.d/*_create-debian-packages --allow-untagged true --allow-uncommitted true --flavor source --target root --function download_tpo_packages

commit_message="get newer Tor package from TPO"

cd -- ~/derivative-binary/aptrepo_remote

git add -A
git status

## Interactive gate: this script is meant to be run by hand. The
## read blocks until the operator presses enter; ctrl+c aborts
## before the commit happens. Non-interactive runs (CI etc.) will
## hang here.
true "press ctrl + c to abort"
read -r question

git commit -a -m "$commit_message"

export build_upload_noninteractive=true
dm-upload-repository
