#!/bin/bash set -e unmount_virtual() { umount "$1/proc" || true umount "$1/sys" || true umount "$1/tree/proc" || true umount "$1/tree/sys" || true } pass_snapshot() { echo -n "$snapshotdir/$1-snapshot.tar.gz" } has_pass() { if [ -e $(pass_snapshot "$1") ] then return 0 else return 1 fi } update_morph() { local dir="$1" cp baserock-bootstrap "$dir/." # update bootstrap script rm -rf "$dir/tree/baserock/gits/morph" mkdir -p "$dir/tree/baserock/gits/morph" cp -r . "$dir/tree/baserock/gits/morph/." } run_pass() { local dir="$1" local passname="$2" local tarball=$(pass_snapshot "$passname") if "$snapshot" && has_pass "$passname" then tar -C "$dir" -xf "$tarball" update_morph "$dir" else update_morph "$dir" "./do-squeeze-chroot" bash -x baserock-bootstrap "$passname" || exit 1 if "$snapshot" then tar -C "$dir" -caf "$tarball" . fi fi } export LC_ALL=C if [ "x$1" = x ] then echo "Usage: $0 chroot-dir" 1>&2 exit 1 fi mkdir -p "$1" dir="$1/squeeze-chroot" : ${snapshot:=true} snapshotdir="$1" cat >"./do-squeeze-chroot" <&2) || ([ "x$GIT_BUNDLES" = x ] && echo GIT_BUNDLES is unspecified >&2) || ([ "x$LFS_MIRROR" = x ] && echo LFS_MIRROR is unspecified >&2) then echo You have to set DEBIAN_MIRROR and other environment variables 1>&2 exit 1 fi #DEBIAN_MIRROR="http://192.168.1.185/debian" #LFS_MIRROR=http://192.168.1.185/lfs/ unmount_virtual "$dir" rm -rf "$dir" mkdir "$dir" chrootsnapshot="$snapshotdir/squeeze.tar.gz" if "$snapshot" && [ -e "$chrootsnapshot" ] then tar -C "$dir" -xf "$chrootsnapshot" else debootstrap \ --include=build-essential,\ gawk,bison,python,autoconf,autopoint,automake,gettext,libtool,\ help2man,texinfo,sudo,qemu-utils,parted,kpartx,mbr,extlinux \ squeeze "$dir" "$DEBIAN_MIRROR" # We need a backport of tar 1.26. On ARM, older versions (possibly # prior to 1.25) have a bug unpacking things onto an NFS filesystem. # code.liw.fi has the backport, so we'll add that to apt's sources.list # and install tar manually. cat <> "$dir/etc/apt/sources.list" deb http://code.liw.fi/debian squeeze main EOF ./do-squeeze-chroot apt-get update ./do-squeeze-chroot apt-get install --allow-unauthenticated tar if "$snapshot" then tar -caf "$chrootsnapshot" -C "$dir" . fi fi hostname > "$dir/etc/hostname" cat < "$dir/etc/hosts" 127.0.0.1 localhost 127.0.1.1 `hostname` EOF if [ "x$LFS_MIRROR" = x ]; then cp wget-list "$dir/wget-list" else perl -M'Env' -lpe 's|^.*/|$LFS_MIRROR|' wget-list >"$dir/wget-list" fi # Unpack existing snapshot, or run pass1 of bootstrap and then make snapshot. if ! "$snapshot" || ! has_pass pass2a then run_pass "$dir" pass1 fi if ! "$snapshot" || ! has_pass pass2b then run_pass "$dir" pass2a fi run_pass "$dir" pass2b snapshot=false run_pass "$dir" pass3 echo "Passes 1, 2, and 3 of bootstrap done (possibly cached)."