#!/bin/bash # Filename: grml-chroot # Purpose: Program to chroot into another system # Authors: grml-team (grml.org), (c) Michael Gebetsroither # Bug-Reports: see http://grml.org/bugs/ # License: This file is licensed under the GPL v2. ################################################################################ PROG_NAME_=$(basename $0) DEST_="" MOUNTED_="" # all mounted destinations function bailout { umount_all die "Bailout" } trap bailout 1 2 3 3 6 9 14 15 function die { echo "Error: $@" >&2 exit 1 } function isMounted { local dir="$1" if cut -d\ -f 2 /proc/mounts | grep -q "$dir"; then return 0 else return 1 fi } function printUsage { cat < "$DEST_"/etc/debian_chroot fi if (( $# < 1 )); then chroot "$DEST_" RC=$? else chroot "$DEST_" "$@" RC=$? fi if [ -z "$STATEDIR" ] ; then umount_all else rm "$DEST_/$STATEDIR/$$" if rmdir "$DEST_/$STATEDIR" 2>/dev/null; then umount_all fi fi exit $RC