. state/config.sh # @@@config@@@
+## Convert the PROXY configuration setting into something that will affect
+## `debootstrap'.
case $PROXY in nil) ;; *) http_proxy=$PROXY; export PROXY ;; esac
+## Parse the command-line.
badp=nil forcep=nil
while getopts "f" opt; do
case $opt in
case $d-$a in *-*-*) echo >&2 "$0: bad chroot name \`$arg'"; exit 2 ;; esac
if [ ! -d /dev/$VG/ ]; then echo >&2 "$0: no volume group \`$VG'"; exit 2; fi
+## Decide whether we need to do special things for installing a foreign
+## architecture.
qemup=nil dbsopts=
for fa in $FOREIGN_ARCHS; do
case $fa in
"$a")
- qemup=t qbsopts=--foreign
- eval qhost=\$${a}_QEMUARCH qhost=\$${a}_QEMUHOST
+ qemup=t dbsopts=--foreign
+ eval qarch=\$${a}_QEMUARCH qhost=\$${a}_QEMUHOST
break
;;
esac
done
+## Construct the logical volume and lay a filesystem onto it.
lv=$LVPREFIX$d-$a
-mnt=mnt/$lv
+mnt=$HERE/mnt/$lv
mkdir -p $mnt
if mountpoint -q $mnt; then umount $mnt; fi
if [ -b /dev/$VG/$lv ]; then
mount -orelatime,data=writeback,commit=3600,barrier=0 /dev/$VG/$lv $mnt/
mkdir -m755 $mnt/fs/
chmod 750 $mnt/
-pkgs=ccache,eatmydata,fakeroot,libfile-fcntllock-perl,locales,tzdata
+
+## Install the base system.
+want=$BASE_PACKAGES
+case $qemup in
+ t) want="$want $FOREIGN_BASE_PACKAGES" ;;
+ nil) want="$want $NATIVE_BASE_PACKAGES" ;;
+esac
+pkgs=; for p in $want; do pkgs=${pkgs:+$pkgs,}$p; done
eatmydata debootstrap $dbsopts --arch=$a --variant=minbase \
--include=$pkgs $d $mnt/fs/ $DEBMIRROR
+## If this is a cross-installation, then install the necessary `qemu' and
+## complete the installation.
case $qemup in
t)
install $LOCAL/cross/$d-$qhost/QEMU/qemu-$qarch-static \
;;
esac
-cd $mnt/fs/usr/
-rm -rf local/; ln -s local.schroot/$a local
+## Set up `/usr/local'.
+rm -rf $mnt/fs/usr/local/; ln -s local.schroot/$a $mnt/fs/usr/local
-cd $mnt/fs/etc/apt/
-rm -rf apt.conf sources.list
-ln -s /usr/local.schroot/config/apt/conf.d/10sbuild apt.conf.d/
-ln -s /usr/local.schroot/config/apt/conf.d/90local apt.conf.d/
-ln -s /usr/local.schroot/config/apt/sources.$d sources.list
+## Install the `apt' configuration.
+rm -rf $mnt/fs/etc/apt/apt.conf $mnt/fs/etc/apt/sources.list
+for c in $LOCAL/etc/apt/apt.conf.d/*; do
+ ln -s /usr/local.schroot/${c#$LOCAL/} $mnt/fs/etc/apt/apt.conf.d/
+done
+ln -s /usr/local.schroot/etc/apt/sources.$d $mnt/fs/etc/apt/sources.list
-cat >apt.conf.d/20arch <<EOF
+cat >$mnt/fs/etc/apt/apt.conf.d/20arch <<EOF
### -*-conf-*-
APT {
};
EOF
-cd $mnt/fs/etc/
-cp /etc/locale.gen /etc/timezone ./
-tz=$(cat timezone); ln -sf /usr/share/zoneinfo/$tz localtime
-ln -sf /proc/mounts mtab
+## Set up the locale and time zone from the host system.
+cp /etc/locale.gen /etc/timezone $mnt/fs/etc/
+tz=$(cat /etc/timezone); ln -sf /usr/share/zoneinfo/$tz $mnt/fs/etc/localtime
+ln -sf /proc/mounts $mnt/fs/etc/mtab
-cd $mnt/fs/etc/default/
-cp /etc/default/locale .
+cp /etc/default/locale $mnt/fs/etc/default/
-cd $mnt/fs/usr/sbin/
-cat >policy-rc.d <<EOF
+## Prevent daemons from starting within the chroot.
+cat >$mnt/fs/usr/sbin/policy-rc.d <<EOF
#! /bin/sh
echo >&2 "policy-rc.d: Services disabled by policy."
exit 101
EOF
-chmod +x policy-rc.d
+chmod +x $mnt/fs/usr/sbin/policy-rc.d
-cd $mnt/fs/etc/ld.so.conf.d/
-cat >libc.conf <<EOF
+## Hack the dynamic linker to prefer libraries in `/usr' over `/usr/local'.
+cat >$mnt/fs/etc/ld.so.conf.d/libc.conf <<EOF
# libc default configuration
EOF
-cat >zzz-local.conf <<EOF
+cat >$mnt/fs/etc/ld.so.conf.d/zzz-local.conf <<EOF
### -*-conf-*-
### Local hack to make /usr/local/ late.
/usr/local/lib
EOF
-cd /
+## We're done setting the chroot environment up.
umount $mnt/
+## If this is a foreign architecture then we need to set it up.
case $qemup in
t)
+ ## Keep the chroot's native Qemu out of our way: otherwise we'll stop
+ ## being able to run programs in the chroot. There's a hack here because
+ ## the `--no-rename' option was required in the same version in which is
+ ## was introduced, so there's no single incantation that will work across
+ ## the boundary.
schroot -uroot -csource:$LVPREFIX$d-$a -- eatmydata sh -e -c "
if dpkg-divert >/dev/null 2>&1 --no-rename --help
then no_rename=--no-rename
fi
dpkg-divert --package install-cross-tools \$no_rename \
- --divert /usr/bin/$qemu.$a --add /usr/bin/$qemu"
+ --divert /usr/bin/qemu-$qarch-static.$a --add /usr/bin/qemu-$qarch-static"
+
+ ## Install faster native tools.
$STATE/bin/install-cross-tools $d $a
+
+ ## Install `build-essential', which had been delayed from earlier.
+ schroot -uroot -csource:$LVPREFIX$d-$a -- \
+ eatmydata apt-get -y install build-essential
;;
esac
+## Set the chroot's package state up properly.
schroot -uroot -csource:$LVPREFIX$d-$a -- eatmydata sh -e -c '
apt-get update
apt-get -y upgrade