chore: improve wanted program check (remove array indirection)
This commit is contained in:
parent
64218c9a5c
commit
38bf1de80c
|
@ -73,7 +73,7 @@ function prepare_installation_environment() {
|
||||||
ntpd
|
ntpd
|
||||||
partprobe
|
partprobe
|
||||||
python3
|
python3
|
||||||
?rhash
|
"?rhash"
|
||||||
sha512sum
|
sha512sum
|
||||||
sgdisk
|
sgdisk
|
||||||
uuidgen
|
uuidgen
|
||||||
|
|
|
@ -351,11 +351,22 @@ function parse_arguments() {
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
# $1: array
|
# $1: program
|
||||||
# $@: elements
|
# $2: checkfile
|
||||||
function append_to_array() {
|
function has_program() {
|
||||||
declare -n _target_array=$1; shift
|
local program="$1"
|
||||||
_target_array+=("$@")
|
local checkfile="$2"
|
||||||
|
if [[ -z "$checkfile" ]]; then
|
||||||
|
type "$program" &>/dev/null \
|
||||||
|
|| return 1
|
||||||
|
elif [[ "${checkfile:0:1}" == "/" ]]; then
|
||||||
|
[[ -e "$checkfile" ]] \
|
||||||
|
|| return 1
|
||||||
|
else
|
||||||
|
type "$checkfile" &>/dev/null \
|
||||||
|
|| return 1
|
||||||
|
fi
|
||||||
|
return 0
|
||||||
}
|
}
|
||||||
|
|
||||||
function check_wanted_programs() {
|
function check_wanted_programs() {
|
||||||
|
@ -367,25 +378,16 @@ function check_wanted_programs() {
|
||||||
for tuple in "$@"; do
|
for tuple in "$@"; do
|
||||||
program="${tuple%%=*}"
|
program="${tuple%%=*}"
|
||||||
checkfile="${tuple##*=}"
|
checkfile="${tuple##*=}"
|
||||||
if [[ "$program" == "?"* ]]; then
|
if ! has_program "${program#"?"}" "$checkfile"; then
|
||||||
program="${program#"?"}"
|
if [[ "$program" == "?"* ]]; then
|
||||||
arr=missing_wanted
|
missing_wanted+=("${program#"?"}")
|
||||||
else
|
else
|
||||||
arr=missing_required
|
missing_required+=("$program")
|
||||||
fi
|
fi
|
||||||
if [[ -z "$checkfile" ]]; then
|
|
||||||
type "$program" &>/dev/null \
|
|
||||||
|| append_to_array "$arr" "$program"
|
|
||||||
elif [[ "${checkfile:0:1}" == "/" ]]; then
|
|
||||||
[[ -e "$checkfile" ]] \
|
|
||||||
|| append_to_array "$arr" "$program"
|
|
||||||
else
|
|
||||||
type "$checkfile" &>/dev/null \
|
|
||||||
|| append_to_array "$arr" "$program"
|
|
||||||
fi
|
fi
|
||||||
done
|
done
|
||||||
|
|
||||||
[[ "${#missing_required[@]}" -eq 0 && "${#missing_required[@]}" -eq 0 ]] \
|
[[ "${#missing_required[@]}" -eq 0 && "${#missing_wanted[@]}" -eq 0 ]] \
|
||||||
&& return
|
&& return
|
||||||
|
|
||||||
if [[ "${#missing_required[@]}" -gt 0 ]]; then
|
if [[ "${#missing_required[@]}" -gt 0 ]]; then
|
||||||
|
|
Loading…
Reference in New Issue