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
10 unshare
-u -- true
>&/dev
/null
&& uargs
+=( -u )
11 unshare
-p -- true
>&/dev
/null
&& uargs
+=( -p -f --mount-proc )
12 UNSHARE
=true
exec unshare
"${uargs[@]}" -- "$0" "$@"
21 local src
=/$1 dst
=${chroot}/${2:-$1}
22 [[ -d ${src} ]] ||
return 0
23 if ! mkdir
-p "${dst}" ; then
24 [[ -w ${chroot} ]] && exit 1 ||
return 0
26 grep -sq "${dst}" /proc/mounts || mount ${mount_args} --bind "${src}" "${dst}"
31 *x86-64
*) echo x86_64
;;
32 *"Intel 80386"*) echo i386
;;
33 *32-bit*PowerPC
*) echo ppc
;;
34 *64-bit*PowerPC
*) echo ppc64
;;
35 *32-bit*S
/390*) echo s390
;;
36 *64-bit*S
/390*) echo s390x
;;
41 [[ -w .
]] ||
return 0
43 if [[ ! -L etc
/mtab
]] ; then
44 ln -sfT /proc
/mounts etc
/mtab
60 $
(printf 'etc/%s ' "${etc[@]}") \
62 if [[ -e /${f} ]] ; then
66 for f
in "${home[@]}" ; do
69 if [[ -e ${f} ]] ; then
74 f
="${HOME}/.profile.d/aliases.sh"
75 if [[ -e ${f} ]] ; then
76 cat "${f}" > root
/.bash_profile
82 Usage: ${0##*/} [options] [program to run]
84 Sets up common mount points and then chroots in and runs a program.
85 If no program is specified, then launch a login shell.
88 -u Unmount all paths in the chroot
89 -m <path> Add path to mount list
90 -d <dir> Use <dir> as chroot (defaults to ${0%/*})
99 local mounts
=( proc sys tmp dev dev
/pts dev
/shm usr
/portage usr
/portage
/distfiles usr
/local
/src
)
104 .
/*) chroot
=${PWD}/${chroot#./} ;;
108 while [[ -n $1 ]] ; do
111 -m) mounts
+=( "$2" ); shift ;;
112 -d) chroot
=$
(realpath
"$2"); shift ;;
114 -*) echo "${0##*/}: unknown option $1"; exit 1 ;;
122 umount
) exec "${0%/*}/umount-tree" -y "${chroot}" ;;
126 for m
in "${mounts[@]}" ; do
133 if type -P setarch
&>/dev
/null
; then
134 local bin_dst
=$
(get_type bin
/bash
)
135 if [[ -n ${bin_dst} ]] ; then
136 setarch
="setarch ${bin_dst}"
140 # Doubtful these settings we want to leak into the chroot.
141 unset ROOT PORTAGE_CONFIGROOT LD_LIBRARY_PATH
142 unset LS_COLORS
# format changes over time
143 [[ $# -eq 0 ]] && set -- env HOME
=/root
/bin
/bash
-l