source: trunk/debathena/scripts/build-server/make-chroot @ 25490

Revision 25490, 2.6 KB checked in by jdreed, 12 years ago (diff)
Make zipping the chroots optional
  • Property svn:executable set to *
RevLine 
[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]9BZ2=0
10if [ "$1" = "-z" ]; then
11    BZ2=1
12    shift
13fi
14
[22687]15set -xe
16
[25482]17: ${CHROOTDIR=/srv}
[25484]18: ${MIRRORHOST=localhost:9999}
[22687]19SUITE=$1
20ARCH=$2
21CHROOT="${SUITE}-${ARCH}-sbuild"
[25490]22FILE="$CHROOTDIR"/"$CHROOT".tar
23[ $BZ2 -eq 1 ] && FILE="${FILE}.bz2"
[24021]24SIZE=4G
[22687]25
26exittrap() { :; }
27for sig in 1 2 13 15; do trap "exit $(($sig + 128))" $sig; done
28trap 'exittrap' EXIT
29
[23147]30if fgrep -qxRs "[$CHROOT]" /etc/schroot/schroot.conf /etc/schroot/chroot.d; then
[22687]31        echo "Chroot $CHROOT already exists." >&2
32        exit 1
33fi
[25482]34if [ -e "$FILE" ]; then
35        echo "Chroot tarball $FILE already exists." >&2
36        exit 1
37fi
[22687]38
[23147]39if [ -d /etc/schroot/chroot.d ]; then
40        CONF=/etc/schroot/chroot.d/$CHROOT
41else
42        CONF=/etc/schroot/schroot.conf
43fi
44
[22687]45if [ "$ARCH" = "i386" ]; then
46        PERSONALITY=linux32
47elif [ "$ARCH" = "amd64" ]; then
48        PERSONALITY=linux
49else
50        echo "Unrecognized architecture $ARCH." >&2
51        exit 1
52fi
53
54DATA="$(dirname "$0")"
55
56SOURCESD="$DATA/sources.list.d"
57if [ -e "$SOURCESD/debian/$SUITE.list" ]; then
58        SOURCES="$SOURCESD/debian/$SUITE.list"
[25484]59        MIRROR="http://$MIRRORHOST/debian"
[22687]60elif [ -e "$SOURCESD/ubuntu/$SUITE.list" ]; then
61        SOURCES="$SOURCESD/ubuntu/$SUITE.list"
[25484]62        MIRROR="http://$MIRRORHOST/ubuntu"
[22687]63else
64        echo "Unrecognized suite $SUITE." >&2
65        exit 1
66fi
67
[25482]68exittrap() { rm -rf "$TMPDIR" || :; }
69TMPDIR=$(mktemp -d /var/tmp/make-chroot.XXXXXX)
70TARGET="$TMPDIR/root"
[24264]71debootstrap --variant=buildd --include=apt,apt-utils,gnupg,build-essential,fakeroot --arch "$ARCH" "$SUITE" "$TARGET" "$MIRROR"
[22687]72install -m a=rx,u+w "$DATA/policy-rc.d" "$TARGET/usr/sbin/"
[22928]73mkdir -p "$TARGET/dev/pts"
74mkdir -p "$TARGET/dev/shm"
75mkdir -p "$TARGET/afs"
76mkdir -p "$TARGET/mit"
[25490]77TAROPTS="cf"
78[ $BZ2 -eq 1 ] && TAROPTS="cjf"
79(cd "$TMPDIR" && tar "$TAROPTS" "$FILE" --numeric-owner root)
[25482]80rm -rf "$TMPDIR"
[22687]81exittrap() { :; }
82
[23147]83! [ -s "$CONF" ] || echo >> "$CONF"
84cat >> "$CONF" <<EOF
[22687]85[$CHROOT]
[25470]86type=file
[22687]87description=$CHROOT
88groups=root,sbuild
89root-groups=root,sbuild
90source-groups=root
[25482]91file=$FILE
[25483]92location=/root
[22687]93personality=$PERSONALITY
94EOF
95
[22928]96schroot --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]101dpkg-divert --local --rename --add /sbin/initctl
102ln -s /bin/true /sbin/initctl
[22696]103debconf-set-selections <<SELECTIONS
104debconf debconf/frontend        select  Noninteractive
105SELECTIONS
[25484]106sed "s|MIRRORHOST|$MIRRORHOST|" <&8 > /etc/apt/sources.list
[22687]107! type apt-key >/dev/null || apt-key add - <&9
108apt-get -q -y update
109apt-get -q -y dist-upgrade
110EOF
Note: See TracBrowser for help on using the repository browser.