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 | |
---|
9 | DEBUG=0 |
---|
10 | BZ2=0 |
---|
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)) |
---|
20 | |
---|
21 | set -xe |
---|
22 | |
---|
23 | : ${CHROOTDIR=/srv} |
---|
24 | : ${MIRRORHOST=localhost:9999} |
---|
25 | : ${DATA="$(dirname "$0")"} |
---|
26 | SUITE=$1 |
---|
27 | ARCH=$2 |
---|
28 | CHROOT="${SUITE}-${ARCH}-sbuild" |
---|
29 | FILE="$CHROOTDIR"/"$CHROOT".tar |
---|
30 | [ $BZ2 -eq 1 ] && FILE="${FILE}.bz2" |
---|
31 | SIZE=4G |
---|
32 | |
---|
33 | exittrap() { :; } |
---|
34 | for sig in 1 2 13 15; do trap "exit $(($sig + 128))" $sig; done |
---|
35 | trap 'exittrap' EXIT |
---|
36 | |
---|
37 | if fgrep -qxRs "[$CHROOT]" /etc/schroot/schroot.conf /etc/schroot/chroot.d; then |
---|
38 | echo "Chroot $CHROOT already exists." >&2 |
---|
39 | exit 1 |
---|
40 | fi |
---|
41 | if [ -e "$FILE" ]; then |
---|
42 | echo "Chroot tarball $FILE already exists." >&2 |
---|
43 | exit 1 |
---|
44 | fi |
---|
45 | |
---|
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 | |
---|
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" |
---|
64 | MIRROR="http://$MIRRORHOST/debian" |
---|
65 | elif [ -e "$SOURCESD/ubuntu/$SUITE.list" ]; then |
---|
66 | SOURCES="$SOURCESD/ubuntu/$SUITE.list" |
---|
67 | MIRROR="http://$MIRRORHOST/ubuntu" |
---|
68 | else |
---|
69 | echo "Unrecognized suite $SUITE." >&2 |
---|
70 | exit 1 |
---|
71 | fi |
---|
72 | |
---|
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 | } |
---|
80 | TMPDIR=$(mktemp -d /var/tmp/make-chroot.XXXXXX) |
---|
81 | TARGET="$TMPDIR/root" |
---|
82 | SCRIPTCFG="default/config" |
---|
83 | debootstrap --variant=buildd --include=apt,apt-utils,gnupg,build-essential,fakeroot --arch "$ARCH" "$SUITE" "$TARGET" "$MIRROR" |
---|
84 | install -m a=rx,u+w "$DATA/policy-rc.d" "$TARGET/usr/sbin/" |
---|
85 | mkdir -p "$TARGET/dev/pts" |
---|
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 |
---|
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 |
---|
96 | mkdir -p "$TARGET/afs" |
---|
97 | mkdir -p "$TARGET/mit" |
---|
98 | TAROPTS="cf" |
---|
99 | [ $BZ2 -eq 1 ] && TAROPTS="cjf" |
---|
100 | (cd "$TMPDIR" && tar "$TAROPTS" "$FILE" --numeric-owner root) |
---|
101 | rm -rf "$TMPDIR" |
---|
102 | exittrap() { :; } |
---|
103 | |
---|
104 | ! [ -s "$CONF" ] || echo >> "$CONF" |
---|
105 | cat >> "$CONF" <<EOF |
---|
106 | [$CHROOT] |
---|
107 | type=file |
---|
108 | description=$CHROOT |
---|
109 | groups=root,sbuild |
---|
110 | root-groups=root,sbuild |
---|
111 | source-groups=root |
---|
112 | script-config=$SCRIPTCFG |
---|
113 | file=$FILE |
---|
114 | location=/root |
---|
115 | personality=$PERSONALITY |
---|
116 | EOF |
---|
117 | |
---|
118 | schroot --chroot="${CHROOT}-source" --directory=/ -- /bin/sh -xe - \ |
---|
119 | 8< "$SOURCES" \ |
---|
120 | 9< "$DATA/debathena-archive.asc" \ |
---|
121 | <<EOF |
---|
122 | #/debootstrap/debootstrap --second-stage |
---|
123 | dpkg-divert --local --rename --add /sbin/initctl |
---|
124 | ln -s /bin/true /sbin/initctl |
---|
125 | debconf-set-selections <<SELECTIONS |
---|
126 | debconf debconf/frontend select Noninteractive |
---|
127 | SELECTIONS |
---|
128 | sed "s|MIRRORHOST|$MIRRORHOST|" <&8 > /etc/apt/sources.list |
---|
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 |
---|