#!/bin/bash -e [[ -w / ]] || exec sudo "$0" "$@" [[ $# -eq 0 ]] && set -- env HOME=/root /bin/bash -l mounts="proc sys dev dev/pts" chroot=${0%/*} case ${chroot} in .) chroot=${PWD} ;; esac 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 " home=" .inputrc .nanorc " for f in \ $(printf 'etc/%s ' ${etc}) \ ; do cp /${f} ${f} done for f in ${home} ; do cp ~/${f} root/${f} done unset LS_COLORS # format changes over time exec \ ${setarch} \ chroot "${chroot}" \ "$@"