From 160ed2763a4e608c5c092839ee257a0401fd5a09 Mon Sep 17 00:00:00 2001 From: Erik Dannenberg Date: Tue, 4 May 2021 11:43:33 +0200 Subject: [PATCH] Improve stage3 parsing #193 * Some mirrors truncate long stage3 file names for display => parse element instead * Handle possible url encoded + char --- cmd/update.sh | 7 ++++--- lib/core.sh | 13 ++++++++----- 2 files changed, 12 insertions(+), 8 deletions(-) diff --git a/cmd/update.sh b/cmd/update.sh index a28081c4..5577a27c 100644 --- a/cmd/update.sh +++ b/cmd/update.sh @@ -7,7 +7,7 @@ # 2: builder_path function update_builders() { __update_builders= - local builder_path current_ns current_builder update_status s3date_remote update_count + local builder_path current_ns current_builder update_status s3date_remote update_count max_cap current_ns="$1" builder_path="$2" update_count=0 @@ -26,9 +26,10 @@ function update_builders() { get_stage3_archive_regex "${STAGE3_BASE}" # shellcheck disable=SC2154 if [[ "${__fetch_stage3_archive_name}" =~ ${__get_stage3_archive_regex} ]]; then - s3date_remote="${BASH_REMATCH[1]}" + max_cap="${#BASH_REMATCH[@]}" + s3date_remote="${BASH_REMATCH[$((max_cap-3))]}" # add time string if captured - [[ -n "${BASH_REMATCH[2]}" ]] && s3date_remote+="${BASH_REMATCH[2]}" + [[ -n "${BASH_REMATCH[$((max_cap-2))]}" ]] && s3date_remote+="${BASH_REMATCH[$((max_cap-2))]}" # shellcheck disable=SC2153 if is_newer_stage3_date "${STAGE3_DATE}" "${s3date_remote}"; then sed -E -i'' s/^STAGE3_DATE=\(\"\|\'\)?[0-9]*\(T[0-9]*Z\)?\(\"\|\'\)?/STAGE3_DATE=\'"${s3date_remote}"\'/g \ diff --git a/lib/core.sh b/lib/core.sh index 102f8c79..e2172a36 100644 --- a/lib/core.sh +++ b/lib/core.sh @@ -366,7 +366,7 @@ function get_stage3_archive_regex() { __get_stage3_archive_regex= local stage3_base stage3_base="$1" - __get_stage3_archive_regex="${stage3_base//+/\\+}-([0-9]{8})(T[0-9]{6}Z)?\\.tar\\.(bz2|xz)" + __get_stage3_archive_regex="${stage3_base//+/(\\+|%2B)?}-([0-9]{8})(T[0-9]{6}Z)?\\.tar\\.(bz2|xz)" } # Fetch latest stage3 archive name/type, returns exit signal 3 if no archive could be found @@ -374,14 +374,17 @@ function fetch_stage3_archive_name() { __fetch_stage3_archive_name= ARCH="${ARCH:-amd64}" ARCH_URL="${ARCH_URL:-${MIRROR}releases/${ARCH}/autobuilds/current-${STAGE3_BASE}/}" - local remote_files remote_line remote_date remote_file_type + local remote_files remote_line remote_date remote_file_type max_cap readarray -t remote_files <<< "$(wget -qO- "${ARCH_URL}")" remote_date=0 get_stage3_archive_regex "${STAGE3_BASE}" for remote_line in "${remote_files[@]}"; do - if [[ "${remote_line}" =~ ${__get_stage3_archive_regex}\< ]]; then - is_newer_stage3_date "${remote_date}" "${BASH_REMATCH[1]}${BASH_REMATCH[2]}" \ - && { remote_date="${BASH_REMATCH[1]}${BASH_REMATCH[2]}"; remote_file_type="${BASH_REMATCH[3]}"; } + if [[ "${remote_line}" =~ href=\"${__get_stage3_archive_regex}\" ]]; then + max_cap="${#BASH_REMATCH[@]}" + is_newer_stage3_date "${remote_date}" "${BASH_REMATCH[$((max_cap-3))]}${BASH_REMATCH[$((max_cap-2))]}" \ + && { remote_date="${BASH_REMATCH[$((max_cap-3))]}${BASH_REMATCH[$((max_cap-2))]}"; + remote_file_type="${BASH_REMATCH[$((max_cap-1))]}"; } + break fi done [[ "${remote_date//[!0-9]/}" -eq 0 ]] && return 3