X-Git-Url: http://git.grml.org/?a=blobdiff_plain;f=usr_sbin%2Fgrml-chroot;h=a894e39040e8f753f3c65b5c690312f131529697;hb=a753f245b085d1f2e213e0b4d66c8041a3a0d4b7;hp=4277c34e9036f2caa8d715c88f77f39153e233d2;hpb=18f85c7883a8fccadf4292c693388e73f866d1b6;p=grml-scripts.git diff --git a/usr_sbin/grml-chroot b/usr_sbin/grml-chroot index 4277c34..a894e39 100755 --- a/usr_sbin/grml-chroot +++ b/usr_sbin/grml-chroot @@ -9,7 +9,6 @@ PROG_NAME_=$(basename $0) DEST_="" MOUNTED_="" # all mounted destinations -COMMAND_="" # command to start in chroot function die @@ -23,7 +22,7 @@ function printUsage cat <1; i--) printf("%s ",$i); print $1; }') + for i in $reverse; do umount "${DEST_}/$i" done } @@ -75,20 +75,49 @@ done shift $(($OPTIND - 1)) if (( $# < 1 )); then + printUsage die "Wrong number of arguments." fi -DEST_="$1" -COMMAND_="${2}" +if ! which awk >/dev/null 2>&1 ; then + die "No awk binary found, required for execution." +fi + +DEST_="$1"; shift if [ ! -d "$DEST_" ]; then die "Target chroot does not exist: $DEST_" fi -mountit "proc" "proc" -mountit "sysfs" "sys" -mountit "/dev" "dev" "--bind" -chroot "$DEST_" $COMMAND_ + +if [ -f "$DEST_"/proc/cmdline ] ; then + echo "Looks like $DEST_ already has filesystems mounted, skipping." +else + mountit "proc" "proc" + mountit "sysfs" "sys" + mountit "/dev" "dev" "--bind" + mountit "devpts" "dev/pts" +fi + +WROTE_DEBIAN_CHROOT="" +if [ ! -f "$DEST_"/etc/debian_chroot ]; then + WROTE_DEBIAN_CHROOT="yes" + echo "Writing /etc/debian_chroot ..." + cat "$DEST_"/etc/hostname > "$DEST_"/etc/debian_chroot +fi + +if (( $# < 1 )); then + chroot "$DEST_" + RC=$? +else + chroot "$DEST_" "$@" + RC=$? +fi umount_all +if [ ! -z "$WROTE_DEBIAN_CHROOT" ]; then + rm "$DEST_"/etc/debian_chroot +fi + +exit $RC