Skip to content

Commit

Permalink
fix: Download links (#248)
Browse files Browse the repository at this point in the history
  • Loading branch information
kroese authored Feb 15, 2025
1 parent f0a7761 commit 507707c
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 303 deletions.
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
FROM scratch
COPY --from=qemux/qemu-arm:2.26 / /
COPY --from=qemux/qemu-arm:2.27 / /

ARG VERSION_ARG="0.00"
ARG DEBCONF_NOWARNINGS="yes"
Expand Down
35 changes: 1 addition & 34 deletions src/define.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ set -Eeuo pipefail
: "${HEIGHT:=""}"
: "${VERIFY:=""}"
: "${REGION:=""}"
: "${EDITION:=""}"
: "${MANUAL:=""}"
: "${REMOVE:=""}"
: "${VERSION:=""}"
Expand Down Expand Up @@ -722,42 +723,12 @@ isESD() {
return 1
}

isMG() {

local id="$1"
local lang="$2"

case "${id,,}" in
"win11${PLATFORM,,}" )
return 0
;;
"win11${PLATFORM,,}-enterprise" | "win11${PLATFORM,,}-enterprise-eval" )
return 0
;;
"win11${PLATFORM,,}-ltsc" | "win11${PLATFORM,,}-enterprise-ltsc-eval" )
return 0
;;
"win10${PLATFORM,,}" )
return 0
;;
"win10${PLATFORM,,}-enterprise" | "win10${PLATFORM,,}-enterprise-eval" )
return 0
;;
"win10${PLATFORM,,}-ltsc" | "win10${PLATFORM,,}-enterprise-ltsc-eval" )
return 0
;;
esac

return 1
}

