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

Revision 25969, 4.5 KB checked in by jdreed, 11 years ago (diff)
- Try the new location for DATA first, then fallback (and warn) to dirname $0 - Add a script-config directive to support the new profile for overlayfs chroots (rather than screwing with mount-defaults)
  • 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
11TYPE=overlayfs
12while getopts 'dzot' opt; do
13    case "$opt" in
14        d)
15            DEBUG=1
16            set -x
17            ;;
18        z)
19            BZ2=1;;
20        o)
21            TYPE=overlayfs;;
22        t)
23            TYPE=tar;;
24    esac
25done
26shift $((OPTIND-1))
27
28if [ $BZ2 -eq 1 ] && [ "$TYPE" != "tar" ]; then
29    echo "-z is meaningless if not using a tar chroot and will be ignored" >&2
30fi
31
32if [ -z "$1" ] || [ -z "$2" ]; then
33    echo "Usage: $0 <suite> <arch>" >&2
34    exit 1
35fi
36
37set -e
38
39: ${VG=/dev/builder}
40: ${CHROOTDIR=/srv}
41: ${MIRRORHOST=localhost:9999}
42: ${DATA="/usr/share/debathena-build-server"}
43if [ ! -d "$DATA" ]; then
44    DATA="$(dirname "$0")"
45    echo "WARNING: Falling back to DATA=$DATA" >&2
46fi
47SUITE=$1
48ARCH=$2
49CHROOT="${SUITE}-${ARCH}-sbuild"
50DEVICE="$VG/$CHROOT"
51FILE="$CHROOTDIR"/"$CHROOT".tar
52[ $BZ2 -eq 1 ] && FILE="${FILE}.bz2"
53SIZE=4G
54
55exittrap() { :; }
56for sig in 1 2 13 15; do trap "exit $(($sig + 128))" $sig; done
57trap 'exittrap' EXIT
58
59if fgrep -qxRs "[$CHROOT]" /etc/schroot/schroot.conf /etc/schroot/chroot.d; then
60        echo "Chroot $CHROOT config already exists." >&2
61        exit 1
62fi
63if [ "$TYPE" = "tar" ] && [ -e "$FILE" ]; then
64        echo "Chroot tarball $FILE already exists." >&2
65        exit 1
66fi
67
68if [ "$TYPE" = "overlayfs" ] && lvdisplay $DEVICE > /dev/null 2>&1; then
69        echo "LV $DEVICE already exists." >&2
70        exit 1
71fi
72
73if [ -d /etc/schroot/chroot.d ]; then
74        CONF=/etc/schroot/chroot.d/$CHROOT
75else
76        CONF=/etc/schroot/schroot.conf
77fi
78
79if [ "$ARCH" = "i386" ]; then
80        PERSONALITY=linux32
81elif [ "$ARCH" = "amd64" ]; then
82        PERSONALITY=linux
83else
84        echo "Unrecognized architecture $ARCH." >&2
85        exit 1
86fi
87
88SOURCESD="$DATA/sources.list.d"
89if [ -e "$SOURCESD/debian/$SUITE.list" ]; then
90        SOURCES="$SOURCESD/debian/$SUITE.list"
91        MIRROR="http://$MIRRORHOST/debian"
92elif [ -e "$SOURCESD/ubuntu/$SUITE.list" ]; then
93        SOURCES="$SOURCESD/ubuntu/$SUITE.list"
94        MIRROR="http://$MIRRORHOST/ubuntu"
95else
96        echo "Unrecognized suite $SUITE. (Did you create the sources.list file?)" >&2
97        exit 1
98fi
99
100if [ "$TYPE" = "overlayfs" ]; then
101    lvcreate --size "$SIZE" --name "$CHROOT" "$VG"
102    mkfs.ext3 "$DEVICE"
103    tune2fs -c 0 -i 0 "$DEVICE"
104fi
105
106exittrap() {
107    if [ $DEBUG -ne 1 ]; then
108        rm -rf "$TMPDIR" || :
109    else
110        echo "DEBUG MODE: Clean up $TMPDIR by hand!"
111    fi
112}
113TMPDIR=$(mktemp -d /var/tmp/make-chroot.XXXXXX)
114if [ "$TYPE" = "overlayfs" ]; then
115    TARGET="$TMPDIR"
116    mount "$DEVICE" "$TARGET"
117else
118    TARGET="$TMPDIR/root"
119    SCRIPTCFG="debathena/config"
120fi
121debootstrap --variant=buildd --include=apt,apt-utils,gnupg,build-essential,fakeroot --arch "$ARCH" "$SUITE" "$TARGET" "$MIRROR"
122install -m a=rx,u+w "$DATA/policy-rc.d" "$TARGET/usr/sbin/"
123mkdir -p "$TARGET/dev/pts"
124# /dev/shm is a symlink to /run/shm on modern distros
125# So if it's not a symlink, then mkdir (and fail if it's something
126# that's not a symlink or a directory) and we have to use an schroot
127# config that bind-mounts /run/shm instead of /dev/shm
128if [ -L "$TARGET/dev/shm" ] &&
129   [ "$(readlink "$TARGET/dev/shm")" = "/run/shm" ]; then
130    SCRIPTCFG="debathena/config-slash-run"
131else
132    mkdir -p "$TARGET/dev/shm"
133fi
134mkdir -p "$TARGET/afs"
135mkdir -p "$TARGET/mit"
136if [ "$TYPE" = "overlayfs" ]; then
137    umount "$TARGET"
138    rmdir "$TARGET"
139else
140    TAROPTS="cf"
141    [ $BZ2 -eq 1 ] && TAROPTS="cjf"
142    (cd "$TMPDIR" && tar "$TAROPTS" "$FILE" --numeric-owner root)
143    rm -rf "$TMPDIR"
144fi
145exittrap() { :; }
146
147! [ -s "$CONF" ] || echo >> "$CONF"
148if [ "$TYPE" = "overlayfs" ]; then
149    cat >> "$CONF" <<EOF
150[$CHROOT]
151type=block-device
152union-type=overlayfs
153description=$CHROOT
154groups=root,sbuild
155root-groups=root,sbuild
156source-groups=root
157script-config=$SCRIPTCFG
158device=$DEVICE
159personality=$PERSONALITY
160EOF
161else
162    cat >> "$CONF" <<EOF
163[$CHROOT]
164type=file
165description=$CHROOT
166groups=root,sbuild
167root-groups=root,sbuild
168source-groups=root
169script-config=$SCRIPTCFG
170file=$FILE
171location=/root
172personality=$PERSONALITY
173EOF
174fi
175
176schroot --chroot="${CHROOT}-source" --directory=/ -- /bin/sh -xe - \
177    8< "$SOURCES" \
178    9< "$DATA/debathena-archive.asc" \
179    <<EOF
180#/debootstrap/debootstrap --second-stage
181dpkg-divert --local --rename --add /sbin/initctl
182ln -s /bin/true /sbin/initctl
183debconf-set-selections <<SELECTIONS
184debconf debconf/frontend        select  Noninteractive
185SELECTIONS
186sed "s|MIRRORHOST|$MIRRORHOST|" <&8 > /etc/apt/sources.list
187! type apt-key >/dev/null || apt-key add - <&9
188apt-get -q -y update
189apt-get -q -y dist-upgrade
190EOF
Note: See TracBrowser for help on using the repository browser.