diff --git a/src/mido.sh b/src/mido.sh index 41189a4..f2095bb 100644 --- a/src/mido.sh +++ b/src/mido.sh @@ -69,223 +69,244 @@ handle_curl_error() { download_windows() { - local HASH="" - local session_id="" - local iso_download_page_html="" - local product_edition_id="" - local language_skuid_table_html="" - local sku_id="" - local iso_download_link_html="" - local iso_download_link="" + local HASH="" + local session_id="" + local iso_download_page_html="" + local product_edition_id="" + local language_skuid_table_html="" + local sku_id="" + local iso_download_link_html="" + local iso_download_link="" + local windows_version="" - echo "Downloading Windows ${RELEASE} (${I18N})" - # Download newer consumer Windows versions from behind gated Microsoft API + case "${id,,}" in + "win11${PLATFORM,,}" ) + windows_version="11" + ;; + "win10${PLATFORM,,}" ) + windows_version="10" + ;; + "win81${PLATFORM,,}" ) + windows_version="8" + ;; + * ) + echo "Unknown version: $id" + return 1 + esac - # Either 8, 10, or 11 - local windows_version="$1" + echo "Downloading $id" - local url="https://www.microsoft.com/en-us/software-download/windows$windows_version" - case "$windows_version" in - 8 | 10) url="${url}ISO";; - esac + local url="https://www.microsoft.com/en-us/software-download/windows$windows_version" + case "$windows_version" in + 8 | 10) url="${url}ISO";; + esac - local user_agent="Mozilla/5.0 (X11; Linux x86_64; rv:100.0) Gecko/20100101 Firefox/100.0" - # uuidgen: For MacOS (installed by default) and other systems (e.g. with no /proc) that don't have a kernel interface for generating random UUIDs - session_id="$(cat /proc/sys/kernel/random/uuid 2> /dev/null || uuidgen --random)" + local user_agent="Mozilla/5.0 (X11; Linux x86_64; rv:100.0) Gecko/20100101 Firefox/100.0" + # uuidgen: For MacOS (installed by default) and other systems (e.g. with no /proc) that don't have a kernel interface for generating random UUIDs + session_id="$(cat /proc/sys/kernel/random/uuid 2> /dev/null || uuidgen --random)" - # Get product edition ID for latest release of given Windows version - # Product edition ID: This specifies both the Windows release (e.g. 22H2) and edition ("multi-edition" is default, either Home/Pro/Edu/etc., we select "Pro" in the answer files) in one number - # 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 $? - } + # Get product edition ID for latest release of given Windows version + # Product edition ID: This specifies both the Windows release (e.g. 22H2) and edition ("multi-edition" is default, either Home/Pro/Edu/etc., we select "Pro" in the answer files) in one number + # 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 '