Skip to content

Commit

Permalink
scripts: check that archive paths exist
Browse files Browse the repository at this point in the history
Check that MetalK8s archive paths point
to existing file and if not print a clear
error message

Refs: #3079
  • Loading branch information
alexandre-allard committed Feb 3, 2021
1 parent 7b5ffcb commit 63c1e73
Showing 1 changed file with 30 additions and 1 deletion.
31 changes: 30 additions & 1 deletion scripts/iso-manager.sh
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,26 @@ get_configured_archives() {
sed -rn 's/^- (.+)$/\1/p'
}

_check_archives() {
local -a not_existing

for archive; do
if [ ! -e "$archive" ]; then
not_existing+=("$archive")
fi
done

if (( ${#not_existing[@]} )); then
echo "The following archives do not exist:" >&2
for archive in "${not_existing[@]}"; do
echo "- $archive" >&2
done
return 1
fi

return 0
}

_add_archives() {
# Skip adding archive if None passed
[ $# -lt 1 ] && return 0
Expand Down Expand Up @@ -150,6 +170,15 @@ _configure_archives() {
_set_env
[ -z "$SALTENV" ] && die "saltenv not set"

if (( ${#ARCHIVES[@]} )); then
run "Check new archives" _check_archives "${ARCHIVES[@]}"
fi
mapfile -t CONFIGURED_ARCHIVES < <(get_configured_archives)
run "Add archives" _add_archives ${ARCHIVES[@]+"${ARCHIVES[@]}"}
if (( ${#CONFIGURED_ARCHIVES[@]} )); then
run "Check $BOOTSTRAP_CONFIG file" _check_archives \
"${CONFIGURED_ARCHIVES[@]}"
fi
if (( ${#ARCHIVES[@]} )); then
run "Add archives" _add_archives "${ARCHIVES[@]}"
fi
run "Configure archives" _configure_archives

0 comments on commit 63c1e73

Please sign in to comment.