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

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