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

backup-raw-after-package-install() {
   ## If derivative-maker is run with --fast2 switch.
   if [ "$dist_build_fast2" = "1" ]; then
      echo "${bold}${cyan}INFO: run with --fast2 switch, skipping $BASH_SOURCE. ${reset}"
      exit 0
   fi

   cp "$binary_image_raw_file" "${dist_binary_build_folder}/$VMNAME-$dist_build_version-backup-after-package-install.raw"
}

main() {
   if [ "$dist_build_install_to_root" = "true" ]; then
      true "${green}INFO: Skipping $BASH_SOURCE, because dist_build_install_to_root is set to true.${reset}"
   else
      if [ "$dist_build_type_long" = "gateway" ]; then
         backup-raw-after-package-install
      elif [ "$dist_build_type_long" = "workstation" ]; then
         backup-raw-after-package-install
      elif [ "$dist_build_type_long" = "custom-workstation" ]; then
         true "${cyan}INFO: Skipping backup-raw-after-package-install for $VMNAME.${reset}"
      else
         error "ERROR: Invalid dist_build_flavor $dist_build_flavor. Please report this bug!"
      fi
   fi
}

main "$@"