validVersion() {

local id="$1"
local lang="$2"
local url

isMG "$id" "$lang" && return 0
isESD "$id" "$lang" && return 0
isMido "$id" "$lang" && return 0

Expand Down Expand Up @@ -795,10 +766,6 @@ addFolder() {
return 0
}

migrateFiles() {
return 0
}

detectLegacy() {
return 1
}
Expand Down
7 changes: 5 additions & 2 deletions src/install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,6 @@ startInstall() {

BOOT="$STORAGE/$file"

! migrateFiles "$BOOT" "$VERSION" && error "Migration failed!" && exit 57

fi

skipInstall "$BOOT" && return 1
Expand Down Expand Up @@ -668,6 +666,11 @@ updateXML() {
sed -z "s/<AdministratorPassword>...............<Value \/>/<AdministratorPassword>\n <Value>$admin<\/Value>/g" -i "$asset"
fi

if [ -n "$EDITION" ]; then
[[ "${EDITION^^}" == "CORE" ]] && EDITION="STANDARDCORE"
sed -i "s/SERVERSTANDARD<\/Value>/SERVER${EDITION^^}<\/Value>/g" "$asset"
fi

return 0
}

Expand Down
270 changes: 4 additions & 266 deletions src/mido.sh
Original file line number Diff line number Diff line change
Expand Up @@ -242,10 +242,10 @@ download_windows_eval() {

[[ "$DEBUG" == [Yy1]* ]] && echo "Getting download link.."

if [[ "$enterprise_type" == "iot" ]]; then
filter="https://go.microsoft.com/fwlink/?linkid=[0-9]\+&clcid=0x[0-9a-z]\+&culture=${culture,,}&country=${country^^}"
else
filter="https://go.microsoft.com/fwlink/p/?LinkID=[0-9]\+&clcid=0x[0-9a-z]\+&culture=${culture,,}&country=${country^^}"
filter="https://go.microsoft.com/fwlink/?linkid=[0-9]\+&clcid=0x[0-9a-z]\+&culture=${culture,,}&country=${country,,}"

if ! echo "$iso_download_page_html" | grep -io "$filter" > /dev/null; then
filter="https://go.microsoft.com/fwlink/p/?linkid=[0-9]\+&clcid=0x[0-9a-z]\+&culture=${culture,,}&country=${country,,}"
fi

iso_download_links=$(echo "$iso_download_page_html" | grep -io "$filter") || {
Expand Down Expand Up @@ -429,243 +429,6 @@ getCatalog() {
return 0
}

getMG() {

local version="$1"
local lang="$2"
local desc="$3"

local locale=""
local culture=""
local language=""
local user_agent=""

user_agent=$(get_agent)
language=$(getLanguage "$lang" "desc")
culture=$(getLanguage "$lang" "culture")

local msg="Requesting download link from massgrave.dev..."
info "$msg" && html "$msg"

local pattern=""
local locale="${culture,,}"
local platform="${PLATFORM,,}"
local url="https://massgrave.dev/"

if [[ "${PLATFORM,,}" != "arm64" ]]; then

case "${version,,}" in
"win11${PLATFORM,,}" )
url+="windows_11_links"
pattern="consumer"
;;
"win11${PLATFORM,,}-enterprise" | "win11${PLATFORM,,}-enterprise-eval" )
url+="windows_11_links"
pattern="business"
;;
"win11${PLATFORM,,}-ltsc" | "win11${PLATFORM,,}-enterprise-ltsc-eval" )
url+="windows_ltsc_links"
pattern="11_enterprise_ltsc"
;;
"win11${PLATFORM,,}-iot" | "win11${PLATFORM,,}-enterprise-iot-eval" )
url+="windows_ltsc_links"
pattern="11_iot"
;;
"win10${PLATFORM,,}" )
url+="windows_10_links"
pattern="consumer"
;;
"win10${PLATFORM,,}-enterprise" | "win10${PLATFORM,,}-enterprise-eval" )
url+="windows_10_links"
pattern="business"
;;
"win10${PLATFORM,,}-ltsc" | "win10${PLATFORM,,}-enterprise-ltsc-eval" )
url+="windows_ltsc_links"
pattern="10_enterprise_ltsc"
;;
"win10${PLATFORM,,}-iot" | "win10${PLATFORM,,}-enterprise-iot-eval" )
url+="windows_ltsc_links"
pattern="10_iot"
;;
"win81${PLATFORM,,}-enterprise" | "win81${PLATFORM,,}-enterprise-eval" )
url+="windows_8.1_links"
pattern="8.1_enterprise"
locale=$(getLanguage "$lang" "code")
[[ "$locale" == "sr" ]] && locale="sr-latn"
;;
"win2025" | "win2025-eval" )
url+="windows_server_links"
pattern="server_2025"
;;
"win2022" | "win2022-eval" )
url+="windows_server_links"
pattern="server_2022"
;;
"win2019" | "win2019-eval" )
url+="windows_server_links"
pattern="server_2019"
;;
"win2016" | "win2016-eval" )
url+="windows_server_links"
pattern="server_2016"
locale=$(getLanguage "$lang" "code")
[[ "$locale" == "hk" ]] && locale="ct"
[[ "$locale" == "tw" ]] && locale="ct"
;;
"win2012r2" | "win2012r2-eval" )
url+="windows_server_links"
pattern="server_2012_r2"
locale=$(getLanguage "$lang" "code")
;;
"win2008r2" | "win2008r2-eval" )
url+="windows_server_links"
pattern="server_2008_r2"
locale=$(getLanguage "$lang" "code")
;;
"win7x64" | "win7x64-enterprise" )
url+="windows_7_links"
pattern="enterprise"
locale=$(getLanguage "$lang" "code")
;;
"win7x64-ultimate" )
url+="windows_7_links"
pattern="ultimate"
locale=$(getLanguage "$lang" "code")
;;
"win7x86" | "win7x86-enterprise" )
platform="x86"
url+="windows_7_links"
pattern="enterprise"
locale=$(getLanguage "$lang" "code")
;;
"win7x86-ultimate" )
platform="x86"
url+="windows_7_links"
pattern="ultimate"
locale=$(getLanguage "$lang" "code")
;;
"winvistax64" | "winvistax64-enterprise" )
url+="windows_vista_links"
pattern="enterprise"
locale=$(getLanguage "$lang" "code")
;;
"winvistax64-ultimate" )
url+="windows_vista_links"
pattern="sp2"
locale=$(getLanguage "$lang" "code")
;;
"winvistax86" | "winvistax86-enterprise" )
platform="x86"
url+="windows_vista_links"
pattern="enterprise"
locale=$(getLanguage "$lang" "code")
;;
"winvistax86-ultimate" )
platform="x86"
url+="windows_vista_links"
pattern="sp2"
locale=$(getLanguage "$lang" "code")
;;
"winxpx86" )
platform="x86"
url+="windows_xp_links"
pattern="xp"
locale=$(getLanguage "$lang" "code")
[[ "$locale" == "pt" ]] && locale="pt-br"
[[ "$locale" == "pp" ]] && locale="pt-pt"
[[ "$locale" == "cn" ]] && locale="zh-hans"
[[ "$locale" == "hk" ]] && locale="zh-hk"
[[ "$locale" == "tw" ]] && locale="zh-tw"
;;
"winxpx64" )
url+="windows_xp_links"
pattern="xp"
locale=$(getLanguage "$lang" "code")
;;
esac

