#!/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 $@"

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

cd "$MYDIR"
cd ..
cd help-steps

dist_build_internal_run="true"

source pre
source colors
source variables

main() {
   true "gpg_bin: $gpg_bin"
   true "dist_local_signing_key_folder: $dist_local_signing_key_folder"
   true "dist_build_reprepro_signing_options: $dist_build_reprepro_signing_options"
   true "make_use_debsign: $make_use_debsign"

   echo "test" | tee "$binary_build_folder_dist/test_sign_file" >/dev/null
   chown "$user_name:$user_name" "$binary_build_folder_dist/test_sign_file"

   #export GNUPGHOME="$dist_local_signing_key_folder"

   $gpg_bin \
      --keyid-format 0xlong \
      --fingerprint \
      --list-secret-keys \
      "$DEBEMAIL"

   $gpg_bin \
      --with-colons \
      --keyid-format 0xlong \
      --fingerprint \
      --list-secret-keys \
      "$DEBEMAIL"

   $gpg_bin \
      --with-colons \
      --keyid-format 0xlong \
      --fingerprint \
      --list-secret-keys \
      "$DEBEMAIL" \
      | awk -F: '$1 == "pub" {print $2}'

   $gpg_bin --keyid-format 0xlong --detach-sign --armor --yes --output "$binary_build_folder_dist/test_sign_file.asc" "$binary_build_folder_dist/test_sign_file"
   $gpg_bin --keyid-format 0xlong --verify "$binary_build_folder_dist/test_sign_file.asc" "$binary_build_folder_dist/test_sign_file"

   gpgv "$binary_build_folder_dist/test_sign_file.asc" "$binary_build_folder_dist/test_sign_file"

   rm "$binary_build_folder_dist/test_sign_file"
   rm "$binary_build_folder_dist/test_sign_file.asc"

   ## TODO: stub
   test -d ~/.signify
}

main "$@"
