From 64218c9a5cb414b50e71a61cc1246f2b2705ed22 Mon Sep 17 00:00:00 2001 From: oddlama Date: Sat, 14 May 2022 00:28:52 +0200 Subject: [PATCH] feat: fallback to sha512sum if rhash is not available. closes #36. --- configure | 2 +- scripts/functions.sh | 26 +++++++++++++++--------- scripts/utils.sh | 48 +++++++++++++++++++++++++++++++++----------- 3 files changed, 54 insertions(+), 22 deletions(-) diff --git a/configure b/configure index 6d4eab0..44745db 100755 --- a/configure +++ b/configure @@ -44,7 +44,7 @@ while [[ $# -gt 0 ]]; do shift done -check_has_programs dialog ncurses=ncursesw6-config +check_wanted_programs dialog ncurses=ncursesw6-config # Determine whether EFI is available HAS_EFI_SUPPORT=$([[ -d /sys/firmware/efi ]] && echo -n "true" || echo -n "false") diff --git a/scripts/functions.sh b/scripts/functions.sh index 42ed4d2..5d4c065 100644 --- a/scripts/functions.sh +++ b/scripts/functions.sh @@ -66,30 +66,31 @@ function preprocess_config() { function prepare_installation_environment() { einfo "Preparing installation environment" - local needed_programs=( + local wanted_programs=( gpg hwclock lsblk ntpd partprobe python3 - rhash + ?rhash + sha512sum sgdisk uuidgen wget ) [[ $USED_BTRFS == "true" ]] \ - && needed_programs+=(btrfs) + && wanted_programs+=(btrfs) [[ $USED_ZFS == "true" ]] \ - && needed_programs+=(zfs) + && wanted_programs+=(zfs) [[ $USED_RAID == "true" ]] \ - && needed_programs+=(mdadm) + && wanted_programs+=(mdadm) [[ $USED_LUKS == "true" ]] \ - && needed_programs+=(cryptsetup) + && wanted_programs+=(cryptsetup) # Check for existence of required programs - check_has_programs "${needed_programs[@]}" + check_wanted_programs "${wanted_programs[@]}" # Sync time now to prevent issues later sync_time @@ -790,6 +791,7 @@ function download_stage3() { || die "Could not cd into '$TMP_DIR'" local STAGE3_RELEASES="$GENTOO_MIRROR/releases/amd64/autobuilds/current-$STAGE3_BASENAME/" + local sha512sums # Download upstream list of files CURRENT_STAGE3="$(download_stdout "$STAGE3_RELEASES")" \ @@ -829,8 +831,14 @@ function download_stage3() { # Check hashes einfo "Verifying tarball integrity" # Replace any absolute paths in the digest file with just the stage3 basename, so it will be found by rhash - rhash -P --check <(grep -B 1 'tar.xz$' "${CURRENT_STAGE3}.DIGESTS" | sed -e 's/ .*stage3-/ stage3-/') \ - || die "Checksum mismatch!" + digest_line=$(grep 'tar.xz$' "${CURRENT_STAGE3}.DIGESTS" | sed -e 's/ .*stage3-/ stage3-/') + if type "$program" &>/dev/null; then + rhash -P --check <(echo "# SHA512"; echo "$digest_line") \ + || die "Checksum mismatch!" + else + sha512sum --check <<< "$digest_line" \ + || die "Checksum mismatch!" + fi # Create verification file in case the script is restarted touch_or_die 0644 "$CURRENT_STAGE3_VERIFIED" diff --git a/scripts/utils.sh b/scripts/utils.sh index a5908d5..b3ddca9 100644 --- a/scripts/utils.sh +++ b/scripts/utils.sh @@ -351,31 +351,51 @@ function parse_arguments() { fi } -function check_has_programs() { - local failed=() +# $1: array +# $@: elements +function append_to_array() { + declare -n _target_array=$1; shift + _target_array+=("$@") +} + +function check_wanted_programs() { + local missing_required=() + local missing_wanted=() local tuple local program local checkfile for tuple in "$@"; do program="${tuple%%=*}" checkfile="${tuple##*=}" + if [[ "$program" == "?"* ]]; then + program="${program#"?"}" + arr=missing_wanted + else + arr=missing_required + fi if [[ -z "$checkfile" ]]; then type "$program" &>/dev/null \ - || failed+=("$program") + || append_to_array "$arr" "$program" elif [[ "${checkfile:0:1}" == "/" ]]; then [[ -e "$checkfile" ]] \ - || failed+=("$program") + || append_to_array "$arr" "$program" else type "$checkfile" &>/dev/null \ - || failed+=("$program") + || append_to_array "$arr" "$program" fi done - [[ "${#failed[@]}" -eq 0 ]] \ + [[ "${#missing_required[@]}" -eq 0 && "${#missing_required[@]}" -eq 0 ]] \ && return - elog "The following programs are required for the installer to work, but are currently missing on your system:" >&2 - elog " ${failed[*]}" >&2 + if [[ "${#missing_required[@]}" -gt 0 ]]; then + elog "The following programs are required for the installer to work, but are currently missing on your system:" >&2 + elog " ${missing_required[*]}" >&2 + fi + if [[ "${#missing_wanted[@]}" -gt 0 ]]; then + elog "Missing optional programs:" >&2 + elog " ${missing_wanted[*]}" >&2 + fi if type pacman &>/dev/null; then declare -A pacman_packages @@ -383,12 +403,12 @@ function check_has_programs() { [ntpd]=ntp [zfs]="" ) - elog "We have detected that pacman is available." - if ask "Do you want to install the missing programs automatically?"; then + elog "Detected pacman package manager." + if ask "Do you want to install all missing programs automatically?"; then local packages local need_zfs=false - for program in "${failed[@]}"; do + for program in "${missing_required[@]}" "${missing_wanted[@]}"; do [[ "$program" == "zfs" ]] \ && need_zfs=true @@ -415,5 +435,9 @@ function check_has_programs() { fi fi - die "Aborted installer because of missing required programs." + if [[ "${#missing_required[@]}" -gt 0 ]]; then + die "Aborted installer because of missing required programs." + else + ask "Continue without recommended programs?" + fi }