#!/bin/bash # SPDX-Version: 3.0 # SPDX-CreationInfo: 2025-06-17; WEIDNER, Marc S.; # 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.; # 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 guard_sourcing || return "${ERR_GUARD_SOURCE}" ####################################### # Check for required deb packages to run the script. # Globals: # DIR_LOG # VAR_AUTO_INSTALL # Arguments: # None # Returns: # 0: on success ####################################### check_pkgs() { ### Declare Arrays, HashMaps, and Variables. # shellcheck disable=SC2154 declare -A hmp_tool_pkg=( [btrfs]="btrfs-progs" [curl]="curl" [dmsetup]="dmsetup" [mkfs.vfat]="dosfstools" [e2label]="e2fsprogs" [tune2fs]="e2fsprogs" [fsck]="e2fsprogs" [expect]="expect" [efibootmgr]="efibootmgr" [fdisk]="fdisk" [file]="file" [awk]="gawk" [gdisk]="gdisk" [jq]="jq" [lsb_release]="lsb-release" [parted]="parted" [pwgen]="pwgen" [tree]="tree" [unzip]="unzip" [wget]="wget" [whois]="whois" ) declare -a ary_missing_pkgs=() ary_unique_pkgs=() declare var_bin="" touch "${DIR_LOG}/0030_check_pkgs.log" ### Collecting missing binaries. for var_bin in "${!hmp_tool_pkg[@]}"; do if ! command -v "${var_bin}" &>/dev/null; then ary_missing_pkgs+=("${hmp_tool_pkg[${var_bin}]}") fi done do_log "debug" "file_only" "0030() [ary_missing_pkgs]='${ary_missing_pkgs[*]}'." ### Installing unique list of packages. # shellcheck disable=SC2312 apt-get -o Acquire::PDiffs=false update 2>&1 | tee -a "${DIR_LOG}/0030_check_pkgs.log" if ((${#ary_missing_pkgs[@]})); then # shellcheck disable=SC2312 mapfile -t ary_unique_pkgs < <(printf '%s\n' "${ary_missing_pkgs[@]}" | sort -u) do_log "debug" "file_only" "0030() [ary_unique_pkgs]='${ary_unique_pkgs[*]}'." # shellcheck disable=SC2312 apt-get install -y --no-install-recommends --no-install-suggests "${ary_unique_pkgs[@]}" 2>&1 | tee -a "${DIR_LOG}/0030_check_pkgs.log" fi if [[ -z "$(command -v debootstrap || true)" ]]; then if grep -RqsE '^[[:space:]]*deb .*backports' /etc/apt/sources.list /etc/apt/sources.list.d; then # shellcheck disable=SC2155 declare codename=$(lsb_release -sc) # shellcheck disable=SC2312 apt-get install -y -t "${codename}-backports" debootstrap 2>&1 | tee -a "${DIR_LOG}/0030_check_pkgs.log" else # shellcheck disable=SC2312 apt-get install -y debootstrap 2>&1 | tee -a "${DIR_LOG}/0030_check_pkgs.log" fi fi if [[ -z "$(command -v dialog || true)" ]]; then # shellcheck disable=SC2312 if ! "${VAR_AUTO_INSTALL}"; then apt-get install -y --no-install-recommends dialog 2>&1 | tee -a "${DIR_LOG}/0030_check_pkgs.log"; fi fi guard_dir; return 0 } # vim: number et ts=2 sw=2 sts=2 ai tw=128 ft=sh