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` 600263139SSascha Silbe# debootstrap < 1.0.67 generates empty sources.list, see Debian#732255 700263139SSascha SilbeMIN_DEBOOTSTRAP_VERSION=1.0.67 895c97501SAlex Bennée 995c97501SAlex Bennéeexit_and_skip() 1095c97501SAlex Bennée{ 1195c97501SAlex Bennée exit 3 1295c97501SAlex Bennée} 1395c97501SAlex Bennée 1495c97501SAlex Bennée# 1595c97501SAlex Bennée# fakeroot is needed to run the bootstrap stage 1695c97501SAlex Bennée# 1795c97501SAlex Bennéeif [ -z $FAKEROOT ]; then 18b5dc88ceSSascha Silbe echo "Please install fakeroot to enable bootstraping" >&2 1995c97501SAlex Bennée exit_and_skip 20341edc0cSSascha Silbe 21341edc0cSSascha Silbefi 22341edc0cSSascha Silbe 23341edc0cSSascha Silbeif [ -z "${DEB_ARCH}" ]; then 24341edc0cSSascha Silbe echo "Please set DEB_ARCH to choose an architecture (e.g. armhf)" >&2 25341edc0cSSascha Silbe exit_and_skip 26341edc0cSSascha Silbe 27341edc0cSSascha Silbefi 28341edc0cSSascha Silbe 29341edc0cSSascha Silbeif [ -z "${DEB_TYPE}" ]; then 30341edc0cSSascha Silbe echo "Please set DEB_TYPE to a Debian archive name (e.g. testing)" >&2 31341edc0cSSascha Silbe exit_and_skip 32341edc0cSSascha Silbe 3395c97501SAlex Bennéefi 3495c97501SAlex Bennée 35*300cf467SAlex Bennée# The following allow finer grain control over the defaults 36*300cf467SAlex Bennéeif [ -z "${DEB_VARIANT}" ]; then 37*300cf467SAlex Bennée DEB_VARIANT=buildd 38*300cf467SAlex Bennéefi 39*300cf467SAlex Bennée 40*300cf467SAlex Bennéeif [ -z "${DEB_URL}" ]; then 41*300cf467SAlex Bennée DEB_URL="http://httpredir.debian.org/debian" 42*300cf467SAlex Bennéefi 43*300cf467SAlex Bennée 4495c97501SAlex Bennée# We check in order for 4595c97501SAlex Bennée# 4695c97501SAlex Bennée# - DEBOOTSTRAP_DIR pointing at a development checkout 4795c97501SAlex Bennée# - PATH for the debootstrap script (installed) 4895c97501SAlex Bennée# 4995c97501SAlex Bennée# If neither option works then we checkout debootstrap from its 5095c97501SAlex Bennée# upstream SCM and run it from there. 5195c97501SAlex Bennée# 5295c97501SAlex Bennée 5395c97501SAlex Bennéeif [ -z $DEBOOTSTRAP_DIR ]; then 5400263139SSascha Silbe NEED_DEBOOTSTRAP=false 5595c97501SAlex Bennée DEBOOTSTRAP=`which debootstrap 2> /dev/null` 5695c97501SAlex Bennée if [ -z $DEBOOTSTRAP ]; then 5795c97501SAlex Bennée echo "No debootstrap installed, attempting to install from SCM" 5800263139SSascha Silbe NEED_DEBOOTSTRAP=true 5900263139SSascha Silbe elif ! (echo "${MIN_DEBOOTSTRAP_VERSION}" ; "${DEBOOTSTRAP}" --version \ 6000263139SSascha Silbe | cut -d ' ' -f 2) | sort -t . -n -k 1,1 -k 2,2 -k 3,3 -c &>/dev/null; then 6100263139SSascha Silbe echo "debootstrap too old, attempting to install from SCM" 6200263139SSascha Silbe NEED_DEBOOTSTRAP=true 6300263139SSascha Silbe fi 6400263139SSascha Silbe if $NEED_DEBOOTSTRAP; then 6595c97501SAlex Bennée DEBOOTSTRAP_SOURCE=https://anonscm.debian.org/git/d-i/debootstrap.git 6695c97501SAlex Bennée git clone ${DEBOOTSTRAP_SOURCE} ./debootstrap.git 6795c97501SAlex Bennée export DEBOOTSTRAP_DIR=./debootstrap.git 6895c97501SAlex Bennée DEBOOTSTRAP=./debootstrap.git/debootstrap 69ae2f659cSSascha Silbe (cd "${DEBOOTSTRAP_DIR}" && "${FAKEROOT}" make ) 7095c97501SAlex Bennée fi 7195c97501SAlex Bennéeelse 7295c97501SAlex Bennée DEBOOTSTRAP=${DEBOOTSTRAP_DIR}/debootstrap 7395c97501SAlex Bennée if [ ! -f $DEBOOTSTRAP ]; then 74b5dc88ceSSascha Silbe echo "Couldn't find script at ${DEBOOTSTRAP}" >&2 7595c97501SAlex Bennée exit_and_skip 7695c97501SAlex Bennée fi 7795c97501SAlex Bennéefi 7895c97501SAlex Bennée 7995c97501SAlex Bennée# 8095c97501SAlex Bennée# Finally check to see if any qemu's are installed 8195c97501SAlex Bennée# 8295c97501SAlex BennéeBINFMT_DIR=/proc/sys/fs/binfmt_misc 8395c97501SAlex Bennéeif [ ! -e $BINFMT_DIR ]; then 84b5dc88ceSSascha Silbe echo "binfmt_misc needs enabling for a QEMU bootstrap to work" >&2 8595c97501SAlex Bennée exit_and_skip 8695c97501SAlex Bennéeelse 8795c97501SAlex Bennée # DEB_ARCH and QEMU arch names are not totally aligned 8895c97501SAlex Bennée case "${DEB_ARCH}" in 8995c97501SAlex Bennée amd64) 9095c97501SAlex Bennée QEMU=qemu-i386 9195c97501SAlex Bennée ;; 9295c97501SAlex Bennée armel|armhf) 9395c97501SAlex Bennée QEMU=qemu-arm 9495c97501SAlex Bennée ;; 9595c97501SAlex Bennée arm64) 9695c97501SAlex Bennée QEMU=qemu-aarch64 9795c97501SAlex Bennée ;; 9895c97501SAlex Bennée powerpc) 9995c97501SAlex Bennée QEMU=qemu-ppc 10095c97501SAlex Bennée ;; 10195c97501SAlex Bennée ppc64el) 10295c97501SAlex Bennée QEMU=qemu-ppc64le 10395c97501SAlex Bennée ;; 10495c97501SAlex Bennée s390) 10595c97501SAlex Bennée QEMU=qemu-s390x 10695c97501SAlex Bennée ;; 10795c97501SAlex Bennée *) 10895c97501SAlex Bennée QEMU=qemu-${DEB_ARCH} 10995c97501SAlex Bennée ;; 11095c97501SAlex Bennée esac 11195c97501SAlex Bennée if [ ! -e "${BINFMT_DIR}/$QEMU" ]; then 112b5dc88ceSSascha Silbe echo "No binfmt_misc rule to run $QEMU, can't bootstrap" >&2 11395c97501SAlex Bennée exit_and_skip 11495c97501SAlex Bennée fi 11595c97501SAlex Bennéefi 11695c97501SAlex Bennée 11795c97501SAlex Bennéeecho "Building a rootfs using ${FAKEROOT} and ${DEBOOTSTRAP} ${DEB_ARCH}/${DEB_TYPE}" 11895c97501SAlex Bennée 119*300cf467SAlex Bennée${FAKEROOT} ${DEBOOTSTRAP} --variant=$DEB_VARIANT --foreign --arch=$DEB_ARCH $DEB_TYPE . $DEB_URL || exit 1 12095c97501SAlex Bennéeexit 0 121