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%/*})
119 proc sys tmp dev dev
/shm run
120 usr
/portage usr
/portage
/distfiles
121 var
/db
/repos
/gentoo var
/cache
/distfiles
128 .
/*) chroot
=${PWD}/${chroot#./} ;;
132 while [[ -n $1 ]] ; do
135 -m) mounts
+=( "$2" ); shift ;;
136 -d) chroot
=$
(realpath
"$2"); shift ;;
138 -*) echo "${0##*/}: unknown option $1"; exit 1 ;;
146 umount
) exec "${0%/*}/umount-tree" -y "${chroot}" ;;
150 for m
in "${mounts[@]}" ; do
153 # Handle special mounts that we don't want to just bind mount.
154 if ! is_mounted
"${chroot}/dev/pts" ; then
155 # Option order matters: on older kernels that don't recognize newinstance,
156 # parsing stops as soon as it hits that.
157 mount
-t devpts devpts
"${chroot}/dev/pts" \
158 -o nosuid
,noexec
,mode
=0620,gid
=5,ptmxmode
=0666,newinstance
164 if type -P setarch
&>/dev
/null
; then
165 local bin_dst
=$
(get_type bin
/bash
)
166 if [[ -n ${bin_dst} ]] ; then
167 setarch
="setarch ${bin_dst}"
171 # Doubtful these settings we want to leak into the chroot.
172 unset ROOT PORTAGE_CONFIGROOT LD_LIBRARY_PATH
173 unset LS_COLORS
# format changes over time
174 [[ $# -eq 0 ]] && set -- env HOME
=/root
/bin
/bash
-l