2012-06-18 04:44:55 +08:00
|
|
|
#!/bin/bash
|
|
|
|
|
|
|
|
shopt -s extglob
|
|
|
|
|
2012-06-18 17:07:37 +08:00
|
|
|
m4_include(common)
|
2012-06-18 04:44:55 +08:00
|
|
|
|
2012-06-18 05:52:39 +08:00
|
|
|
usage() {
|
|
|
|
cat <<EOF
|
|
|
|
usage: ${0##*/} <chroot-dir>
|
|
|
|
|
|
|
|
EOF
|
|
|
|
}
|
|
|
|
|
2012-06-18 04:44:55 +08:00
|
|
|
if [[ -z $1 || $1 = @(-h|--help) ]]; then
|
2012-06-18 05:52:39 +08:00
|
|
|
usage
|
2012-06-18 04:44:55 +08:00
|
|
|
exit $(( $# ? 0 : 1 ))
|
|
|
|
fi
|
|
|
|
|
2012-06-18 05:52:39 +08:00
|
|
|
|
2012-06-18 04:44:55 +08:00
|
|
|
[[ -d $1 ]] || die "Can't create chroot on non-directory %s" "$1"
|
|
|
|
|
|
|
|
if ! api_fs_mount "$1"; then
|
|
|
|
api_fs_umount 2>/dev/null
|
|
|
|
die "failed to setup API filesystems in chroot %s" "$1"
|
|
|
|
fi
|
2012-06-18 17:35:45 +08:00
|
|
|
mount -B /etc/resolv.conf "$1/etc/resolv.conf"
|
2012-06-18 04:44:55 +08:00
|
|
|
|
|
|
|
chroot "$@"
|
2012-06-18 17:35:45 +08:00
|
|
|
umount "$1/etc/resolv.conf"
|
2012-06-18 04:44:55 +08:00
|
|
|
api_fs_umount "$1"
|