-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild.sh
89 lines (74 loc) · 1.88 KB
/
build.sh
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
#!/bin/sh
set -eu
locale () {
case "$(echo $1 | cut -d _ -f 3)" in
English) echo en-us;;
EnglishInternational) echo en-gb;;
*) echo unable to determine locale Windows >&2; exit 1;;
esac
}
[ -f "${IMAGE:-}" ] || {
echo IMAGE either not set or non-existent >&2
exit 1
}
_IMAGE=$(basename "$IMAGE")
case "$_IMAGE" in
Win11_*|Windows11_*) WINVER=11;;
Win10_*|Windows10_*) WINVER=10;;
*) echo unable to determine version of Windows >&2;
exit 1
;;
esac
case "$_IMAGE" in
# main
Win1[10]_*) VERSION=$(echo $_IMAGE | cut -d _ -f 2)
LOCALE=$(locale $_IMAGE)
;;
# insider preview
Windows1[10]_*) VERSION=$(echo $_IMAGE | cut -d _ -f 6 | cut -d . -f 1-2 | tr . -)
LOCALE=$(echo $_IMAGE | cut -d _ -f 5)
;;
*) echo unable to determine version of Windows >&2;
exit 1
;;
esac
: ${VIRTIO:=virtio-win.iso}
[ -f "$VIRTIO" ] || {
echo VIRTIO either not set or non-existent >&2
exit 1
}
WINSSH=$(find . -mindepth 1 -maxdepth 1 -type f -name 'OpenSSH-Win64-v*.msi' | sort -r | head -n 1)
[ "$WINSSH" ] || {
echo "unable to find 'OpenSSH-Win64-v*.msi'" >&2
exit 1
}
rm -rf assets
mkdir -p assets
ln $WINSSH assets/OpenSSH-Win64.msi
[ "${ACCEL:-}" ] || case "$(uname -s)" in
Linux) ACCEL=kvm:tcg;;
Darwin) ACCEL=hcf:tcg;;
esac
# support screen resizing (virtio seems not to work)
VGA=qxl
set -- -only=qemu.main \
-var iso="$IMAGE" \
-var iso_virtio="$VIRTIO" \
${ACCEL:+-var accel=$ACCEL} \
${CORES:+-var cores=$CORES} \
${RAM:+-var ram=$RAM} \
${VGA:+-var vga=$VGA} \
${SPICE:+-var spice=$SPICE}
m4 \
-D WINVER=$WINVER \
-D VERSION=$VERSION \
-D LOCALE=$LOCALE \
-D PASSWORD=${PASSWORD:-password} \
Autounattend.xml.m4 > Autounattend.xml
# /tmp is usually noexec...unless you are insane...
export TMPDIR="$PWD"
packer init setup.pkr.hcl
packer validate "$@" setup.pkr.hcl
packer build -on-error=ask "$@" setup.pkr.hcl
qemu-img snapshot -c initial output/packer-main
exit 0