Permalink
Cannot retrieve contributors at this time
Fetching contributors…
| #!/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 $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 | |
| } | |
| _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" |