docker: debian-bootstrap.pre: print error messages to stderr
[qemu/kevin.git] / tests / docker / dockerfiles / debian-bootstrap.pre
blob9b95a6b3ce2586751d40c2b4e610fd4cd5168dd4
1 #!/bin/sh
3 # Simple wrapper for debootstrap, run in the docker build context
5 FAKEROOT=`which fakeroot 2> /dev/null`
7 exit_and_skip()
9     exit 3
13 # fakeroot is needed to run the bootstrap stage
15 if [ -z $FAKEROOT ]; then
16     echo "Please install fakeroot to enable bootstraping" >&2
17     exit_and_skip
20 # We check in order for
22 #  - DEBOOTSTRAP_DIR pointing at a development checkout
23 #  - PATH for the debootstrap script (installed)
25 # If neither option works then we checkout debootstrap from its
26 # upstream SCM and run it from there.
29 if [ -z $DEBOOTSTRAP_DIR ]; then
30     DEBOOTSTRAP=`which debootstrap 2> /dev/null`
31     if [ -z $DEBOOTSTRAP ]; then
32         echo "No debootstrap installed, attempting to install from SCM"
33         DEBOOTSTRAP_SOURCE=https://anonscm.debian.org/git/d-i/debootstrap.git
34         git clone ${DEBOOTSTRAP_SOURCE} ./debootstrap.git
35         export DEBOOTSTRAP_DIR=./debootstrap.git
36         DEBOOTSTRAP=./debootstrap.git/debootstrap
37     fi
38 else
39     DEBOOTSTRAP=${DEBOOTSTRAP_DIR}/debootstrap
40     if [ ! -f $DEBOOTSTRAP ]; then
41         echo "Couldn't find script at ${DEBOOTSTRAP}" >&2
42         exit_and_skip
43     fi
47 # Finally check to see if any qemu's are installed
49 BINFMT_DIR=/proc/sys/fs/binfmt_misc
50 if [ ! -e $BINFMT_DIR ]; then
51    echo "binfmt_misc needs enabling for a QEMU bootstrap to work" >&2
52    exit_and_skip
53 else
54     # DEB_ARCH and QEMU arch names are not totally aligned
55     case "${DEB_ARCH}" in
56         amd64)
57             QEMU=qemu-i386
58             ;;
59         armel|armhf)
60             QEMU=qemu-arm
61             ;;
62         arm64)
63             QEMU=qemu-aarch64
64             ;;
65         powerpc)
66             QEMU=qemu-ppc
67             ;;
68         ppc64el)
69             QEMU=qemu-ppc64le
70             ;;
71         s390)
72             QEMU=qemu-s390x
73             ;;
74         *)
75             QEMU=qemu-${DEB_ARCH}
76         ;;
77     esac
78     if [ ! -e "${BINFMT_DIR}/$QEMU" ]; then
79         echo "No binfmt_misc rule to run $QEMU, can't bootstrap" >&2
80         exit_and_skip
81     fi
84 echo "Building a rootfs using ${FAKEROOT} and ${DEBOOTSTRAP} ${DEB_ARCH}/${DEB_TYPE}"
86 ${FAKEROOT} ${DEBOOTSTRAP} --variant=buildd --foreign --arch=$DEB_ARCH $DEB_TYPE . http://httpredir.debian.org/debian || exit 1
87 exit 0