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

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