195c97501SAlex Bennée#!/bin/sh 295c97501SAlex Bennée# 395c97501SAlex Bennée# Simple wrapper for debootstrap, run in the docker build context 495c97501SAlex Bennée# 595c97501SAlex BennéeFAKEROOT=`which fakeroot 2> /dev/null` 695c97501SAlex Bennée 795c97501SAlex Bennéeexit_and_skip() 895c97501SAlex Bennée{ 995c97501SAlex Bennée exit 3 1095c97501SAlex Bennée} 1195c97501SAlex Bennée 1295c97501SAlex Bennée# 1395c97501SAlex Bennée# fakeroot is needed to run the bootstrap stage 1495c97501SAlex Bennée# 1595c97501SAlex Bennéeif [ -z $FAKEROOT ]; then 16b5dc88ceSSascha Silbe echo "Please install fakeroot to enable bootstraping" >&2 1795c97501SAlex Bennée exit_and_skip 18*341edc0cSSascha Silbe 19*341edc0cSSascha Silbefi 20*341edc0cSSascha Silbe 21*341edc0cSSascha Silbeif [ -z "${DEB_ARCH}" ]; then 22*341edc0cSSascha Silbe echo "Please set DEB_ARCH to choose an architecture (e.g. armhf)" >&2 23*341edc0cSSascha Silbe exit_and_skip 24*341edc0cSSascha Silbe 25*341edc0cSSascha Silbefi 26*341edc0cSSascha Silbe 27*341edc0cSSascha Silbeif [ -z "${DEB_TYPE}" ]; then 28*341edc0cSSascha Silbe echo "Please set DEB_TYPE to a Debian archive name (e.g. testing)" >&2 29*341edc0cSSascha Silbe exit_and_skip 30*341edc0cSSascha Silbe 3195c97501SAlex Bennéefi 3295c97501SAlex Bennée 3395c97501SAlex Bennée# We check in order for 3495c97501SAlex Bennée# 3595c97501SAlex Bennée# - DEBOOTSTRAP_DIR pointing at a development checkout 3695c97501SAlex Bennée# - PATH for the debootstrap script (installed) 3795c97501SAlex Bennée# 3895c97501SAlex Bennée# If neither option works then we checkout debootstrap from its 3995c97501SAlex Bennée# upstream SCM and run it from there. 4095c97501SAlex Bennée# 4195c97501SAlex Bennée 4295c97501SAlex Bennéeif [ -z $DEBOOTSTRAP_DIR ]; then 4395c97501SAlex Bennée DEBOOTSTRAP=`which debootstrap 2> /dev/null` 4495c97501SAlex Bennée if [ -z $DEBOOTSTRAP ]; then 4595c97501SAlex Bennée echo "No debootstrap installed, attempting to install from SCM" 4695c97501SAlex Bennée DEBOOTSTRAP_SOURCE=https://anonscm.debian.org/git/d-i/debootstrap.git 4795c97501SAlex Bennée git clone ${DEBOOTSTRAP_SOURCE} ./debootstrap.git 4895c97501SAlex Bennée export DEBOOTSTRAP_DIR=./debootstrap.git 4995c97501SAlex Bennée DEBOOTSTRAP=./debootstrap.git/debootstrap 5095c97501SAlex Bennée fi 5195c97501SAlex Bennéeelse 5295c97501SAlex Bennée DEBOOTSTRAP=${DEBOOTSTRAP_DIR}/debootstrap 5395c97501SAlex Bennée if [ ! -f $DEBOOTSTRAP ]; then 54b5dc88ceSSascha Silbe echo "Couldn't find script at ${DEBOOTSTRAP}" >&2 5595c97501SAlex Bennée exit_and_skip 5695c97501SAlex Bennée fi 5795c97501SAlex Bennéefi 5895c97501SAlex Bennée 5995c97501SAlex Bennée# 6095c97501SAlex Bennée# Finally check to see if any qemu's are installed 6195c97501SAlex Bennée# 6295c97501SAlex BennéeBINFMT_DIR=/proc/sys/fs/binfmt_misc 6395c97501SAlex Bennéeif [ ! -e $BINFMT_DIR ]; then 64b5dc88ceSSascha Silbe echo "binfmt_misc needs enabling for a QEMU bootstrap to work" >&2 6595c97501SAlex Bennée exit_and_skip 6695c97501SAlex Bennéeelse 6795c97501SAlex Bennée # DEB_ARCH and QEMU arch names are not totally aligned 6895c97501SAlex Bennée case "${DEB_ARCH}" in 6995c97501SAlex Bennée amd64) 7095c97501SAlex Bennée QEMU=qemu-i386 7195c97501SAlex Bennée ;; 7295c97501SAlex Bennée armel|armhf) 7395c97501SAlex Bennée QEMU=qemu-arm 7495c97501SAlex Bennée ;; 7595c97501SAlex Bennée arm64) 7695c97501SAlex Bennée QEMU=qemu-aarch64 7795c97501SAlex Bennée ;; 7895c97501SAlex Bennée powerpc) 7995c97501SAlex Bennée QEMU=qemu-ppc 8095c97501SAlex Bennée ;; 8195c97501SAlex Bennée ppc64el) 8295c97501SAlex Bennée QEMU=qemu-ppc64le 8395c97501SAlex Bennée ;; 8495c97501SAlex Bennée s390) 8595c97501SAlex Bennée QEMU=qemu-s390x 8695c97501SAlex Bennée ;; 8795c97501SAlex Bennée *) 8895c97501SAlex Bennée QEMU=qemu-${DEB_ARCH} 8995c97501SAlex Bennée ;; 9095c97501SAlex Bennée esac 9195c97501SAlex Bennée if [ ! -e "${BINFMT_DIR}/$QEMU" ]; then 92b5dc88ceSSascha Silbe echo "No binfmt_misc rule to run $QEMU, can't bootstrap" >&2 9395c97501SAlex Bennée exit_and_skip 9495c97501SAlex Bennée fi 9595c97501SAlex Bennéefi 9695c97501SAlex Bennée 9795c97501SAlex Bennéeecho "Building a rootfs using ${FAKEROOT} and ${DEBOOTSTRAP} ${DEB_ARCH}/${DEB_TYPE}" 9895c97501SAlex Bennée 9995c97501SAlex Bennée${FAKEROOT} ${DEBOOTSTRAP} --variant=buildd --foreign --arch=$DEB_ARCH $DEB_TYPE . http://httpredir.debian.org/debian || exit 1 10095c97501SAlex Bennéeexit 0 101