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
*) echo ppc
;;
42 *64-bit*PowerPC
*) echo ppc64
;;
43 *32-bit*S
/390*) echo s390
;;
44 *64-bit*S
/390*) echo s390x
;;
45 *64-bit*MIPS
*) echo mips64
;;
46 *32-bit*MIPS
*N32
*)echo mips64
;;
47 *32-bit*MIPS
*) echo mips
;;
48 *32-bit*PA-RISC
*) echo parisc
;;
49 *64-bit*PA-RISC
*) echo parisc64
;;
50 *32-bit*SPARC
*) echo sparc
;;
51 *64-bit*SPARC
*) echo sparc64
;;
56 [[ -w .
]] ||
return 0
58 if [[ ! -L etc
/mtab
]] ; then
59 ln -sfT /proc
/mounts etc
/mtab
75 $
(printf 'etc/%s ' "${etc[@]}") \
77 if [[ -e /${f} ]] ; then
81 for f
in "${home[@]}" ; do
84 if [[ -e ${f} ]] ; then
89 if [[ ! -d root
/.git
]] ; then
90 f
="${HOME}/.profile.d/aliases.sh"
91 if [[ -e ${f} ]] ; then
92 cat "${f}" > root
/.bash_profile
99 Usage: ${0##*/} [options] [program to run]
101 Sets up common mount points and then chroots in and runs a program.
102 If no program is specified, then launch a login shell.
105 -u Unmount all paths in the chroot
106 -m <path> Add path to mount list
107 -d <dir> Use <dir> as chroot (defaults to ${0%/*})
116 local mounts
=( proc sys tmp dev dev
/shm run usr
/portage usr
/portage
/distfiles usr
/local
/src
)
121 .
/*) chroot
=${PWD}/${chroot#./} ;;
125 while [[ -n $1 ]] ; do
128 -m) mounts
+=( "$2" ); shift ;;
129 -d) chroot
=$
(realpath
"$2"); shift ;;
131 -*) echo "${0##*/}: unknown option $1"; exit 1 ;;
139 umount
) exec "${0%/*}/umount-tree" -y "${chroot}" ;;
143 for m
in "${mounts[@]}" ; do
146 # Handle special mounts that we don't want to just bind mount.
147 if ! is_mounted
"${chroot}/dev/pts" ; then
148 mount
-t devpts devpts
"${chroot}/dev/pts" \
149 -o nosuid
,noexec
,newinstance
,ptmxmode
=0666,mode
=0620,gid
=5
155 if type -P setarch
&>/dev
/null
; then
156 local bin_dst
=$
(get_type bin
/bash
)
157 if [[ -n ${bin_dst} ]] ; then
158 setarch
="setarch ${bin_dst}"
162 # Doubtful these settings we want to leak into the chroot.
163 unset ROOT PORTAGE_CONFIGROOT LD_LIBRARY_PATH
164 unset LS_COLORS
# format changes over time
165 [[ $# -eq 0 ]] && set -- env HOME
=/root
/bin
/bash
-l