#!/bin/bash
# SPDX-Version: 3.0
# SPDX-CreationInfo: 2025-05-05; 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

guard_sourcing || return "${ERR_GUARD_SRCE}"

#######################################
# Check for required Deb Packages to run the script.
# Globals:
#   BASH_SOURCE
#   VAR_HANDLER_AUTOBUILD
# Arguments:
#   None
# Returns:
#   0: on success
#######################################
check_pkgs() {
  printf "\e[95m++++ ++++ ++++ ++++ ++++ ++++ ++ 🧪 %s starting ... \e[0m\n" "${BASH_SOURCE[0]}"

  apt-get update -qq > /dev/null 2>&1

  apt-get install -y --no-install-recommends gnupg gpgv gpg-agent pinentry-curses pinentry-tty gnupg-utils

  if ! command -v lsb_release >/dev/null 2>&1; then

    apt-get install -y --no-install-recommends lsb-release

  fi

  if ! command -v batcat >/dev/null 2>&1; then

    apt-get install -y --no-install-recommends bat

  fi

  if ! command -v debootstrap >/dev/null 2>&1; then

      apt-get install -y debootstrap

  fi

  if [[ ! -f /usr/share/live/build/VERSION ]]; then

    apt-get install -y live-build

  fi

  if [[ "${VAR_HANDLER_AUTOBUILD}" == "false" ]]; then

    if ! command -v dialog >/dev/null 2>&1; then

      apt-get install -y --no-install-recommends dialog

    fi

  fi

  if ! command -v mkpasswd >/dev/null 2>&1; then

    apt-get install -y --no-install-recommends whois

  fi

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

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