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

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