|
7.1.3
by niajaba
added --part partfile argument |
1 |
#!/bin/bash
|
|
1
by Soren Hansen
Import current builder script.. |
2 |
#
|
3 |
# Ubuntu Jeos image builder
|
|
|
16
by Soren Hansen
Fixed indentation |
4 |
# Copyright (C) 2007-2008 Canonical Ltd.
|
|
1
by Soren Hansen
Import current builder script.. |
5 |
#
|
|
5
by Soren Hansen
Merged Neal's changes with a few slight modifications. |
6 |
# Authors: Soren Hansen <soren@canonical.com>
|
7 |
# Neal McBurnett <neal@mcburnett.org>
|
|
|
7
by Soren Hansen
Merged changes from Mike Frisch. |
8 |
# Michael Vogt <michael.vogt@ubuntu.com>
|
9 |
# Mike Frisch
|
|
|
7.1.3
by niajaba
added --part partfile argument |
10 |
# Nick Barcet <nick.barcet@canonical.com>
|
|
7.2.2
by nijaba
Integrated patch from onno to allow specification of username and password |
11 |
# Onno Benschop <onno@itmaze.com.au>
|
|
1
by Soren Hansen
Import current builder script.. |
12 |
#
|
13 |
# This program is free software; you can redistribute it and/or modify
|
|
14 |
# it under the terms of the GNU General Public License as published by
|
|
15 |
# the Free Software Foundation; either version 2 of the License, or
|
|
16 |
# (at your option) any later version.
|
|
17 |
#
|
|
18 |
# This program is distributed in the hope that it will be useful,
|
|
19 |
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
20 |
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
21 |
# GNU General Public License for more details.
|
|
22 |
#
|
|
23 |
# You should have received a copy of the GNU General Public License along
|
|
24 |
# with this program; if not, write to the Free Software Foundation, Inc.,
|
|
25 |
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
|
26 |
||
|
4.1.2
by Neal McBurnett
add qemu support, produce a directory not a zip, etc |
27 |
# Todo:
|
28 |
# create launchjeos command for vmware vm's
|
|
29 |
# fix perl locale warnings
|
|
30 |
# review security of running as root, messing with $DESTINATION
|
|
31 |
||
|
18
by Soren Hansen
A *lot* of silencing. |
32 |
# Keep perl inside the chroot quiet
|
33 |
LANG=C |
|
34 |
||
|
1
by Soren Hansen
Import current builder script.. |
35 |
usage () { |
36 |
cat <<EOT
|
|
|
27
by Soren Hansen
Massive refactoring.. |
37 |
usage: ubuntu-vm-builder <vm> <suite>
|
38 |
[--addpkg PKG]
|
|
39 |
[(-a|--arch) [i386,amd64]]
|
|
|
4.1.2
by Neal McBurnett
add qemu support, produce a directory not a zip, etc |
40 |
[(-d|--dest) <destination (directory)>]
|
|
1
by Soren Hansen
Import current builder script.. |
41 |
[--domain DOMAIN]
|
42 |
[-h|--help]
|
|
43 |
[--hostname NAME]
|
|
44 |
[--mem num]
|
|
45 |
[--mirror URL]
|
|
46 |
[--removepkg PKG]
|
|
47 |
[(-t|--tmp) temp_dir]
|
|
|
7.2.2
by nijaba
Integrated patch from onno to allow specification of username and password |
48 |
[--user username]
|
49 |
[--name fullname]
|
|
50 |
[--pass password]
|
|
|
10
by Soren Hansen
Merging mvo's changes one commit at a time... |
51 |
[--part partitionfile]
|
|
5.1.3
by Michael Vogt
ubuntu-jeos-builder: |
52 |
[--rootsize size]
|
|
5.1.6
by Michael Vogt
merged with trunk/ |
53 |
[--no-opt]
|
|
10
by Soren Hansen
Merging mvo's changes one commit at a time... |
54 |
[--optsize size]
|
55 |
[--swapsize size]
|
|
|
6
by Soren Hansen
Merged changes from mvo. Changes include: |
56 |
[--kernel-flavour <flavour>]
|
57 |
[--components <comma separated list of components>]
|
|
58 |
[--ssh-key <public key file>]
|
|
|
7.2.4
by nijaba
Integrated Onno's patch adding --exec option |
59 |
[--exec <script to execute>]
|
|
7.1.2
by niajaba
- updated syntax part of the usage |
60 |
[--ip address [
|
|
10
by Soren Hansen
Merging mvo's changes one commit at a time... |
61 |
[--mask value]
|
62 |
[--net value]
|
|
63 |
[--bcast value]
|
|
64 |
[--gw address]
|
|
65 |
[--dns address] ]
|
|
|
1
by Soren Hansen
Import current builder script.. |
66 |
|
|
27
by Soren Hansen
Massive refactoring.. |
67 |
vm Generate image for the specified virtualisation software.
|
68 |
Valid choices are: vmw6 vmserver vbox qemu kvm
|
|
69 |
suite Use the specified Ubuntu suite.
|
|
70 |
Valid options: hardy, gutsy, feisty, edgy, dapper
|
|
|
1
by Soren Hansen
Import current builder script.. |
71 |
--addpkg PKG Install PKG into the guest (can be specfied multiple times)
|
|
27
by Soren Hansen
Massive refactoring.. |
72 |
-a, --arch ARCH Specify the target architecture.
|
73 |
Valid options: i386 amd64 (defaults to host architecture)
|
|
|
4.1.2
by Neal McBurnett
add qemu support, produce a directory not a zip, etc |
74 |
-d, --dest Specify the destination directory.
|
|
16
by Soren Hansen
Fixed indentation |
75 |
Default: ubuntu-vm-$SUITE-$ARCH
|
|
1
by Soren Hansen
Import current builder script.. |
76 |
--domain DOMAIN Set DOMAIN as the domain name of the guest. Default:
|
77 |
The domain of the machine running this script.
|
|
78 |
-h, --help This help text.
|
|
|
16
by Soren Hansen
Fixed indentation |
79 |
-v, --verbose Show a lot of information as the vm is generated.
|
|
1
by Soren Hansen
Import current builder script.. |
80 |
--hostname NAME Set NAME as the hostname of the guest. Default: ubuntu
|
|
7.1.1
by niajaba
- allow to set ip address |
81 |
Also uses this name as the VM name
|
|
1
by Soren Hansen
Import current builder script.. |
82 |
--mem NN Assign NN megabytes of memory to the guest vm.
|
83 |
Default: 128
|
|
84 |
--mirror URL Use Ubuntu mirror at URL instead of the default, which
|
|
|
4.1.2
by Neal McBurnett
add qemu support, produce a directory not a zip, etc |
85 |
is: http://archive.ubuntu.com/ubuntu
|
|
1
by Soren Hansen
Import current builder script.. |
86 |
--removepkg PKG Remove PKG from the guest (can be specfied multiple times)
|
87 |
-t, --tmp TMPDIR Use TMPDIR as temporary working area for the image
|
|
88 |
generation. Defaults to \$TMPDIR if set, or /tmp if not.
|
|
|
16
by Soren Hansen
Fixed indentation |
89 |
--user username Set the name of the user to be added. Default: ubuntu.
|
90 |
--name fullname Set the full name of the user to be added. Default: Ubuntu.
|
|
91 |
--pass password Set the password for the user. Default: ubuntu.
|
|
|
12
by Soren Hansen
...and another.. |
92 |
--no-opt Do not build the /opt image
|
|
7.1.3
by niajaba
added --part partfile argument |
93 |
--part partfile Allows to specify a partition table in partfile
|
94 |
each line of partfile should specify (root first):
|
|
|
10
by Soren Hansen
Merging mvo's changes one commit at a time... |
95 |
mountpoint size
|
96 |
where size is in megabytes. You can have up to 4 virtual disks,
|
|
|
7.2.7
by nijaba
- fixed bugs when not using --part option |
97 |
a new disk starts on a line with ---
|
|
10
by Soren Hansen
Merging mvo's changes one commit at a time... |
98 |
ie :
|
99 |
root 1000
|
|
100 |
/opt 1000
|
|
101 |
swap 256
|
|
|
7.2.7
by nijaba
- fixed bugs when not using --part option |
102 |
---
|
103 |
/var 2000
|
|
104 |
/log 1500
|
|
|
7.2.11
by nijaba
* Updated man page |
105 |
The following three options are not used if --part is specified:
|
|
28
by Soren Hansen
Moved the device.map rewriting code into suites/* and corrected a few mistakes in the man page. |
106 |
--rootsize size The size in MB of the root filesystem (default 4096)
|
|
27
by Soren Hansen
Massive refactoring.. |
107 |
--optsize size The size in MB of the /opt filesystem (default 4096)
|
108 |
--swapsize size The size in MB of the swap partition (default 1024)
|
|
|
6
by Soren Hansen
Merged changes from mvo. Changes include: |
109 |
--kernel-flavour The kernel image flavour to install (default: virtual for
|
|
16
by Soren Hansen
Fixed indentation |
110 |
>=gutsy on i386, server otherwise)
|
|
5.1.2
by Michael Vogt
ubuntu-jeos-builder: |
111 |
--components A comma seperaed list of distro components to include
|
112 |
(e.g. main,universe). This defaults to "main"
|
|
|
5.1.4
by Michael Vogt
ubuntu-jeos-builder: |
113 |
--ssh-key Add the given ssh public key file (absolute path)
|
|
6
by Soren Hansen
Merged changes from mvo. Changes include: |
114 |
to root's authorized keys and install openssh-server
|
|
5.1.4
by Michael Vogt
ubuntu-jeos-builder: |
115 |
(WARNING: this has strong security implications)
|
|
7.2.4
by nijaba
Integrated Onno's patch adding --exec option |
116 |
--exec Run the given script file. You can use
|
|
7.2.5
by nijaba
* now support --part file specifying multiple partition per virtual disks. Partition sizes must now be specified in megabytes. |
117 |
'chroot root <cmd>' to execute code in the guest.
|
|
7.1.1
by niajaba
- allow to set ip address |
118 |
--ip address Ip address in dotted form
|
119 |
(defaults to dhcp if not specified)
|
|
120 |
||
|
7.2.11
by nijaba
* Updated man page |
121 |
Options below are discarded if --ip is not specified
|
|
7.1.1
by niajaba
- allow to set ip address |
122 |
--mask value IP mask in dotted form (default: 255.255.255.0)
|
123 |
--net value IP net address (default: X.X.X.0)
|
|
124 |
--bcast value IP broadcast (default: X.X.X.255)
|
|
125 |
--gw address Gateway address (default: X.X.X.1)
|
|
126 |
--dns address Name server address (default: X.X.X.1)
|
|
|
5.1.1
by Michael Vogt
* ubuntu-jeos-builder: |
127 |
|
|
1
by Soren Hansen
Import current builder script.. |
128 |
('*' denotes default option)
|
129 |
||
|
27
by Soren Hansen
Massive refactoring.. |
130 |
EOT
|
131 |
||
132 |
#
|
|
133 |
# Emit usage info specific to each vm type
|
|
134 |
#
|
|
135 |
for vm in /usr/share/ubuntu-vm-builder/vms/*
|
|
136 |
do
|
|
137 |
vm="`basename "$vm"`" |
|
138 |
echo "Options specific for vm type $vm:" |
|
139 |
/usr/share/ubuntu-vm-builder/vms/$vm usage
|
|
140 |
done
|
|
141 |
||
142 |
cat <<EOT
|
|
143 |
||
|
16
by Soren Hansen
Fixed indentation |
144 |
ubuntu-vm-builder is Copyright (C) 2007-2008 Canonical Ltd. and
|
|
27
by Soren Hansen
Massive refactoring.. |
145 |
written by Soren Hansen <soren@canonical.com>.
|
|
1
by Soren Hansen
Import current builder script.. |
146 |
EOT
|
147 |
}
|
|
148 |
||
|
16
by Soren Hansen
Fixed indentation |
149 |
info () { |
150 |
test -n "$VERBOSE" && echo "$@" |
|
151 |
}
|
|
152 |
||
|
27
by Soren Hansen
Massive refactoring.. |
153 |
if [ $# -lt 2 ] |
|
1
by Soren Hansen
Import current builder script.. |
154 |
then
|
|
27
by Soren Hansen
Massive refactoring.. |
155 |
usage
|
156 |
exit 1
|
|
|
1
by Soren Hansen
Import current builder script.. |
157 |
fi
|
|
27
by Soren Hansen
Massive refactoring.. |
158 |
|
159 |
#
|
|
160 |
# Import a stack of sanity checks
|
|
161 |
#
|
|
162 |
. /usr/share/ubuntu-vm-builder/sanity-checks |
|
163 |
||
164 |
#
|
|
165 |
# First arg is the vm tech to use
|
|
166 |
#
|
|
167 |
check_vm "$1"
|
|
168 |
VM="$1" |
|
169 |
. /usr/share/ubuntu-vm-builder/vms/$VM
|
|
170 |
shift
|
|
171 |
||
172 |
#
|
|
173 |
# Second arg is the Ubuntu suite to install
|
|
174 |
#
|
|
175 |
check_suite "$1"
|
|
176 |
SUITE="$1" |
|
177 |
. /usr/share/ubuntu-vm-builder/suites/$SUITE
|
|
178 |
shift
|
|
179 |
||
|
29
by Soren Hansen
Postpone kernel check until we know for sure which architecture we'll be doing. |
180 |
vm_getopt_extra=`vm_getopt_args` |
|
27
by Soren Hansen
Massive refactoring.. |
181 |
|
|
29
by Soren Hansen
Postpone kernel check until we know for sure which architecture we'll be doing. |
182 |
TEMP=`getopt -q -o a:d:hs:t: --long addpkg:,arch:,dest:,domain:,help,hostname:,mem:,mirror:,removepkg:,suite:,tmp:,vm:,user:,name:,pass:,part:,rootsize:,swapsize:,optsize:,ip:,mask:,net:,bcast:,gw:,dns:,kernel-flavour:,components:,ssh-key:,no-opt,exec:,$vm_getopt_extra -- "$@"` |
|
1
by Soren Hansen
Import current builder script.. |
183 |
eval set -- "$TEMP" |
184 |
||
185 |
while true |
|
186 |
do
|
|
187 |
case "$1" in |
|
188 |
--addpkg)
|
|
189 |
PKGCMD="$PKGCMD $2" |
|
190 |
shift 2
|
|
191 |
;; |
|
192 |
-a|--arch)
|
|
|
27
by Soren Hansen
Massive refactoring.. |
193 |
validite_arch $2
|
194 |
ARCH="$2" |
|
|
1
by Soren Hansen
Import current builder script.. |
195 |
shift 2
|
196 |
;; |
|
197 |
-d|--dest)
|
|
|
27
by Soren Hansen
Massive refactoring.. |
198 |
check_dest_dir "$2"
|
199 |
if [ ! "${2#/}" = "${2}" ] |
|
|
1
by Soren Hansen
Import current builder script.. |
200 |
then
|
|
27
by Soren Hansen
Massive refactoring.. |
201 |
# Absolute path given
|
202 |
DESTINATION="$2" |
|
|
1
by Soren Hansen
Import current builder script.. |
203 |
else
|
|
27
by Soren Hansen
Massive refactoring.. |
204 |
# Relative path given
|
205 |
DESTINATION="${PWD}/$2" |
|
|
1
by Soren Hansen
Import current builder script.. |
206 |
fi
|
207 |
shift 2 |
|
208 |
;; |
|
209 |
--domain)
|
|
210 |
DOMAIN="$2" |
|
211 |
shift 2
|
|
212 |
;; |
|
213 |
--hostname)
|
|
|
27
by Soren Hansen
Massive refactoring.. |
214 |
VMHOSTNAME="$2" |
|
1
by Soren Hansen
Import current builder script.. |
215 |
shift 2
|
216 |
;; |
|
217 |
--mem)
|
|
218 |
MEM="$2" |
|
219 |
shift 2
|
|
220 |
;; |
|
221 |
--mirror)
|
|
222 |
MIRROR="$2" |
|
223 |
shift 2
|
|
224 |
;; |
|
225 |
--removepkg)
|
|
226 |
PKGCMD="$PKGCMD ${2}-" |
|
227 |
shift 2
|
|
228 |
;; |
|
229 |
-t|--tmp)
|
|
230 |
TMPDIR="$2" |
|
231 |
shift 2
|
|
232 |
;; |
|
233 |
--vm)
|
|
|
27
by Soren Hansen
Massive refactoring.. |
234 |
check_vm "$2"
|
|
1
by Soren Hansen
Import current builder script.. |
235 |
shift 2
|
236 |
;; |
|
|
7.2.2
by nijaba
Integrated patch from onno to allow specification of username and password |
237 |
--user)
|
|
16
by Soren Hansen
Fixed indentation |
238 |
USER="$2" |
239 |
shift 2
|
|
240 |
;; |
|
241 |
--name)
|
|
242 |
NAME="$2" |
|
243 |
shift 2
|
|
244 |
;; |
|
245 |
--pass)
|
|
246 |
PASS="$2" |
|
247 |
shift 2
|
|
248 |
;; |
|
|
7.1.3
by niajaba
added --part partfile argument |
249 |
--part)
|
250 |
PARTFILE="$2" |
|
251 |
shift 2
|
|
252 |
;; |
|
|
5.1.1
by Michael Vogt
* ubuntu-jeos-builder: |
253 |
--rootsize)
|
254 |
ROOTSIZE="$2" |
|
255 |
shift 2
|
|
256 |
;; |
|
|
7.1.1
by niajaba
- allow to set ip address |
257 |
--swapsize)
|
|
16
by Soren Hansen
Fixed indentation |
258 |
SWAPSIZE="$2" |
259 |
shift 2
|
|
260 |
;; |
|
|
7.1.1
by niajaba
- allow to set ip address |
261 |
--optsize)
|
|
16
by Soren Hansen
Fixed indentation |
262 |
OPTSIZE="$2" |
263 |
shift 2
|
|
264 |
;; |
|
|
6
by Soren Hansen
Merged changes from mvo. Changes include: |
265 |
--kernel-flavour)
|
266 |
KERNEL_FLAVOUR="$2" |
|
|
5.1.2
by Michael Vogt
ubuntu-jeos-builder: |
267 |
shift 2
|
268 |
;; |
|
269 |
--components)
|
|
270 |
COMPS="$2" |
|
271 |
shift 2
|
|
272 |
;; |
|
|
5.1.4
by Michael Vogt
ubuntu-jeos-builder: |
273 |
--ssh-key)
|
274 |
SSHKEY="$2" |
|
275 |
shift 2
|
|
276 |
;; |
|
|
12
by Soren Hansen
...and another.. |
277 |
--exec)
|
278 |
EXEC="$2" |
|
279 |
shift 2
|
|
280 |
;; |
|
|
7.1.1
by niajaba
- allow to set ip address |
281 |
--ip)
|
|
16
by Soren Hansen
Fixed indentation |
282 |
IP="$2" |
|
7.1.1
by niajaba
- allow to set ip address |
283 |
shift 2
|
284 |
;; |
|
285 |
--mask)
|
|
|
16
by Soren Hansen
Fixed indentation |
286 |
MASK="$2" |
|
7.1.1
by niajaba
- allow to set ip address |
287 |
shift 2
|
288 |
;; |
|
289 |
--net)
|
|
|
16
by Soren Hansen
Fixed indentation |
290 |
NETWORK="$2" |
|
7.1.1
by niajaba
- allow to set ip address |
291 |
shift 2
|
292 |
;; |
|
293 |
--bcast)
|
|
|
16
by Soren Hansen
Fixed indentation |
294 |
BCAST="$2" |
|
7.1.1
by niajaba
- allow to set ip address |
295 |
shift 2
|
296 |
;; |
|
297 |
--gw)
|
|
298 |
GW=$2 |
|
299 |
shift 2
|
|
300 |
;; |
|
301 |
--dns)
|
|
302 |
DNS=$2 |
|
303 |
shift 2
|
|
304 |
;; |
|
|
5.1.5
by Michael Vogt
ubuntu-jeos-builder: |
305 |
--no-opt)
|
306 |
OPTFS="no" |
|
307 |
shift 1
|
|
308 |
;; |
|
|
16
by Soren Hansen
Fixed indentation |
309 |
-v|--verbose)
|
310 |
VERBOSE="YEAH" |
|
311 |
shift 1
|
|
312 |
;; |
|
|
27
by Soren Hansen
Massive refactoring.. |
313 |
-h|--help)
|
314 |
usage |
|
315 |
exit 0
|
|
316 |
;; |
|
|
1
by Soren Hansen
Import current builder script.. |
317 |
--)
|
318 |
shift
|
|
319 |
break
|
|
320 |
;; |
|
|
17
by Soren Hansen
Fixed -s (suite) |
321 |
*)
|
|
29
by Soren Hansen
Postpone kernel check until we know for sure which architecture we'll be doing. |
322 |
vm_getopt "$@"
|
323 |
if [ $argsused -gt 0 ] |
|
324 |
then
|
|
325 |
shift $argsused |
|
326 |
else
|
|
327 |
# The vm had no clue what this was either
|
|
328 |
echo "Unknown option: $1" |
|
329 |
usage |
|
330 |
exit 1
|
|
331 |
fi
|
|
|
17
by Soren Hansen
Fixed -s (suite) |
332 |
;; |
|
1
by Soren Hansen
Import current builder script.. |
333 |
esac
|
334 |
done
|
|
335 |
||
|
27
by Soren Hansen
Massive refactoring.. |
336 |
if [ -z "$ARCH" ] |
337 |
then
|
|
338 |
if [ "`uname -m`" = x86_64 ] |
|
339 |
then
|
|
340 |
ARCH="amd64" |
|
341 |
else
|
|
342 |
ARCH="i386" |
|
343 |
fi
|
|
344 |
fi
|
|
345 |
||
346 |
if [ -z "$KERNEL_FLAVOUR" ] |
|
347 |
then
|
|
348 |
default_kernel
|
|
|
29
by Soren Hansen
Postpone kernel check until we know for sure which architecture we'll be doing. |
349 |
else
|
350 |
check_kernel_flavour "$KERNEL_FLAVOUR" |
|
|
27
by Soren Hansen
Massive refactoring.. |
351 |
fi
|
352 |
||
353 |
if [ -z "$TMPDIR" ] |
|
354 |
then
|
|
355 |
TMPDIR="/tmp" |
|
356 |
fi
|
|
357 |
||
358 |
if [ -z "$USER" ] |
|
359 |
then
|
|
360 |
USER=ubuntu |
|
361 |
fi
|
|
362 |
||
363 |
if [ -z "$PASS" ] |
|
364 |
then
|
|
365 |
PASS=ubuntu |
|
366 |
fi
|
|
367 |
||
368 |
if [ -z "$MIRROR" ] |
|
369 |
then
|
|
370 |
MIRROR="http://archive.ubuntu.com/ubuntu" |
|
371 |
fi
|
|
372 |
||
373 |
if [ -z "$MEM" ] |
|
374 |
then
|
|
375 |
MEM=128 |
|
376 |
fi
|
|
377 |
||
378 |
if [ -z "$VMHOSTNAME" ] |
|
379 |
then
|
|
380 |
VMHOSTNAME="ubuntu" |
|
381 |
fi
|
|
382 |
||
383 |
if [ -z "$DOMAIN" ] |
|
384 |
then
|
|
385 |
DOMAIN="`hostname -d`" |
|
386 |
fi
|
|
387 |
||
388 |
if [ -z "$ROOTSIZE" ] |
|
389 |
then
|
|
390 |
ROOTSIZE="1024" |
|
391 |
fi
|
|
392 |
||
393 |
SWAPSIZE="1024" |
|
394 |
||
395 |
if [ -z "$COMPS" ] |
|
396 |
then
|
|
397 |
if [ "$KERNEL_FLAVOUR" = "virtual" ] |
|
398 |
then
|
|
399 |
COMPS="main" |
|
400 |
else
|
|
401 |
COMPS="main,restricted" |
|
402 |
fi
|
|
403 |
fi
|
|
404 |
||
405 |
declare -a MOUNTPOINTS
|
|
406 |
declare -a MOUNTSIZES
|
|
407 |
declare -a MOUNTDISKS
|
|
408 |
declare -a DISKIMGS
|
|
409 |
declare -a DISKSIZES
|
|
410 |
declare -a PARTITION_START
|
|
411 |
declare -a PARTITION_END
|
|
412 |
||
|
1
by Soren Hansen
Import current builder script.. |
413 |
if [ $# -gt 0 ]; |
414 |
then
|
|
415 |
usage
|
|
|
29
by Soren Hansen
Postpone kernel check until we know for sure which architecture we'll be doing. |
416 |
echo
|
417 |
echo "Excess option(s): $@" |
|
|
1
by Soren Hansen
Import current builder script.. |
418 |
exit 1
|
419 |
fi
|
|
420 |
||
|
4.1.2
by Neal McBurnett
add qemu support, produce a directory not a zip, etc |
421 |
if [ ! "`id -u`" = 0 ] |
422 |
then
|
|
423 |
echo "$0 must be run as root (e.g. by means of sudo)" |
|
424 |
exit 1
|
|
425 |
fi
|
|
426 |
||
|
16
by Soren Hansen
Fixed indentation |
427 |
# DISKIMGS holds the base names of the disk image files.
|
|
25.1.1
by nicolas barcet
Fixed loop bug |
428 |
# LOOPDEV[i] holds the loop device name for disk image i
|
|
16
by Soren Hansen
Fixed indentation |
429 |
# MOUNTPOINTS[i] holds the mountpoint of partition i.
|
430 |
# MOUNTDISKS[i] holds
|
|
431 |
# MOUNTSIZES[i] holds the size of partition i.
|
|
|
25.1.1
by nicolas barcet
Fixed loop bug |
432 |
|
|
7.1.3
by niajaba
added --part partfile argument |
433 |
if [ -z "$PARTFILE" ]; then |
|
7.2.5
by nijaba
* now support --part file specifying multiple partition per virtual disks. Partition sizes must now be specified in megabytes. |
434 |
let partstart=0 |
|
12
by Soren Hansen
...and another.. |
435 |
let partid=0 |
|
7.2.5
by nijaba
* now support --part file specifying multiple partition per virtual disks. Partition sizes must now be specified in megabytes. |
436 |
let NUMDISKS=0 |
437 |
DISKIMGS[0]="root" |
|
438 |
||
|
12
by Soren Hansen
...and another.. |
439 |
MOUNTPOINTS[$partid]="root" |
440 |
MOUNTDISKS[$partid]="a" |
|
|
16
by Soren Hansen
Fixed indentation |
441 |
MOUNTSIZES[$partid]="$ROOTSIZE" |
|
12
by Soren Hansen
...and another.. |
442 |
let PARTITION_START[$partid]=$partstart |
443 |
let PARTITION_END[$partid]=$partstart+MOUNTSIZES[$partid] |
|
444 |
let partstart=PARTITION_END[$partid]+1 |
|
445 |
||
446 |
if [ "$OPTFS" = "yes" ] |
|
447 |
then
|
|
448 |
let partid=$partid+1 |
|
449 |
MOUNTPOINTS[$partid]="/opt" |
|
|
16
by Soren Hansen
Fixed indentation |
450 |
MOUNTDISKS[$partid]="a" |
|
12
by Soren Hansen
...and another.. |
451 |
if [ -z "$OPTSIZE" ]; then |
452 |
MOUNTSIZES[$partid]="4000" |
|
453 |
else
|
|
454 |
MOUNTSIZES[$partid]="$OPTSIZE" |
|
455 |
fi
|
|
456 |
let PARTITION_START[$partid]=$partstart |
|
457 |
let PARTITION_END[$partid]=$partstart+MOUNTSIZES[$partid] |
|
458 |
let partstart=PARTITION_END[$partid]+1 |
|
459 |
fi
|
|
460 |
||
461 |
let partid=$partid+1 |
|
462 |
MOUNTPOINTS[$partid]="swap" |
|
463 |
MOUNTDISKS[$partid]="a" |
|
|
7.1.3
by niajaba
added --part partfile argument |
464 |
if [ -z "$SWAPSIZE" ]; then |
|
16
by Soren Hansen
Fixed indentation |
465 |
MOUNTSIZES[$partid]="1000" |
|
7.1.3
by niajaba
added --part partfile argument |
466 |
else
|
|
16
by Soren Hansen
Fixed indentation |
467 |
MOUNTSIZES[$partid]="$SWAPSIZE" |
|
7.1.3
by niajaba
added --part partfile argument |
468 |
fi
|
|
16
by Soren Hansen
Fixed indentation |
469 |
let PARTITION_START[$partid]=$partstart |
470 |
let PARTITION_END[$partid]=$partstart+MOUNTSIZES[$partid] |
|
471 |
let DISKSIZES[0]=PARTITION_END[$partid]+1 |
|
|
7.1.3
by niajaba
added --part partfile argument |
472 |
else
|
|
7.2.5
by nijaba
* now support --part file specifying multiple partition per virtual disks. Partition sizes must now be specified in megabytes. |
473 |
letters=("a" "b" "c" "d") |
|
7.1.3
by niajaba
added --part partfile argument |
474 |
let index=0 |
|
7.2.5
by nijaba
* now support --part file specifying multiple partition per virtual disks. Partition sizes must now be specified in megabytes. |
475 |
let diskindex=0 |
476 |
let partnum=0 |
|
477 |
let partstart=0 |
|
478 |
||
479 |
echo "Disks and partitions:" |
|
480 |
||
|
7.1.3
by niajaba
added --part partfile argument |
481 |
exec 10<$PARTFILE |
482 |
while read line<&10 |
|
483 |
do
|
|
|
7.2.5
by nijaba
* now support --part file specifying multiple partition per virtual disks. Partition sizes must now be specified in megabytes. |
484 |
if [ "$line" = "---" ]; then |
485 |
let DISKSIZES[$diskindex]=$partstart |
|
486 |
let diskindex=$diskindex+1 |
|
487 |
let partstart=0 |
|
488 |
let partnum=0 |
|
489 |
if [ $diskindex -gt 3 ]; then |
|
490 |
echo "Sorry, no more than 4 IDE disks..." |
|
491 |
exit 1
|
|
492 |
fi
|
|
493 |
else
|
|
494 |
MOUNTDISKS[$index]="${letters[$diskindex]}" |
|
495 |
MOUNTPOINTS[$index]=${line%\ *} |
|
496 |
MOUNTSIZES[$index]=`echo "${line#*\ }" | sed 's/^[ \t]*//'` |
|
497 |
let PARTITION_START[$index]=$partstart |
|
498 |
let PARTITION_END[$index]=$partstart+MOUNTSIZES[$index] |
|
499 |
if [ $partnum -eq 0 ]; then |
|
500 |
DISKIMGS[$diskindex]=`echo "${MOUNTPOINTS[$index]}" | sed 's%\/%%g' | sed 's/[ \t]*$//'` |
|
|
16
by Soren Hansen
Fixed indentation |
501 |
info " Disk: $diskindex ${DISKIMGS[$diskindex]}"
|
|
7.2.5
by nijaba
* now support --part file specifying multiple partition per virtual disks. Partition sizes must now be specified in megabytes. |
502 |
fi
|
|
7.1.4
by nijaba
- limit to 4 disk |
503 |
|
|
16
by Soren Hansen
Fixed indentation |
504 |
info " Partition: $partnum ${MOUNTPOINTS[$index]} start: $partstart end: ${PARTITION_END[$index]} size: ${MOUNTSIZES[$index]}" |
|
7.2.5
by nijaba
* now support --part file specifying multiple partition per virtual disks. Partition sizes must now be specified in megabytes. |
505 |
let partstart=PARTITION_END[$index]+1 |
506 |
let index=$index+1 |
|
507 |
let partnum=$partnum+1 |
|
508 |
||
509 |
fi
|
|
|
7.1.3
by niajaba
added --part partfile argument |
510 |
done
|
|
7.2.5
by nijaba
* now support --part file specifying multiple partition per virtual disks. Partition sizes must now be specified in megabytes. |
511 |
let DISKSIZES[$diskindex]=$partstart |
512 |
let NUMDISK=$diskindex |
|
|
7.1.3
by niajaba
added --part partfile argument |
513 |
fi
|
514 |
||
|
23
by Soren Hansen
Don't default to virtual kernel if we're not installing i386. |
515 |
WORKINGDIR=`mktemp -d -p $TMPDIR vm-builder-XXXXXXXXXX` || exit 1 |
|
7.1.4
by nijaba
- limit to 4 disk |
516 |
|
517 |
if [ -z "$DESTINATION" ] |
|
518 |
then
|
|
|
18
by Soren Hansen
A *lot* of silencing. |
519 |
DESTINATION="$PWD/ubuntu-vm-$SUITE-$ARCH" |
|
7.1.4
by nijaba
- limit to 4 disk |
520 |
fi
|
521 |
||
522 |
if [ -n "${SUDO_USER}" ]; then |
|
|
18
by Soren Hansen
A *lot* of silencing. |
523 |
sudo -u "${SUDO_USER}" mkdir "${DESTINATION}" |
|
7.1.4
by nijaba
- limit to 4 disk |
524 |
else
|
|
18
by Soren Hansen
A *lot* of silencing. |
525 |
mkdir "${DESTINATION}" |
|
7.1.4
by nijaba
- limit to 4 disk |
526 |
fi
|
527 |
||
528 |
if [ $? -ne 0 ]; then |
|
|
18
by Soren Hansen
A *lot* of silencing. |
529 |
echo "Error creating directory ${DESTINATION}. Unable to proceed." |
530 |
rm -rf "${WORKINGDIR}"
|
|
531 |
exit 1
|
|
|
7.1.4
by nijaba
- limit to 4 disk |
532 |
fi
|
533 |
||
|
7.1.1
by niajaba
- allow to set ip address |
534 |
if [ -z "$IP" ]; then |
535 |
IP="DHCP" |
|
536 |
else
|
|
537 |
if [ -z "$MASK" ]; then |
|
538 |
MASK="255.255.255.0" |
|
539 |
echo "setting mask to \"$MASK\"" |
|
540 |
fi
|
|
541 |
if [ -z "$NET" ]; then |
|
542 |
NET=`echo $IP | sed 's/\./.0./3' | sed 's/\.[[:digit:]]\{1,3\}$//'` |
|
543 |
echo "setting network to \"$NET\"" |
|
544 |
fi
|
|
545 |
if [ -z "$BCAST" ]; then |
|
546 |
BCAST=`echo $IP | sed 's/\./.255./3' | sed 's/\.[[:digit:]]\{1,3\}$//'` |
|
547 |
echo "setting broadcast to \"$BCAST\"" |
|
548 |
fi
|
|
549 |
if [ -z "$GW" ]; then |
|
550 |
GW=`echo $IP | sed 's/\./.1./3' | sed 's/\.[[:digit:]]\{1,3\}$//'` |
|
551 |
echo "setting gateway to \"$GW\"" |
|
552 |
fi
|
|
553 |
if [ -z "$DNS" ]; then |
|
554 |
DNS=`echo $IP | sed 's/\./.1./3' | sed 's/\.[[:digit:]]\{1,3\}$//'` |
|
555 |
echo "setting name server to \"$DNS\"" |
|
556 |
fi
|
|
557 |
||
558 |
||
559 |
fi
|
|
560 |
||
|
1
by Soren Hansen
Import current builder script.. |
561 |
do_initial_user () { |
562 |
#
|
|
563 |
# Set up a user with sudo etc.
|
|
564 |
#
|
|
565 |
||
|
7.2.2
by nijaba
Integrated patch from onno to allow specification of username and password |
566 |
chroot root adduser --disabled-password --gecos "${NAME}" ${USER} > /dev/null |
|
1
by Soren Hansen
Import current builder script.. |
567 |
chroot root chpasswd <<EOF
|
|
7.2.2
by nijaba
Integrated patch from onno to allow specification of username and password |
568 |
${USER}:${PASS}
|
|
1
by Soren Hansen
Import current builder script.. |
569 |
EOF
|
570 |
||
571 |
chroot root addgroup --system admin >/dev/null 2>&1 |
|
|
7.2.2
by nijaba
Integrated patch from onno to allow specification of username and password |
572 |
chroot root adduser ${USER} admin >/dev/null 2>&1 |
|
1
by Soren Hansen
Import current builder script.. |
573 |
|
|
4
by Soren Hansen
Since we require ubuntu-jeos-builder to run as root these days, we don't need sponge anymore. |
574 |
cat >> root/etc/sudoers << EOF
|
|
1
by Soren Hansen
Import current builder script.. |
575 |
|
576 |
# Members of the admin group may gain root privileges
|
|
577 |
%admin ALL=(ALL) ALL
|
|
578 |
EOF
|
|
579 |
||
580 |
for group in adm audio cdrom dialout floppy video plugdev dip netdev powerdev lpadmin scanner; do |
|
|
7.2.2
by nijaba
Integrated patch from onno to allow specification of username and password |
581 |
chroot root adduser ${USER} $group >/dev/null 2>&1 |
|
1
by Soren Hansen
Import current builder script.. |
582 |
done
|
583 |
||
584 |
}
|
|
585 |
||
586 |
do_network_setup () { |
|
|
27
by Soren Hansen
Massive refactoring.. |
587 |
echo $VMHOSTNAME > root/etc/hostname |
|
1
by Soren Hansen
Import current builder script.. |
588 |
|
|
4
by Soren Hansen
Since we require ubuntu-jeos-builder to run as root these days, we don't need sponge anymore. |
589 |
cat > root/etc/hosts <<EOF
|
|
1
by Soren Hansen
Import current builder script.. |
590 |
127.0.0.1 localhost
|
|
27
by Soren Hansen
Massive refactoring.. |
591 |
127.0.1.1 $VMHOSTNAME.$DOMAIN $VMHOSTNAME
|
|
1
by Soren Hansen
Import current builder script.. |
592 |
EOF
|
593 |
||
|
4
by Soren Hansen
Since we require ubuntu-jeos-builder to run as root these days, we don't need sponge anymore. |
594 |
cat > root/etc/network/interfaces <<EOF
|
|
1
by Soren Hansen
Import current builder script.. |
595 |
# This file describes the network interfaces available on your system
|
596 |
# and how to activate them. For more information, see interfaces(5).
|
|
597 |
||
598 |
# The loopback network interface
|
|
599 |
auto lo
|
|
600 |
iface lo inet loopback
|
|
601 |
||
602 |
# The primary network interface
|
|
603 |
auto eth0
|
|
|
7.1.1
by niajaba
- allow to set ip address |
604 |
EOF
|
|
7.2.3
by nijaba
Fixed comparison bug on DHCP |
605 |
if [ "$IP" = "DHCP" ]; then |
|
7.1.1
by niajaba
- allow to set ip address |
606 |
cat >> root/etc/network/interfaces <<EOF |
|
1
by Soren Hansen
Import current builder script.. |
607 |
iface eth0 inet dhcp
|
608 |
EOF
|
|
|
7.1.1
by niajaba
- allow to set ip address |
609 |
else
|
610 |
cat >> root/etc/network/interfaces <<EOF |
|
611 |
iface eth0 inet static
|
|
612 |
address $IP
|
|
613 |
netmask $MASK
|
|
614 |
network $NET
|
|
615 |
broadcast $BCAST
|
|
616 |
gateway $GW
|
|
617 |
# dns-* options are implemented by the resolvconf package, if installed
|
|
618 |
dns-nameservers $DNS
|
|
619 |
dns-search $DOMAIN
|
|
620 |
EOF
|
|
621 |
fi
|
|
|
7.2.8
by nijaba
/var/run/network was not created in some case, network would not start |
622 |
|
623 |
#temporary fix for /var/run/network not being created
|
|
624 |
if [ ! -e root/var/run/network ]; then |
|
625 |
echo "Creating /var/run/network" |
|
626 |
mkdir root/var/run/network |
|
627 |
fi
|
|
|
1
by Soren Hansen
Import current builder script.. |
628 |
}
|
629 |
||
630 |
do_bootloader () { |
|
|
27
by Soren Hansen
Massive refactoring.. |
631 |
#
|
632 |
# The suite will have defined updategrub
|
|
633 |
#
|
|
634 |
sed -e "s,%UPDATEGRUB%/$updategrub/g" << EOF | cat > root/etc/kernel-img.conf |
|
|
1
by Soren Hansen
Import current builder script.. |
635 |
do_symlinks = yes
|
636 |
relative_links = yes
|
|
637 |
do_bootfloppy = no
|
|
638 |
do_initrd = yes
|
|
639 |
link_in_boot = no
|
|
|
5.1.2
by Michael Vogt
ubuntu-jeos-builder: |
640 |
postinst_hook = %UPDATEGRUB%
|
641 |
postrm_hook = %UPDATEGRUB%
|
|
|
1
by Soren Hansen
Import current builder script.. |
642 |
do_bootloader = no
|
643 |
EOF
|
|
644 |
||
645 |
chroot root apt-get --force-yes -y install grub |
|
646 |
||
647 |
mkdir root/boot/grub |
|
648 |
#
|
|
649 |
# Create device.map
|
|
650 |
#
|
|
|
4
by Soren Hansen
Since we require ubuntu-jeos-builder to run as root these days, we don't need sponge anymore. |
651 |
cat > root/boot/grub/device.map << EOF
|
|
1
by Soren Hansen
Import current builder script.. |
652 |
(fd0) /dev/fd0
|
653 |
EOF
|
|
|
28
by Soren Hansen
Moved the device.map rewriting code into suites/* and corrected a few mistakes in the man page. |
654 |
suite_generate_device_map |
|
1
by Soren Hansen
Import current builder script.. |
655 |
|
656 |
if [ $ARCH = "amd64" ] |
|
657 |
then
|
|
658 |
grubarch="x86_64-pc" |
|
659 |
else
|
|
660 |
grubarch="i386-pc" |
|
661 |
fi
|
|
662 |
#
|
|
663 |
# No animals (and only one human) were harmed during the making of the following boot loader installation.
|
|
664 |
#
|
|
665 |
||
666 |
# This should replicate pretty closely what grub's stage2 shell does when asked to install
|
|
667 |
BOOTSEC_BPB_OFFSET=$((0x3)) |
|
668 |
BOOTSEC_BPB_LENGTH=$((0x3B)) |
|
669 |
STAGE1_WINDOWS_NT_MAGIC=$((0x1b8)) |
|
670 |
STAGE1_PARTEND=$((0x1fe)) |
|
671 |
STAGE1_BOOT_DRIVE=$((0x40)) |
|
672 |
STAGE1_BOOT_DRIVE_CHECK=$((0x4b)) |
|
673 |
STAGE1_STAGE2_SECTOR=$((0x44)) |
|
674 |
STAGE1_STAGE2_ADDRESS=$((0x42)) |
|
675 |
STAGE1_STAGE2_SEGMENT=$((0x48)) |
|
676 |
STAGE2_FORCE_LBA=$((0x11)) |
|
677 |
STAGE2_VER_STR_OFFS=$((0x12)) |
|
678 |
||
|
27
by Soren Hansen
Massive refactoring.. |
679 |
# grubroot and updategrub are set by $SUITE
|
|
5.1.2
by Michael Vogt
ubuntu-jeos-builder: |
680 |
cp $grubroot/$grubarch/stage1 stage1_buffer |
|
18
by Soren Hansen
A *lot* of silencing. |
681 |
dd bs=512 count=1 if=root.raw of=old_sect 2> /dev/null |
|
1
by Soren Hansen
Import current builder script.. |
682 |
|
|
18
by Soren Hansen
A *lot* of silencing. |
683 |
dd bs=1 count=$BOOTSEC_BPB_LENGTH conv=notrunc skip=$BOOTSEC_BPB_OFFSET seek=$BOOTSEC_BPB_OFFSET if=old_sect of=stage1_buffer 2> /dev/null |
684 |
dd bs=1 count=$(($STAGE1_PARTEND - $STAGE1_WINDOWS_NT_MAGIC)) conv=notrunc skip=$STAGE1_WINDOWS_NT_MAGIC seek=$STAGE1_WINDOWS_NT_MAGIC if=old_sect of=stage1_buffer 2> /dev/null |
|
|
1
by Soren Hansen
Import current builder script.. |
685 |
|
686 |
# Set boot device to GRUB_UNKNOWN_DEVICE (that's what grub does) and force lba
|
|
|
18
by Soren Hansen
A *lot* of silencing. |
687 |
/bin/echo -ne '\xff\01' | dd bs=1 count=2 conv=notrunc seek=$STAGE1_BOOT_DRIVE of=stage1_buffer 2> /dev/null |
|
1
by Soren Hansen
Import current builder script.. |
688 |
|
689 |
# Hack to workaround buggy bios'es
|
|
|
18
by Soren Hansen
A *lot* of silencing. |
690 |
/bin/echo -ne '\x90\x90' | dd bs=1 count=2 conv=notrunc seek=$STAGE1_BOOT_DRIVE_CHECK of=stage1_buffer 2> /dev/null |
|
1
by Soren Hansen
Import current builder script.. |
691 |
|
|
18
by Soren Hansen
A *lot* of silencing. |
692 |
dd if=$grubroot/$grubarch/e2fs_stage1_5 of=stage2_first_buffer bs=512 count=1 2> /dev/null |
693 |
dd if=$grubroot/$grubarch/e2fs_stage1_5 of=stage2_second_buffer bs=512 count=1 skip=1 2> /dev/null |
|
|
1
by Soren Hansen
Import current builder script.. |
694 |
|
695 |
# Stage 2 (actually 1.5) is at sector 1 (0-indexed)
|
|
|
18
by Soren Hansen
A *lot* of silencing. |
696 |
/bin/echo -ne '\1\0\0\0' | dd bs=1 count=4 conv=notrunc seek=$STAGE1_STAGE2_SECTOR of=stage1_buffer 2> /dev/null |
|
1
by Soren Hansen
Import current builder script.. |
697 |
# Set address and segment accordingly
|
|
18
by Soren Hansen
A *lot* of silencing. |
698 |
/bin/echo -ne '\0\x20' | dd bs=1 count=2 conv=notrunc seek=$STAGE1_STAGE2_ADDRESS of=stage1_buffer 2> /dev/null |
699 |
/bin/echo -ne '\0\02' | dd bs=1 count=2 conv=notrunc seek=$STAGE1_STAGE2_SEGMENT of=stage1_buffer 2> /dev/null |
|
|
1
by Soren Hansen
Import current builder script.. |
700 |
|
|
18
by Soren Hansen
A *lot* of silencing. |
701 |
/bin/echo -ne '\1' | dd bs=1 count=1 conv=notrunc seek=$STAGE2_FORCE_LBA of=stage2_second_buffer 2> /dev/null |
|
1
by Soren Hansen
Import current builder script.. |
702 |
|
703 |
# These two are unexplained..
|
|
|
18
by Soren Hansen
A *lot* of silencing. |
704 |
/bin/echo -ne '\x10' | dd bs=1 count=1 conv=notrunc seek=508 of=stage2_first_buffer 2> /dev/null |
705 |
/bin/echo -ne '\0' | dd bs=1 count=1 conv=notrunc seek=$((0x19)) of=stage2_second_buffer 2> /dev/null |
|
|
1
by Soren Hansen
Import current builder script.. |
706 |
|
707 |
# I couldn't figure out how to reimplement this properly in posix shell, so I'll hardcode the offset for now
|
|
708 |
||
|
18
by Soren Hansen
A *lot* of silencing. |
709 |
/bin/echo -ne ' /boot/grub/menu.lst\0' | dd bs=1 count=21 conv=notrunc seek=$((0x2c)) of=stage2_second_buffer 2> /dev/null |
|
1
by Soren Hansen
Import current builder script.. |
710 |
|
711 |
#
|
|
712 |
# Stuff this all back into the disk image
|
|
713 |
#
|
|
|
18
by Soren Hansen
A *lot* of silencing. |
714 |
dd bs=512 count=1 if=stage1_buffer conv=notrunc of=root.raw 2> /dev/null |
715 |
dd bs=512 count=1 seek=1 if=stage2_first_buffer conv=notrunc of=root.raw 2> /dev/null |
|
716 |
dd bs=512 count=1 seek=2 if=stage2_second_buffer conv=notrunc of=root.raw 2> /dev/null |
|
717 |
dd bs=512 seek=3 skip=2 if=$grubroot/$grubarch/e2fs_stage1_5 conv=notrunc of=root.raw 2> /dev/null |
|
|
1
by Soren Hansen
Import current builder script.. |
718 |
|
|
5.1.2
by Michael Vogt
ubuntu-jeos-builder: |
719 |
cp $grubroot/$grubarch/* root/boot/grub/ |
|
1
by Soren Hansen
Import current builder script.. |
720 |
|
721 |
# Hacky-di-hack.. First generate the template, then remove the errant kopt_2_6 (which hardcodes the root device to /dev/hda1) and then rerun update-grub.
|
|
|
5.1.2
by Michael Vogt
ubuntu-jeos-builder: |
722 |
chroot root $updategrub -y
|
|
28
by Soren Hansen
Moved the device.map rewriting code into suites/* and corrected a few mistakes in the man page. |
723 |
suite_mangle_grub_menu_lst |
|
5.1.2
by Michael Vogt
ubuntu-jeos-builder: |
724 |
chroot root $updategrub
|
|
1
by Soren Hansen
Import current builder script.. |
725 |
chroot root grub-set-default 0 |
726 |
rm old_sect stage1_buffer stage2_first_buffer stage2_second_buffer |
|
727 |
}
|
|
728 |
||
729 |
do_disk_images() { |
|
730 |
#
|
|
|
7.1.3
by niajaba
added --part partfile argument |
731 |
# Create disk images, partitions and format
|
732 |
#
|
|
|
7.2.5
by nijaba
* now support --part file specifying multiple partition per virtual disks. Partition sizes must now be specified in megabytes. |
733 |
|
734 |
for ((i=0; i<${#DISKIMGS[@]}; i++)); do |
|
735 |
# create disk image
|
|
736 |
let size=${DISKSIZES[$i]}*1024 |
|
|
18
by Soren Hansen
A *lot* of silencing. |
737 |
qemu-img create -f raw ${DISKIMGS[$i]}.raw $size > /dev/null |
|
7.2.5
by nijaba
* now support --part file specifying multiple partition per virtual disks. Partition sizes must now be specified in megabytes. |
738 |
|
739 |
# label the disk
|
|
740 |
parted --script ${DISKIMGS[$i]}.raw mklabel msdos |
|
741 |
done
|
|
742 |
|
|
743 |
let diskindex=-1 |
|
744 |
curdisk="" |
|
745 |
||
746 |
# create the partitions
|
|
|
7.1.3
by niajaba
added --part partfile argument |
747 |
for ((i=0;i<${#MOUNTPOINTS[@]};i++)); do |
|
7.2.5
by nijaba
* now support --part file specifying multiple partition per virtual disks. Partition sizes must now be specified in megabytes. |
748 |
if [ "$curdisk" != "${MOUNTDISKS[$i]i}" ]; then |
749 |
let diskindex++ |
|
750 |
img="${DISKIMGS[$diskindex]}" |
|
751 |
curdisk=${MOUNTDISKS[$i]} |
|
|
18
by Soren Hansen
A *lot* of silencing. |
752 |
info "Disk: $curdisk $img"
|
|
7.2.5
by nijaba
* now support --part file specifying multiple partition per virtual disks. Partition sizes must now be specified in megabytes. |
753 |
fi
|
|
7.1.3
by niajaba
added --part partfile argument |
754 |
|
755 |
# Create partition and format
|
|
|
18
by Soren Hansen
A *lot* of silencing. |
756 |
info " creating partition ${MOUNTPOINTS[$i]} on $img"
|
|
7.2.5
by nijaba
* now support --part file specifying multiple partition per virtual disks. Partition sizes must now be specified in megabytes. |
757 |
if [ "${MOUNTPOINTS[$i]}" = "swap" ]; then |
758 |
parted --script -- $img.raw mkpartfs primary linux-swap ${PARTITION_START[$i]} ${PARTITION_END[$i]} |
|
|
7.1.3
by niajaba
added --part partfile argument |
759 |
else
|
|
7.2.5
by nijaba
* now support --part file specifying multiple partition per virtual disks. Partition sizes must now be specified in megabytes. |
760 |
parted --script -- $img.raw mkpartfs primary ext2 ${PARTITION_START[$i]} ${PARTITION_END[$i]} |
761 |
fi
|
|
762 |
done
|
|
763 |
||
764 |
#mount the disk loops
|
|
765 |
for ((i=0;i<${#DISKIMGS[@]};i++)); do |
|
|
25.1.1
by nicolas barcet
Fixed loop bug |
766 |
LOOPDEV[$i]=$(losetup -s -f ${DISKIMGS[$i]}.raw) |
767 |
kpartx -a ${LOOPDEV[$i]} > /dev/null |
|
|
7.2.5
by nijaba
* now support --part file specifying multiple partition per virtual disks. Partition sizes must now be specified in megabytes. |
768 |
done
|
769 |
||
770 |
#format the partitions
|
|
771 |
let diskindex=-1 |
|
772 |
curdisk="" |
|
773 |
for ((i=0;i<${#MOUNTPOINTS[@]};i++)); do |
|
774 |
if [ "$curdisk" != "${MOUNTDISKS[$i]}" ]; then |
|
775 |
let diskindex++ |
|
776 |
img="${DISKIMGS[$diskindex]}" |
|
777 |
curdisk=${MOUNTDISKS[$i]} |
|
778 |
let partindex=1 |
|
|
25.1.1
by nicolas barcet
Fixed loop bug |
779 |
mapper=$(echo ${LOOPDEV[$diskindex]} | sed s-/dev/-/dev/mapper/-) |
|
7.2.5
by nijaba
* now support --part file specifying multiple partition per virtual disks. Partition sizes must now be specified in megabytes. |
780 |
fi
|
|
25.1.1
by nicolas barcet
Fixed loop bug |
781 |
|
|
7.2.5
by nijaba
* now support --part file specifying multiple partition per virtual disks. Partition sizes must now be specified in megabytes. |
782 |
if [ "${MOUNTPOINTS[$i]}" = "swap" ]; then |
|
25.1.1
by nicolas barcet
Fixed loop bug |
783 |
info formating ${mapper}p${partindex} as swap for ${MOUNTPOINTS[$i]} |
784 |
mkswap ${mapper}p${partindex} |
|
|
7.2.5
by nijaba
* now support --part file specifying multiple partition per virtual disks. Partition sizes must now be specified in megabytes. |
785 |
else
|
|
25.1.1
by nicolas barcet
Fixed loop bug |
786 |
info formating ${mapper}p${partindex} as ext3 for ${MOUNTPOINTS[$i]} |
787 |
mkfs.ext3 -q ${mapper}p${partindex} |
|
|
7.2.5
by nijaba
* now support --part file specifying multiple partition per virtual disks. Partition sizes must now be specified in megabytes. |
788 |
fi
|
|
25.1.1
by nicolas barcet
Fixed loop bug |
789 |
/lib/udev/vol_id --uuid ${mapper}p${partindex} > ${MOUNTPOINTS[$i]}.uuid |
|
7.2.5
by nijaba
* now support --part file specifying multiple partition per virtual disks. Partition sizes must now be specified in megabytes. |
790 |
let partindex++
|
791 |
done
|
|
792 |
||
|
1
by Soren Hansen
Import current builder script.. |
793 |
}
|
794 |
||
795 |
do_debootstrap() { |
|
796 |
mkdir root |
|
|
5.1.2
by Michael Vogt
ubuntu-jeos-builder: |
797 |
debootstrap --components="$COMPS" --arch $ARCH $SUITE root "$MIRROR" |
798 |
}
|
|
799 |
||
|
1
by Soren Hansen
Import current builder script.. |
800 |
do_kernel_n_friends () { |
|
6
by Soren Hansen
Merged changes from mvo. Changes include: |
801 |
PKGS="linux-$KERNEL_FLAVOUR" |
|
27
by Soren Hansen
Massive refactoring.. |
802 |
vm_extra_packages |
803 |
suite_extra_packages |
|
|
1
by Soren Hansen
Import current builder script.. |
804 |
chroot root apt-get --force-yes -y install $PKGS
|
805 |
}
|
|
806 |
||
807 |
do_add_remove_packages () { |
|
808 |
cmd="apt-get --purge install " |
|
|
26
by Soren Hansen
Merged Nick's fix for icky race condition in loopback device creating. Thanks! |
809 |
chroot root apt-get -y --force-yes --purge install $PKGCMD
|
|
1
by Soren Hansen
Import current builder script.. |
810 |
}
|
811 |
||
|
5.1.4
by Michael Vogt
ubuntu-jeos-builder: |
812 |
do_add_ssh_key () { |
813 |
if [ -z "$SSHKEY" ] |
|
814 |
then
|
|
815 |
return
|
|
816 |
fi
|
|
817 |
if [ ! -f "$SSHKEY" ] |
|
818 |
then
|
|
819 |
echo "NO $SSHKEY found" |
|
820 |
return
|
|
821 |
fi
|
|
822 |
# we have a key, add it
|
|
823 |
chroot root apt-get install --force-yes -y openssh-server |
|
824 |
mkdir root/root/.ssh |
|
825 |
cp "$SSHKEY" root/root/.ssh/authorized_keys
|
|
826 |
}
|
|
827 |
||
|
7.2.4
by nijaba
Integrated Onno's patch adding --exec option |
828 |
do_exec_script () { |
|
27
by Soren Hansen
Massive refactoring.. |
829 |
if [ -z "$EXEC" ] |
830 |
then
|
|
831 |
return
|
|
832 |
fi
|
|
833 |
||
834 |
if [ ! -f "$EXEC" ] |
|
835 |
then
|
|
836 |
echo "Script '$EXEC' not found." |
|
837 |
return
|
|
838 |
fi
|
|
839 |
#
|
|
840 |
# Execute the script.
|
|
841 |
#
|
|
842 |
"$EXEC"
|
|
|
7.2.5
by nijaba
* now support --part file specifying multiple partition per virtual disks. Partition sizes must now be specified in megabytes. |
843 |
}
|
844 |
||
845 |
mount_parts () { |
|
846 |
base="$1" |
|
847 |
if [ "$base" = "" ]; then |
|
848 |
echo base is empty.... exiting |
|
849 |
exit 0
|
|
|
7.2.4
by nijaba
Integrated Onno's patch adding --exec option |
850 |
fi
|
|
7.2.5
by nijaba
* now support --part file specifying multiple partition per virtual disks. Partition sizes must now be specified in megabytes. |
851 |
let diskindex=-1 |
852 |
curdisk="" |
|
853 |
for ((i=0;i<${#MOUNTPOINTS[@]};i++)); do |
|
854 |
if [ "$curdisk" != "${MOUNTDISKS[$i]}" ]; then |
|
855 |
let diskindex++ |
|
856 |
img="${DISKIMGS[$diskindex]}" |
|
857 |
curdisk=${MOUNTDISKS[$i]} |
|
858 |
let partindex=1 |
|
|
25.1.1
by nicolas barcet
Fixed loop bug |
859 |
mapper=$(echo ${LOOPDEV[$diskindex]} | sed s-/dev/-/dev/mapper/-) |
|
7.2.5
by nijaba
* now support --part file specifying multiple partition per virtual disks. Partition sizes must now be specified in megabytes. |
860 |
fi
|
861 |
||
862 |
if [ "${MOUNTPOINTS[$i]}" = "root" ]; then |
|
|
25.1.1
by nicolas barcet
Fixed loop bug |
863 |
mount ${mapper}p${partindex} $base |
|
7.2.5
by nijaba
* now support --part file specifying multiple partition per virtual disks. Partition sizes must now be specified in megabytes. |
864 |
elif [ "${MOUNTPOINTS[$i]}" != "swap" ]; then |
865 |
mkdir $base${MOUNTPOINTS[$i]} |
|
|
25.1.1
by nicolas barcet
Fixed loop bug |
866 |
mount ${mapper}p${partindex} $base${MOUNTPOINTS[$i]} |
|
7.2.5
by nijaba
* now support --part file specifying multiple partition per virtual disks. Partition sizes must now be specified in megabytes. |
867 |
fi
|
868 |
let partindex++ |
|
869 |
done
|
|
870 |
}
|
|
871 |
||
872 |
umount_parts () { |
|
873 |
base="$1" |
|
|
27
by Soren Hansen
Massive refactoring.. |
874 |
for ((i=${#MOUNTPOINTS[@]};i>-1;i--)); do |
875 |
if [ "${MOUNTPOINTS[$i]}" = "root" ]; then |
|
876 |
echo umount $base |
|
877 |
umount $base
|
|
878 |
elif [ "${MOUNTPOINTS[$i]}" != "swap" ]; then |
|
879 |
echo umount $base${MOUNTPOINTS[$i]} |
|
880 |
umount $base${MOUNTPOINTS[$i]} |
|
881 |
fi
|
|
882 |
done
|
|
|
7.2.4
by nijaba
Integrated Onno's patch adding --exec option |
883 |
}
|
884 |
||
|
1
by Soren Hansen
Import current builder script.. |
885 |
do_copy_to_disk_images () { |
886 |
||
887 |
chroot root apt-get clean |
|
888 |
#
|
|
|
7.2.5
by nijaba
* now support --part file specifying multiple partition per virtual disks. Partition sizes must now be specified in megabytes. |
889 |
# Copy the debootstrapped filesystem into the partitions
|
|
1
by Soren Hansen
Import current builder script.. |
890 |
#
|
891 |
mkdir target |
|
|
7.2.5
by nijaba
* now support --part file specifying multiple partition per virtual disks. Partition sizes must now be specified in megabytes. |
892 |
mount_parts target |
|
18
by Soren Hansen
A *lot* of silencing. |
893 |
info Copy the debootstrapped filesystem |
|
1
by Soren Hansen
Import current builder script.. |
894 |
cp -a root/* target |
|
7.2.5
by nijaba
* now support --part file specifying multiple partition per virtual disks. Partition sizes must now be specified in megabytes. |
895 |
umount_parts target |
|
1
by Soren Hansen
Import current builder script.. |
896 |
rmdir target |
897 |
rm -rf root |
|
898 |
}
|
|
899 |
||
900 |
do_target_vm_conversion () { |
|
|
18
by Soren Hansen
A *lot* of silencing. |
901 |
info Convert to format $VM
|
|
4.1.2
by Neal McBurnett
add qemu support, produce a directory not a zip, etc |
902 |
|
|
27
by Soren Hansen
Massive refactoring.. |
903 |
vm_target_conversion |
|
1
by Soren Hansen
Import current builder script.. |
904 |
|
|
7.2.5
by nijaba
* now support --part file specifying multiple partition per virtual disks. Partition sizes must now be specified in megabytes. |
905 |
for ((i=0;i<${#DISKIMGS[@]};i++)); do |
906 |
qemu-img convert $QEMU_IMG_CONVERT_OPTS ${DISKIMGS[$i]}.raw "${DISKIMGS[$i]}${QEMU_IMG_CONVERT_EXTENSION}" |
|
|
7.1.3
by niajaba
added --part partfile argument |
907 |
done
|
|
5
by Soren Hansen
Merged Neal's changes with a few slight modifications. |
908 |
|
909 |
test -n "${SUDO_USER}" && chown "$SUDO_USER" $FILES |
|
|
4.1.2
by Neal McBurnett
add qemu support, produce a directory not a zip, etc |
910 |
mv $FILES $DESTINATION |
|
5
by Soren Hansen
Merged Neal's changes with a few slight modifications. |
911 |
echo "Done. Images are in ${DESTINATION}." |
|
1
by Soren Hansen
Import current builder script.. |
912 |
}
|
913 |
||
914 |
do_cleanup () { |
|
|
7.2.5
by nijaba
* now support --part file specifying multiple partition per virtual disks. Partition sizes must now be specified in megabytes. |
915 |
#unmount the disk loops
|
916 |
for ((i=0;i<${#DISKIMGS[@]};i++)); do |
|
|
25.1.1
by nicolas barcet
Fixed loop bug |
917 |
kpartx -d ${LOOPDEV[$i]} > /dev/null |
918 |
losetup -d ${LOOPDEV[$i]} |
|
|
7.2.5
by nijaba
* now support --part file specifying multiple partition per virtual disks. Partition sizes must now be specified in megabytes. |
919 |
done
|
920 |
||
|
7.1.3
by niajaba
added --part partfile argument |
921 |
for ((i=0;i<${#MOUNTPOINTS[@]};i++)); do |
|
7.2.5
by nijaba
* now support --part file specifying multiple partition per virtual disks. Partition sizes must now be specified in megabytes. |
922 |
rm ${MOUNTPOINTS[$i]}.uuid |
|
7.1.3
by niajaba
added --part partfile argument |
923 |
done
|
|
7.2.5
by nijaba
* now support --part file specifying multiple partition per virtual disks. Partition sizes must now be specified in megabytes. |
924 |
for ((i=0;i<${#DISKIMGS[@]};i++)); do |
925 |
rm ${DISKIMGS[$i]}.raw |
|
926 |
done
|
|
|
1
by Soren Hansen
Import current builder script.. |
927 |
cd / |
|
7.2.5
by nijaba
* now support --part file specifying multiple partition per virtual disks. Partition sizes must now be specified in megabytes. |
928 |
rm -rf "$WORKINGDIR"
|
|
1
by Soren Hansen
Import current builder script.. |
929 |
}
|
930 |
||
931 |
cd "$WORKINGDIR" |
|
932 |
||
933 |
do_disk_images |
|
934 |
do_debootstrap |
|
|
27
by Soren Hansen
Massive refactoring.. |
935 |
suite_do_fstab |
|
1
by Soren Hansen
Import current builder script.. |
936 |
do_initial_user |
937 |
do_network_setup |
|
938 |
do_bootloader |
|
939 |
do_kernel_n_friends |
|
940 |
do_add_remove_packages |
|
|
5.1.4
by Michael Vogt
ubuntu-jeos-builder: |
941 |
do_add_ssh_key |
|
7.2.4
by nijaba
Integrated Onno's patch adding --exec option |
942 |
do_exec_script |
|
1
by Soren Hansen
Import current builder script.. |
943 |
do_copy_to_disk_images |
944 |
do_target_vm_conversion |
|
945 |
do_cleanup |
|
946 |
||
947 |
exit 0
|