future-install-scripts/arch-chroot.in
Dave Reisner 2be79c6259 run the chroot in a new PID namespace
This automatically tears down any processes remaining in the chroot
when we exit. I'm looking at you, gnupg.
2014-12-11 21:40:52 -05:00

33 lines
693 B
Bash

#!/bin/bash
shopt -s extglob
m4_include(common)
usage() {
cat <<EOF
usage: ${0##*/} chroot-dir [command]
-h Print this help message
If 'command' is unspecified, ${0##*/} will launch /bin/sh.
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
shift
[[ -d $chrootdir ]] || die "Can't create chroot on non-directory %s" "$chrootdir"
api_fs_mount "$chrootdir" || die "failed to setup API filesystems in chroot %s" "$chrootdir"
track_mount /etc/resolv.conf "$chrootdir/etc/resolv.conf" --bind
SHELL=/bin/sh unshare --fork --pid chroot "$chrootdir" "$@"