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