-
Notifications
You must be signed in to change notification settings - Fork 17
Expand file tree
/
Copy pathremove-windows-iso-prompt.sh
More file actions
executable file
·131 lines (106 loc) · 3.1 KB
/
remove-windows-iso-prompt.sh
File metadata and controls
executable file
·131 lines (106 loc) · 3.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
#!/bin/bash
set -e # Exit when any command fails
#
# Functions
#
function echo_err() {
>&2 echo "$@"
}
function show_usage() {
if [ -n "$1" ]; then
tput setaf 1
echo_err "Error: $1";
tput sgr0
fi
echo_err
echo_err "Usage: $0 <iso_file> [output_file] [OPTIONS]"
echo_err ' <iso_file> Path to Windows ISO file.'
echo_err ' [output_file] Path for modified ISO (default: <iso_file>.noprompt.iso).'
echo_err " --help, -h Display this help message."
echo_err
exit 1
}
#
# Main
#
# Parse arguments -- https://stackoverflow.com/a/14203146/33244
POSITIONAL_ARGS=()
while [[ "$#" -gt 0 ]]; do case $1 in
-h|--help) show_usage;;
-*|--*) show_usage "Unknown option: $1";;
*) POSITIONAL_ARGS+=("$1"); shift;;
esac; done
set -- "${POSITIONAL_ARGS[@]}" # restore positional parameters
ISO_FILE="$1"
if [ -z "$ISO_FILE" ]; then show_usage "You must inform an ISO file."; fi;
if [ ! -f "$ISO_FILE" ]; then
echo_err "Error: ISO file '$ISO_FILE' not found"
exit 1
fi
if [ -n "$2" ]; then
OUTPUT_FILE="$2"
else
OUTPUT_FILE="${ISO_FILE%.iso}.noprompt.iso"
fi
TEMP_DIR="/tmp/iso-mod-$$"
cleanup() {
if mountpoint -q "$TEMP_DIR/mount" 2>/dev/null; then
umount "$TEMP_DIR/mount" 2>/dev/null || true
fi
[ -d "$TEMP_DIR" ] && rm -rf "$TEMP_DIR"
}
trap cleanup EXIT
mkdir -p "$TEMP_DIR/mount"
# Get volume label using isoinfo (part of genisoimage)
VOLUME_LABEL=$(isoinfo -d -i "$ISO_FILE" 2>/dev/null | grep "Volume id:" | cut -d: -f2 | tr -d ' ')
if [ -z "$VOLUME_LABEL" ]; then
VOLUME_LABEL="WINISO"
fi
echo "Processing ISO: $ISO_FILE"
echo "Output: $OUTPUT_FILE"
echo "Volume label: $VOLUME_LABEL"
# Mount the ISO
echo "Mounting ISO..."
mount -o loop,ro "$ISO_FILE" "$TEMP_DIR/mount"
# Copy contents to writable directory
echo "Copying ISO contents..."
cp -r "$TEMP_DIR/mount" "$TEMP_DIR/contents"
# Unmount early
umount "$TEMP_DIR/mount"
# Check for no-prompt EFI image
EFI_DIR="$TEMP_DIR/contents/efi/microsoft/boot"
EFI_SYS_BIN="$EFI_DIR/efisys.bin"
EFI_SYS_NOPROMPT="$EFI_DIR/efisys_noprompt.bin"
if [ ! -f "$EFI_SYS_NOPROMPT" ]; then
echo_err "Error: efisys_noprompt.bin not found. This indicates the ISO image may be corrupted."
echo_err "Official Windows ISO images should always contain this file."
exit 1
fi
echo "Found no-prompt EFI image, replacing efisys.bin..."
# Replace the default efisys.bin with the noprompt version
cp "$EFI_SYS_NOPROMPT" "$EFI_SYS_BIN"
# Create new ISO from mount point with proper dual boot support
echo "Creating modified ISO..."
(
cd "$TEMP_DIR/contents"
genisoimage \
-allow-limited-size \
-iso-level 4 \
-U \
-D \
-N \
-joliet \
-joliet-long \
-relaxed-filenames \
-V "$VOLUME_LABEL" \
-b boot/etfsboot.com \
-no-emul-boot \
-boot-load-size 8 \
-hide boot.catalog \
-eltorito-alt-boot \
-e efi/microsoft/boot/efisys.bin \
-no-emul-boot \
-o "$OUTPUT_FILE" \
.
)
echo "Done! Modified ISO created: $OUTPUT_FILE"