mirror of
https://github.com/dockur/windows.git
synced 2026-08-03 12:37:20 +01:00
feat: Inline local variable declarations (#1951)
This commit is contained in:
+35
-38
@@ -6,7 +6,7 @@ handleCurlError() {
|
||||
local code="$1"
|
||||
local server="$2"
|
||||
local reason="${3:-}"
|
||||
local signal=""
|
||||
local signal
|
||||
|
||||
if [ -n "$reason" ] && (( code <= 125 )); then
|
||||
error "Request to $server servers failed: ${reason%.}."
|
||||
@@ -43,8 +43,7 @@ curlRequest() {
|
||||
local agent="$3"
|
||||
shift 3
|
||||
|
||||
local log reason
|
||||
local rc=0 response=""
|
||||
local log reason response
|
||||
|
||||
if ! log=$(mktemp -p "$QEMU_DIR"); then
|
||||
error "Failed to create a temporary curl log."
|
||||
@@ -62,7 +61,7 @@ curlRequest() {
|
||||
--tlsv1.2 \
|
||||
--http1.1 \
|
||||
"$@" 2>"$log")
|
||||
rc=$?
|
||||
local rc=$?
|
||||
} || :
|
||||
|
||||
if (( rc != 0 )); then
|
||||
@@ -90,14 +89,14 @@ downloadWindows() {
|
||||
local lang="$2"
|
||||
local desc="$3"
|
||||
|
||||
local ovToken="" ovTicks="" ovTime=""
|
||||
local skuId="" skuUrl="" skuJson=""
|
||||
local linkUrl="" linkJson="" link=""
|
||||
local language="" orgId="" ovData=""
|
||||
local instance="" vlsUrl="" ovUrl=""
|
||||
local session="" agent="" type=""
|
||||
local winVer="" page="" productId=""
|
||||
local rc=0 profile="606624d44113"
|
||||
local ovToken="" ovTicks="" ovTime
|
||||
local skuId skuJson
|
||||
local linkJson link
|
||||
local language ovData
|
||||
local session agent
|
||||
local type winVer
|
||||
local page productId
|
||||
local profile="606624d44113"
|
||||
|
||||
agent=$(getAgent)
|
||||
language=$(getLanguage "$lang" "name")
|
||||
@@ -142,8 +141,8 @@ downloadWindows() {
|
||||
|
||||
# Microsoft download "protection" requires the sessionId to be whitelisted through vlscppe.microsoft.com/tags
|
||||
|
||||
orgId="y6jn8c31"
|
||||
vlsUrl="https://vlscppe.microsoft.com/tags?org_id=$orgId&session_id=$session"
|
||||
local orgId="y6jn8c31"
|
||||
local vlsUrl="https://vlscppe.microsoft.com/tags?org_id=$orgId&session_id=$session"
|
||||
|
||||
enabled "$DEBUG" && echo "Getting Session ID: $session"
|
||||
|
||||
@@ -157,8 +156,8 @@ downloadWindows() {
|
||||
# Microsoft download "protection" also requires an ov-df.microsoft.com request/reply
|
||||
# 1) Request mdt.js to get w and rticks. InstanceId is (currently) constant.
|
||||
|
||||
instance="560dc9f3-1aa5-4a2f-b63c-9e18f8d0e175"
|
||||
ovUrl="https://ov-df.microsoft.com/mdt.js?instanceId=$instance&PageId=si&session_id=$session"
|
||||
local instance="560dc9f3-1aa5-4a2f-b63c-9e18f8d0e175"
|
||||
local ovUrl="https://ov-df.microsoft.com/mdt.js?instanceId=$instance&PageId=si&session_id=$session"
|
||||
|
||||
enabled "$DEBUG" && echo -n "Getting OV data: "
|
||||
|
||||
@@ -199,7 +198,7 @@ downloadWindows() {
|
||||
|
||||
enabled "$DEBUG" && echo -n "Getting language SKU ID: "
|
||||
|
||||
skuUrl="https://www.microsoft.com/software-download-connector/api/getskuinformationbyproductedition?profile=$profile&ProductEditionId=$productId&SKU=undefined&friendlyFileName=undefined&Locale=en-US&sessionID=$session"
|
||||
local skuUrl="https://www.microsoft.com/software-download-connector/api/getskuinformationbyproductedition?profile=$profile&ProductEditionId=$productId&SKU=undefined&friendlyFileName=undefined&Locale=en-US&sessionID=$session"
|
||||
|
||||
curlRequest skuJson "Microsoft" "$agent" \
|
||||
--referer "$url" \
|
||||
@@ -207,7 +206,7 @@ downloadWindows() {
|
||||
--max-filesize 100K \
|
||||
-- "$skuUrl" || return 1
|
||||
|
||||
{ skuId=$(echo "$skuJson" | jq --arg LANG "$language" -r '.Skus[] | select(.Language==$LANG).Id') 2>/dev/null; rc=$?; } || :
|
||||
{ skuId=$(echo "$skuJson" | jq --arg LANG "$language" -r '.Skus[] | select(.Language==$LANG).Id') 2>/dev/null; local rc=$?; } || :
|
||||
|
||||
if [ -z "$skuId" ] || [[ "${skuId,,}" == "null" ]] || (( rc != 0 )); then
|
||||
language=$(getLanguage "$lang" "desc")
|
||||
@@ -221,7 +220,7 @@ downloadWindows() {
|
||||
# Get ISO download link
|
||||
# If any request is going to be blocked by Microsoft it's always this last one (the previous requests always seem to succeed)
|
||||
|
||||
linkUrl="https://www.microsoft.com/software-download-connector/api/GetProductDownloadLinksBySku?profile=$profile&ProductEditionId=undefined&SKU=$skuId&friendlyFileName=undefined&Locale=en-US&sessionID=$session"
|
||||
local linkUrl="https://www.microsoft.com/software-download-connector/api/GetProductDownloadLinksBySku?profile=$profile&ProductEditionId=undefined&SKU=$skuId&friendlyFileName=undefined&Locale=en-US&sessionID=$session"
|
||||
|
||||
curlRequest linkJson "Microsoft" "$agent" \
|
||||
--referer "$url" \
|
||||
@@ -262,8 +261,8 @@ downloadWindowsEval() {
|
||||
local id="$1"
|
||||
local lang="$2"
|
||||
local desc="$3"
|
||||
local filter="" culture="" compare="" language=""
|
||||
local agent="" type="" winVer=""
|
||||
local culture compare type
|
||||
local agent language winVer
|
||||
|
||||
case "${id,,}" in
|
||||
"win11${PLATFORM,,}-enterprise-eval" )
|
||||
@@ -301,9 +300,7 @@ downloadWindowsEval() {
|
||||
culture=$(getLanguage "$lang" "culture")
|
||||
|
||||
local country="${culture#*-}"
|
||||
local link=""
|
||||
local links=""
|
||||
local page=""
|
||||
local link="" links page
|
||||
local url="https://www.microsoft.com/en-us/evalcenter/download-$winVer"
|
||||
|
||||
enabled "$DEBUG" && echo "Parsing download page: ${url}"
|
||||
@@ -321,7 +318,7 @@ downloadWindowsEval() {
|
||||
|
||||
enabled "$DEBUG" && echo "Getting download link.."
|
||||
|
||||
filter="https://go.microsoft.com/fwlink/?linkid=[0-9]\+&clcid=0x[0-9a-z]\+&culture=${culture,,}&country=${country,,}"
|
||||
local filter="https://go.microsoft.com/fwlink/?linkid=[0-9]\+&clcid=0x[0-9a-z]\+&culture=${culture,,}&country=${country,,}"
|
||||
|
||||
if ! echo "$page" | 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,,}"
|
||||
@@ -474,8 +471,7 @@ downloadWindowsLtsc() {
|
||||
local id="$1"
|
||||
local lang="$2"
|
||||
local desc="$3"
|
||||
local alternate=""
|
||||
local alternate_desc=""
|
||||
local alternate alternate_desc
|
||||
|
||||
case "${id,,}" in
|
||||
"win11${PLATFORM,,}-enterprise-iot-eval" )
|
||||
@@ -691,7 +687,7 @@ getESD() {
|
||||
local xmlFile="products.xml"
|
||||
local esdFile="esd_edition.xml"
|
||||
local filterFile="products_filter.xml"
|
||||
local log query rc=0 reason=""
|
||||
local log
|
||||
|
||||
file=$(getCatalog "$version" "file")
|
||||
catalog=$(getCatalog "$version" "url")
|
||||
@@ -721,11 +717,12 @@ getESD() {
|
||||
{
|
||||
LC_ALL=C wget "$catalog" -O "$dir/$file" --no-verbose --timeout=30 \
|
||||
--no-http-keep-alive --output-file="$log"
|
||||
rc=$?
|
||||
local rc=$?
|
||||
} || :
|
||||
|
||||
if (( rc != 0 )); then
|
||||
|
||||
local reason
|
||||
reason=$(sed -n \
|
||||
-e 's/^wget: //p' \
|
||||
-e 's/^[0-9-]\{10\} [0-9:]\{8\} ERROR //p' \
|
||||
@@ -771,7 +768,7 @@ getESD() {
|
||||
return 1
|
||||
fi
|
||||
|
||||
query='//File[Architecture="'${PLATFORM,,}'"]'"${edition}"''
|
||||
local query='//File[Architecture="'${PLATFORM,,}'"]'"${edition}"''
|
||||
result=$(xmllint --nonet --xpath "${query}" "$dir/$xmlFile" 2>/dev/null || true)
|
||||
|
||||
if [ -z "$result" ]; then
|
||||
@@ -854,7 +851,7 @@ verifyFile() {
|
||||
fi
|
||||
|
||||
local algo="SHA256"
|
||||
local hash="" rc=0
|
||||
local hash
|
||||
|
||||
[ -z "$check" ] && return 0
|
||||
! enabled "$VERIFY" && return 0
|
||||
@@ -866,7 +863,7 @@ verifyFile() {
|
||||
if [[ "${algo,,}" != "sha256" ]]; then
|
||||
|
||||
hash=$(sha1sum "$iso" | cut -f1 -d' ') || {
|
||||
rc=$?
|
||||
local rc=$?
|
||||
|
||||
if (( rc >= 129 )); then
|
||||
exit "$rc"
|
||||
@@ -879,7 +876,7 @@ verifyFile() {
|
||||
else
|
||||
|
||||
hash=$(sha256sum "$iso" | cut -f1 -d' ') || {
|
||||
rc=$?
|
||||
local rc=$?
|
||||
|
||||
if (( rc >= 129 )); then
|
||||
exit "$rc"
|
||||
@@ -939,7 +936,7 @@ tryDownload() {
|
||||
local desc="$6"
|
||||
local seconds="$7"
|
||||
local web_desc="$8"
|
||||
local total rc=0
|
||||
local total
|
||||
|
||||
if downloadRetry \
|
||||
"$iso" \
|
||||
@@ -952,9 +949,9 @@ tryDownload() {
|
||||
"$size" \
|
||||
"$desc" \
|
||||
"$web_desc"; then
|
||||
rc=0
|
||||
local rc=0
|
||||
else
|
||||
rc=$?
|
||||
local rc=$?
|
||||
fi
|
||||
|
||||
(( rc == 0 )) || return "$rc"
|
||||
@@ -987,9 +984,9 @@ fallbackEnglish() {
|
||||
local lang="$3"
|
||||
local desc="$4"
|
||||
local web_desc="$5"
|
||||
local culture msg web_msg
|
||||
local culture web_msg
|
||||
|
||||
msg="No working download method was found for $desc, falling back to English..."
|
||||
local msg="No working download method was found for $desc, falling back to English..."
|
||||
info "$msg"
|
||||
|
||||
# Preserve the requested regional format and keyboard layout.
|
||||
|
||||
Reference in New Issue
Block a user