feat: Refactor

This commit is contained in:
Kroese 2024-05-01 17:30:24 +02:00 committed by GitHub
parent 116bb06b50
commit c36451b431
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -7,6 +7,8 @@ set -Eeuo pipefail
: "${DETECTED:=""}"
: "${PLATFORM:="x64"}"
MIRRORS=5
parseVersion() {
[ -z "$VERSION" ] && VERSION="win11"
@ -40,7 +42,7 @@ parseVersion() {
;;
"vista" | "winvista" | "windowsvista" | "windows vista" )
VERSION="winvista${PLATFORM,,}"
DETECTED="winvista${PLATFORM,,}-ultimate"
DETECTED="winvista${PLATFORM,,}-enterprise"
;;
"xp" | "xp32" | "winxp" | "windowsxp" | "windows xp" )
VERSION="winxpx86"
@ -93,25 +95,28 @@ printVersion() {
local id="$1"
local desc="$2"
[[ "$id" == "win7"* ]] && desc="Windows 7"
[[ "$id" == "win8"* ]] && desc="Windows 8"
[[ "$id" == "win10"* ]] && desc="Windows 10"
[[ "$id" == "win11"* ]] && desc="Windows 11"
[[ "$id" == "winxp"* ]] && desc="Windows XP"
[[ "$id" == "winvista"* ]] && desc="Windows Vista"
case "${id,,}" in
"tiny11"* ) desc="Tiny 11" ;;
"tiny10"* ) desc="Tiny 10" ;;
"core11"* ) desc="Core 11" ;;
"win7"* ) desc="Windows 7" ;;
"win8"* ) desc="Windows 8" ;;
"win10"* ) desc="Windows 10" ;;
"win11"* ) desc="Windows 11" ;;
"winxp"* ) desc="Windows XP" ;;
"winvista"* ) desc="Windows Vista" ;;
"win2025"* ) desc="Windows Server 2025" ;;
"win2022"* ) desc="Windows Server 2022" ;;
"win2019"* ) desc="Windows Server 2019" ;;
"win2016"* ) desc="Windows Server 2016" ;;
"win2012"* ) desc="Windows Server 2012" ;;
"win2008"* ) desc="Windows Server 2008" ;;
esac
[[ "$id" == "win2025"* ]] && desc="Windows Server 2025"
[[ "$id" == "win2022"* ]] && desc="Windows Server 2022"
[[ "$id" == "win2019"* ]] && desc="Windows Server 2019"
[[ "$id" == "win2016"* ]] && desc="Windows Server 2016"
[[ "$id" == "win2012"* ]] && desc="Windows Server 2012"
[[ "$id" == "win2008"* ]] && desc="Windows Server 2008"
[[ "$id" == "tiny11"* ]] && desc="Tiny 11"
[[ "$id" == "tiny10"* ]] && desc="Tiny 10"
[[ "$id" == "core11"* ]] && desc="Core 11"
[ -z "$desc" ] && desc="Windows"
if [ -z "$desc" ]; then
desc="Windows"
[[ "${PLATFORM,,}" != "x64" ]] && desc="$desc for ${PLATFORM}")
fi
echo "$desc"
return 0
@ -119,57 +124,43 @@ printVersion() {
getName() {
local file="$1"
local desc="$2"
local id=""
local desc="$1"
local file="${1,,}"
[[ "${file,,}" == "win11"* ]] && desc="Windows 11"
[[ "${file,,}" == "win10"* ]] && desc="Windows 10"
[[ "${file,,}" == "win8"* ]] && desc="Windows 8"
[[ "${file,,}" == "win7"* ]] && desc="Windows 7"
[[ "${file,,}" == "winxp"* ]] && desc="Windows XP"
[[ "${file,,}" == "winvista"* ]] && desc="Windows Vista"
[[ "${file,,}" == "tiny10"* ]] && desc="Tiny 10"
[[ "${file,,}" == "tiny11"* ]] && desc="Tiny 11"
[[ "${file,,}" == "tiny11core"* ]] && desc="Tiny 11 Core"
[[ "${file,,}" == "tiny11_core"* ]] && desc="Tiny 11 Core"
[[ "${file,,}" == *"windows11"* ]] && desc="Windows 11"
[[ "${file,,}" == *"windows10"* ]] && desc="Windows 10"
[[ "${file,,}" == *"windows8"* ]] && desc="Windows 8"
[[ "${file,,}" == *"windows7"* ]] && desc="Windows 7"
[[ "${file,,}" == *"windowsxp"* ]] && desc="Windows XP"
[[ "${file,,}" == *"windowsvista"* ]] && desc="Windows Vista"
[[ "${file,,}" == *"windows_11"* ]] && desc="Windows 11"
[[ "${file,,}" == *"windows_10"* ]] && desc="Windows 10"
[[ "${file,,}" == *"windows_8"* ]] && desc="Windows 8"
[[ "${file,,}" == *"windows_7"* ]] && desc="Windows 7"
[[ "${file,,}" == *"windows_xp"* ]] && desc="Windows XP"
[[ "${file,,}" == *"windows_vista"* ]] && desc="Windows Vista"
[[ "${file,,}" == *"windows 11"* ]] && desc="Windows 11"
[[ "${file,,}" == *"windows 10"* ]] && desc="Windows 10"
[[ "${file,,}" == *"windows 8"* ]] && desc="Windows 8"
[[ "${file,,}" == *"windows 7"* ]] && desc="Windows 7"
[[ "${file,,}" == *"windows xp"* ]] && desc="Windows XP"
[[ "${file,,}" == *"windows vista"* ]] && desc="Windows Vista"
[[ "${file,,}" == *"server2008"* ]] && desc="Windows Server 2008"
[[ "${file,,}" == *"server2012"* ]] && desc="Windows Server 2012"
[[ "${file,,}" == *"server2016"* ]] && desc="Windows Server 2016"
[[ "${file,,}" == *"server2019"* ]] && desc="Windows Server 2019"
[[ "${file,,}" == *"server2022"* ]] && desc="Windows Server 2022"
[[ "${file,,}" == *"server2025"* ]] && desc="Windows Server 2025"
[[ "${file,,}" == *"server_2008"* ]] && desc="Windows Server 2008"
[[ "${file,,}" == *"server_2012"* ]] && desc="Windows Server 2012"
[[ "${file,,}" == *"server_2016"* ]] && desc="Windows Server 2016"
[[ "${file,,}" == *"server_2019"* ]] && desc="Windows Server 2019"
[[ "${file,,}" == *"server_2022"* ]] && desc="Windows Server 2022"
[[ "${file,,}" == *"server_2025"* ]] && desc="Windows Server 2025"
[[ "${file,,}" == *"server 2008"* ]] && desc="Windows Server 2008"
[[ "${file,,}" == *"server 2012"* ]] && desc="Windows Server 2012"
[[ "${file,,}" == *"server 2016"* ]] && desc="Windows Server 2016"
[[ "${file,,}" == *"server 2019"* ]] && desc="Windows Server 2019"
[[ "${file,,}" == *"server 2022"* ]] && desc="Windows Server 2022"
[[ "${file,,}" == *"server 2025"* ]] && desc="Windows Server 2025"
case "${file/ /_}" in
"win7"* | "win_7"* | *"windows7"* | *"windows_7"* )
id="win7${PLATFORM,,}"
;;
"win8"* | "win_8"* | *"windows8"* | *"windows_8"* )
id="win81${PLATFORM,,}"
;;
"win10"*| "win_10"* | *"windows10"* | *"windows_10"* )
id="win10${PLATFORM,,}"
;;
"win11"* | "win_11"* *"windows11"* | *"windows_11"* )
id="win11${PLATFORM,,}"
;;
*"winxp"* | *"win_xp"* | *"windowsxp"* | *"windows_xp"* )
id="winxpx86"
;;
*"winvista"* | *"win_vista"* | *"windowsvista"* | *"windows_vista"* )
id="winvista${PLATFORM,,}"
;;
"tiny11core"* | "tiny11_core"* | "tiny_11_core"* ) id="core11" ;;
"tiny11"* | "tiny_11"* ) id="tiny11" ;;
"tiny10"* | "tiny_10"* ) id="tiny10" ;;
*"server2025"* | *"server_2025"* ) id="win2025" ;;
*"server2022"* | *"server_2022"* ) id="win2022" ;;
*"server2019"* | *"server_2019"* ) id="win2019" ;;
*"server2016"* | *"server_2016"* ) id="win2016" ;;
*"server2012"* | *"server_2012"* ) id="win2012r2" ;;
*"server2008"* | *"server_2008"* ) id="win2008r2" ;;
esac
[ -z "$desc" ] && desc="Windows"
if [ -n "$id" ]; then
desc=$(printVersion "$id" "$desc")
fi
echo "$desc"
return 0
@ -177,78 +168,64 @@ getName() {
getVersion() {
local id=""
local name="$1"
local detected=""
if [[ "${name,,}" == *"windows 7"* ]]; then
detected="win7${PLATFORM,,}"
[[ "${name,,}" == *"ultimate"* ]] && detected="win7${PLATFORM,,}-ultimate"
[[ "${name,,}" == *"enterprise"* ]] && detected="win7${PLATFORM,,}-enterprise"
fi
case "${name,,}" in
*"server 2025"* ) id="win2025" ;;
*"server 2022"* ) id="win2022" ;;
*"server 2019"* ) id="win2019" ;;
*"server 2016"* ) id="win2016" ;;
*"server 2012"* ) id="win2012r2" ;;
*"server 2008"* ) id="win2008r2" ;;
*"windows 7"* ) id="win7${PLATFORM,,}" ;;
*"windows 8"* ) id="win81${PLATFORM,,}" ;;
*"windows 10"* ) id="win10${PLATFORM,,}" ;;
*"windows 11"* ) id="win11${PLATFORM,,}" ;;
*"windows vista"* ) id="winvista${PLATFORM,,}" ;;
esac
if [[ "${name,,}" == *"windows vista"* ]]; then
detected="winvista${PLATFORM,,}"
[[ "${name,,}" == *"ultimate"* ]] && detected="winvista${PLATFORM,,}-ultimate"
[[ "${name,,}" == *"enterprise"* ]] && detected="winvista${PLATFORM,,}-enterprise"
fi
case "${id,,}" in
"win7"* | "winvista"* )
case "${name,,}" in
*" home"* ) id="$id-home" ;;
*" starter"* ) id="$id-starter" ;;
*" ultimate"* ) id="$id-ultimate" ;;
*" enterprise"* ) id="$id-enterprise" ;;
esac
;;
"win8"* )
case "${name,,}" in
*" enterprise evaluation"* ) id="$id-enterprise-eval" ;;
*" enterprise"* ) id="$id-enterprise" ;;
esac
;;
"win10"* )
case "${name,,}" in
*" iot"* ) id="$id-iot" ;;
*" ltsc"* ) id="$id-ltsc" ;;
*" home"* ) id="$id-home" ;;
*" education"* ) id="$id-education" ;;
*" enterprise evaluation"* ) id="$id-enterprise-eval" ;;
*" enterprise"* ) id="$id-enterprise" ;;
esac
;;
"win11"* )
case "${name,,}" in
*" home"* ) id="$id-home" ;;
*" education"* ) id="$id-education" ;;
*" enterprise evaluation"* ) id="$id-enterprise-eval" ;;
*" enterprise"* ) id="$id-enterprise" ;;
esac
;;
"win2025"* | "win2022"* | "win2019"* | "win2016"* | "win2012"* | "win2008"* )
case "${name,,}" in
*" evaluation"* ) id="$id-eval" ;;
esac
;;
esac
if [[ "${name,,}" == *"server 2025"* ]]; then
detected="win2025"
[[ "${name,,}" == *"evaluation"* ]] && detected="win2025-eval"
fi
if [[ "${name,,}" == *"server 2022"* ]]; then
detected="win2022"
[[ "${name,,}" == *"evaluation"* ]] && detected="win2022-eval"
fi
if [[ "${name,,}" == *"server 2019"* ]]; then
detected="win2019"
[[ "${name,,}" == *"evaluation"* ]] && detected="win2019-eval"
fi
if [[ "${name,,}" == *"server 2016"* ]]; then
detected="win2016"
[[ "${name,,}" == *"evaluation"* ]] && detected="win2016-eval"
fi
if [[ "${name,,}" == *"server 2012"* ]]; then
detected="win2012r2"
[[ "${name,,}" == *"evaluation"* ]] && detected="win2012r2-eval"
fi
if [[ "${name,,}" == *"server 2008"* ]]; then
detected="win2008r2"
[[ "${name,,}" == *"evaluation"* ]] && detected="win2008r2-eval"
fi
if [[ "${name,,}" == *"windows 8"* ]]; then
detected="win81${PLATFORM,,}"
[[ "${name,,}" == *"enterprise"* ]] && detected="win81${PLATFORM,,}-enterprise"
[[ "${name,,}" == *"enterprise evaluation"* ]] && detected="win81${PLATFORM,,}-enterprise-eval"
fi
if [[ "${name,,}" == *"windows 11"* ]]; then
detected="win11${PLATFORM,,}"
[[ "${name,,}" == *"enterprise"* ]] && detected="win11${PLATFORM,,}-enterprise"
[[ "${name,,}" == *"enterprise evaluation"* ]] && detected="win11${PLATFORM,,}-enterprise-eval"
fi
if [[ "${name,,}" == *"windows 10"* ]]; then
detected="win10${PLATFORM,,}"
if [[ "${name,,}" == *" iot "* ]]; then
detected="win10${PLATFORM,,}-iot"
else
if [[ "${name,,}" == *"ltsc"* ]]; then
detected="win10${PLATFORM,,}-ltsc"
else
[[ "${name,,}" == *"enterprise"* ]] && detected="win10${PLATFORM,,}-enterprise"
[[ "${name,,}" == *"enterprise evaluation"* ]] && detected="win10${PLATFORM,,}-enterprise-eval"
fi
fi
fi
echo "$detected"
echo "$id"
return 0
}
@ -266,21 +243,11 @@ switchEdition() {
"win81${PLATFORM,,}-enterprise-eval" )
DETECTED="win81${PLATFORM,,}-enterprise"
;;
"win2022-eval")
DETECTED="win2022"
;;
"win2019-eval")
DETECTED="win2019"
;;
"win2016-eval")
DETECTED="win2016"
;;
"win2012r2-eval")
DETECTED="win2012r2"
;;
"win2008r2-eval")
DETECTED="win2008r2"
;;
"win2022-eval" ) DETECTED="win2022" ;;
"win2019-eval" ) DETECTED="win2019" ;;
"win2016-eval" ) DETECTED="win2016" ;;
"win2012r2-eval" ) DETECTED="win2012r2" ;;
"win2008r2-eval" ) DETECTED="win2008r2" ;;
esac
return 0
@ -291,12 +258,8 @@ isESD() {
local id="$1"
case "${id,,}" in
"win11${PLATFORM,,}")
return 0
;;
"win10${PLATFORM,,}")
return 0
;;
"win11${PLATFORM,,}" ) return 0 ;;
"win10${PLATFORM,,}" ) return 0 ;;
esac
return 1
@ -366,7 +329,10 @@ getLink1() {
"win7${PLATFORM,,}" | "win7${PLATFORM,,}-enterprise" )
url="$host/7/en_windows_7_enterprise_with_sp1_${PLATFORM,,}_dvd_u_677651.iso"
;;
"winvista${PLATFORM,,}" | "winvista${PLATFORM,,}-ultimate")
"win7${PLATFORM,,}-ultimate" )
url="$host/7/en_windows_7_with_sp1_${PLATFORM,,}.iso"
;;
"winvista${PLATFORM,,}-ultimate" )
url="$host/vista/en_windows_vista_sp2_${PLATFORM,,}_dvd_342267.iso"
;;
"winxpx86" )
@ -403,7 +369,13 @@ getLink2() {
"win7${PLATFORM,,}" | "win7${PLATFORM,,}-enterprise" )
url="$host/Windows%207/en_windows_7_enterprise_with_sp1_${PLATFORM,,}_dvd_u_677651.iso"
;;
"winvista${PLATFORM,,}" | "winvista${PLATFORM,,}-ultimate")
"win7${PLATFORM,,}-ultimate" )
url="$host/Windows%207/en_windows_7_ultimate_with_sp1_${PLATFORM,,}_dvd_u_677332.iso"
;;
"winvista${PLATFORM,,}" | "winvista${PLATFORM,,}-enterprise" )
url="$host/Windows%20Vista/en_windows_vista_enterprise_sp2_${PLATFORM,,}_dvd_342332.iso"
;;
"winvista${PLATFORM,,}-ultimate" )
url="$host/Windows%20Vista/en_windows_vista_sp2_${PLATFORM,,}_dvd_342267.iso"
;;
"winxpx86" )
@ -425,15 +397,9 @@ getLink3() {
local host="https://file.cnxiaobai.com/Windows"
case "${id,,}" in
"core11")
url="$host/%E7%B3%BB%E7%BB%9F%E5%AE%89%E8%A3%85%E5%8C%85/Tiny%2010_11/tiny11%20core%20${PLATFORM,,}%20beta%201.iso"
;;
"tiny11")
url="$host/%E7%B3%BB%E7%BB%9F%E5%AE%89%E8%A3%85%E5%8C%85/Tiny%2010_11/tiny11%202311%20${PLATFORM,,}.iso"
;;
"tiny10")
url="$host/%E7%B3%BB%E7%BB%9F%E5%AE%89%E8%A3%85%E5%8C%85/Tiny%2010_11/tiny10%2023H2%20${PLATFORM,,}.iso"
;;
"core11" ) url="$host/%E7%B3%BB%E7%BB%9F%E5%AE%89%E8%A3%85%E5%8C%85/Tiny%2010_11/tiny11%20core%20${PLATFORM,,}%20beta%201.iso" ;;
"tiny11" ) url="$host/%E7%B3%BB%E7%BB%9F%E5%AE%89%E8%A3%85%E5%8C%85/Tiny%2010_11/tiny11%202311%20${PLATFORM,,}.iso" ;;
"tiny10" ) url="$host/%E7%B3%BB%E7%BB%9F%E5%AE%89%E8%A3%85%E5%8C%85/Tiny%2010_11/tiny10%2023H2%20${PLATFORM,,}.iso" ;;
esac
echo "$url"
@ -447,15 +413,9 @@ getLink4() {
local host="https://archive.org/download"
case "${id,,}" in
"core11")
url="$host/tiny-11-core-x-64-beta-1/tiny11%20core%20${PLATFORM,,}%20beta%201.iso"
;;
"tiny11")
url="$host/tiny11-2311/tiny11%202311%20${PLATFORM,,}.iso"
;;
"tiny10")
url="$host/tiny-10-23-h2/tiny10%20${PLATFORM,,}%2023h2.iso"
;;
"core11" ) url="$host/tiny-11-core-x-64-beta-1/tiny11%20core%20${PLATFORM,,}%20beta%201.iso" ;;
"tiny11" ) url="$host/tiny11-2311/tiny11%202311%20${PLATFORM,,}.iso" ;;
"tiny10" ) url="$host/tiny-10-23-h2/tiny10%20${PLATFORM,,}%2023h2.iso" ;;
esac
echo "$url"
@ -513,7 +473,13 @@ getLink5() {
"win7${PLATFORM,,}" | "win7${PLATFORM,,}-enterprise" )
url="$host/en_windows_7_enterprise_with_sp1_${PLATFORM,,}_dvd_u_677651.iso"
;;
"winvista${PLATFORM,,}" | "winvista${PLATFORM,,}-ultimate")
"win7${PLATFORM,,}-ultimate" )
url="$host/en_windows_7_ultimate_with_sp1_${PLATFORM,,}_dvd_u_677332.iso"
;;
"winvista${PLATFORM,,}" | "winvista${PLATFORM,,}-enterprise" )
url="$host/en_windows_vista_enterprise_sp2_${PLATFORM,,}_dvd_342332.iso"
;;
"winvista${PLATFORM,,}-ultimate" )
url="$host/en_windows_vista_sp2_${PLATFORM,,}_dvd_342267.iso"
;;
esac
@ -525,26 +491,12 @@ getLink5() {
getLink() {
local url=""
local index="$1"
local id="$2"
local func="getLink$1"
case "${index,,}" in
"1")
url=$(getLink1 "$id")
;;
"2")
url=$(getLink2 "$id")
;;
"3")
url=$(getLink3 "$id")
;;
"4")
url=$(getLink4 "$id")
;;
"5")
url=$(getLink5 "$id")
;;
esac
if [ "$1" -gt 0 ] && [ "$1" -le "$MIRRORS" ]; then
url=$($func "$id")
fi
echo "$url"
return 0
@ -558,7 +510,7 @@ validVersion() {
isESD "$id" && return 0
isMido "$id" && return 0
for i in {1..9}
for i in {1..MIRRORS}
do
url=$(getLink "$i" "$id")
@ -661,10 +613,12 @@ configXP() {
fi
if [[ "${arch,,}" == "x86" ]]; then
# Windows XP Pro x86 generic key (no activation)
# Windows XP Professional x86 generic key (no activation, trial-only)
# This is not a pirated key, it comes from the official MS documentation.
key="DR8GV-C8V6J-BYXHG-7PYJR-DB66Y"
else
# Windows XP Pro x64 generic key (no activation)
# Windows XP Professional x64 generic key (no activation, trial-only)
# This is not a pirated key, it comes from the official MS documentation.
key="B2RBK-7KPT9-4JP6X-QQFWM-PJD6G"
fi