#!/bin/sh # Usage: make-chroot SUITE ARCH # Constructs a chroot environment for the Debian/Ubuntu version SUITE # and architecture ARCH, and sets up schroot configuration for it. # Assumes an approx cache is running at localhost:9999. DEBUG=0 BZ2=0 while getopts 'dz' opt; do case "$opt" in d) DEBUG=1;; z) BZ2=1;; esac done shift $((OPTIND-1)) set -xe : ${CHROOTDIR=/srv} : ${MIRRORHOST=localhost:9999} : ${DATA="$(dirname "$0")"} SUITE=$1 ARCH=$2 CHROOT="${SUITE}-${ARCH}-sbuild" FILE="$CHROOTDIR"/"$CHROOT".tar [ $BZ2 -eq 1 ] && FILE="${FILE}.bz2" SIZE=4G exittrap() { :; } for sig in 1 2 13 15; do trap "exit $(($sig + 128))" $sig; done trap 'exittrap' EXIT if fgrep -qxRs "[$CHROOT]" /etc/schroot/schroot.conf /etc/schroot/chroot.d; then echo "Chroot $CHROOT already exists." >&2 exit 1 fi if [ -e "$FILE" ]; then echo "Chroot tarball $FILE already exists." >&2 exit 1 fi if [ -d /etc/schroot/chroot.d ]; then CONF=/etc/schroot/chroot.d/$CHROOT else CONF=/etc/schroot/schroot.conf fi if [ "$ARCH" = "i386" ]; then PERSONALITY=linux32 elif [ "$ARCH" = "amd64" ]; then PERSONALITY=linux else echo "Unrecognized architecture $ARCH." >&2 exit 1 fi SOURCESD="$DATA/sources.list.d" if [ -e "$SOURCESD/debian/$SUITE.list" ]; then SOURCES="$SOURCESD/debian/$SUITE.list" MIRROR="http://$MIRRORHOST/debian" elif [ -e "$SOURCESD/ubuntu/$SUITE.list" ]; then SOURCES="$SOURCESD/ubuntu/$SUITE.list" MIRROR="http://$MIRRORHOST/ubuntu" else echo "Unrecognized suite $SUITE." >&2 exit 1 fi exittrap() { if [ $DEBUG -ne 1 ]; then rm -rf "$TMPDIR" || : else echo "DEBUG MODE: Clean up $TMPDIR by hand!" fi } TMPDIR=$(mktemp -d /var/tmp/make-chroot.XXXXXX) TARGET="$TMPDIR/root" SCRIPTCFG="default/config" debootstrap --variant=buildd --include=apt,apt-utils,gnupg,build-essential,fakeroot --arch "$ARCH" "$SUITE" "$TARGET" "$MIRROR" install -m a=rx,u+w "$DATA/policy-rc.d" "$TARGET/usr/sbin/" mkdir -p "$TARGET/dev/pts" # /dev/shm is a symlink to /run/shm on modern distros # So if it's not a symlink, then mkdir (and fail if it's something # that's not a symlink or a directory) and we have to use an schroot # config that bind-mounts /run/shm instead of /dev/shm if [ -L "$TARGET/dev/shm" ] && [ "$(readlink "$TARGET/dev/shm")" = "/run/shm" ]; then SCRIPTCFG="default-slash-run/config" else mkdir -p "$TARGET/dev/shm" fi mkdir -p "$TARGET/afs" mkdir -p "$TARGET/mit" TAROPTS="cf" [ $BZ2 -eq 1 ] && TAROPTS="cjf" (cd "$TMPDIR" && tar "$TAROPTS" "$FILE" --numeric-owner root) rm -rf "$TMPDIR" exittrap() { :; } ! [ -s "$CONF" ] || echo >> "$CONF" cat >> "$CONF" < /etc/apt/sources.list ! type apt-key >/dev/null || apt-key add - <&9 apt-get -q -y update apt-get -q -y dist-upgrade EOF