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

Revision 25661, 3.2 KB checked in by jdreed, 12 years ago (diff)
- Deal with /run chroots - Allow $DATA to be overridden for testing purposes - Add -d option for debugging which won't nuke the directory on a failure
  • 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
9DEBUG=0
10BZ2=0
11while getopts 'dz' opt; do
12    case "$opt" in
13        d)
14            DEBUG=1;;
15        z)
16            BZ2=1;;
17    esac
18done
19shift $((OPTIND-1))
20
21set -xe
22
23: ${CHROOTDIR=/srv}
24: ${MIRRORHOST=localhost:9999}
25: ${DATA="$(dirname "$0")"}
26SUITE=$1
27ARCH=$2
28CHROOT="${SUITE}-${ARCH}-sbuild"
29FILE="$CHROOTDIR"/"$CHROOT".tar
30[ $BZ2 -eq 1 ] && FILE="${FILE}.bz2"
31SIZE=4G
32
33exittrap() { :; }
34for sig in 1 2 13 15; do trap "exit $(($sig + 128))" $sig; done
35trap 'exittrap' EXIT
36
37if fgrep -qxRs "[$CHROOT]" /etc/schroot/schroot.conf /etc/schroot/chroot.d; then
38        echo "Chroot $CHROOT already exists." >&2
39        exit 1
40fi
41if [ -e "$FILE" ]; then
42        echo "Chroot tarball $FILE already exists." >&2
43        exit 1
44fi
45
46if [ -d /etc/schroot/chroot.d ]; then
47        CONF=/etc/schroot/chroot.d/$CHROOT
48else
49        CONF=/etc/schroot/schroot.conf
50fi
51
52if [ "$ARCH" = "i386" ]; then
53        PERSONALITY=linux32
54elif [ "$ARCH" = "amd64" ]; then
55        PERSONALITY=linux
56else
57        echo "Unrecognized architecture $ARCH." >&2
58        exit 1
59fi
60
61SOURCESD="$DATA/sources.list.d"
62if [ -e "$SOURCESD/debian/$SUITE.list" ]; then
63        SOURCES="$SOURCESD/debian/$SUITE.list"
64        MIRROR="http://$MIRRORHOST/debian"
65elif [ -e "$SOURCESD/ubuntu/$SUITE.list" ]; then
66        SOURCES="$SOURCESD/ubuntu/$SUITE.list"
67        MIRROR="http://$MIRRORHOST/ubuntu"
68else
69        echo "Unrecognized suite $SUITE." >&2
70        exit 1
71fi
72
73exittrap() {
74    if [ $DEBUG -ne 1 ]; then
75        rm -rf "$TMPDIR" || :
76    else
77        echo "DEBUG MODE: Clean up $TMPDIR by hand!"
78    fi
79}
80TMPDIR=$(mktemp -d /var/tmp/make-chroot.XXXXXX)
81TARGET="$TMPDIR/root"
82SCRIPTCFG="default/config"
83debootstrap --variant=buildd --include=apt,apt-utils,gnupg,build-essential,fakeroot --arch "$ARCH" "$SUITE" "$TARGET" "$MIRROR"
84install -m a=rx,u+w "$DATA/policy-rc.d" "$TARGET/usr/sbin/"
85mkdir -p "$TARGET/dev/pts"
86# /dev/shm is a symlink to /run/shm on modern distros
87# So if it's not a symlink, then mkdir (and fail if it's something
88# that's not a symlink or a directory) and we have to use an schroot
89# config that bind-mounts /run/shm instead of /dev/shm
90if [ -L "$TARGET/dev/shm" ] &&
91   [ "$(readlink "$TARGET/dev/shm")" = "/run/shm" ]; then
92    SCRIPTCFG="default-slash-run/config"
93else
94    mkdir -p "$TARGET/dev/shm"
95fi
96mkdir -p "$TARGET/afs"
97mkdir -p "$TARGET/mit"
98TAROPTS="cf"
99[ $BZ2 -eq 1 ] && TAROPTS="cjf"
100(cd "$TMPDIR" && tar "$TAROPTS" "$FILE" --numeric-owner root)
101rm -rf "$TMPDIR"
102exittrap() { :; }
103
104! [ -s "$CONF" ] || echo >> "$CONF"
105cat >> "$CONF" <<EOF
106[$CHROOT]
107type=file
108description=$CHROOT
109groups=root,sbuild
110root-groups=root,sbuild
111source-groups=root
112script-config=$SCRIPTCFG
113file=$FILE
114location=/root
115personality=$PERSONALITY
116EOF
117
118schroot --chroot="${CHROOT}-source" --directory=/ -- /bin/sh -xe - \
119    8< "$SOURCES" \
120    9< "$DATA/debathena-archive.asc" \
121    <<EOF
122#/debootstrap/debootstrap --second-stage
123dpkg-divert --local --rename --add /sbin/initctl
124ln -s /bin/true /sbin/initctl
125debconf-set-selections <<SELECTIONS
126debconf debconf/frontend        select  Noninteractive
127SELECTIONS
128sed "s|MIRRORHOST|$MIRRORHOST|" <&8 > /etc/apt/sources.list
129! type apt-key >/dev/null || apt-key add - <&9
130apt-get -q -y update
131apt-get -q -y dist-upgrade
132EOF
Note: See TracBrowser for help on using the repository browser.