| 
									
										
										
										
											2016-07-19 21:20:39 +08:00
										 |  |  | #!/bin/sh | 
					
						
							|  |  |  | # | 
					
						
							|  |  |  | # Simple wrapper for debootstrap, run in the docker build context | 
					
						
							|  |  |  | # | 
					
						
							|  |  |  | FAKEROOT=`which fakeroot 2> /dev/null` | 
					
						
							| 
									
										
										
										
											2016-09-06 22:05:49 +02:00
										 |  |  | # debootstrap < 1.0.67 generates empty sources.list, see Debian#732255 | 
					
						
							|  |  |  | MIN_DEBOOTSTRAP_VERSION=1.0.67 | 
					
						
							| 
									
										
										
										
											2016-07-19 21:20:39 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | exit_and_skip() | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     exit 3 | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | # | 
					
						
							|  |  |  | # fakeroot is needed to run the bootstrap stage | 
					
						
							|  |  |  | # | 
					
						
							|  |  |  | if [ -z $FAKEROOT ]; then | 
					
						
							| 
									
										
										
										
											2016-09-06 22:05:46 +02:00
										 |  |  |     echo "Please install fakeroot to enable bootstraping" >&2 | 
					
						
							| 
									
										
										
										
											2016-07-19 21:20:39 +08:00
										 |  |  |     exit_and_skip | 
					
						
							| 
									
										
										
										
											2016-09-06 22:05:47 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  | fi | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | if [ -z "${DEB_ARCH}" ]; then | 
					
						
							|  |  |  |     echo "Please set DEB_ARCH to choose an architecture (e.g. armhf)" >&2 | 
					
						
							|  |  |  |     exit_and_skip | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | fi | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | if [ -z "${DEB_TYPE}" ]; then | 
					
						
							|  |  |  |     echo "Please set DEB_TYPE to a Debian archive name (e.g. testing)" >&2 | 
					
						
							|  |  |  |     exit_and_skip | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-07-19 21:20:39 +08:00
										 |  |  | fi | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | # We check in order for | 
					
						
							|  |  |  | # | 
					
						
							|  |  |  | #  - DEBOOTSTRAP_DIR pointing at a development checkout | 
					
						
							|  |  |  | #  - PATH for the debootstrap script (installed) | 
					
						
							|  |  |  | # | 
					
						
							|  |  |  | # If neither option works then we checkout debootstrap from its | 
					
						
							|  |  |  | # upstream SCM and run it from there. | 
					
						
							|  |  |  | # | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | if [ -z $DEBOOTSTRAP_DIR ]; then | 
					
						
							| 
									
										
										
										
											2016-09-06 22:05:49 +02:00
										 |  |  |     NEED_DEBOOTSTRAP=false | 
					
						
							| 
									
										
										
										
											2016-07-19 21:20:39 +08:00
										 |  |  |     DEBOOTSTRAP=`which debootstrap 2> /dev/null` | 
					
						
							|  |  |  |     if [ -z $DEBOOTSTRAP ]; then | 
					
						
							|  |  |  |         echo "No debootstrap installed, attempting to install from SCM" | 
					
						
							| 
									
										
										
										
											2016-09-06 22:05:49 +02:00
										 |  |  |         NEED_DEBOOTSTRAP=true | 
					
						
							|  |  |  |     elif ! (echo "${MIN_DEBOOTSTRAP_VERSION}" ; "${DEBOOTSTRAP}" --version \ | 
					
						
							|  |  |  |             | cut -d ' ' -f 2) | sort -t . -n -k 1,1 -k 2,2 -k 3,3 -c &>/dev/null; then | 
					
						
							|  |  |  |         echo "debootstrap too old, attempting to install from SCM" | 
					
						
							|  |  |  |         NEED_DEBOOTSTRAP=true | 
					
						
							|  |  |  |     fi | 
					
						
							|  |  |  |     if $NEED_DEBOOTSTRAP; then | 
					
						
							| 
									
										
										
										
											2016-07-19 21:20:39 +08:00
										 |  |  |         DEBOOTSTRAP_SOURCE=https://anonscm.debian.org/git/d-i/debootstrap.git | 
					
						
							|  |  |  |         git clone ${DEBOOTSTRAP_SOURCE} ./debootstrap.git | 
					
						
							|  |  |  |         export DEBOOTSTRAP_DIR=./debootstrap.git | 
					
						
							|  |  |  |         DEBOOTSTRAP=./debootstrap.git/debootstrap | 
					
						
							| 
									
										
										
										
											2016-09-06 22:05:50 +02:00
										 |  |  |         (cd "${DEBOOTSTRAP_DIR}" && "${FAKEROOT}" make ) | 
					
						
							| 
									
										
										
										
											2016-07-19 21:20:39 +08:00
										 |  |  |     fi | 
					
						
							|  |  |  | else | 
					
						
							|  |  |  |     DEBOOTSTRAP=${DEBOOTSTRAP_DIR}/debootstrap | 
					
						
							|  |  |  |     if [ ! -f $DEBOOTSTRAP ]; then | 
					
						
							| 
									
										
										
										
											2016-09-06 22:05:46 +02:00
										 |  |  |         echo "Couldn't find script at ${DEBOOTSTRAP}" >&2 | 
					
						
							| 
									
										
										
										
											2016-07-19 21:20:39 +08:00
										 |  |  |         exit_and_skip | 
					
						
							|  |  |  |     fi | 
					
						
							|  |  |  | fi | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | # | 
					
						
							|  |  |  | # Finally check to see if any qemu's are installed | 
					
						
							|  |  |  | # | 
					
						
							|  |  |  | BINFMT_DIR=/proc/sys/fs/binfmt_misc | 
					
						
							|  |  |  | if [ ! -e $BINFMT_DIR ]; then | 
					
						
							| 
									
										
										
										
											2016-09-06 22:05:46 +02:00
										 |  |  |    echo "binfmt_misc needs enabling for a QEMU bootstrap to work" >&2 | 
					
						
							| 
									
										
										
										
											2016-07-19 21:20:39 +08:00
										 |  |  |    exit_and_skip | 
					
						
							|  |  |  | else | 
					
						
							|  |  |  |     # DEB_ARCH and QEMU arch names are not totally aligned | 
					
						
							|  |  |  |     case "${DEB_ARCH}" in | 
					
						
							|  |  |  |         amd64) | 
					
						
							|  |  |  |             QEMU=qemu-i386 | 
					
						
							|  |  |  |             ;; | 
					
						
							|  |  |  |         armel|armhf) | 
					
						
							|  |  |  |             QEMU=qemu-arm | 
					
						
							|  |  |  |             ;; | 
					
						
							|  |  |  |         arm64) | 
					
						
							|  |  |  |             QEMU=qemu-aarch64 | 
					
						
							|  |  |  |             ;; | 
					
						
							|  |  |  |         powerpc) | 
					
						
							|  |  |  |             QEMU=qemu-ppc | 
					
						
							|  |  |  |             ;; | 
					
						
							|  |  |  |         ppc64el) | 
					
						
							|  |  |  |             QEMU=qemu-ppc64le | 
					
						
							|  |  |  |             ;; | 
					
						
							|  |  |  |         s390) | 
					
						
							|  |  |  |             QEMU=qemu-s390x | 
					
						
							|  |  |  |             ;; | 
					
						
							|  |  |  |         *) | 
					
						
							|  |  |  |             QEMU=qemu-${DEB_ARCH} | 
					
						
							|  |  |  |         ;; | 
					
						
							|  |  |  |     esac | 
					
						
							|  |  |  |     if [ ! -e "${BINFMT_DIR}/$QEMU" ]; then | 
					
						
							| 
									
										
										
										
											2016-09-06 22:05:46 +02:00
										 |  |  |         echo "No binfmt_misc rule to run $QEMU, can't bootstrap" >&2 | 
					
						
							| 
									
										
										
										
											2016-07-19 21:20:39 +08:00
										 |  |  |         exit_and_skip | 
					
						
							|  |  |  |     fi | 
					
						
							|  |  |  | fi | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | echo "Building a rootfs using ${FAKEROOT} and ${DEBOOTSTRAP} ${DEB_ARCH}/${DEB_TYPE}" | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | ${FAKEROOT} ${DEBOOTSTRAP} --variant=buildd --foreign --arch=$DEB_ARCH $DEB_TYPE . http://httpredir.debian.org/debian || exit 1 | 
					
						
							|  |  |  | exit 0 |