From dc24f4e1dc5a586226cdff475c3dc9e981104e6c Mon Sep 17 00:00:00 2001 From: Mike Frysinger Date: Sun, 16 Aug 2009 16:12:34 -0400 Subject: [PATCH] chroot helper --- .bin/custom-chroot | 55 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 55 insertions(+) create mode 100644 .bin/custom-chroot diff --git a/.bin/custom-chroot b/.bin/custom-chroot new file mode 100644 index 0000000..6ad7bb6 --- /dev/null +++ b/.bin/custom-chroot @@ -0,0 +1,55 @@ +!/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}" "$@" -- 2.39.5