-
Notifications
You must be signed in to change notification settings - Fork 128
/
rumprun
executable file
·829 lines (690 loc) · 16.6 KB
/
rumprun
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
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
#!/bin/sh
#
# Copyright (c) 2014 Martin Lucina. All Rights Reserved.
# Copyright (c) 2015 Antti Kantee. All Rights Reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions
# are met:
# 1. Redistributions of source code must retain the above copyright
# notice, this list of conditions and the following disclaimer.
# 2. Redistributions in binary form must reproduce the above copyright
# notice, this list of conditions and the following disclaimer in the
# documentation and/or other materials provided with the distribution.
#
# THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS
# OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
# DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
# SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
# SUCH DAMAGE.
#
#
# rumprun: "driver" script for running rumprun application stacks
#
# default values
MEM_DEFAULT=64
if [ "${RUMPRUN_WARNING_STFU}" != 'please' ]; then
exec 3>&1 1>&2
echo
echo !!!
echo !!! NOTE: rumprun is experimental. syntax may change in the future
echo !!!
echo
exec 1>&3 3>&-
fi
die ()
{
echo rumprun: error: "$@" 1>&2
exit 1
}
scriptopts='DhSt:T:'
guestopts='b:dD:e:g:iI:M:n:N:pW:'
# script option default values
DUMPCMD=
CANSUDO=false
PRESERVETMPDIR=false
usage ()
{
cat <<EOM
usage: rumprun [script args] PLATFORM [guest args] APP [ -- ] [app args]
PLATFORM is the rumprun runtime platform to use
iso : bake app and config into a bootable iso image
kvm : hw guest via qemu -enable-kvm
qemu : hw guest via qemu -no-kvm
xen : xen guest via xl(1)
APP is the binary to rumprun. app args are processed by APP.
script args are:
[-h] [-DS] [-t tmpdir] [-T tmpdir]
-h display this message
-D dump backend commands instead of running them
-S execute sudo where potentially necessary
-t use tmpdir as dir for temp files (default: /tmp/rumprun.XXXXXXXX)
-T same as -t, except do not remove temporary directory
guest args are:
[-dip] [-b blkspec] [-D port] [-e VAR[=VALUE]] [-g args]
[-I iftag,ifopts] [-M mem] [-N name] [-W iftag,netspec]
-b configures a block device. The format of "blkspec" is:
hostpath[,mountpoint] where:
hostpath = image that is passed to the guest as a block device
mountpoint = if "hostpath" is a file system image, mountpoint on guest
-D attaches a gdb server on port to the guest
-d destroys the guest on poweroff
-e set environment VAR to VALUE
-g specify 'args' to guest. handling, if any, is guest-dependent.
-I create guest network interface and attach the user-specified
iftag to it. the format is:
iftag,ifbasename,[backendopts]
e.g. -I 'qnet0,vioif,-net tap=/dev/tap0'
-i attaches to guest console on startup
-M set the guest's memory to mem megabytes, default is ${MEM_DEFAULT}
-N set the guest's name to name, default is rumprun-APP
-p creates the guest but leaves it paused
-W configure network interface new style, where "netspec" is
inet,dhcp - IPv4 with DHCP
inet,static,addr/mask[,gateway] - IPv4 with static IP
inet6,auto - IPv6 with stateless autoconfiguration
e.g. -W qnet0,inet,static,1.2.3.4/24
EOM
exit 1
}
nuketmpdir ()
{
[ -z "${TMPDIR}" ] && return
${PRESERVETMPDIR} && return
realtmpdir="${TMPDIR}"
TMPDIR=''
rm -rf "${realtmpdir}"
}
setuptmpdir ()
{
if [ -z "${TMPDIR}" ]; then
TMPDIR=$(mktemp -d /tmp/rumprun.XXXXXXXX)
else
[ ! -d "${TMPDIR}" ] || die ${TMPDIR} already exists
mkdir -p "${TMPDIR}" || die could not create ${TMPDIR}
chmod 700 "${TMPDIR}" \
|| { rm -rf "${TMPDIR}" ; die could not chmod ${TMPDIR}; }
fi
trap nuketmpdir 0 INT TERM
}
check_app ()
{
[ -f $1 ] || die "file not found: $1"
if ! grep -q __RuMpRuN_baked__ $1; then
die "$1: not a rumprun unikernel (did you forget rumpbake?)"
fi
}
store_netspec=usage
store_blkspec=usage
nindex=0
bindex=0
createif_qemu ()
{
local iftag ifbasename scratch qemuargs
iftag="${1%%,*}"
scratch="${1#*,}"
ifbasename="${scratch%%,*}"
qemuargs="${scratch#*,}"
opt_netif="${opt_netif} -net nic,model=virtio ${qemuargs}"
eval ${iftag}2ifname=${ifbasename}${nindex}
eval ${iftag}2cloner=false
nindex=$(expr $nindex + 1)
}
createif_iso ()
{
local iftag
local ifbasename
iftag="${1%%,*}"
ifbasename="${1#*,}"
[ "${iftag}" != "${ifbasename}" ] || usage
eval ${iftag}2ifname=${ifbasename}${nindex}
eval ${iftag}2cloner=false
nindex=$(expr $nindex + 1)
}
createif_xen ()
{
local iftag
local ifbasename
local scratch
iftag="${1%%,*}"
scratch="${1#*,}"
ifbasename="${scratch%%,*}"
backendopts="${scratch#*,}"
[ "${iftag}" != "${ifbasename}" ] || usage
eval ${iftag}2ifname=${ifbasename}${nindex}
eval ${iftag}2index=${nindex}
eval ${iftag}2cloner=true
nindex=$(expr $nindex + 1)
# it's magic ;)
conf_vif="${conf_vif}'${backendopts}',"
}
json_depth=0
json_indent ()
{
for x in $(seq ${json_depth}); do
printf '\t' >> ${TMPDIR}/json.cfg
done
}
json_append_ln ()
{
json_indent
echo "$*, " >> ${TMPDIR}/json.cfg
}
json_open_block ()
{
json_append_ln "${1:+\"$1\" : }" {
json_depth=$((${json_depth}+1))
}
json_finalize_block ()
{
[ ${json_depth} -ne 0 ] || die internal json error
json_depth=$((${json_depth}-1))
json_append_ln }
}
# Detect the filesystem type of the image at $1.
detect_fstype ()
{
eval $(blkid -o export $1)
if [ $? -ne 0 ]; then
TYPE=unknown
fi
case ${TYPE} in
ext2)
echo ext2fs
return 0
;;
ufs)
echo ffs
return 0
;;
iso9660)
echo cd9660
return 0
;;
*)
echo unknown
return 1
;;
esac
}
json_store_netspec ()
{
json_open_block net
# XXX: should not assume vioif or -net user
json_append_ln '"if": "'$(eval echo \${${iftag}2ifname})'"'
if $(eval \${${iftag}2cloner}); then
json_append_ln '"cloner": "'true'"'
fi
json_append_ln '"type": "'${iftype}'"'
json_append_ln '"method": "'${ifmethod}'"'
[ -n "${ifaddr}" ] || { json_finalize_block ; return ; }
json_append_ln '"addr": "'${ifaddr}'"'
json_append_ln '"mask": "'${ifmask}'"'
[ -n "${ifgw}" ] || { json_finalize_block ; return ; }
json_append_ln '"gw": "'${ifgw}'"'
json_finalize_block
}
parse_netspec ()
{
iftag=$1
shift
IFS=,
set -- $1
unset IFS
[ $# -lt 2 ] && usage
iftype=$1
ifmethod=$2
[ "${iftype}" != "inet" -a "${iftype}" != "inet6" ] && return 1
case ${ifmethod} in
auto)
;;
dhcp)
;;
static)
ifaddr=${3%/*}
ifmask=${3#*/}
[ -n "${ifaddr}" ] || usage
[ -n "${ifmask}" ] || usage
ifgw=$4
;;
*)
return 1
;;
esac
${store_netspec}
return 0
}
parse_newnetspec ()
{
iftag=${1%%,*}
parse_netspec ${iftag} "${1#*,}"
}
json_store_xen_blkspec ()
{
vdev=xvd$(echo ${bindex} | tr '[0-9]' '[a-j]')
conf_disk="${conf_disk}'file:$image,$vdev,w',"
json_open_block blk
json_append_ln '"source": "'etfs'"'
json_append_ln '"path": "'${vdev}'"'
# if the image does not need to be mounted, we're done
[ -n "${mountpoint}" ] || { json_finalize_block ; return ; }
json_append_ln '"fstype": "'${fstype}'"'
json_append_ln '"mountpoint": "'${mountpoint}'"'
json_finalize_block
}
json_store_qemu_blkspec ()
{
# XXX: should not generate the interface here
opt_drivespec="${opt_drivespec} -drive if=virtio,file=${image}"
# if the image does not need to be mounted, we're done
[ -n "${mountpoint}" ] || return
json_open_block blk
# XXX: should not assume ld (virtio)
json_append_ln '"source": "'dev'"'
json_append_ln '"path": "'/dev/ld${bindex}a'"'
json_append_ln '"fstype": "'${fstype}'"'
json_append_ln '"mountpoint": "'${mountpoint}'"'
json_finalize_block
}
json_store_iso_blkspec ()
{
mkdir -p "${ISODIR}/images"
# XXX: might have accidental clashes due to images from
# many source subdirectories
[ ! -f "${ISODIR}/images/$(basename ${image})" ] \
|| die image \"${image}\" already exists in destdir
cp ${image} "${ISODIR}/images/"
# well, this is a bit questionable, but ...
[ -n "${mountpoint}" ] || return
json_open_block blk
json_append_ln '"source": "'vnd'"'
json_append_ln '"path": "'images/$(basename ${image})'"'
json_append_ln '"fstype": "'${fstype}'"'
json_append_ln '"mountpoint": "'${mountpoint}'"'
json_finalize_block
}
json_store_kernfs ()
{
json_open_block blk
json_append_ln '"source": "dev"' # XXX: not really dev
json_append_ln '"path": "virtual"'
json_append_ln '"fstype": "kernfs"'
json_append_ln '"mountpoint": "/kern"'
json_finalize_block
}
parse_blkspec ()
{
spec=$1
image=${spec%,*}
image=$(readlink -f ${image})
mountpoint=$(echo ${spec} | sed -n 's/.*,\(.*\)/\1/p')
[ -n "$image" ] || usage
[ -f "$image" ] || die File $image does not exist
if [ -n "$mountpoint" ]; then
fstype=$(detect_fstype $image)
[ $? -ne 0 ] && die File $image: unknown fstype
fi
${store_blkspec}
bindex=$(expr $bindex + 1)
}
# run_xen: Generate Xen configuration and run application stack.
run_xen ()
{
[ -z "${DUMPCMD}" ] || echo WARNING: -D not perfectly supported by Xen
# try to find gdbsx from common locations
unset gdbsx
for x in gdbsx /usr/lib/xen-4.4/bin/gdbsx ; do
if type ${x}> /dev/null 2>&1; then
gdbsx=$(which ${x})
break
fi
done
store_blkspec=json_store_xen_blkspec
store_netspec=json_store_netspec
conf="${TMPDIR}/xr.conf"
>${conf}
OPTIND=1
conf_disk=
conf_vif=
opt_pause=
opt_interactive=
opt_destroy='on_poweroff="preserve"'
opt_mem=${MEM_DEFAULT}
opt_name=
opt_debug=
sudo=''
json_open_block
while getopts "${guestopts}" opt; do
case "$opt" in
# -n: NETSPEC
n)
netname=_net${nindex}
createif_xen ${netname},xenif || usage
parse_newnetspec "${netname},${OPTARG}" || usage
;;
# -b: BLKSPEC: hostpath,mountpoint
b)
parse_blkspec "${OPTARG}" || usage
;;
# -e: Set guest environment variable.
e)
json_append_ln "\"env\": \"${OPTARG}\""
;;
# -p: Leave the domain paused after creation.
p)
opt_pause=1
;;
# -i: Attach to domain console on startup.
i)
opt_interactive=1
;;
# -I: create interface
I)
createif_xen "${OPTARG}" || usage
;;
# -d: Destroy domain on poweroff instead of preserving it.
d)
opt_destroy='on_poweroff="destroy"'
;;
# -N: Override domain name.
N)
opt_name=${OPTARG}
;;
# -M: Set domain memory.
M)
opt_mem=${OPTARG}
;;
# -D PORT: attach gdbsx to domain.
D)
if [ -z "${gdbsx}" ]; then
die "'gdbsx' is required for -D, please install it."
fi
opt_debug=${OPTARG}
;;
W)
parse_newnetspec "${OPTARG}" || usage
;;
*)
usage
;;
esac
done
# Remaining arguments belong to the application.
shift $((OPTIND-1))
[ "$1" = "--" ] && shift
[ $# -lt 1 ] && usage
# kernfs is always present on Xen
json_store_kernfs
json_append_ln "\"cmdline\": \""$@"\""
json_finalize_block
# Clean up vif and disk, xl does not like trailing commas.
conf_vif=$(echo ${conf_vif} | sed -e s/,\$//)
[ -n ${conf_vif} ] && conf_vif="vif=[${conf_vif}]"
conf_disk=$(echo ${conf_disk} | sed -e s/,\$//)
[ -n ${conf_disk} ] && conf_disk="disk=[${conf_disk}]"
name=${opt_name:-rumprun-$(basename $1)}
app=$(readlink -f $1)
shift
check_app ${app}
# Generate xl configuration file.
cat <<EOM >"${TMPDIR}/xr.conf"
kernel="${app}"
name="${name}"
vcpus=1
memory=${opt_mem}
on_crash="preserve"
${opt_destroy}
${conf_vif}
${conf_disk}
EOM
if ${CANSUDO} && [ $(id -u) -ne 0 ]; then
sudo='sudo'
fi
# Create the domain and leave it paused so that we can get its domid.
if ! ${DUMPCMD} ${sudo} xl create -p ${conf} >/dev/null; then
die xl create failed
fi
domid=$(${DUMPCMD} ${sudo} xl domid ${name})
# Write provisioning information for domain to xenstore.
prefix=/local/domain/${domid}/rumprun
${DUMPCMD} ${sudo} xenstore-write \
"${prefix}/cfg" "$(cat ${TMPDIR}/json.cfg)"
nuketmpdir
# Attach debugger if requested.
if [ -n "$opt_debug" ]; then
if objdump -f ${app} | grep -q elf64; then
bits=64
else
bits=32
fi
${DUMPCMD} ${sudo} ${gdbsx} -a ${domid} ${bits} ${opt_debug} &
fi
# Go go go!
[ -z "$opt_pause" ] && ${DUMPCMD} ${sudo} xl unpause ${domid}
if [ -n "$opt_interactive" ]; then
${DUMPCMD} exec ${sudo} xl console $domid
else
echo xen:${domid}
fi
}
run_qemu ()
{
store_blkspec=json_store_qemu_blkspec
store_netspec=json_store_netspec
opt_interactive=
opt_drivespec=
opt_debug=
opt_pause=
opt_netif=
opt_guestargs=
opt_mem=${MEM_DEFAULT}
json_open_block
variant=$1
shift
while getopts "${guestopts}" opt; do
case "$opt" in
b)
parse_blkspec "${OPTARG}" || usage
;;
d)
die -d not supported on qemu/kvm
;;
D)
opt_debug="-gdb tcp::${OPTARG}"
;;
e)
json_append_ln "\"env\": \"${OPTARG}\""
;;
g)
# toimii ku gunan vessa
opt_guestargs="${opt_guestargs} ${OPTARG}"
;;
i)
opt_interactive=1
;;
I)
createif_qemu "${OPTARG}" || usage
nindex=$(expr $nindex + 1)
;;
M)
opt_mem=${OPTARG}
;;
n)
netname=_net${nindex}
createif_qemu "${netname},vioif,-net user"
parse_netspec ${netname} "${OPTARG}" || usage
;;
N)
# ignored
opt_name=${OPTARG}
;;
p)
opt_pause="-S"
;;
W)
parse_newnetspec "${OPTARG}" || usage
;;
*)
usage
;;
esac
done
shift $((${OPTIND}-1))
if [ "${variant}" = "kvm" ]; then
opt_kvm=-enable-kvm
else
opt_kvm=-no-kvm
fi
json_append_ln "\"cmdline\": \""$@"\""
json_finalize_block
# internal check
[ ${json_depth} -eq 0 ] || die internal error, final depth ${json_depth}
json_coma="$(sed 's/,/,,/g' < "${TMPDIR}/json.cfg")"
[ -n "${opt_netif}" ] || opt_netif="-net none"
check_app $1
# XXX: using host objdump here is wrong, but xen uses it too,
# and both offenses should be easy to fix at the same time
if objdump -f ${1} | grep -q elf64; then
qemu=qemu-system-x86_64
else
qemu=qemu-system-i386
fi
qemucmd="${DUMPCMD} ${qemu} ${opt_netif} ${opt_kvm} \
${opt_drivespec} ${opt_debug} ${opt_pause} -m ${opt_mem} \
${opt_guestargs} -kernel $1"
if [ -n "$opt_interactive" ]; then
${qemucmd} -append "${json_coma}"
else
qemucmd="${qemucmd} -display none"
${qemucmd} -append "${json_coma}" 1>/dev/null 2>&1 &
echo qemu:$!
fi
}
bake_iso ()
{
type xorriso >/dev/null || die bake_iso needs xorriso
type grub-mkrescue >/dev/null || die bake_iso needs grub-mkrescue
store_blkspec=json_store_iso_blkspec
store_netspec=json_store_netspec
opt_interactive=
opt_drivespec=
opt_debug=
opt_pause=
opt_netif=
opt_mem=${MEM_DEFAULT}
blk_specified=false
ISODIR="${TMPDIR}/iso"
mkdir -p "${ISODIR}"
json_open_block
while getopts "${guestopts}" opt; do
case "$opt" in
b)
${blk_specified} \
&& die only one -b parameter supported. will fix.
blk_specified=true
parse_blkspec "${OPTARG}" || usage
;;
d)
die -d not supported on iso
;;
D)
die -D not supported on iso
;;
e)
json_append_ln "\"env\": \"${OPTARG}\""
;;
i)
die -i not supported on iso
;;
I)
createif_iso "${OPTARG}" || usage
nindex=$(expr $nindex + 1)
;;
M)
die -M not supported on iso
;;
N)
opt_name=${OPTARG}
;;
p)
die -p not supported on iso
;;
W)
parse_newnetspec "${OPTARG}" || usage
;;
*)
usage
;;
esac
done
shift $((${OPTIND}-1))
bootimage=$1
check_app ${bootimage}
: ${opt_name:=rumprun-$(echo ${bootimage} | tr / _).iso}
[ ! -f ${opt_name} ] || die target ${opt_name} already exists
json_append_ln "\"cmdline\": \""$@"\""
json_finalize_block
[ ${json_depth} -eq 0 ] || die internal error, final depth ${json_depth}
# create the iso directory structure
mkdir -p "${ISODIR}/boot/grub"
printf 'set timeout=0\n' > "${ISODIR}/boot/grub/grub.cfg"
printf 'menuentry "rumpkernel" {\n' >> "${ISODIR}/boot/grub/grub.cfg"
printf '\tmultiboot /boot/%s ROOTFSCFG=/json.cfg\n}\n' $(basename $1) \
>> "${ISODIR}/boot/grub/grub.cfg"
cp ${bootimage} "${ISODIR}/boot"
cp "${TMPDIR}/json.cfg" "${ISODIR}"
grub-mkrescue "${ISODIR}" -o ${opt_name}
}
if [ $# -lt 2 ]; then
usage
fi
while getopts "${scriptopts}" opt; do
case "${opt}" in
D)
DUMPCMD=echo
;;
h)
usage
;;
S)
CANSUDO=true
;;
t)
TMPDIR="${OPTARG}"
;;
T)
PRESERVETMPDIR=true
TMPDIR="${OPTARG}"
;;
esac
done
shift $((${OPTIND}-1))
OPTIND=1
platform="$1"
shift
setuptmpdir
case ${platform} in
xen)
run_xen "$@"
;;
iso)
bake_iso "$@"
;;
kvm)
run_qemu kvm "$@"
;;
qemu)
run_qemu qemu "$@"
;;
*)
echo Invalid platform \"${platform}\" 1>&2
usage
;;
esac
exit 0