#!/bin/bash

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

## This script is supposed to be run:
## - For official binary builds by a builder (developer).
## - For debug builds: (dm-virtualbox-build-debug)
## - By the CI.

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

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

true "$0: START"

true "$0: checklist..."
df -h
sleep 2

## Debugging.
whoami
ls -la
pwd

if [ "${CI:-}" = "true" ]; then
  ## fetch/merge git submodules
  ## CI testing of 'derivative-update'.
  derivative_update_args=()
  previous_arg=""
  for arg_item in "$@"; do
    case "${previous_arg}" in
      --allow-uncommitted|--allow-untagged)
        derivative_update_args+=( "${previous_arg}" "${arg_item}" )
        ;;
    esac
    previous_arg="${arg_item}"
  done
  ./derivative-update --update-only "${derivative_update_args[@]}"
fi

true "$0: --------------------"
./help-steps/dm-build-official-one "$@"
true "$0: --------------------"

true "$0: END"
