From 58af2d9d9dd191b7c89cad817a9819ef125c9238 Mon Sep 17 00:00:00 2001 From: Martin Wimpress Date: Mon, 13 May 2024 15:34:08 +0100 Subject: [PATCH] style(windows): make windows download output consistent and more verbose --- quickget | 50 ++++++++++++++++++++++++++++++-------------------- 1 file changed, 30 insertions(+), 20 deletions(-) diff --git a/quickget b/quickget index 5bd4593..ead8f55 100755 --- a/quickget +++ b/quickget @@ -2946,7 +2946,7 @@ function unattended_windows() { EOF } -handle_curl_error() { +function handle_curl_error() { local error_code="$1" local fatal_error_action=2 case "$error_code" in @@ -3064,9 +3064,19 @@ function download_windows_server() { # Download enterprise evaluation Windows versions local windows_version="$1" local enterprise_type="$2" + local PRETTY_RELEASE="" + + case "${RELEASE}" in + "10-ltsc") PRETTY_RELEASE="10 LTSC";; + "2012-r2") PRETTY_RELEASE="2012 R2";; + *) PRETTY_RELEASE="${RELEASE}";; + esac + + echo "Downloading $(pretty_name "${OS}") ${PRETTY_RELEASE} (${I18N})" local url="https://www.microsoft.com/en-us/evalcenter/download-$windows_version" + echo " - Parsing download page: ${url}" iso_download_page_html="$(curl --silent --location --max-filesize 1M --fail --proto =https --tlsv1.2 --http1.1 -- "$url")" || { handle_curl_error $? return $? @@ -3080,14 +3090,6 @@ function download_windows_server() { local CULTURE="" local COUNTRY="" - local PRETTY_RELEASE="" - - case "${RELEASE}" in - "10-ltsc") PRETTY_RELEASE="10 LTSC";; - "2012-r2") PRETTY_RELEASE="2012 R2";; - *) PRETTY_RELEASE="${RELEASE}";; - esac - case "${I18N}" in "English (Great Britain)") CULTURE="en-gb" @@ -3127,9 +3129,10 @@ function download_windows_server() { COUNTRY="US";; esac + echo " - Getting download link.." iso_download_links="$(echo "$iso_download_page_html" | grep -o "https://go.microsoft.com/fwlink/p/?LinkID=[0-9]\+&clcid=0x[0-9a-z]\+&culture=${CULTURE}&country=${COUNTRY}")" || { # This should only happen if there's been some change to the download endpoint web address - echo "- Windows server download page gave us no download link" + echo " - Windows server download page gave us no download link" return 1 } @@ -3156,7 +3159,7 @@ function download_windows_server() { # Limit untrusted size for input validation iso_download_link="$(echo "$iso_download_link" | head -c 1024)" - echo "Downloading $(pretty_name "${OS}") ${PRETTY_RELEASE} (${I18N}): $iso_download_link" + echo " - URL: $iso_download_link" # Use highest TLS version for endpoints that support it case "$iso_download_link" in @@ -3179,6 +3182,8 @@ function download_windows_workstation() { local sku_id="" local iso_download_link_html="" local iso_download_link="" + + echo "Downloading Windows ${RELEASE} (${I18N})" # This function is adapted from the Mido project: # https://github.com/ElliotKillick/Mido # Download newer consumer Windows versions from behind gated Microsoft API @@ -3200,16 +3205,19 @@ function download_windows_workstation() { # This is the *only* request we make that Fido doesn't. Fido manually maintains a list of all the Windows release/edition product edition IDs in its script (see: $WindowsVersions array). This is helpful for downloading older releases (e.g. Windows 10 1909, 21H1, etc.) but we always want to get the newest release which is why we get this value dynamically # Also, keeping a "$WindowsVersions" array like Fido does would be way too much of a maintenance burden # Remove "Accept" header that curl sends by default + echo " - Parsing download page: ${url}" iso_download_page_html="$(curl --silent --user-agent "$user_agent" --header "Accept:" --max-filesize 1M --fail --proto =https --tlsv1.2 --http1.1 -- "$url")" || { handle_curl_error $? return $? } + echo -n " - Getting Product edition ID: " # tr: Filter for only numerics to prevent HTTP parameter injection # head -c was recently added to POSIX: https://austingroupbugs.net/view.php?id=407 product_edition_id="$(echo "$iso_download_page_html" | grep -Eo '