+ *x86-64*) echo x86_64;;
+ *"Intel 80386"*) echo i386;;
+ *32-bit*PowerPC*MSB*) echo ppc;;
+ *64-bit*PowerPC*MSB*) echo ppc64;;
+ *32-bit*PowerPC*LSB*) echo ppcle;;
+ *64-bit*PowerPC*LSB*) echo ppc64le;;
+ *32-bit*S/390*) echo s390;;
+ *64-bit*S/390*) echo s390x;;
+ *64-bit*MIPS*) echo mips64;;
+ *32-bit*MIPS*N32*) echo mips64;;
+ *32-bit*MIPS*) echo mips;;
+ *32-bit*PA-RISC*) echo parisc;;
+ *64-bit*PA-RISC*) echo parisc64;;
+ *32-bit*SPARC*) echo sparc;;
+ *64-bit*SPARC*) echo sparc64;;
+ esac
+}
+
+init_chroot() {
+ [[ -w . ]] || return 0
+
+ if [[ ! -L etc/mtab ]] ; then
+ ln -sfT /proc/mounts etc/mtab
+ fi
+ local f dst
+ local etc=(
+ hosts
+ locale.gen
+ localtime
+ resolv.conf
+ )
+ local home=(
+ .inputrc
+ .gdbinit
+ .gitconfig
+ .nanorc
+ )
+ for f in \
+ $(printf 'etc/%s ' "${etc[@]}") \
+ ; do
+ if [[ -e /${f} ]] ; then
+ cp "/${f}" "${f}"
+ fi
+ done
+ for f in "${home[@]}" ; do
+ df="root/${f}"
+ f="${HOME}/${f}"
+ if [[ -e ${f} ]] ; then
+ cp "${f}" "${df}"
+ fi
+ done
+
+ if [[ ! -d root/.git ]] ; then
+ f="${HOME}/.profile.d/aliases.sh"
+ if [[ -e ${f} ]] ; then
+ cat "${f}" > root/.bash_profile
+ fi
+ fi
+}
+
+usage() {
+ cat <<-EOF
+ Usage: ${0##*/} [options] [program to run]
+
+ Sets up common mount points and then chroots in and runs a program.
+ If no program is specified, then launch a login shell.
+
+ Options:
+ -u Unmount all paths in the chroot
+ -m <path> Add path to mount list
+ -d <dir> Use <dir> as chroot (defaults to ${0%/*})
+ -h This help screen
+ EOF
+ exit
+}
+
+main() {
+ bootstrap "$@"
+
+ local mounts=(
+ proc sys tmp dev dev/shm run
+ usr/portage usr/portage/distfiles
+ var/db/repos/gentoo var/cache/distfiles
+ usr/local/src
+ )
+
+ local chroot=${0%/*}
+ case ${chroot} in
+ .) chroot=${PWD} ;;
+ ./*) chroot=${PWD}/${chroot#./} ;;