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