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

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