-
Notifications
You must be signed in to change notification settings - Fork 46
/
build-appliance
executable file
·178 lines (157 loc) · 3.39 KB
/
build-appliance
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
#!/bin/bash
#
# build-appliance - build or update a test appliance
#
# For details, see usage() and Documentation/building-rootfs.md
set -e -u
gen_image_args=
gce_image_args=
OUT_TAR=
DATECODE=
BUILD_ENV=
SUDO_ENV=sudo
DO_GCE=
NO_BUILD=
ADD_PACKAGES=
d=$(dirname "$0")
if test $d = "." ; then
DIR=$(pwd)
else
DIR=$(realpath $(dirname "$0"))
fi
cd "$DIR"
if test -f config.custom ; then
. config.custom
else
. config
fi
. run-fstests/util/arch-funcs
set_default_arch
usage()
{
cat <<EOF
Usage: build-appliance [OPTION]...
Build or update a test appliance.
Options:
--add-package PACKAGE
Install the package or comma-delimited list of packages
as additional packages in the test appliance
--chroot CHROOT Use the specified build chroot, where CHROOT is the chroot
name in /etc/schroot/schroot.conf, e.g. "stretch-amd64".
--gce Build a GCE test appliance as well as a kvm/android
test appliance
--out-tar Build a root_fs.tar.gz, not a root_fs.img
--out-both Build both the root_Fs.img as well as the root_fs.tar.gz
--no-out-tar Build/update a root_fs.img, not a root_fs.tar.gz
--update Update only; don't do a clean build. (Only supported with
.img output currently.)
EOF
}
UPDATE=false
longopts="help"
longopts+=",add-package:"
longopts+=",chroot:"
longopts+=",out-tar"
longopts+=",out-both"
longopts+=",no-build"
longopts+=",no-out-tar"
longopts+=",update"
longopts+=",gce"
longopts+=",datecode:"
if ! options=$(getopt -o "" -l "$longopts" -- "$@"); then
usage 1>&2
exit 2
fi
eval set -- "$options"
while (( $# >= 0 )); do
case "$1" in
--help)
usage
exit 0
;;
--add-package)
ADD_PACKAGES="$ADD_PACKAGES $2"
shift
;;
--chroot)
BUILD_ENV="schroot -c $2 --"
SUDO_ENV="schroot -c $2 -u root --"
MY_ARCH=$(schroot -c $2 -- dpkg --print-architecture)
shift
;;
--out-tar)
OUT_TAR=yes
;;
--out-both)
OUT_TAR=both
;;
--no-build)
NO_BUILD=yes
;;
--no-out-tar)
OUT_TAR=
;;
--update)
UPDATE=true
;;
--gce)
DO_GCE=yes
;;
--datecode) shift
DATECODE="$1"
;;
--)
shift
break
;;
*)
echo 1>&2 "Invalid option: \"$1\""
usage 1>&2
exit 2
;;
esac
shift
done
if $UPDATE && [ "$OUT_TAR" = "yes" ]; then
echo 1>&2 "--update is only supported with .img output currently!"
exit 1
fi
set_my_arch
set_canonicalized_arch "$MY_ARCH"
cd fstests-bld
if $UPDATE; then
$BUILD_ENV ./update-all
gen_image_args+=" --update"
else
if test -z "$NO_BUILD" ; then
$BUILD_ENV make all-clean-first
fi
fi
$BUILD_ENV ./gen-tarball --arch "$ARCH"
case "$OUT_TAR" in
both) gen_image_args+=" --both" ;;
yes) gen_image_args+=" --out-tar" ;;
esac
if test -n "$ADD_PACKAGES" ; then
a=$(echo $ADD_PACKAGES | sed -e 's/ /,/')
gen_image_args+=" -a $a"
gce_image_args+= "--add-package $a"
unset a
fi
cd ../run-fstests
if test -n "$DO_GCE"; then
d=
if test -n "$DATECODE" ; then
d="--datecode $DATECODE"
fi
./gce-xfstests create-image $gce_image_args --arch=$ARCH $d \
>& /tmp/gce-xfstests-create.$$ &
fi
cd ../test-appliance
$SUDO_ENV ./gen-image $gen_image_args --src_date @$(git log -1 --pretty=%ct)
if test -n "$DO_GCE"; then
tail -n +1 -f /tmp/gce-xfstests-create.$$ &
wait %./gce-xfstests
kill %tail
rm -f /tmp/gce-xfstests-create.$$
fi