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

Revision 25660, 2.8 KB checked in by jdreed, 12 years ago (diff)
Don't barf if /dev/shm is a symlink
  • 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
9BZ2=0
10if [ "$1" = "-z" ]; then
11    BZ2=1
12    shift
13fi
14
15set -xe
16
17: ${CHROOTDIR=/srv}
18: ${MIRRORHOST=localhost:9999}
19SUITE=$1
20ARCH=$2
21CHROOT="${SUITE}-${ARCH}-sbuild"
22FILE="$CHROOTDIR"/"$CHROOT".tar
23[ $BZ2 -eq 1 ] && FILE="${FILE}.bz2"
24SIZE=4G
25
26exittrap() { :; }
27for sig in 1 2 13 15; do trap "exit $(($sig + 128))" $sig; done
28trap 'exittrap' EXIT
29
30if fgrep -qxRs "[$CHROOT]" /etc/schroot/schroot.conf /etc/schroot/chroot.d; then
31        echo "Chroot $CHROOT already exists." >&2
32        exit 1
33fi
34if [ -e "$FILE" ]; then
35        echo "Chroot tarball $FILE already exists." >&2
36        exit 1
37fi
38
39if [ -d /etc/schroot/chroot.d ]; then
40        CONF=/etc/schroot/chroot.d/$CHROOT
41else
42        CONF=/etc/schroot/schroot.conf
43fi
44
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"
59        MIRROR="http://$MIRRORHOST/debian"
60elif [ -e "$SOURCESD/ubuntu/$SUITE.list" ]; then
61        SOURCES="$SOURCESD/ubuntu/$SUITE.list"
62        MIRROR="http://$MIRRORHOST/ubuntu"
63else
64        echo "Unrecognized suite $SUITE." >&2
65        exit 1
66fi
67
68exittrap() { rm -rf "$TMPDIR" || :; }
69TMPDIR=$(mktemp -d /var/tmp/make-chroot.XXXXXX)
70TARGET="$TMPDIR/root"
71debootstrap --variant=buildd --include=apt,apt-utils,gnupg,build-essential,fakeroot --arch "$ARCH" "$SUITE" "$TARGET" "$MIRROR"
72install -m a=rx,u+w "$DATA/policy-rc.d" "$TARGET/usr/sbin/"
73mkdir -p "$TARGET/dev/pts"
74# /dev/shm is a symlink to /run/shm on modern distros
75# So if it's not a symlink, then mkdir (and fail if it's something
76# that's not a symlink or a directory)
77[ -L "$TARGET/dev/shm" ] || mkdir -p "$TARGET/dev/shm"
78mkdir -p "$TARGET/afs"
79mkdir -p "$TARGET/mit"
80TAROPTS="cf"
81[ $BZ2 -eq 1 ] && TAROPTS="cjf"
82(cd "$TMPDIR" && tar "$TAROPTS" "$FILE" --numeric-owner root)
83rm -rf "$TMPDIR"
84exittrap() { :; }
85
86! [ -s "$CONF" ] || echo >> "$CONF"
87cat >> "$CONF" <<EOF
88[$CHROOT]
89type=file
90description=$CHROOT
91groups=root,sbuild
92root-groups=root,sbuild
93source-groups=root
94file=$FILE
95location=/root
96personality=$PERSONALITY
97EOF
98
99schroot --chroot="${CHROOT}-source" --directory=/ -- /bin/sh -xe - \
100    8< "$SOURCES" \
101    9< "$DATA/debathena-archive.asc" \
102    <<EOF
103#/debootstrap/debootstrap --second-stage
104dpkg-divert --local --rename --add /sbin/initctl
105ln -s /bin/true /sbin/initctl
106debconf-set-selections <<SELECTIONS
107debconf debconf/frontend        select  Noninteractive
108SELECTIONS
109sed "s|MIRRORHOST|$MIRRORHOST|" <&8 > /etc/apt/sources.list
110! type apt-key >/dev/null || apt-key add - <&9
111apt-get -q -y update
112apt-get -q -y dist-upgrade
113EOF
Note: See TracBrowser for help on using the repository browser.