Merge remote-tracking branch 'remotes/bonzini-gitlab/tags/for-upstream' into staging
[qemu/ar7.git] / tests / docker / dockerfiles / debian-bootstrap.pre
blob35c85f7db8a1bab2e4f7aeeabab42ddde6d179af
1 #!/bin/sh
3 # Simple wrapper for debootstrap, run in the docker build context
5 FAKEROOT=$(which fakeroot 2> /dev/null)
6 # debootstrap < 1.0.67 generates empty sources.list, see Debian#732255
7 MIN_DEBOOTSTRAP_VERSION=1.0.67
9 exit_and_skip()
11     exit 3
15 # fakeroot is needed to run the bootstrap stage
17 if [ -z $FAKEROOT ]; then
18     echo "Please install fakeroot to enable bootstraping" >&2
19     exit_and_skip
23 if [ -z "${DEB_ARCH}" ]; then
24     echo "Please set DEB_ARCH to choose an architecture (e.g. armhf)" >&2
25     exit_and_skip
29 if [ -z "${DEB_TYPE}" ]; then
30     echo "Please set DEB_TYPE to a Debian archive name (e.g. testing)" >&2
31     exit_and_skip
35 # The following allow finer grain control over the defaults
36 if [ -z "${DEB_VARIANT}" ]; then
37     DEB_VARIANT=buildd
40 if [ -z "${DEB_URL}" ]; then
41     DEB_URL="http://httpredir.debian.org/debian"
44 # We check in order for
46 #  - DEBOOTSTRAP_DIR pointing at a development checkout
47 #  - PATH for the debootstrap script (installed)
49 # If neither option works then we checkout debootstrap from its
50 # upstream SCM and run it from there.
53 if [ -z $DEBOOTSTRAP_DIR ]; then
54     NEED_DEBOOTSTRAP=false
55     DEBOOTSTRAP=$(which debootstrap 2> /dev/null)
56     if [ -z $DEBOOTSTRAP ]; then
57         echo "No debootstrap installed, attempting to install from SCM"
58         NEED_DEBOOTSTRAP=true
59     else
60         INSTALLED_VERSION=$(${DEBOOTSTRAP} --version | sed 's/debootstrap \([0-9\.]*\)[^0-9\.]*.*/\1/')
61         if ! (echo "${MIN_DEBOOTSTRAP_VERSION}" ; echo "${INSTALLED_VERSION}") \
62                 | sort -t . -n -k 1,1 -k 2,2 -k 3,3 -C ; then
63             echo "debootstrap too old, attempting to install from SCM"
64             NEED_DEBOOTSTRAP=true
65         fi
66     fi
67     if $NEED_DEBOOTSTRAP; then
68         DEBOOTSTRAP_SOURCE=https://salsa.debian.org/installer-team/debootstrap.git
69         git clone ${DEBOOTSTRAP_SOURCE} ./debootstrap.git
70         export DEBOOTSTRAP_DIR=./debootstrap.git
71         DEBOOTSTRAP=./debootstrap.git/debootstrap
72         (cd "${DEBOOTSTRAP_DIR}" && "${FAKEROOT}" make )
73     fi
74 else
75     DEBOOTSTRAP=${DEBOOTSTRAP_DIR}/debootstrap
76     if [ ! -f $DEBOOTSTRAP ]; then
77         echo "Couldn't find script at ${DEBOOTSTRAP}" >&2
78         exit_and_skip
79     fi
83 # Add optional args
85 if [ -n "${DEB_KEYRING}" ]; then
86     DEBOOTSTRAP="${DEBOOTSTRAP} --keyring=${DEB_KEYRING}"
90 # Finally check to see if any qemu's are installed
92 BINFMT_DIR=/proc/sys/fs/binfmt_misc
93 if [ ! -e $BINFMT_DIR ]; then
94    echo "binfmt_misc needs enabling for a QEMU bootstrap to work" >&2
95    exit_and_skip
96 else
97     # DEB_ARCH and QEMU arch names are not totally aligned
98     case "${DEB_ARCH}" in
99         amd64)
100             QEMU=qemu-i386
101             ;;
102         armel|armhf)
103             QEMU=qemu-arm
104             ;;
105         arm64)
106             QEMU=qemu-aarch64
107             ;;
108         powerpc)
109             QEMU=qemu-ppc
110             ;;
111         ppc64el)
112             QEMU=qemu-ppc64le
113             ;;
114         s390)
115             QEMU=qemu-s390x
116             ;;
117         *)
118             QEMU=qemu-${DEB_ARCH}
119         ;;
120     esac
121     if [ ! -e "${BINFMT_DIR}/$QEMU" ]; then
122         echo "No binfmt_misc rule to run $QEMU, can't bootstrap" >&2
123         exit_and_skip
124     fi
127 echo "Building a rootfs using ${FAKEROOT} and ${DEBOOTSTRAP} ${DEB_ARCH}/${DEB_TYPE}"
129 ${FAKEROOT} ${DEBOOTSTRAP} --variant=$DEB_VARIANT --foreign --arch=$DEB_ARCH $DEB_TYPE . $DEB_URL || exit 1
130 exit 0