-
Notifications
You must be signed in to change notification settings - Fork 25
/
build-iso
executable file
·74 lines (63 loc) · 1.78 KB
/
build-iso
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
#!/bin/sh
set -e
. "$(dirname "$0")/config.sh"
ORIG="work/ubuntu-$VERSION-$DISTRO-$ARCH.iso"
COPY="work/ubuntu-$VERSION-$DISTRO-$ARCH"
ISO="work/$NICKNAME-ubuntu-$VERSION-$DISTRO-$ARCH.iso"
MOUNT="work/mount"
PLATFORM=$(uname)
# Download the original ISO if it isn't present already.
[ -f "$ORIG" ] || curl -L -o "$ORIG" \
"http://releases.ubuntu.com/$VERSION/ubuntu-$VERSION-$DISTRO-$ARCH.iso"
rm -rf "$MOUNT"
mkdir "$MOUNT"
echo Mounting ISO
# Make a writable copy of the original ISO.
if [ "$PLATFORM" = "Darwin" ]; then
# os x
DEVNODE=$(sudo hdiutil attach -nomount "$ORIG" | head -1 | awk "{print \$1}")
sudo mount -t cd9660 "$DEVNODE" "$MOUNT"
else
# linux
sudo mount -o loop "$ORIG" "$MOUNT"
fi
echo Syncing files from ISO
rsync -a "$MOUNT/" "$COPY"
echo Unmounting ISO
sudo umount "$MOUNT"
if [ "$PLATFORM" = "Darwin" ]; then
sudo hdiutil eject "$DEVNODE"
fi
rm -rf "$MOUNT"
chmod -R +w "$COPY"
echo Injecting custom configs
# Customize the writable copy.
cp "isolinux.cfg" "$COPY/isolinux/"
m4 \
-D __HOST__="$HOST" \
-D __DOMAIN__="$DOMAIN" \
-D __KERNEL__="linux-$([ "$ARCH" = "i386" ] \
&& echo generic-pae \
|| echo server
)" \
-D __ROOT_PASSWORD__="$ROOT_PASSWORD" \
-D __USERNAME__="$USERNAME" \
-D __PASSWORD__="$PASSWORD" \
"unattended.seed.m4" > "$COPY/preseed/unattended.seed"
m4 \
-D __USERNAME__="$USERNAME" \
sudoers.m4 > "$COPY/sudoers"
cp "$PUBLIC_KEY" "auto_resize_vda.sh" "$COPY/"
m4 \
-D __USERNAME__="$USERNAME" \
-D __PUBLIC_KEY__="$PUBLIC_KEY" \
"late_command.sh.m4" > "$COPY/late_command.sh"
echo Building a custom ISO
# Build a custom ISO.
mkisofs -r -V "Ubuntu $VERSION for Terraform" \
-cache-inodes -J -l -no-emul-boot \
-b isolinux/isolinux.bin \
-c isolinux/boot.cat \
-boot-load-size 4 -boot-info-table \
-o "$ISO" "$COPY"
echo Built "$ISO"