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 UNSHARE=true exec unshare -m -- "$0" "$@"
18 local src=/$1 dst=${chroot}/${2:-$1}
19 [[ -d ${src} ]] || return 0
20 if ! mkdir -p "${dst}" ; then
21 [[ -w ${chroot} ]] && exit 1 || return 0
23 grep -sq "${dst}" /proc/mounts || mount ${mount_args} --bind "${src}" "${dst}"
28 *x86-64*) echo x86_64;;
29 *"Intel 80386"*) echo i386;;
30 *32-bit*PowerPC*) echo ppc;;
31 *64-bit*PowerPC*) echo ppc64;;
32 *32-bit*S/390*) echo s390;;
33 *64-bit*S/390*) echo s390x;;
38 [[ -w . ]] || return 0
40 if [[ ! -L etc/mtab ]] ; then
41 ln -sfT /proc/mounts etc/mtab
57 $(printf 'etc/%s ' "${etc[@]}") \
59 if [[ -e /${f} ]] ; then
63 for f in "${home[@]}" ; do
66 if [[ -e ${f} ]] ; then
71 f="${HOME}/.profile.d/aliases.sh"
72 if [[ -e ${f} ]] ; then
73 cat "${f}" > root/.bash_profile
79 Usage: ${0##*/} [options] [program to run]
81 Sets up common mount points and then chroots in and runs a program.
82 If no program is specified, then launch a login shell.
85 -u Unmount all paths in the chroot
86 -m <path> Add path to mount list
87 -d <dir> Use <dir> as chroot (defaults to ${0%/*})
96 local mounts=( proc sys tmp dev dev/pts dev/shm usr/portage usr/portage/distfiles usr/local/src )
101 ./*) chroot=${PWD}/${chroot#./} ;;
105 while [[ -n $1 ]] ; do
108 -m) mounts+=( "$2" ); shift ;;
109 -d) chroot=$(realpath "$2"); shift ;;
111 -*) echo "${0##*/}: unknown option $1"; exit 1 ;;
119 umount) exec "${0%/*}/umount-tree" -y "${chroot}" ;;
123 for m in "${mounts[@]}" ; do
130 if type -P setarch &>/dev/null ; then
131 local bin_dst=$(get_type bin/bash)
132 if [[ -n ${bin_dst} ]] ; then
133 setarch="setarch ${bin_dst}"
137 unset LS_COLORS # format changes over time
138 [[ $# -eq 0 ]] && set -- env HOME=/root /bin/bash -l