Files
CISS.debian.installer/lib/cdi_0030_checks/0030_check_pkgs.sh
Marc S. Weidner e809c89a5f
All checks were successful
🛡️ Shell Script Linting / 🛡️ Shell Script Linting (push) Successful in 2m50s
V8.00.000.2025.06.17
Signed-off-by: Marc S. Weidner <msw@coresecret.dev>
2025-09-05 22:51:59 +02:00

100 lines
3.1 KiB
Bash

#!/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
guard_sourcing
#######################################
# 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.
apt-get update > /dev/null 2>&1
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