X-Git-Url: http://git.grml.org/?a=blobdiff_plain;f=usr_sbin%2Fgrml-chroot;h=6e292d5129679f5f47383be520bb27623a226400;hb=3559bd707848cb41e6e0de2432db793385a26edf;hp=4277c34e9036f2caa8d715c88f77f39153e233d2;hpb=18f85c7883a8fccadf4292c693388e73f866d1b6;p=grml-scripts.git diff --git a/usr_sbin/grml-chroot b/usr_sbin/grml-chroot index 4277c34..6e292d5 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,11 +75,15 @@ 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_" @@ -89,6 +93,26 @@ fi mountit "proc" "proc" mountit "sysfs" "sys" mountit "/dev" "dev" "--bind" -chroot "$DEST_" $COMMAND_ +mountit "devpts" "dev/pts" + +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