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

true "INFO: Currently running script: ${BASH_SOURCE[0]} $*"

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

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

source pre
source variables

export-libvirt-xml() {
   mkdir --parents "$binary_build_folder_dist"

   cp "$libvirt_source_kvm_file" "$libvirt_target_kvm_file"

   #if [ "${dist_build_type_short:-}" = "kicksecure" ]; then
      #true
   #elif [ "${dist_build_type_short:-}" = "custom-workstation" ]; then
      #true
   #else
      ## The Whonix-External / Whonix-Internal libvirt network XML files were
      ## removed from the 'libvirt-dist' package, so there is nothing to copy
      ## here anymore. Left commented (not deleted) to document the former
      ## behavior in case per-network XML returns.
      #cp "$libvirt_source_network_file_external" "$libvirt_target_network_file_external"
      #cp "$libvirt_source_network_file_internal" "$libvirt_target_network_file_internal"
      #true
   #fi
}

main() {
#    if [ "${dist_build_host_operating_system:-}" = "true" ]; then
#       true "${green}INFO: Skipping ${BASH_SOURCE[0]}, because dist_build_host_operating_system is '$dist_build_host_operating_system', ok.${reset}"
#       return 0
#    fi

   if [ "${dist_build_raw:-}" = "true" ]; then
      ## Required for Linux libvirt KVM raw image builds.
      ## Interest to maintain arm64 Linux libvirt KVM raw images has been
      ## indicated by HulaHoop until qcow2 image builds are fixed.
      ## XXX: Superfluous for non-libvirt raw image builds.
      export-libvirt-xml "$@"
   elif [ "${dist_build_qcow2:-}" = "true" ]; then
      export-libvirt-xml "$@"
   else
      true "${green}INFO: Skipping ${BASH_SOURCE[0]}, because dist_build_qcow2 is not set to 'true'.${reset}"
   fi
}

main "$@"
