future-install-scripts/arch-chroot.in
Dave Reisner 1d9c98c5ee enforce user-specified root directory
Remove the -r option, forcing the user to explicitly pass a root
directory. This removes some confusion wherein we set defaults, but
wouldn't allow all the defaults to be accepted.

This also adds some mild documentation to the help output for genfstab
and pacstrap.
2012-07-15 10:07:11 -04:00

32 lines
588 B
Bash

#!/bin/bash
shopt -s extglob
m4_include(common)
usage() {
cat <<EOF
usage: ${0##*/} chroot-dir
EOF
}
if [[ -z $1 || $1 = @(-h|--help) ]]; then
usage
exit $(( $# ? 0 : 1 ))
fi
(( EUID == 0 )) || die 'This script must be run with root privileges'
chrootdir=$1
[[ -d $chrootdir ]] || die "Can't create chroot on non-directory %s" "$1"
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"
chroot "$@"
umount "$chrootdir/etc/resolv.conf"