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