]> git.wh0rd.org Git - home.git/commitdiff
chroot helper
authorMike Frysinger <vapier@gentoo.org>
Sun, 16 Aug 2009 20:12:34 +0000 (16:12 -0400)
committerMike Frysinger <vapier@gentoo.org>
Sat, 28 Apr 2012 19:36:08 +0000 (15:36 -0400)
.bin/custom-chroot [new file with mode: 0644]

diff --git a/.bin/custom-chroot b/.bin/custom-chroot
new file mode 100644 (file)
index 0000000..6ad7bb6
--- /dev/null
@@ -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}" "$@"