--- /dev/null
+!/bin/bash -e
+
+[[ -w / ]] || exec sudo "$0" "$@"
+[[ $# -eq 0 ]] && set -- /bin/bash -l
+mounts="proc sys dev dev/pts"
+
+chroot=${0%/*}
+cd "${chroot}"
+
+maybe_mount() {
+ local src=$1 dst=${2:-$1}
+ mkdir -p $d/$m
+ grep -sq "${chroot}/${dst}" /proc/mounts || mount --bind "/${src}" "${chroot}/${dst}"
+}
+for m in ${mounts} ; do
+ maybe_mount ${m}
+done
+
+get_type() {
+ case $(file "$1") in
+ *x86-64*) echo x86_64;;
+ *"Intel 80386"*) echo i386;;
+ esac
+}
+bin_dst=$(get_type bin/bash)
+bin_src=$(get_type /bin/bash)
+if [[ ${bin_dst} == ${bin_src} ]] ; then
+ setarch=
+else
+ setarch="setarch ${bin_dst}"
+fi
+
+if [[ ! -L /etc/mtab ]] ; then
+ rm -f etc/mtab
+ ln -sf /proc/mounts etc/mtab
+fi
+etc="
+ hosts
+ locale.gen
+ localtime
+ resolv.conf
+"
+root="
+ .inputrc
+ .nanorc
+"
+for f in \
+ $(printf 'etc/%s ' ${etc}) \
+ $(printf 'root/%s ' ${root}) \
+; do
+ cp /${f} ${f}
+done
+
+unset LS_COLORS # format changes over time
+exec ${setarch} chroot "${chroot}" "$@"