#!/bin/bash

## Copyright (C) 2012 - 2025 ENCRYPTED SUPPORT LLC <adrelanos@whonix.org>
## See the file COPYING for copying conditions.

## {{ usage

## From Whonix main source code folder.

## jessie - untested
#ln -r -s ./packages/kicksecure/developer-meta-files/debug-steps/1400_backup-raw-after-grml-debootstrap ./build-steps.d/
#./build-steps.d/*_backup-raw-after-grml-debootstrap

## }}

set -x
set -o errexit
set -o nounset
set -o pipefail
set -o errtrace
shopt -s inherit_errexit

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

backup-raw-after-grml-debootstrap() {
   ## If derivative-maker is run with --fast1 switch.
   if [ "$dist_build_fast1" = "1" ]; then
      printf '%s\n' "${bold}${cyan}INFO: run with --fast1 switch, skipping ${BASH_SOURCE[0]}. ${reset}"
      exit 0
   fi

   cp -- "$binary_image_raw_file" "${dist_binary_build_folder}/$VMNAME-$dist_build_version-backup-after-grml-debootstrap.raw"
}

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

main "$@"
