diff --git a/src/install.sh b/src/install.sh index f9bd402..90dd92f 100644 --- a/src/install.sh +++ b/src/install.sh @@ -22,7 +22,11 @@ backup () { fi - mkdir -p "$root" + if ! makeDir "$root"; then + error "Failed to create directory \"$root\" !" + return 1 + fi + local folder="$name" local dir="$root/$folder" @@ -34,7 +38,11 @@ backup () { done rm -rf "$dir" - mkdir -p "$dir" + + if ! makeDir "$dir"; then + error "Failed to create directory \"$dir\" !" + return 1 + fi [ -f "$iso" ] && mv -f "$iso" "$dir/" find "$STORAGE" -maxdepth 1 -type f -iname 'data.*' -not -iname '*.iso' -exec mv -n {} "$dir/" \; @@ -156,7 +164,9 @@ startInstall() { ! backup "" && error "Backup failed!" fi - mkdir -p "$TMP" + if ! makeDir "$TMP"; then + error "Failed to create directory \"$TMP\" !" + fi if [ -z "$CUSTOM" ]; then @@ -188,6 +198,10 @@ finishInstall() { error "Failed to find ISO file: $iso" && return 1 fi + if [[ "$iso" == "$STORAGE/"* ]]; then + ! setOwner "$iso" && error "Failed to set the owner for \"$iso\" !" + fi + if [[ "$aborted" != [Yy1]* ]]; then # Mark ISO as prepared via magic byte byte="16" && [[ "$MANUAL" == [Yy1]* ]] && byte="17" @@ -196,56 +210,78 @@ finishInstall() { fi fi - cp -f /run/version "$STORAGE/windows.ver" + local file="$STORAGE/windows.ver" + cp -f /run/version "$file" + ! setOwner "$file" && error "Failed to set the owner for \"$file\" !" if [[ "$iso" == "$STORAGE/"* ]]; then if [[ "$aborted" != [Yy1]* ]] || [ -z "$CUSTOM" ]; then base=$(basename "$iso") - echo "$base" > "$STORAGE/windows.base" + file="$STORAGE/windows.base" + echo "$base" > "$file" + ! setOwner "$file" && error "Failed to set the owner for \"$file\" !" fi fi if [[ "${PLATFORM,,}" == "x64" ]]; then if [[ "${BOOT_MODE,,}" == "windows_legacy" ]]; then - echo "$BOOT_MODE" > "$STORAGE/windows.mode" + file="$STORAGE/windows.mode" + echo "$BOOT_MODE" > "$file" + ! setOwner "$file" && error "Failed to set the owner for \"$file\" !" if [[ "${MACHINE,,}" != "q35" ]]; then - echo "$MACHINE" > "$STORAGE/windows.old" + file="$STORAGE/windows.old" + echo "$MACHINE" > "$file" + ! setOwner "$file" && error "Failed to set the owner for \"$file\" !" fi else # Enable secure boot + TPM on manual installs as Win11 requires if [[ "$MANUAL" == [Yy1]* || "$aborted" == [Yy1]* ]]; then if [[ "${DETECTED,,}" == "win11"* ]]; then BOOT_MODE="windows_secure" - echo "$BOOT_MODE" > "$STORAGE/windows.mode" + file="$STORAGE/windows.mode" + echo "$BOOT_MODE" > "$file" + ! setOwner "$file" && error "Failed to set the owner for \"$file\" !" fi fi # Enable secure boot on multi-socket systems to workaround freeze if [ -n "$SOCKETS" ] && [[ "$SOCKETS" != "1" ]]; then BOOT_MODE="windows_secure" - echo "$BOOT_MODE" > "$STORAGE/windows.mode" + file="$STORAGE/windows.mode" + echo "$BOOT_MODE" > "$file" + ! setOwner "$file" && error "Failed to set the owner for \"$file\" !" fi fi fi if [ -n "${ARGS:-}" ]; then ARGUMENTS="$ARGS ${ARGUMENTS:-}" - echo "$ARGS" > "$STORAGE/windows.args" + file="$STORAGE/windows.args" + echo "$ARGS" > "$file" + ! setOwner "$file" && error "Failed to set the owner for \"$file\" !" fi if [ -n "${VGA:-}" ] && [[ "${VGA:-}" != "virtio"* ]]; then - echo "$VGA" > "$STORAGE/windows.vga" + file="$STORAGE/windows.vga" + echo "$VGA" > "$file" + ! setOwner "$file" && error "Failed to set the owner for \"$file\" !" fi if [ -n "${USB:-}" ] && [[ "${USB:-}" != "qemu-xhci"* ]]; then - echo "$USB" > "$STORAGE/windows.usb" + file="$STORAGE/windows.usb" + echo "$USB" > "$file" + ! setOwner "$file" && error "Failed to set the owner for \"$file\" !" fi if [ -n "${DISK_TYPE:-}" ] && [[ "${DISK_TYPE:-}" != "scsi" ]]; then - echo "$DISK_TYPE" > "$STORAGE/windows.type" + file="$STORAGE/windows.type" + echo "$DISK_TYPE" > "$file" + ! setOwner "$file" && error "Failed to set the owner for \"$file\" !" fi if [ -n "${ADAPTER:-}" ] && [[ "${ADAPTER:-}" != "virtio-net-pci" ]]; then - echo "$ADAPTER" > "$STORAGE/windows.net" + file="$STORAGE/windows.net" + echo "$ADAPTER" > "$file" + ! setOwner "$file" && error "Failed to set the owner for \"$file\" !" fi rm -rf "$TMP" @@ -351,7 +387,10 @@ extractESD() { fi rm -rf "$dir" - mkdir -p "$dir" + + if ! makeDir "$dir"; then + error "Failed to create directory \"$dir\" !" && return 1 + fi size=9606127360 size_gb=$(formatBytes "$size") @@ -486,14 +525,17 @@ extractImage() { info "$msg..." && html "$msg..." rm -rf "$dir" - mkdir -p "$dir" + + if ! makeDir "$dir"; then + error "Failed to create directory \"$dir\" !" && return 1 + fi size=$(stat -c%s "$iso") size_gb=$(formatBytes "$size") space=$(df --output=avail -B 1 "$dir" | tail -n 1) space_gb=$(formatBytes "$space") - if ((size<100000000)); then + if (( size < 100000000 )); then error "Invalid ISO file: Size is smaller than 100 MB" && return 1 fi @@ -1177,6 +1219,8 @@ buildImage() { [[ "$error" != "$hide" ]] && echo "$error" mv -f "$out" "$BOOT" || return 1 + ! setOwner "$BOOT" && error "Failed to set the owner for \"$BOOT\" !" + return 0 }