blob: 35c85f7db8a1bab2e4f7aeeabab42ddde6d179af (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
|
#!/bin/sh
#
# Simple wrapper for debootstrap, run in the docker build context
#
FAKEROOT=$(which fakeroot 2> /dev/null)
# debootstrap < 1.0.67 generates empty sources.list, see Debian#732255
MIN_DEBOOTSTRAP_VERSION=1.0.67
exit_and_skip()
{
exit 3
}
#
# fakeroot is needed to run the bootstrap stage
#
if [ -z $FAKEROOT ]; then
echo "Please install fakeroot to enable bootstraping" >&2
exit_and_skip
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
fi
# The following allow finer grain control over the defaults
if [ -z "${DEB_VARIANT}" ]; then
DEB_VARIANT=buildd
fi
if [ -z "${DEB_URL}" ]; then
DEB_URL="http://httpredir.debian.org/debian"
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
NEED_DEBOOTSTRAP=false
DEBOOTSTRAP=$(which debootstrap 2> /dev/null)
if [ -z $DEBOOTSTRAP ]; then
echo "No debootstrap installed, attempting to install from SCM"
NEED_DEBOOTSTRAP=true
else
INSTALLED_VERSION=$(${DEBOOTSTRAP} --version | sed 's/debootstrap \([0-9\.]*\)[^0-9\.]*.*/\1/')
if ! (echo "${MIN_DEBOOTSTRAP_VERSION}" ; echo "${INSTALLED_VERSION}") \
| sort -t . -n -k 1,1 -k 2,2 -k 3,3 -C ; then
echo "debootstrap too old, attempting to install from SCM"
NEED_DEBOOTSTRAP=true
fi
fi
if $NEED_DEBOOTSTRAP; then
DEBOOTSTRAP_SOURCE=https://salsa.debian.org/installer-team/debootstrap.git
git clone ${DEBOOTSTRAP_SOURCE} ./debootstrap.git
export DEBOOTSTRAP_DIR=./debootstrap.git
DEBOOTSTRAP=./debootstrap.git/debootstrap
(cd "${DEBOOTSTRAP_DIR}" && "${FAKEROOT}" make )
fi
else
DEBOOTSTRAP=${DEBOOTSTRAP_DIR}/debootstrap
if [ ! -f $DEBOOTSTRAP ]; then
echo "Couldn't find script at ${DEBOOTSTRAP}" >&2
exit_and_skip
fi
fi
#
# Add optional args
#
if [ -n "${DEB_KEYRING}" ]; then
DEBOOTSTRAP="${DEBOOTSTRAP} --keyring=${DEB_KEYRING}"
fi
#
# Finally check to see if any qemu's are installed
#
BINFMT_DIR=/proc/sys/fs/binfmt_misc
if [ ! -e $BINFMT_DIR ]; then
echo "binfmt_misc needs enabling for a QEMU bootstrap to work" >&2
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
echo "No binfmt_misc rule to run $QEMU, can't bootstrap" >&2
exit_and_skip
fi
fi
echo "Building a rootfs using ${FAKEROOT} and ${DEBOOTSTRAP} ${DEB_ARCH}/${DEB_TYPE}"
${FAKEROOT} ${DEBOOTSTRAP} --variant=$DEB_VARIANT --foreign --arch=$DEB_ARCH $DEB_TYPE . $DEB_URL || exit 1
exit 0
|