-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathautoinstall.sh
executable file
·228 lines (206 loc) · 5.58 KB
/
autoinstall.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
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
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
#! /bin/bash
#
# General configuration
#
basedir="/media/psf/Home/installation-scripts/ubuntu-unattended"
downloads="/media/psf/Home/Downloads"
tmpdir="${TMPDIR:-/tmp}"
builddir="$tmpdir/build.$$"
mntdir="$tmpdir/mnt.$$"
#
# Ubuntu release selection
#
release_name="precise"
release_version="12.04.2"
release_variant="server"
release_architecture="amd64"
release_base_url="http://releases.ubuntu.com"
release_base_name="ubuntu-$release_version-$release_variant-$release_architecture"
release_image_file="$release_base_name.iso"
release_url="$release_base_url/$release_name/$release_image_file"
#
# Target settings
#
target_base_name="${release_base_name}-auto"
target_directory="$basedir"
target_image_file="$target_base_name.iso"
progress() {
echo "$*" >&2
}
error() {
code="$1"; shift
echo "ERROR: $*" >&2
exit $code
}
create_directory() {
path="$1"
if [ ! -d "$path" ]; then
progress "Creating directory $path..."
mkdir -p "$path" || error 2 "Failed to create directory $path"
fi
}
extract_iso() {
archive="$1"
if [ ! -r "$archive" ]; then
error 1 "Cannot read ISO image $archive."
fi
directory="$2"
if [ ! -d "$directory" ]; then
mkdir "$directory" || exit 2 "Cannot extract CD to $directory"
fi
progress "Mounting image $archive (you may be asked for your password to authorize)..."
create_directory "$mntdir"
sudo mount -r -o loop "$archive" "$mntdir" || error 2 "Failed to mount image $archive"
progress "Copying image contents..."
cp -rT "$mntdir" "$directory" || error 2 "Failed to copy content of image $archive to $directory"
chmod -R u+w "$directory"
progress "Unmounting image $archive from $mntdir..."
sudo umount "$mntdir"
rmdir "$mntdir"
}
preset_language() {
progress "Presetting language to 'en'..."
echo "en" >"isolinux/lang" || error 2 "Failed to write $(pwd)/isolinux/lang"
}
create_kscfg() {
if [ ! -f "ks.cfg" ]; then
progress "Create ks.cfg file..."
cat >"ks.cfg" <<EOF
#Generated by Kickstart Configurator
#platform=AMD64 or Intel EM64T
#System language
lang en_US
#Language modules to install
langsupport en_US
#System keyboard
keyboard gb_mac_intl
#System mouse
mouse
#System timezone
timezone --utc Europe/Berlin
#Root password
rootpw --disabled
#Initial user
user akaadmin --fullname "AKA Admin" --password changemesoon
#Reboot after installation
reboot
#Use text mode install
text
#Install OS instead of upgrade
install
#Use CDROM installation media
cdrom
#System bootloader configuration
bootloader --location=mbr
#Clear the Master Boot Record
zerombr yes
#Partition clearing information
clearpart --all --initlabel
#Disk partitioning information
part / --fstype ext4 --size 1 --grow
part swap --recommended
#System authorization infomation
auth --useshadow --enablemd5
#Network information
network --bootproto=dhcp --device=eth0
network --bootproto=static --ip=10.0.2.2 --netmask=255.255.255.0 --gateway=10.0.2.1 --nameserver=10.0.2.1 --device=eth1
#Firewall configuration
firewall --disabled
#Do not configure the X Window System
skipx
%packages
@ ubuntu-server
openssh-server
%post --nochroot
echo done
EOF
fi
}
create_kspreseed() {
if [ ! -f "ks.preseed" ]; then
progress "Create ks.preseed file..."
cat >"ks.preseed" <<EOF
d-i partman/confirm_write_new_label boolean true
d-i partman/choose_partition \
select Finish partitioning and write changes to disk
d-i partman/confirm boolean true
EOF
fi
}
patch_txtcfg() {
(cd "isolinux";
patch -p0 <<EOF
*** txt.cfg.orig 2013-05-14 10:06:19.000000000 +0200
--- txt.cfg 2013-05-14 10:07:54.000000000 +0200
***************
*** 2,8 ****
label install
menu label ^Install Ubuntu Server
kernel /install/vmlinuz
! append file=/cdrom/preseed/ubuntu-server.seed vga=788 initrd=/install/initrd.gz quiet --
label cloud
menu label ^Multiple server install with MAAS
kernel /install/vmlinuz
--- 2,8 ----
label install
menu label ^Install Ubuntu Server
kernel /install/vmlinuz
! append file=/cdrom/preseed/ubuntu-server.seed initrd=/install/initrd.gz ks=cdrom:/ks.cfg preseed/file=/cdrom/ks.preseed --
label cloud
menu label ^Multiple server install with MAAS
kernel /install/vmlinuz
EOF
)
}
patch_isolinuxcfg() {
(cd "isolinux";
patch -p0 <<EOF
*** isolinux.cfg.orig 2013-05-14 10:20:37.000000000 +0200
--- isolinux.cfg 2013-05-14 10:20:50.000000000 +0200
***************
*** 2,6 ****
include menu.cfg
default vesamenu.c32
prompt 0
! timeout 0
ui gfxboot bootlogo
--- 2,6 ----
include menu.cfg
default vesamenu.c32
prompt 0
! timeout 5
ui gfxboot bootlogo
EOF
)
}
modify_release() {
preset_language && \
create_kscfg && \
create_kspreseed && \
patch_txtcfg && \
patch_isolinuxcfg
}
create_image() {
if [ ! -f "$target_directory/$target_image_file" ]; then
if [ ! -f "$downloads/$release_image_file" ]; then
progress "Downloading Ubuntu $release_name $release_variant..."
curl "$release_url" -o "$downloads/$release_image_file"
fi
create_directory "$builddir"
extract_iso "$downloads/$release_image_file" "$builddir"
(cd "$builddir" && modify_release
) || error 2 "Failed to modify image"
create_directory "$target_directory"
progress "Creating ISO image $target_image_file..."
mkisofs -D -r -V "UNATTENDED_UBUNTU" -cache-inodes -J -l \
-b isolinux/isolinux.bin \
-c isolinux/boot.cat -no-emul-boot -boot-load-size 4 \
-boot-info-table \
-o "$target_directory/$target_image_file" \
"$builddir" || error 2 "Failed to create image $target_image_file"
if [ "x$builddir" != x -a "x$builddir" != "x/" ]; then
rm -rf "$builddir"
fi
fi
}
create_image