else

case "${version,,}" in
"win11${PLATFORM,,}" | "win11${PLATFORM,,}-enterprise" | "win11${PLATFORM,,}-enterprise-eval" )
url+="windows_arm_links"
pattern="11_business"
;;
"win11${PLATFORM,,}-ltsc" | "win11${PLATFORM,,}-enterprise-ltsc-eval" )
url+="windows_arm_links"
pattern="11_iot_enterprise_ltsc"
;;
"win10${PLATFORM,,}" | "win10${PLATFORM,,}-enterprise" | "win10${PLATFORM,,}-enterprise-eval" )
url+="windows_arm_links"
pattern="Pro_10"
locale="$language"
[[ "$locale" == "Chinese" ]] && locale="ChnSimp"
[[ "$locale" == "Chinese HK" ]] && locale="ChnTrad"
[[ "$locale" == "Chinese TW" ]] && locale="ChnTrad"
;;
"win10${PLATFORM,,}-ltsc" | "win10${PLATFORM,,}-enterprise-ltsc-eval" )
url+="windows_arm_links"
pattern="10_iot_enterprise_ltsc"
;;
esac

fi

local body=""

[[ "$DEBUG" == [Yy1]* ]] && echo "Parsing product page: ${url}"
body=$(curl --silent --max-time 30 --user-agent "$user_agent" --location --max-filesize 1M --fail --proto =https --tlsv1.2 --http1.1 -- "$url") || {
handle_curl_error "$?" "Massgrave"
return $?
}

local list=""
list=$(echo "$body" | xmllint --html --nonet --xpath "//a[contains(text(), '.iso')]" - 2>/dev/null)

local result=""
result=$(echo "$list" | grep -i "${platform}" | grep "${pattern}" | grep -i -m 1 "${locale,,}_")
result=$(echo "$result" | sed -r 's/.*href="([^"]+).*/\1/g')
local page="$result"

if [ -z "$page" ]; then
if [[ "${lang,,}" != "en" ]] && [[ "${lang,,}" != "en-"* ]]; then
error "No download in the $language language available for $desc!"
else
error "Failed to parse download link for $desc! Please report this at $SUPPORT/issues."
fi
return 1
fi

[[ "$DEBUG" == [Yy1]* ]] && echo "Parsing download page: ${page}"
result=$(curl --silent --max-time 30 --request GET --user-agent "$user_agent" --referer "$url" --head --proto =https --tlsv1.2 --http1.1 -- "$page") || {
handle_curl_error "$?" "Massgrave"
return $?
}

if [[ "${result,,}" == *"content-type: text"* ]]; then
body=$(curl --silent --max-time 30 --user-agent "$user_agent" --referer "$url" --location --max-filesize 1M --fail --proto =https --tlsv1.2 --http1.1 -- "$page") || {
handle_curl_error "$?" "Massgrave"
return $?
}

list=$(echo "$body" | xmllint --html --nonet --xpath "//a[contains(@href, '.iso')]" - 2>/dev/null)
list=$(echo "$list" | sed -r 's/.*href="([^"]+).*/\1/g')
page=$(echo "$list" | sed 's/&amp;/\&/g;')

if [ -z "$page" ]; then
if [[ "${lang,,}" != "en" ]] && [[ "${lang,,}" != "en-"* ]]; then
error "No download in the $language language available for $desc!"
else
error "Failed to parse download link for $desc! Please report this at $SUPPORT/issues."
fi
return 1
fi
fi

MG_URL="$page"
return 0
}

getESD() {

local dir="$1"
Expand Down Expand Up @@ -950,31 +713,6 @@ downloadImage() {

done

if isMG "$version" "$lang"; then

if [[ "$tried" != "n" ]]; then
info "Failed to download $desc, will try a diferent method now..."
fi

tried="y"
success="n"

if getMG "$version" "$lang" "$desc"; then
success="y"
else
info "$msg" && html "$msg" && sleep "$delay"
getMG "$version" "$lang" "$desc" && success="y"
fi

if [[ "$success" == "y" ]]; then
downloadFile "$iso" "$MG_URL" "" "" "$lang" "$desc" && return 0
info "$msg" && html "$msg" && sleep "$delay"
downloadFile "$iso" "$MG_URL" "" "" "$lang" "$desc" && return 0
rm -f "$iso"
fi

fi

return 1
}

Expand Down

0 comments on commit 507707c

Please sign in to comment.