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

###########################################################################################
# 3.8.7. Functions - installation - updating files                                        #
###########################################################################################

###########################################################################################
# Updating alias and banner files.
# Globals:
#   MODULE_ERR
#   MODULE_TXT
#   PATH_ABS
#   TARGET
#   accounts_user_login
#   accounts_user_name
# Arguments:
#   None
###########################################################################################
3_8_7_functions_installation_setup_files() {
  declare -g -x MODULE_ERR="3_8_7_functions_installation_setup_files"
  declare -g -x MODULE_TXT="Updating banner files"
  do_show_header "${MODULE_TXT}"

  cp "${PATH_ABS}"/.assets/.alias "${TARGET}"/root/.alias
  chown root:root "${TARGET}"/root/.alias
  chmod 0600 "${TARGET}"/root/.alias
  do_log "info" "false" "'${TARGET}/root/.alias' installed."

  cp "${PATH_ABS}"/.assets/banner "${TARGET}"/etc/banner
  chown root:root "${TARGET}"/etc/banner
  chmod 0644 "${TARGET}"/etc/banner
  do_log "info" "false" "'${TARGET}/etc/banner' installed."

  cp "${PATH_ABS}"/.assets/.clean_logout "${TARGET}"/root/.clean_logout
  chown root:root "${TARGET}"/root/.clean_logout
  chmod 0600 "${TARGET}"/root/.clean_logout
  do_log "info" "false" "'${TARGET}/root/.clean_logout' installed."

  cp "${PATH_ABS}"/.assets/motd "${TARGET}"/etc/motd
  chown root:root "${TARGET}"/etc/motd
  chmod 0644 "${TARGET}"/etc/motd
  do_log "info" "false" "'${TARGET}/etc/motd' installed."

  cat "${PATH_ABS}"/.assets/.bashrc_cat >> "${TARGET}"/root/.bashrc
  do_log "info" "false" "'${TARGET}/root/.bashrc' updated."

  if [[ ${accounts_user_login,,} == "true" ]]; then
    cat "${PATH_ABS}"/.assets/.bashrc_cat >> "${TARGET}"/home/"${accounts_user_name}"/.bashrc
    do_log "info" "false" "'${TARGET}/home/${accounts_user_name}/.bashrc' updated."
  fi

  do_show_footer "${MODULE_TXT}"
}
# vim: number et ts=2 sw=2 sts=2 ai tw=128 ft=sh:
