feat: fallback to sha512sum if rhash is not available. closes #36.

This commit is contained in:
oddlama 2022-05-14 00:28:52 +02:00
parent 6a57329962
commit 64218c9a5c
No known key found for this signature in database
GPG Key ID: 14EFE510775FE39A
3 changed files with 54 additions and 22 deletions

2
configure vendored
View File

@ -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")

View File

@ -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-/') \
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"

View File

@ -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
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 " ${failed[*]}" >&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
if [[ "${#missing_required[@]}" -gt 0 ]]; then
die "Aborted installer because of missing required programs."
else
ask "Continue without recommended programs?"
fi
}