1 | #!/bin/sh |
---|
2 | |
---|
3 | # Usage: make-chroot SUITE ARCH |
---|
4 | |
---|
5 | # Constructs a chroot environment for the Debian/Ubuntu version SUITE |
---|
6 | # and architecture ARCH, and sets up schroot configuration for it. |
---|
7 | # Assumes an approx cache is running at localhost:9999. |
---|
8 | |
---|
9 | BZ2=0 |
---|
10 | if [ "$1" = "-z" ]; then |
---|
11 | BZ2=1 |
---|
12 | shift |
---|
13 | fi |
---|
14 | |
---|
15 | set -xe |
---|
16 | |
---|
17 | : ${CHROOTDIR=/srv} |
---|
18 | : ${MIRRORHOST=localhost:9999} |
---|
19 | SUITE=$1 |
---|
20 | ARCH=$2 |
---|
21 | CHROOT="${SUITE}-${ARCH}-sbuild" |
---|
22 | FILE="$CHROOTDIR"/"$CHROOT".tar |
---|
23 | [ $BZ2 -eq 1 ] && FILE="${FILE}.bz2" |
---|
24 | SIZE=4G |
---|
25 | |
---|
26 | exittrap() { :; } |
---|
27 | for sig in 1 2 13 15; do trap "exit $(($sig + 128))" $sig; done |
---|
28 | trap 'exittrap' EXIT |
---|
29 | |
---|
30 | if fgrep -qxRs "[$CHROOT]" /etc/schroot/schroot.conf /etc/schroot/chroot.d; then |
---|
31 | echo "Chroot $CHROOT already exists." >&2 |
---|
32 | exit 1 |
---|
33 | fi |
---|
34 | if [ -e "$FILE" ]; then |
---|
35 | echo "Chroot tarball $FILE already exists." >&2 |
---|
36 | exit 1 |
---|
37 | fi |
---|
38 | |
---|
39 | if [ -d /etc/schroot/chroot.d ]; then |
---|
40 | CONF=/etc/schroot/chroot.d/$CHROOT |
---|
41 | else |
---|
42 | CONF=/etc/schroot/schroot.conf |
---|
43 | fi |
---|
44 | |
---|
45 | if [ "$ARCH" = "i386" ]; then |
---|
46 | PERSONALITY=linux32 |
---|
47 | elif [ "$ARCH" = "amd64" ]; then |
---|
48 | PERSONALITY=linux |
---|
49 | else |
---|
50 | echo "Unrecognized architecture $ARCH." >&2 |
---|
51 | exit 1 |
---|
52 | fi |
---|
53 | |
---|
54 | DATA="$(dirname "$0")" |
---|
55 | |
---|
56 | SOURCESD="$DATA/sources.list.d" |
---|
57 | if [ -e "$SOURCESD/debian/$SUITE.list" ]; then |
---|
58 | SOURCES="$SOURCESD/debian/$SUITE.list" |
---|
59 | MIRROR="http://$MIRRORHOST/debian" |
---|
60 | elif [ -e "$SOURCESD/ubuntu/$SUITE.list" ]; then |
---|
61 | SOURCES="$SOURCESD/ubuntu/$SUITE.list" |
---|
62 | MIRROR="http://$MIRRORHOST/ubuntu" |
---|
63 | else |
---|
64 | echo "Unrecognized suite $SUITE." >&2 |
---|
65 | exit 1 |
---|
66 | fi |
---|
67 | |
---|
68 | exittrap() { rm -rf "$TMPDIR" || :; } |
---|
69 | TMPDIR=$(mktemp -d /var/tmp/make-chroot.XXXXXX) |
---|
70 | TARGET="$TMPDIR/root" |
---|
71 | debootstrap --variant=buildd --include=apt,apt-utils,gnupg,build-essential,fakeroot --arch "$ARCH" "$SUITE" "$TARGET" "$MIRROR" |
---|
72 | install -m a=rx,u+w "$DATA/policy-rc.d" "$TARGET/usr/sbin/" |
---|
73 | mkdir -p "$TARGET/dev/pts" |
---|
74 | mkdir -p "$TARGET/dev/shm" |
---|
75 | mkdir -p "$TARGET/afs" |
---|
76 | mkdir -p "$TARGET/mit" |
---|
77 | TAROPTS="cf" |
---|
78 | [ $BZ2 -eq 1 ] && TAROPTS="cjf" |
---|
79 | (cd "$TMPDIR" && tar "$TAROPTS" "$FILE" --numeric-owner root) |
---|
80 | rm -rf "$TMPDIR" |
---|
81 | exittrap() { :; } |
---|
82 | |
---|
83 | ! [ -s "$CONF" ] || echo >> "$CONF" |
---|
84 | cat >> "$CONF" <<EOF |
---|
85 | [$CHROOT] |
---|
86 | type=file |
---|
87 | description=$CHROOT |
---|
88 | groups=root,sbuild |
---|
89 | root-groups=root,sbuild |
---|
90 | source-groups=root |
---|
91 | file=$FILE |
---|
92 | location=/root |
---|
93 | personality=$PERSONALITY |
---|
94 | EOF |
---|
95 | |
---|
96 | schroot --chroot="${CHROOT}-source" --directory=/ -- /bin/sh -xe - \ |
---|
97 | 8< "$SOURCES" \ |
---|
98 | 9< "$DATA/debathena-archive.asc" \ |
---|
99 | <<EOF |
---|
100 | #/debootstrap/debootstrap --second-stage |
---|
101 | dpkg-divert --local --rename --add /sbin/initctl |
---|
102 | ln -s /bin/true /sbin/initctl |
---|
103 | debconf-set-selections <<SELECTIONS |
---|
104 | debconf debconf/frontend select Noninteractive |
---|
105 | SELECTIONS |
---|
106 | sed "s|MIRRORHOST|$MIRRORHOST|" <&8 > /etc/apt/sources.list |
---|
107 | ! type apt-key >/dev/null || apt-key add - <&9 |
---|
108 | apt-get -q -y update |
---|
109 | apt-get -q -y dist-upgrade |
---|
110 | EOF |
---|