4 [[ $(id -u) -eq 0 ]] || exec sudo env -uUNSHARE HOME="$HOME" "$0" "$@"
6 if [[ -z ${UNSHARE} ]] ; then
8 if type -P unshare >&/dev/null ; then
9 test_arg() { unshare "$@" -- true >&/dev/null && uargs+=( "$@" ) || :; }
13 test_arg -p -f --mount-proc
14 test_arg --propagation=private
15 UNSHARE=true exec unshare "${uargs[@]}" -- "$0" "$@"
25 grep -sq "${dst}" /proc/mounts
29 local src=/$1 dst=${chroot}/${2:-$1}
30 [[ -d ${src} ]] || return 0
31 if ! mkdir -p "${dst}" ; then
32 [[ -w ${chroot} ]] && exit 1 || return 0
34 is_mounted "${dst}" || mount ${mount_args} --bind "${src}" "${dst}"
39 *x86-64*) echo x86_64;;
40 *"Intel 80386"*) echo i386;;
41 *32-bit*PowerPC*MSB*) echo ppc;;
42 *64-bit*PowerPC*MSB*) echo ppc64;;
43 *32-bit*PowerPC*LSB*) echo ppcle;;
44 *64-bit*PowerPC*LSB*) echo ppc64le;;
45 *32-bit*S/390*) echo s390;;
46 *64-bit*S/390*) echo s390x;;
47 *64-bit*MIPS*) echo mips64;;
48 *32-bit*MIPS*N32*) echo mips64;;
49 *32-bit*MIPS*) echo mips;;
50 *32-bit*PA-RISC*) echo parisc;;
51 *64-bit*PA-RISC*) echo parisc64;;
52 *32-bit*SPARC*) echo sparc;;
53 *64-bit*SPARC*) echo sparc64;;
58 [[ -w . ]] || return 0
60 if [[ ! -L etc/mtab ]] ; then
61 ln -sfT /proc/mounts etc/mtab
77 $(printf 'etc/%s ' "${etc[@]}") \
79 if [[ -e /${f} ]] ; then
83 for f in "${home[@]}" ; do
86 if [[ -e ${f} ]] ; then
91 if [[ ! -d root/.git ]] ; then
92 f="${HOME}/.profile.d/aliases.sh"
93 if [[ -e ${f} ]] ; then
94 cat "${f}" > root/.bash_profile
101 Usage: ${0##*/} [options] [program to run]
103 Sets up common mount points and then chroots in and runs a program.
104 If no program is specified, then launch a login shell.
107 -u Unmount all paths in the chroot
108 -m <path> Add path to mount list
109 -d <dir> Use <dir> as chroot (defaults to ${0%/*})
118 local mounts=( proc sys tmp dev dev/shm run usr/portage usr/portage/distfiles usr/local/src )
123 ./*) chroot=${PWD}/${chroot#./} ;;
127 while [[ -n $1 ]] ; do
130 -m) mounts+=( "$2" ); shift ;;
131 -d) chroot=$(realpath "$2"); shift ;;
133 -*) echo "${0##*/}: unknown option $1"; exit 1 ;;
141 umount) exec "${0%/*}/umount-tree" -y "${chroot}" ;;
145 for m in "${mounts[@]}" ; do
148 # Handle special mounts that we don't want to just bind mount.
149 if ! is_mounted "${chroot}/dev/pts" ; then
150 mount -t devpts devpts "${chroot}/dev/pts" \
151 -o nosuid,noexec,newinstance,ptmxmode=0666,mode=0620,gid=5
157 if type -P setarch &>/dev/null ; then
158 local bin_dst=$(get_type bin/bash)
159 if [[ -n ${bin_dst} ]] ; then
160 setarch="setarch ${bin_dst}"
164 # Doubtful these settings we want to leak into the chroot.
165 unset ROOT PORTAGE_CONFIGROOT LD_LIBRARY_PATH
166 unset LS_COLORS # format changes over time
167 [[ $# -eq 0 ]] && set -- env HOME=/root /bin/bash -l