Files
CISS.debian.installer/lib/cdi_0030_checks/0030_check_pkgs.sh
Marc S. Weidner d0b363d7d4
All checks were successful
🛡️ Shell Script Linting / 🛡️ Shell Script Linting (push) Successful in 53s
V8.00.000.2025.06.17
Signed-off-by: Marc S. Weidner <msw@coresecret.dev>
2025-09-05 21:35:38 +02:00

92 lines
2.7 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:
# VAR_AUTO_INSTALL
# Arguments:
# None
#######################################
check_pkgs() {
### Declare Arrays, HashMaps, and Variables.
# shellcheck disable=SC2154
declare -A hmp_command_packages=(
[apt-transport-https]=apt-transport-https
[bzip2]=bzip2
[ca-certificates]=ca-certificates
[curl]=curl
[expect]=expect
[fdisk]=fdisk
[gdisk]=gdisk
[git]=git
[gpg]=gnupg
[lsb_release]=lsb-release
[mkfs.btrfs]=btrfs-progs
[mkfs.ext4]=e2fsprogs
[mkfs.fat]=dosfstools
[mkswap]=util-linux
[mkfs.xfs]=xfsprogs
[parted]=parted
[pwgen]=pwgen
[tar]=tar
[wget]=wget
[whois]=whois
[xz]=xz-utils
[yq]=yq
)
declare -a ary_missing_pkgs=() ary_unique_pkgs=()
declare var_cmd=""
### Collecting missing binaries.
for var_cmd in "${!hmp_command_packages[@]}"; do
if ! command -v "${var_cmd}" &>/dev/null; then
ary_missing_pkgs+=("${hmp_command_packages[${var_cmd}]}")
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[*]}'."
apt-get install -y --no-install-recommends --no-install-suggests "${ary_unique_pkgs[*]}" 2>&1
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)
apt-get install -y -t "${codename}-backports" debootstrap
else
apt-get install -y debootstrap
fi
fi
if [[ -z "$(command -v dialog || true)" ]]; then
if ! "${VAR_AUTO_INSTALL}"; then apt-get install -y --no-install-recommends dialog; fi
fi
guard_dir && return 0
}
# vim: number et ts=2 sw=2 sts=2 ai tw=128 ft=sh