Browse Source

bin: add do_chroot helpering handling the needed bind mounts

Signed-off-by: Alejandro Mery <amery@geeks.cl>
master
Alejandro Mery 11 years ago
parent
commit
424b78b6df
1 changed files with 38 additions and 0 deletions
  1. +38
    -0
      files/bin/do_chroot

+ 38
- 0
files/bin/do_chroot

@ -0,0 +1,38 @@
#!/bin/sh
arg0=$(basename "$0")
fatal() {
echo "F: $arg0: $@"
exit 1
}
if [ $# -gt 0 -a -d "$1" ]; then
DIR="$1"
shift
else
DIR="."
fi
cd "$DIR" || fatal "$DIR: invalid chroot dir"
DIR=$(pwd -P)
error=false
for x in dev dev/pts sys tmp; do
if ! grep -q " $DIR/$x " /proc/mounts; then
mount --bind /$x $DIR/$x || error=true
if $error; then
[ "$x" != dev ] || fatal "can't do anything"
break
fi
fi
done
$error || chroot "$DIR" "$@"
while grep -q " $DIR/" /proc/mounts; do
sleep 0.2
grep " $DIR/" /proc/mounts | cut -d' ' -f2 | tac | xargs -r --verbose -- umount
done

Loading…
Cancel
Save