#!/bin/bash
# SPDX-Version: 3.0
# SPDX-CreationInfo: 2025-06-17; WEIDNER, Marc S.; <msw@coresecret.dev>
# SPDX-ExternalRef: GIT https://git.coresecret.dev/msw/CISS.debian.installer.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.installer
# SPDX-Security-Contact: security@coresecret.eu

#######################################
# Performing Branch Selection
# Globals:
#   BASH_COMMAND
#   BRANCH_URL
#   HANDLER_BRA
#   LINENO
#   LOG_ERR
#   MODULE_ERR
#   PPID
#   PWD
# Arguments:
#  None
#######################################
0000_performing_branch_confirmation() {
  clear

  declare BRANCH_SELECTION=""

  exec 2>&1

  if [[ ${HANDLER_BRA,,} = 1  ]]; then

    dialog --create-rc ~/.dialogrc
    sed -i 's/screen_color = (CYAN,BLUE,ON)/screen_color = (WHITE,RED,ON)/' ~/.dialogrc
    sed -i 's/title_color = (BLUE,WHITE,ON)/title_color = (RED,WHITE,ON)/' ~/.dialogrc

    if BRANCH_SELECTION=$(dialog --ascii-lines \
      --colors \
      --title "! WARNING !" \
      --backtitle "CISS.2025.hardened.debian.installer" \
      --yes-label "yes" \
      --no-label "No" \
      --yesno "You are on:\nBranch 'Testing'.\nPlease confirm to proceed.\nHit 'Yes' to stay on Branch 'Testing'.\nHit 'No' to exit." 9 60 3>&1 1>&2 2>&3 3>&-); then
      declare -g -r -x BRANCH_URL="https://cendev.eu/marc.weidner/CISS.2025.debian.installer/raw/branch/testing/"

    else

      clear

      rm -f ~/.dialogrc

      do_clean_exit "0" "${LINENO}" "${BASH_COMMAND}" "${MODULE_ERR}" "$$" "${PPID}" "${PWD}" "$-"

    fi

  else

    declare -g -r -x BRANCH_URL="https://cendev.eu/marc.weidner/CISS.2025.debian.installer/raw/branch/master/"

  fi

  exec 2>> "${LOG_ERR}"

  clear

  if [[ ${HANDLER_BRA} = 1 ]]; then

    do_log "info" "true" "Branch 'testing' confirmed: '${BRANCH_SELECTION}'."

  fi

  if [[ -f ~/.dialogrc ]]; then

    rm -f ~/.dialogrc

  fi
}
# vim: number et ts=2 sw=2 sts=2 ai tw=128 ft=sh:
