[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 | |
---|
[25490] | 9 | BZ2=0 |
---|
| 10 | if [ "$1" = "-z" ]; then |
---|
| 11 | BZ2=1 |
---|
| 12 | shift |
---|
| 13 | fi |
---|
| 14 | |
---|
[22687] | 15 | set -xe |
---|
| 16 | |
---|
[25482] | 17 | : ${CHROOTDIR=/srv} |
---|
[25484] | 18 | : ${MIRRORHOST=localhost:9999} |
---|
[22687] | 19 | SUITE=$1 |
---|
| 20 | ARCH=$2 |
---|
| 21 | CHROOT="${SUITE}-${ARCH}-sbuild" |
---|
[25490] | 22 | FILE="$CHROOTDIR"/"$CHROOT".tar |
---|
| 23 | [ $BZ2 -eq 1 ] && FILE="${FILE}.bz2" |
---|
[24021] | 24 | SIZE=4G |
---|
[22687] | 25 | |
---|
| 26 | exittrap() { :; } |
---|
| 27 | for sig in 1 2 13 15; do trap "exit $(($sig + 128))" $sig; done |
---|
| 28 | trap 'exittrap' EXIT |
---|
| 29 | |
---|
[23147] | 30 | if fgrep -qxRs "[$CHROOT]" /etc/schroot/schroot.conf /etc/schroot/chroot.d; then |
---|
[22687] | 31 | echo "Chroot $CHROOT already exists." >&2 |
---|
| 32 | exit 1 |
---|
| 33 | fi |
---|
[25482] | 34 | if [ -e "$FILE" ]; then |
---|
| 35 | echo "Chroot tarball $FILE already exists." >&2 |
---|
| 36 | exit 1 |
---|
| 37 | fi |
---|
[22687] | 38 | |
---|
[23147] | 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 | |
---|
[22687] | 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" |
---|
[25484] | 59 | MIRROR="http://$MIRRORHOST/debian" |
---|
[22687] | 60 | elif [ -e "$SOURCESD/ubuntu/$SUITE.list" ]; then |
---|
| 61 | SOURCES="$SOURCESD/ubuntu/$SUITE.list" |
---|
[25484] | 62 | MIRROR="http://$MIRRORHOST/ubuntu" |
---|
[22687] | 63 | else |
---|
| 64 | echo "Unrecognized suite $SUITE." >&2 |
---|
| 65 | exit 1 |
---|
| 66 | fi |
---|
| 67 | |
---|
[25482] | 68 | exittrap() { rm -rf "$TMPDIR" || :; } |
---|
| 69 | TMPDIR=$(mktemp -d /var/tmp/make-chroot.XXXXXX) |
---|
| 70 | TARGET="$TMPDIR/root" |
---|
[24264] | 71 | debootstrap --variant=buildd --include=apt,apt-utils,gnupg,build-essential,fakeroot --arch "$ARCH" "$SUITE" "$TARGET" "$MIRROR" |
---|
[22687] | 72 | install -m a=rx,u+w "$DATA/policy-rc.d" "$TARGET/usr/sbin/" |
---|
[22928] | 73 | mkdir -p "$TARGET/dev/pts" |
---|
| 74 | mkdir -p "$TARGET/dev/shm" |
---|
| 75 | mkdir -p "$TARGET/afs" |
---|
| 76 | mkdir -p "$TARGET/mit" |
---|
[25490] | 77 | TAROPTS="cf" |
---|
| 78 | [ $BZ2 -eq 1 ] && TAROPTS="cjf" |
---|
| 79 | (cd "$TMPDIR" && tar "$TAROPTS" "$FILE" --numeric-owner root) |
---|
[25482] | 80 | rm -rf "$TMPDIR" |
---|
[22687] | 81 | exittrap() { :; } |
---|
| 82 | |
---|
[23147] | 83 | ! [ -s "$CONF" ] || echo >> "$CONF" |
---|
| 84 | cat >> "$CONF" <<EOF |
---|
[22687] | 85 | [$CHROOT] |
---|
[25470] | 86 | type=file |
---|
[22687] | 87 | description=$CHROOT |
---|
| 88 | groups=root,sbuild |
---|
| 89 | root-groups=root,sbuild |
---|
| 90 | source-groups=root |
---|
[25482] | 91 | file=$FILE |
---|
[25483] | 92 | location=/root |
---|
[22687] | 93 | personality=$PERSONALITY |
---|
| 94 | EOF |
---|
| 95 | |
---|
[22928] | 96 | schroot --chroot="${CHROOT}-source" --directory=/ -- /bin/sh -xe - \ |
---|
[22687] | 97 | 8< "$SOURCES" \ |
---|
| 98 | 9< "$DATA/debathena-archive.asc" \ |
---|
| 99 | <<EOF |
---|
[22928] | 100 | #/debootstrap/debootstrap --second-stage |
---|
[24144] | 101 | dpkg-divert --local --rename --add /sbin/initctl |
---|
| 102 | ln -s /bin/true /sbin/initctl |
---|
[22696] | 103 | debconf-set-selections <<SELECTIONS |
---|
| 104 | debconf debconf/frontend select Noninteractive |
---|
| 105 | SELECTIONS |
---|
[25484] | 106 | sed "s|MIRRORHOST|$MIRRORHOST|" <&8 > /etc/apt/sources.list |
---|
[22687] | 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 |
---|