#!/bin/bash
# SPDX-Version: 3.0
# SPDX-CreationInfo: 2025-10-07; WEIDNER, Marc S.; <msw@coresecret.dev>
# SPDX-ExternalRef: GIT https://git.coresecret.dev/msw/CISS.debian.live.builder.git
# SPDX-FileContributor: WEIDNER, Marc S.; Centurion Intelligence Consulting Agency
# SPDX-FileCopyrightText: 2024-2025; WEIDNER, Marc S.; <msw@coresecret.dev>
# SPDX-FileType: SOURCE
# SPDX-License-Identifier: EUPL-1.2 OR LicenseRef-CCLA-1.0
# SPDX-LicenseComment: This file is part of the CISS.debian.installer.secure framework.
# SPDX-PackageName: CISS.debian.live.builder
# SPDX-Security-Contact: security@coresecret.eu

#######################################
# Version file generator for '/root/cdlb.txt' of Live ISO.
# Globals:
#   BASH_SOURCE
#   SOURCE_DATE_EPOCH
#   VAR_VER_BASH
#   VAR_DATE_INFO
#   VAR_VER_DS
#   VAR_GIT_REL
#   VAR_HANDLER_BUILD_DIR
#   VAR_HOST
#   VAR_VER_LB
#   VAR_VERSION
# Arguments:
#   None
# Returns:
#   0: on success
#######################################
note_target() {
  printf "\e[95m++++ ++++ ++++ ++++ ++++ ++++ ++ 🧪 %s starting ... \e[0m\n" "${BASH_SOURCE[0]}"

  cat << EOF >| "${VAR_HANDLER_BUILD_DIR}/config/includes.chroot/root/ciss-debian-live-builder.txt"
################################################################################
  This CISS.debian.live ISO was built by:

  CISS.debian.live.builder from https://git.coresecret.dev/msw
  A lightweight Shell Wrapper for building a hardened Debian Live ISO Image.

  Version     : ${VAR_VERSION}
  Git         : ${VAR_GIT_REL}
  Epoch       : ${SOURCE_DATE_EPOCH}
  Date        : ${VAR_DATE_INFO}
  Host        : ${VAR_HOST}
  Bash        : ${VAR_VER_BASH}
  Debootstrap : ${VAR_VER_DS}
  Live-Build  : ${VAR_VER_LB}

  This program is free software. Distribution and modification under
  EUPL-1.2 permitted. USAGE w/o ANY WARRANTY. USE IT AT YOUR OWN RISK!

  Please file bugs @
  https://git.coresecret.dev/msw/CISS.debian.live.builder/issues

  Contact:
  https://coresecret.eu/
  security@coresecret.eu
  PGP Key 2D98 07F4 1030 1776 597E BDC9 9F54 8853 35A3 C9AD
  https://keys.openpgp.org/vks/v1/by-fingerprint/2D9807F410301776597EBDC99F54885335A3C9AD

  Please consider donating to my work at:
  https://coresecret.eu/spenden/
################################################################################
EOF
  chmod 0444 "${VAR_HANDLER_BUILD_DIR}/config/includes.chroot/root/ciss-debian-live-builder.txt"

  cat << EOF >| "${VAR_HANDLER_BUILD_DIR}/config/includes.chroot/root/ciss-debian-live-builder.env"
export CDLB_VERSION="${VAR_VERSION}"
export CDLB_GIT_REL="${VAR_GIT_REL}"
export CDLB_CR_DATE="${VAR_DATE_INFO}"
export CDLB_CR_HOST="${VAR_HOST}"
export CDLB_VER_BASH="${VAR_VER_BASH}"
export CDLB_VER_DS="${VAR_VER_DS}"
export CDLB_VER_LB="${VAR_VER_LB}"
export CDLB_SOURCE_DATE_EPOCH="${SOURCE_DATE_EPOCH}"
EOF
  chmod 0444 "${VAR_HANDLER_BUILD_DIR}/config/includes.chroot/root/ciss-debian-live-builder.env"

  printf "\e[92m++++ ++++ ++++ ++++ ++++ ++++ ++ ✅ %s successfully applied. \e[0m\n" "${BASH_SOURCE[0]}"

  return 0
}
### Prevents accidental 'unset -f'.
# shellcheck disable=SC2034
readonly -f note_target
# vim: number et ts=2 sw=2 sts=2 ai tw=128 ft=sh
