Prompt the user to download the Windows iso manually. Closes #612

pull/637/head
Martin Wimpress 2 years ago
parent 4286405639
commit 8d3cf4c1a7
No known key found for this signature in database
GPG Key ID: 61DF940515E06DA3
  1. 126
      quickget

@ -1907,12 +1907,19 @@ function dbg_windows() {
# Adapted from https://gist.github.com/hongkongkiwi/15a5bf16437315df256c118c163607cb # Adapted from https://gist.github.com/hongkongkiwi/15a5bf16437315df256c118c163607cb
function get_windows() { function get_windows() {
# Use the API to automatically download a Windows .iso image
# The API we were using is unmaintained and not currently functional
# 0 : Prompt for a manual ISO download
# 1 : Use the API for automated download
local API_GUIDED_DOWNLOAD=0
local ARCH="x64" local ARCH="x64"
local INDEX=0 local INDEX=0
local LANG_CODE="en" local LANG_CODE="en"
local LANG_EDITION="${1}" local LANG_EDITION="${1}"
local LATEST_WINDOWS_VERSION="" local LATEST_WINDOWS_VERSION=""
local WINDOWS_NAME="" local WINDOWS_NAME=""
local WINDOWS_ISO_URL=""
local VERSION_ID="" local VERSION_ID=""
local EDITION_ID="" local EDITION_ID=""
local LANGUAGE_ID="" local LANGUAGE_ID=""
@ -1922,59 +1929,72 @@ function get_windows() {
local DOWNLOAD_ID="" local DOWNLOAD_ID=""
local DOWNLOAD_URL="" local DOWNLOAD_URL=""
# Ignore the most recent Windows 10 release for now. if [ ${API_GUIDED_DOWNLOAD} -eq 1 ]; then
case ${RELEASE} in # Ignore the most recent Windows 10 release for now.
10) INDEX=0;; case ${RELEASE} in
11) INDEX=0;; 10) INDEX=0;;
esac 11) INDEX=0;;
esac
echo "Getting Windows ${RELEASE} URL..."
WINDOWS_VERSIONS=$(wget -4 -q -O- "https://tb.rg-adguard.net/php/get_version.php?type_id=1" | jq '.versions | sort_by(-(.version_id | tonumber))')
dbg_windows "${WINDOWS_VERSIONS}"
LATEST_WINDOWS_VERSION=$(echo "${WINDOWS_VERSIONS}" | jq -c 'map(select(.name | contains("Windows '"${RELEASE}"'")))['${INDEX}']')
dbg_windows "${LATEST_WINDOWS_VERSION}"
WINDOWS_NAME=$(echo "${LATEST_WINDOWS_VERSION}" | jq -r .name)
dbg_windows "${WINDOWS_NAME}"
VERSION_ID=$(echo "${LATEST_WINDOWS_VERSION}" | jq -r .version_id)
dbg_windows "${VERSION_ID}"
case ${RELEASE} in echo "Getting Windows ${RELEASE} URL..."
8) EDITION_ID=$(wget -4 -q -O- "https://tb.rg-adguard.net/php/get_edition.php?version_id=${VERSION_ID}&lang=name_${LANG_CODE}" | jq -r '.editions[] | select(.name_'${LANG_CODE}'=="Windows 8.1 Pro + Core").edition_id');; WINDOWS_VERSIONS=$(wget -4 -q -O- "https://tb.rg-adguard.net/php/get_version.php?type_id=1" | jq '.versions | sort_by(-(.version_id | tonumber))')
10|11) EDITION_ID=$(wget -4 -q -O- "https://tb.rg-adguard.net/php/get_edition.php?version_id=${VERSION_ID}&lang=name_${LANG_CODE}" | jq -r '.editions[] | select(.name_'${LANG_CODE}'=="Windows '"${RELEASE}"'").edition_id');; dbg_windows "${WINDOWS_VERSIONS}"
esac LATEST_WINDOWS_VERSION=$(echo "${WINDOWS_VERSIONS}" | jq -c 'map(select(.name | contains("Windows '"${RELEASE}"'")))['${INDEX}']')
dbg_windows "${EDITION_ID}" dbg_windows "${LATEST_WINDOWS_VERSION}"
WINDOWS_NAME=$(echo "${LATEST_WINDOWS_VERSION}" | jq -r .name)
LANGUAGE_ID=$(wget -4 -q -O- "https://tb.rg-adguard.net/php/get_language.php?edition_id=${EDITION_ID}&lang=name_${LANG_CODE}" | jq -r '.languages[] | select(.name_'${LANG_CODE}'=="'"${LANG_EDITION}"'").language_id') dbg_windows "${WINDOWS_NAME}"
dbg_windows "${LANGUAGE_ID}" VERSION_ID=$(echo "${LATEST_WINDOWS_VERSION}" | jq -r .version_id)
ARCH_INFO=$(wget -4 -q -O- "https://tb.rg-adguard.net/php/get_arch.php?language_id=${LANGUAGE_ID}") dbg_windows "${VERSION_ID}"
dbg_windows "${ARCH_INFO}"
FILE_NAME=$(echo "${ARCH_INFO}" | jq -r '.archs[] | select(.name | contains("'${ARCH}'")).name') case ${RELEASE} in
dbg_windows "${FILE_NAME}" 8) EDITION_ID=$(wget -4 -q -O- "https://tb.rg-adguard.net/php/get_edition.php?version_id=${VERSION_ID}&lang=name_${LANG_CODE}" | jq -r '.editions[] | select(.name_'${LANG_CODE}'=="Windows 8.1 Pro + Core").edition_id');;
ARCH_ID=$(echo "${ARCH_INFO}" | jq -r '.archs[] | select(.name | contains("'${ARCH}'")).arch_id') 10|11) EDITION_ID=$(wget -4 -q -O- "https://tb.rg-adguard.net/php/get_edition.php?version_id=${VERSION_ID}&lang=name_${LANG_CODE}" | jq -r '.editions[] | select(.name_'${LANG_CODE}'=="Windows '"${RELEASE}"'").edition_id');;
dbg_windows "${ARCH_ID}" esac
DOWNLOAD_INFO=$(wget -4 -q -O- "https://tb.rg-adguard.net/dl.php?fileName=${ARCH_ID}&lang=en") dbg_windows "${EDITION_ID}"
dbg_windows "${DOWNLOAD_INFO}"
DOWNLOAD_SHA1=$(echo "${DOWNLOAD_INFO}" | sed -e 's/<[^>]*>//g' | grep -o -P '(?<=SHA1: ).*(?= expire)' | sed 's/Link//') LANGUAGE_ID=$(wget -4 -q -O- "https://tb.rg-adguard.net/php/get_language.php?edition_id=${EDITION_ID}&lang=name_${LANG_CODE}" | jq -r '.languages[] | select(.name_'${LANG_CODE}'=="'"${LANG_EDITION}"'").language_id')
dbg_windows "${DOWNLOAD_SHA1}" dbg_windows "${LANGUAGE_ID}"
DOWNLOAD_ID=$(echo "${DOWNLOAD_INFO}" | grep -oP '(?<=https:\/\/tb\.rg-adguard\.net/dl\.php\?go=)[0-9a-z]+') ARCH_INFO=$(wget -4 -q -O- "https://tb.rg-adguard.net/php/get_arch.php?language_id=${LANGUAGE_ID}")
dbg_windows "${DOWNLOAD_ID}" dbg_windows "${ARCH_INFO}"
REDIRECT_URL="https://tb.rg-adguard.net/dl.php?go=${DOWNLOAD_ID}" FILE_NAME=$(echo "${ARCH_INFO}" | jq -r '.archs[] | select(.name | contains("'${ARCH}'")).name')
dbg_windows "${REDIRECT_URL}" dbg_windows "${FILE_NAME}"
DOWNLOAD_URL=$(curl --head --silent --write-out "%{redirect_url}\n" --output /dev/null "${REDIRECT_URL}") ARCH_ID=$(echo "${ARCH_INFO}" | jq -r '.archs[] | select(.name | contains("'${ARCH}'")).arch_id')
dbg_windows "${DOWNLOAD_URL}" dbg_windows "${ARCH_ID}"
DOWNLOAD_INFO=$(wget -4 -q -O- "https://tb.rg-adguard.net/dl.php?fileName=${ARCH_ID}&lang=en")
MS_BASE_URL="https://software.download.prss.microsoft.com/" dbg_windows "${DOWNLOAD_INFO}"
if [[ ! ${DOWNLOAD_URL} =~ ^${MS_BASE_URL} ]]; then DOWNLOAD_SHA1=$(echo "${DOWNLOAD_INFO}" | sed -e 's/<[^>]*>//g' | grep -o -P '(?<=SHA1: ).*(?= expire)' | sed 's/Link//')
echo "Download URL not leading to Microsoft CDN" dbg_windows "${DOWNLOAD_SHA1}"
exit 1 DOWNLOAD_ID=$(echo "${DOWNLOAD_INFO}" | grep -oP '(?<=https:\/\/tb\.rg-adguard\.net/dl\.php\?go=)[0-9a-z]+')
fi dbg_windows "${DOWNLOAD_ID}"
REDIRECT_URL="https://tb.rg-adguard.net/dl.php?go=${DOWNLOAD_ID}"
dbg_windows "${REDIRECT_URL}"
DOWNLOAD_URL=$(curl --head --silent --write-out "%{redirect_url}\n" --output /dev/null "${REDIRECT_URL}")
dbg_windows "${DOWNLOAD_URL}"
MS_BASE_URL="https://software.download.prss.microsoft.com/"
if [[ ! ${DOWNLOAD_URL} =~ ^${MS_BASE_URL} ]]; then
echo "Download URL not leading to Microsoft CDN"
exit 1
fi
echo "Downloading ${WINDOWS_NAME}..." echo "Downloading ${WINDOWS_NAME}..."
web_get "${DOWNLOAD_URL}" "${VM_PATH}" "${FILE_NAME}" web_get "${DOWNLOAD_URL}" "${VM_PATH}" "${FILE_NAME}"
# Windows 10 doesn't include a SHA1, so only check the integrity if the SHA1 is available. # Windows 10 doesn't include a SHA1, so only check the integrity if the SHA1 is available.
if [ -n "${DOWNLOAD_SHA1}" ]; then if [ -n "${DOWNLOAD_SHA1}" ]; then
check_hash "${FILE_NAME}" "${DOWNLOAD_SHA1}" check_hash "${FILE_NAME}" "${DOWNLOAD_SHA1}"
fi
else
case ${RELEASE} in
10) WINDOWS_ISO_URL="https://www.microsoft.com/software-download/windows10";;
11) WINDOWS_ISO_URL="https://www.microsoft.com/software-download/windows11";;
esac
echo "######################################################################"
echo "# Download a Windows ${RELEASE} .iso image from:"
echo "# - ${WINDOWS_ISO_URL}"
echo "# Put the .iso image in the ${VM_PATH} directory and rename"
echo "# it to windows-${RELEASE}.iso."
echo "######################################################################"
fi fi
web_get "https://fedorapeople.org/groups/virt/virtio-win/direct-downloads/stable-virtio/virtio-win.iso" "${VM_PATH}" web_get "https://fedorapeople.org/groups/virt/virtio-win/direct-downloads/stable-virtio/virtio-win.iso" "${VM_PATH}"
@ -1991,7 +2011,11 @@ function get_windows() {
mkisofs -quiet -l -o "${VM_PATH}/unattended.iso" "${VM_PATH}/unattended/" mkisofs -quiet -l -o "${VM_PATH}/unattended.iso" "${VM_PATH}/unattended/"
;; ;;
esac esac
make_vm_config "${FILE_NAME}" "virtio-win.iso"
case "${API_GUIDED_DOWNLOAD}" in
0) make_vm_config "windows-${RELEASE}.iso" "virtio-win.iso";;
1) make_vm_config "${FILE_NAME}" "virtio-win.iso";;
esac
} }
create_vm() { create_vm() {

Loading…
Cancel
Save