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

source pre
source colors
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
      cp "$libvirt_source_network_file_external" "$libvirt_target_network_file_external"
      cp "$libvirt_source_network_file_internal" "$libvirt_target_network_file_internal"
   fi
}

main() {
#    if [ "$dist_build_host_operating_system" = "true" ]; then
#       true "${green}INFO: Skipping $BASH_SOURCE, 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, because dist_build_qcow2 is not set to 'true'.${reset}"
   fi
}

main "$@"
