This repository has been archived by the owner on Feb 16, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 7
/
rootstock-touch
executable file
·346 lines (321 loc) · 9.5 KB
/
rootstock-touch
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
#!/bin/sh
# shellcheck disable=SC2039,SC2124,SC2010
#
# Copyright (c) 2014 Canonical
# Copyright (c) 2017 The UBports Project
#
# Author: Oliver Grawert <ogra@canonical.com>
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License as
# published by the Free Software Foundation; either version 2 of the
# License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
# USA
#
set -e
# needs 6.5GB free diskspace for building
# TODO:
# - allow single deb to be injected
export LC_ALL=C
SUITE="xenial"
ARCH="armhf"
NOW=$(date +%Y%m%d)
OUTDIR="./out-$NOW"
TAILPID=
KEEP=
DO_PPA=
PREINSTALLED="true"
IMAGEFORMAT="plain"
PROJECT_="ubports-touch"
HOSTARCH=$(dpkg-architecture -qDEB_HOST_ARCH)
CHROOT=$(mktemp -d /tmp/rootstock.XXXXX)
cleanup()
{
[ -n "$TAILPID" ] && kill -9 $TAILPID
if [ -e "$CHROOT" ]; then
umount $CHROOT/sys >/dev/null 2>&1 || true
umount $CHROOT/proc >/dev/null 2>&1 || true
if [ -e "$CHROOT/build.log" ]; then
LOG=./build-$NOW-$ARCH.log
[ -e "$OUTDIR" ] && LOG=$OUTDIR/build-$NOW-$ARCH.log
cp $CHROOT/build.log $LOG
fi
[ -z "$KEEP" ] && rm -rf $CHROOT >/dev/null 2>&1 || true
fi
}
trap cleanup 0 1 2 3 15
usage()
{
echo "usage: $(basename $0)\n
-h|--help this page
-a|--arch (i386|armhf|arm64) pick an arch, default: armhf
-m|--mirror (url) url to local mirror
-o|--outdir (dir) output dir, default: ./out-\$timestamp
-k|--keep-chroot keep the build environment around for inspection
-p|--ppa (ppa url) a ppa url in the form of ppa:user/ppaname
-s|--series Ubuntu distro series
-t|--type project type (ubports-touch|ubuntu-touch|ubuntu-core)
-b|--buidir (dir) buildir, default: tmp\n
-n|--native build with native hardware without need of chroot\n
-c|--native-chroot use native chroot (used for cross arch bulding)\n
-l|--native-mirror (url) mirror to use on native chroot (used for cross arch bulding)\n"
# -i|--inject-package (path to deb) inject a single .deb in the build
exit 1
}
SUDOARGS="$@"
while [ $# -gt 0 ]; do
case "$1" in
-h|--help)
usage
;;
-a|--arch)
[ -n "$2" ] && ARCH=$2 shift || usage
;;
-m|--mirror)
[ -n "$2" ] && MIRROR=$2 shift || usage
;;
-l|--native_mirror)
[ -n "$2" ] && NATIVE_MIRROR=$2 shift || usage
;;
-o|--outdir)
[ -n "$2" ] && OUTDIR=$2 shift || usage
;;
-k|--keep-chroot)
KEEP=1
;;
-p|--ppa)
[ -n "$2" ] && PPAOPT=$2 shift || usage
MYPPA=$(echo $PPAOPT|sed 's/^.*://')
PPA_USER=${MYPPA%%/*}
PPA_NAME=${MYPPA##*/}
DO_PPA=1
;;
-s|--series)
[ -n "$2" ] && SUITE=$2 shift || usage
;;
-t|--type)
[ -n "$2" ] && PROJECT_=$2 shift || usage
;;
-b|--buildir)
[ -n "$2" ] && CHROOT=$2 shift || usage
;;
-n|--native)
NATIVE=1
;;
-c|--native-chroot)
NATIVE_CHROOT=1
NATIVE_BOOTSTRAP_BIN="debootstrap --arch $HOSTARCH"
if [ $HOSTARCH = "armhf" ] || [ $HOSTARCH = "arm64" ]; then
NATIVE_MIRROR="${NATIVE_MIRROR:-http://ports.ubuntu.com/ubuntu-ports}"
else
NATIVE_MIRROR="${NATIVE_MIRROR:-http://archive.ubuntu.com/ubuntu}"
fi
;;
*)
usage
;;
esac
shift
done
case $ARCH in
i386|amd64)
case $HOSTARCH in
armhf|arm64)
echo "arm machine cannot build i386 or amd64"
exit 1
;;
*)
MIRROR="${MIRROR:-http://archive.ubuntu.com/ubuntu}"
BOOTSTRAP_BIN="debootstrap --arch $ARCH"
IS_NATIVE=1
LB_BOOTSTRAP_QEMU_ARCHITECTURES=""
LB_BOOTSTRAP_QEMU_STATIC=""
;;
esac
;;
armhf)
case $HOSTARCH in
armhf)
MIRROR="${MIRROR:-http://ports.ubuntu.com/ubuntu-ports}"
BOOTSTRAP_BIN="debootstrap --arch $ARCH --variant=minbase"
LB_BOOTSTRAP_QEMU_ARCHITECTURES=""
LB_BOOTSTRAP_QEMU_STATIC=""
IS_NATIVE=1
;;
*)
[ ! "$(which qemu-debootstrap)" ] && echo "please install the qemu-user-static package" && exit 1
MIRROR="${MIRROR:-http://ports.ubuntu.com/ubuntu-ports}"
BOOTSTRAP_BIN="qemu-debootstrap --arch armhf --variant=minbase"
LB_BOOTSTRAP_QEMU_ARCHITECTURES="armhf"
LB_BOOTSTRAP_QEMU_STATIC="/usr/bin/qemu-arm-static"
;;
esac
;;
arm64)
case $HOSTARCH in
arm64)
MIRROR="${MIRROR:-http://ports.ubuntu.com/ubuntu-ports}"
BOOTSTRAP_BIN="debootstrap --arch $ARCH --variant=minbase"
LB_BOOTSTRAP_QEMU_ARCHITECTURES=""
LB_BOOTSTRAP_QEMU_STATIC=""
IS_NATIVE=1
;;
*)
[ ! "$(which qemu-debootstrap)" ] && echo "please install the qemu-user-static package" && exit 1
MIRROR="${MIRROR:-http://ports.ubuntu.com/ubuntu-ports}"
BOOTSTRAP_BIN="qemu-debootstrap --arch arm64 --variant=minbase"
LB_BOOTSTRAP_QEMU_ARCHITECTURES="arm64"
LB_BOOTSTRAP_QEMU_STATIC="/usr/bin/qemu-aarch64-static"
;;
esac
;;
*)
usage
;;
esac
case $PROJECT_ in
ubuntu-core)
SUBPROJECT=system-image
EXTRA_PPAS=snappy-dev/image
PROJECT=$PROJECT_
;;
ubuntu-touch)
EXTRA_PPAS="ci-train-ppa-service/stable-phone-overlay:1001"
PROJECT=$PROJECT_
;;
ubports-touch)
EXTRA_PPAS="ci-train-ppa-service/stable-phone-overlay:1001 ubports-developers/overlay:1011"
PROJECT="ubuntu-touch"
;;
esac
BUILDOPTS="SUBPROJECT=${SUBPROJECT} \
EXTRA_PPAS=\"${EXTRA_PPAS}\" \
PREINSTALLED=${PREINSTALLED} \
LB_BOOTSTRAP_QEMU_ARCHITECTURES=${LB_BOOTSTRAP_QEMU_ARCHITECTURES} \
LB_BOOTSTRAP_QEMU_STATIC=${LB_BOOTSTRAP_QEMU_STATIC} \
IMAGEFORMAT=${IMAGEFORMAT} \
MIRROR=${MIRROR} \
NOW=${NOW} \
SUITE=${SUITE} \
PROJECT=${PROJECT} \
ARCH=${ARCH}"
[ "$(id -u)" -ne 0 ] && exec sudo ORGUSER=$(whoami) $0 $SUDOARGS
mkdir $CHROOT || true
touch $CHROOT/build.log
tail -f $CHROOT/build.log &
TAILPID=$!
exec 3>&1 4>&2 >$CHROOT/build.log 2>&1
do_chroot()
{
ROOT="$1"
CMD="$2"
chroot $ROOT mount -t proc proc /proc
chroot $ROOT mount -t sysfs sys /sys
chroot $ROOT $CMD
chroot $ROOT umount /sys
chroot $ROOT umount /proc
}
set_up_ppa()
{
PPA_API="https://launchpad.net/api/1.0/~$PPA_USER/+archive/$PPA_NAME"
PPA_FINGERPRINT="$(wget -O- -q $PPA_API|tr ',' '\n'|\
grep signing_key_fingerprint|\
sed s/\"//g|tail -c9)"
KEY_URL="http://keyserver.ubuntu.com/pks/lookup?op=get&search=0x$PPA_FINGERPRINT"
KEY=$(wget -O- -q $KEY_URL|sed -e '/-----/,$!d'|sed '/^<.*/d')
PPA_CONFDIR="$CHROOT/usr/share/livecd-rootfs/live-build/ubuntu-touch/archives"
mkdir -p "$PPA_CONFDIR"
echo "$KEY" >"$PPA_CONFDIR/$PPA_USER-$PPA_NAME.key.chroot"
PPA_SOURCESLIST="deb http://ppa.launchpad.net/$PPA_USER/$PPA_NAME/ubuntu $SUITE main"
echo "$PPA_SOURCESLIST" >"$PPA_CONFDIR/$PPA_USER-$PPA_NAME.list.chroot"
}
build_chroot()
{
if [ $NATIVE_CHROOT = "1" ]; then
$NATIVE_BOOTSTRAP_BIN $SUITE $CHROOT $NATIVE_MIRROR
else
$BOOTSTRAP_BIN $SUITE $CHROOT $MIRROR
fi
echo "nameserver 8.8.8.8" >$CHROOT/etc/resolv.conf
if [ "$NATIVE_CHROOT" = "1" ]; then
echo "deb $NATIVE_MIRROR $SUITE main universe" >$CHROOT/etc/apt/sources.list
echo "deb $NATIVE_MIRROR $SUITE-updates main universe" >>$CHROOT/etc/apt/sources.list
else
echo "deb $MIRROR $SUITE main universe" >$CHROOT/etc/apt/sources.list
echo "deb $MIRROR $SUITE-updates main universe" >>$CHROOT/etc/apt/sources.list
fi
echo "deb http://ppa.launchpad.net/ubports-developers/overlay/ubuntu $SUITE main" >>$CHROOT/etc/apt/sources.list
do_chroot $CHROOT "apt-key adv --keyserver keyserver.ubuntu.com --recv-keys 6506B829CB0EE80B"
do_chroot $CHROOT "apt-get -y update"
if [ "$NATIVE_CHROOT" = "1" ]; then
do_chroot $CHROOT "apt-get -y install livecd-rootfs debootstrap qemu-user-static"
else
do_chroot $CHROOT "apt-get -y install livecd-rootfs debootstrap"
fi
mkdir -p $CHROOT/build
chroot $CHROOT sh -c "cd /build && rm -rf auto && mkdir -p auto && \
for f in config build clean; do ln -s /usr/share/livecd-rootfs/live-build/auto/\$f auto/; done"
# hack for click package location
sed -i 's,archive-team.internal,cdimage.ubports.com/clicks/,' \
$CHROOT/usr/share/livecd-rootfs/live-build/ubuntu-touch/hooks/60-install-click.chroot || true
}
build_touch()
{
chroot $CHROOT mount -t proc proc /proc
chroot $CHROOT mount -t sysfs sys /sys
chroot $CHROOT sh -c "cd /build && lb clean --purge"
if [ "$NATIVE_CHROOT" = "1" ]; then
chroot $CHROOT sh -c "cd /build && $BUILDOPTS lb config --bootstrap-qemu-arch $ARCH -a $ARCH"
else
chroot $CHROOT sh -c "cd /build && $BUILDOPTS lb config"
fi
chroot $CHROOT sh -c "cd /build && $BUILDOPTS lb build"
chroot $CHROOT umount /sys
chroot $CHROOT umount /proc
}
build_touch_native()
{
RETURN_DIR=$(pwd)
mkdir $CHROOT/build
cd $CHROOT/build
sh -c "rm -rf auto && mkdir -p auto && \
for f in config build clean; do ln -s /usr/share/livecd-rootfs/live-build/auto/\$f auto/; done"
sh -c "lb clean --purge"
sh -c "$BUILDOPTS lb config --bootstrap-qemu-arch $ARCH -a $ARCH"
sh -c "$BUILDOPTS lb build"
cd $RETURN_DIR
}
copy_artefacts()
{
mkdir -p $OUTDIR
for file in $(ls $CHROOT/build/livecd.*|grep -v bootimg); do
cp $file "$OUTDIR/$(echo $file|sed -e s/^.*livecd.// -e s/rootfs/rootfs-$SUITE-$ARCH/ -e s/ubuntu/ubports/)"
done
if [ -n "$ORGUSER" ]; then
chown -R $ORGUSER $OUTDIR
fi
}
_echo()
{
echo $1 >> $CHROOT/build.log
}
if [ "$NATIVE" != "1" ]; then
build_chroot
fi
[ -n "$DO_PPA" ] && set_up_ppa
if [ "$NATIVE" = "1" ]; then
build_touch_native
else
build_touch
fi
copy_artefacts
_echo "done"