future-install-scripts/arch-chroot.in

32 lines
590 B
Plaintext
Raw Normal View History

2012-06-18 04:44:55 +08:00
#!/bin/bash
shopt -s extglob
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
(( EUID == 0 )) || die 'This script must be run with root privileges'
chrootdir=$1
2012-06-18 05:52:39 +08:00
[[ -d $chrootdir ]] || die "Can't create chroot on non-directory %s" "$1"
2012-06-18 04:44:55 +08:00
trap 'api_fs_umount "$chrootdir" 2>/dev/null' EXIT
api_fs_mount "$chrootdir" || die "failed to setup API filesystems in chroot %s" "$1"
mount -B /etc/resolv.conf "$chrootdir/etc/resolv.conf"
2012-06-18 04:44:55 +08:00
chroot "$@"
umount "$chrootdir/etc/resolv.conf"