mirror of
https://github.com/dockur/windows.git
synced 2026-07-07 05:07:26 +01:00
feat: Normalize boolean option handling (#1784)
This commit is contained in:
+2
-2
@@ -1287,7 +1287,7 @@ isMido() {
|
||||
local lang="$2"
|
||||
local sum
|
||||
|
||||
[[ "${MIDO:-}" == [Nn]* ]] && return 1
|
||||
disabled "${MIDO:-}" && return 1
|
||||
|
||||
sum=$(getMido "$id" "en" "sum")
|
||||
[ -n "$sum" ] && return 0
|
||||
@@ -1300,7 +1300,7 @@ isESD() {
|
||||
local id="$1"
|
||||
local lang="$2"
|
||||
|
||||
[[ "${ESD:-}" == [Nn]* ]] && return 1
|
||||
disabled "${ESD:-}" && return 1
|
||||
|
||||
case "${id,,}" in
|
||||
"win11${PLATFORM,,}" | "win10${PLATFORM,,}" )
|
||||
|
||||
+1
-1
@@ -46,7 +46,7 @@ sed -u \
|
||||
-e 's/failed to load Boot/skipped Boot/g' \
|
||||
-e 's/0): Not Found/0)/g' &
|
||||
|
||||
if [[ "$SHUTDOWN" != [Yy1]* ]]; then
|
||||
if ! enabled "$SHUTDOWN"; then
|
||||
exec "${cmd[@]}" ${ARGS:+ $ARGS} >"$pipe"
|
||||
fi
|
||||
|
||||
|
||||
+14
-14
@@ -110,7 +110,7 @@ skipInstall() {
|
||||
# Check if the ISO was already processed by our script
|
||||
magic=$(dd if="$iso" bs=1 count=1 status=none | tr -d '\000')
|
||||
magic="$(printf '%s' "$magic" | od -A n -t x1 -v | tr -d ' \n')"
|
||||
byte="16" && [[ "$MANUAL" == [Yy1]* ]] && byte="17"
|
||||
byte="16" && enabled "$MANUAL" && byte="17"
|
||||
|
||||
if [[ "$magic" != "$byte" ]]; then
|
||||
|
||||
@@ -215,7 +215,7 @@ finishInstall() {
|
||||
|
||||
if [[ "$aborted" != [Yy1]* ]]; then
|
||||
# Mark ISO as prepared via magic byte
|
||||
byte="16" && [[ "$MANUAL" == [Yy1]* ]] && byte="17"
|
||||
byte="16" && enabled "$MANUAL" && byte="17"
|
||||
if ! printf '%b' "\x$byte" | dd of="$iso" bs=1 seek=0 count=1 conv=notrunc status=none; then
|
||||
warn "failed to set magic byte in ISO file: $iso"
|
||||
fi
|
||||
@@ -243,7 +243,7 @@ finishInstall() {
|
||||
fi
|
||||
else
|
||||
# Enable secure boot + TPM on manual installs as Win11 requires
|
||||
if [[ "$MANUAL" == [Yy1]* || "$aborted" == [Yy1]* ]]; then
|
||||
if enabled "$MANUAL" || [[ "$aborted" == [Yy1]* ]]; then
|
||||
if [[ "${DETECTED,,}" == "win11"* ]]; then
|
||||
BOOT_MODE="windows_secure"
|
||||
file="$STORAGE/windows.mode"
|
||||
@@ -296,7 +296,7 @@ abortInstall() {
|
||||
local efi
|
||||
|
||||
[[ "${iso,,}" == *".esd" ]] && exit 60
|
||||
[[ "${UNPACK:-}" == [Yy1]* ]] && exit 60
|
||||
enabled "${UNPACK:-}" && exit 60
|
||||
|
||||
efi=$(find "$dir" -maxdepth 1 -type d -iname efi -print -quit)
|
||||
|
||||
@@ -556,7 +556,7 @@ extractImage() {
|
||||
|
||||
fKill "progress.sh"
|
||||
|
||||
if [[ "${UNPACK:-}" != [Yy1]* ]]; then
|
||||
if ! enabled "${UNPACK:-}"; then
|
||||
|
||||
LABEL=$(isoinfo -d -i "$iso" | sed -n 's/Volume id: //p')
|
||||
|
||||
@@ -739,7 +739,7 @@ detectImage() {
|
||||
|
||||
skipVersion "${DETECTED,,}" && return 0
|
||||
|
||||
if ! setXML "" && [[ "$MANUAL" != [Yy1]* ]]; then
|
||||
if ! setXML "" && ! enabled "$MANUAL"; then
|
||||
MANUAL="Y"
|
||||
desc=$(printEdition "$DETECTED" "this version")
|
||||
warn "the answer file for $desc was not found ($DETECTED.xml), $FB."
|
||||
@@ -776,7 +776,7 @@ detectImage() {
|
||||
|
||||
if [ -z "$DETECTED" ]; then
|
||||
msg="Failed to determine Windows version from image"
|
||||
if setXML "" || [[ "$MANUAL" == [Yy1]* ]]; then
|
||||
if setXML "" || enabled "$MANUAL"; then
|
||||
info "${msg}!"
|
||||
else
|
||||
MANUAL="Y"
|
||||
@@ -803,8 +803,8 @@ detectImage() {
|
||||
msg="the answer file for $desc was not found ($DETECTED.xml)"
|
||||
local fallback="/run/assets/${DETECTED%%-*}.xml"
|
||||
|
||||
if setXML "$fallback" || [[ "$MANUAL" == [Yy1]* ]]; then
|
||||
[[ "$MANUAL" != [Yy1]* ]] && warn "${msg}."
|
||||
if setXML "$fallback" || enabled "$MANUAL"; then
|
||||
! enabled "$MANUAL" && warn "${msg}."
|
||||
else
|
||||
MANUAL="Y"
|
||||
warn "${msg}, $FB."
|
||||
@@ -1047,7 +1047,7 @@ updateImage() {
|
||||
|
||||
if [ ! -s "$asset" ] || [ ! -f "$asset" ]; then
|
||||
asset=""
|
||||
if [[ "$MANUAL" != [Yy1]* ]]; then
|
||||
if ! enabled "$MANUAL"; then
|
||||
MANUAL="Y"
|
||||
warn "no answer file provided, $FB."
|
||||
fi
|
||||
@@ -1093,7 +1093,7 @@ updateImage() {
|
||||
fi
|
||||
fi
|
||||
|
||||
if [[ "$MANUAL" != [Yy1]* ]]; then
|
||||
if ! enabled "$MANUAL"; then
|
||||
|
||||
xml=$(basename "$asset")
|
||||
info "Adding $xml for automatic installation..."
|
||||
@@ -1111,7 +1111,7 @@ updateImage() {
|
||||
|
||||
fi
|
||||
|
||||
if [[ "$MANUAL" == [Yy1]* ]]; then
|
||||
if enabled "$MANUAL"; then
|
||||
|
||||
wimlib-imagex update "$wim" "$index" --command "delete --force /$file" > /dev/null || true
|
||||
|
||||
@@ -1124,11 +1124,11 @@ updateImage() {
|
||||
fi
|
||||
|
||||
local find="$file"
|
||||
[[ "$MANUAL" == [Yy1]* ]] && find="$org"
|
||||
enabled "$MANUAL" && find="$org"
|
||||
path=$(find "$dir" -maxdepth 1 -type f -iname "$find" -print -quit)
|
||||
|
||||
if [ -f "$path" ]; then
|
||||
if [[ "$MANUAL" != [Yy1]* ]]; then
|
||||
if ! enabled "$MANUAL"; then
|
||||
mv -f "$path" "${path%.*}.org"
|
||||
else
|
||||
mv -f "$path" "${path%.*}.xml"
|
||||
|
||||
+17
-17
@@ -90,15 +90,15 @@ download_windows() {
|
||||
# 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
|
||||
[[ "$DEBUG" == [Yy1]* ]] && echo "Parsing download page: ${url}"
|
||||
enabled "$DEBUG" && echo "Parsing download page: ${url}"
|
||||
download_page_html=$(curl --silent --max-time 30 --user-agent "$user_agent" --header "Accept:" --max-filesize 1M --fail --proto =https --tlsv1.2 --http1.1 -- "$url") || {
|
||||
handle_curl_error "$?" "Microsoft"
|
||||
return $?
|
||||
}
|
||||
|
||||
[[ "$DEBUG" == [Yy1]* ]] && echo -n "Getting Product edition ID: "
|
||||
enabled "$DEBUG" && echo -n "Getting Product edition ID: "
|
||||
product_edition_id=$(echo "$download_page_html" | grep -Eo '<option value="[0-9]+">Windows' | cut -d '"' -f 2 | head -n 1 | tr -cd '0-9' | head -c 16)
|
||||
[[ "$DEBUG" == [Yy1]* ]] && echo "$product_edition_id"
|
||||
enabled "$DEBUG" && echo "$product_edition_id"
|
||||
|
||||
if [ -z "$product_edition_id" ]; then
|
||||
error "Product edition ID not found!"
|
||||
@@ -110,7 +110,7 @@ download_windows() {
|
||||
org_id="y6jn8c31"
|
||||
vls_url="https://vlscppe.microsoft.com/tags?org_id=$org_id&session_id=$session_id"
|
||||
|
||||
[[ "$DEBUG" == [Yy1]* ]] && echo "Getting Session ID: $session_id"
|
||||
enabled "$DEBUG" && echo "Getting Session ID: $session_id"
|
||||
|
||||
# Permit Session ID
|
||||
curl --silent --max-time 30 --output /dev/null --user-agent "$user_agent" --header "Accept:" --max-filesize 100K --fail --proto =https --tlsv1.2 --http1.1 -- "$vls_url" || {
|
||||
@@ -125,7 +125,7 @@ download_windows() {
|
||||
instance_id="560dc9f3-1aa5-4a2f-b63c-9e18f8d0e175"
|
||||
ov_url="https://ov-df.microsoft.com/mdt.js?instanceId=$instance_id&PageId=si&session_id=$session_id"
|
||||
|
||||
[[ "$DEBUG" == [Yy1]* ]] && echo -n "Getting OV data: "
|
||||
enabled "$DEBUG" && echo -n "Getting OV data: "
|
||||
|
||||
ov_data=$(curl --silent --max-time 30 --user-agent "$user_agent" --header "Accept:" --max-filesize 1M --fail --proto =https --tlsv1.2 --http1.1 -- "$ov_url") || {
|
||||
handle_curl_error "$?" "Microsoft"
|
||||
@@ -145,7 +145,7 @@ download_windows() {
|
||||
return 1
|
||||
fi
|
||||
|
||||
[[ "$DEBUG" == [Yy1]* ]] && echo "$ovw"
|
||||
enabled "$DEBUG" && echo "$ovw"
|
||||
|
||||
sleep 0.2
|
||||
|
||||
@@ -154,7 +154,7 @@ download_windows() {
|
||||
mdt=$(date +%s%3N)
|
||||
ov_url="https://ov-df.microsoft.com/?session_id=$session_id&CustomerId=$instance_id&PageId=si&w=$ovw&mdt=$mdt&rticks=$rticks"
|
||||
|
||||
[[ "$DEBUG" == [Yy1]* ]] && echo "Sending OV reply: $instance_id"
|
||||
enabled "$DEBUG" && echo "Sending OV reply: $instance_id"
|
||||
|
||||
curl --silent --max-time 30 --output /dev/null --user-agent "$user_agent" --header "Accept:" --max-filesize 100K --fail --proto =https --tlsv1.2 --http1.1 -- "$ov_url" || {
|
||||
# This should only happen if there's been some change to how this API works
|
||||
@@ -162,7 +162,7 @@ download_windows() {
|
||||
return $?
|
||||
}
|
||||
|
||||
[[ "$DEBUG" == [Yy1]* ]] && echo -n "Getting language SKU ID: "
|
||||
enabled "$DEBUG" && echo -n "Getting language SKU ID: "
|
||||
|
||||
sku_url="https://www.microsoft.com/software-download-connector/api/getskuinformationbyproductedition?profile=$profile&ProductEditionId=$product_edition_id&SKU=undefined&friendlyFileName=undefined&Locale=en-US&sessionID=$session_id"
|
||||
language_skuid_json=$(curl --silent --max-time 30 --request GET --user-agent "$user_agent" --referer "$url" --header "Accept:" --max-filesize 100K --fail --proto =https --tlsv1.2 --http1.1 -- "$sku_url") || {
|
||||
@@ -178,8 +178,8 @@ download_windows() {
|
||||
return 1
|
||||
fi
|
||||
|
||||
[[ "$DEBUG" == [Yy1]* ]] && echo "$sku_id"
|
||||
[[ "$DEBUG" == [Yy1]* ]] && echo "Getting ISO download link..."
|
||||
enabled "$DEBUG" && echo "$sku_id"
|
||||
enabled "$DEBUG" && echo "Getting ISO download link..."
|
||||
|
||||
# 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)
|
||||
@@ -267,7 +267,7 @@ download_windows_eval() {
|
||||
local iso_download_page_html=""
|
||||
local url="https://www.microsoft.com/en-us/evalcenter/download-$windows_version"
|
||||
|
||||
[[ "$DEBUG" == [Yy1]* ]] && echo "Parsing download page: ${url}"
|
||||
enabled "$DEBUG" && echo "Parsing download page: ${url}"
|
||||
iso_download_page_html=$(curl --silent --max-time 30 --user-agent "$user_agent" --location --max-filesize 1M --fail --proto =https --tlsv1.2 --http1.1 -- "$url") || {
|
||||
handle_curl_error "$?" "Microsoft"
|
||||
return $?
|
||||
@@ -279,7 +279,7 @@ download_windows_eval() {
|
||||
return 1
|
||||
fi
|
||||
|
||||
[[ "$DEBUG" == [Yy1]* ]] && echo "Getting download link.."
|
||||
enabled "$DEBUG" && echo "Getting download link.."
|
||||
|
||||
filter="https://go.microsoft.com/fwlink/?linkid=[0-9]\+&clcid=0x[0-9a-z]\+&culture=${culture,,}&country=${country,,}"
|
||||
|
||||
@@ -350,7 +350,7 @@ download_windows_eval() {
|
||||
fi ;;
|
||||
"arm64" )
|
||||
if [[ "${iso_download_link,,}" != *"a64"* && "${iso_download_link,,}" != *"arm64"* ]]; then
|
||||
if [[ "$DEBUG" == [Yy1]* ]]; then
|
||||
if enabled "$DEBUG"; then
|
||||
echo "Found download link: $iso_download_link"
|
||||
echo "Link for ARM platform currently not available!"
|
||||
fi
|
||||
@@ -358,7 +358,7 @@ download_windows_eval() {
|
||||
fi ;;
|
||||
esac
|
||||
|
||||
if [[ "$DEBUG" == [Yy1]* && "$VERIFY" == [Yy1]* && "${lang,,}" == "en"* ]]; then
|
||||
if enabled "$DEBUG" && enabled "$VERIFY" && [[ "${lang,,}" == "en"* ]]; then
|
||||
compare=$(getMido "$id" "$lang" "")
|
||||
if [[ "${iso_download_link,,}" != "${compare,,}" ]]; then
|
||||
echo "Retrieved link does not match the fixed link: $compare"
|
||||
@@ -632,7 +632,7 @@ verifyFile() {
|
||||
local check="$4"
|
||||
|
||||
if [ -n "$size" ] && [[ "$total" != "$size" && "$size" != "0" ]]; then
|
||||
if [[ "$VERIFY" == [Yy1]* || "$DEBUG" == [Yy1]* ]]; then
|
||||
if enabled "$VERIFY" || enabled "$DEBUG"; then
|
||||
warn "The downloaded file has a different size ( $total bytes) than expected ( $size bytes). Please report this at $SUPPORT/issues"
|
||||
fi
|
||||
fi
|
||||
@@ -641,7 +641,7 @@ verifyFile() {
|
||||
local algo="SHA256"
|
||||
|
||||
[ -z "$check" ] && return 0
|
||||
[[ "$VERIFY" != [Yy1]* ]] && return 0
|
||||
! enabled "$VERIFY" && return 0
|
||||
[[ "${#check}" == "40" ]] && algo="SHA1"
|
||||
|
||||
local msg="Verifying downloaded ISO..."
|
||||
@@ -700,7 +700,7 @@ downloadFile() {
|
||||
fi
|
||||
|
||||
info "$msg..."
|
||||
[[ "$DEBUG" == [Yy1]* ]] && echo "Downloading: $url"
|
||||
enabled "$DEBUG" && echo "Downloading: $url"
|
||||
|
||||
{ wget "$url" -O "$iso" --continue -q --timeout=30 --no-http-keep-alive --user-agent "$agent" --show-progress "$progress"; rc=$?; } || :
|
||||
|
||||
|
||||
+2
-2
@@ -101,7 +101,7 @@ finish() {
|
||||
local file="$STORAGE/windows.boot"
|
||||
touch "$file"
|
||||
! setOwner "$file" && error "Failed to set the owner for \"$file\" !"
|
||||
if [[ "$REMOVE" != [Nn]* ]]; then
|
||||
if ! disabled "$REMOVE"; then
|
||||
rm -f "$BOOT" 2>/dev/null || true
|
||||
fi
|
||||
fi
|
||||
@@ -219,7 +219,7 @@ graceful_shutdown() {
|
||||
finish "$code"
|
||||
}
|
||||
|
||||
[[ "$SHUTDOWN" != [Yy1]* ]] && return 0
|
||||
! enabled "$SHUTDOWN" && return 0
|
||||
[ -n "${QEMU_TIMEOUT:-}" ] && TIMEOUT="$QEMU_TIMEOUT"
|
||||
|
||||
_trap graceful_shutdown SIGTERM SIGHUP SIGABRT SIGQUIT
|
||||
|
||||
+9
-9
@@ -13,10 +13,10 @@ SMB_PID="/var/run/samba/smbd.pid"
|
||||
|
||||
rm -f "$SMB_PID" "$NMB_PID" "$DDN_PID"
|
||||
|
||||
[[ "$SAMBA" == [Nn]* ]] && return 0
|
||||
[[ "$NETWORK" == [Nn]* ]] && return 0
|
||||
disabled "$SAMBA" && return 0
|
||||
disabled "$NETWORK" && return 0
|
||||
|
||||
if [[ "$DHCP" == [Yy1]* ]]; then
|
||||
if enabled "$DHCP"; then
|
||||
socket="$IP"
|
||||
hostname="$IP"
|
||||
interfaces="$VM_NET_DEV"
|
||||
@@ -37,7 +37,7 @@ fi
|
||||
|
||||
html "Initializing shared folder..."
|
||||
SAMBA_CONFIG="/etc/samba/smb.conf"
|
||||
[[ "$DEBUG" == [Yy1]* ]] && echo "Starting Samba daemon..."
|
||||
enabled "$DEBUG" && echo "Starting Samba daemon..."
|
||||
|
||||
addShare() {
|
||||
local dir="$1"
|
||||
@@ -179,7 +179,7 @@ if ! smbd -l /var/log/samba; then
|
||||
error "Failed to start Samba daemon!"
|
||||
fi
|
||||
|
||||
if [[ "$SAMBA_DEBUG" == [Yy1]* ]]; then
|
||||
if enabled "$SAMBA_DEBUG"; then
|
||||
tail -fn +0 /var/log/samba/log.smbd --pid=$$ &
|
||||
fi
|
||||
|
||||
@@ -191,7 +191,7 @@ esac
|
||||
if [[ "${BOOT_MODE:-}" == "windows_legacy" ]]; then
|
||||
|
||||
# Enable NetBIOS on Windows 7 and lower
|
||||
[[ "$DEBUG" == [Yy1]* ]] && echo "Starting NetBIOS daemon..."
|
||||
enabled "$DEBUG" && echo "Starting NetBIOS daemon..."
|
||||
|
||||
rm -f /var/log/samba/log.nmbd
|
||||
|
||||
@@ -200,14 +200,14 @@ if [[ "${BOOT_MODE:-}" == "windows_legacy" ]]; then
|
||||
error "Failed to start NetBIOS daemon!"
|
||||
fi
|
||||
|
||||
if [[ "$SAMBA_DEBUG" == [Yy1]* ]]; then
|
||||
if enabled "$SAMBA_DEBUG"; then
|
||||
tail -fn +0 /var/log/samba/log.nmbd --pid=$$ &
|
||||
fi
|
||||
|
||||
else
|
||||
|
||||
# Enable Web Service Discovery on Vista and up
|
||||
[[ "$DEBUG" == [Yy1]* ]] && echo "Starting wsddn daemon..."
|
||||
enabled "$DEBUG" && echo "Starting wsddn daemon..."
|
||||
rm -f /var/log/wsddn.log
|
||||
|
||||
if ! wsddn -i "${interfaces%%,*}" -H "$hostname" --unixd --log-file=/var/log/wsddn.log --pid-file="$DDN_PID"; then
|
||||
@@ -215,7 +215,7 @@ else
|
||||
error "Failed to start wsddn daemon!"
|
||||
fi
|
||||
|
||||
if [[ "$SAMBA_DEBUG" == [Yy1]* ]]; then
|
||||
if enabled "$SAMBA_DEBUG"; then
|
||||
tail -fn +0 /var/log/wsddn.log --pid=$$ &
|
||||
fi
|
||||
|
||||
|
||||
Reference in New Issue
Block a user