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
-i -- true
>&/dev
/null
&& uargs
+=( -i )
12 unshare
-p -- true
>&/dev
/null
&& uargs
+=( -p -f --mount-proc )
13 UNSHARE
=true
exec unshare
"${uargs[@]}" -- "$0" "$@"
22 local src
=/$1 dst
=${chroot}/${2:-$1}
23 [[ -d ${src} ]] ||
return 0
24 if ! mkdir
-p "${dst}" ; then
25 [[ -w ${chroot} ]] && exit 1 ||
return 0
27 grep -sq "${dst}" /proc/mounts || mount ${mount_args} --bind "${src}" "${dst}"
32 *x86-64
*) echo x86_64
;;
33 *"Intel 80386"*) echo i386
;;
34 *32-bit*PowerPC
*) echo ppc
;;
35 *64-bit*PowerPC
*) echo ppc64
;;
36 *32-bit*S
/390*) echo s390
;;
37 *64-bit*S
/390*) echo s390x
;;
38 *64-bit*MIPS
*) echo mips64
;;
39 *32-bit*MIPS
*N32
*)echo mips64
;;
40 *32-bit*MIPS
*) echo mips
;;
41 *32-bit*PA-RISC
*) echo parisc
;;
42 *64-bit*PA-RISC
*) echo parisc64
;;
43 *32-bit*SPARC
*) echo sparc
;;
44 *64-bit*SPARC
*) echo sparc64
;;
49 [[ -w .
]] ||
return 0
51 if [[ ! -L etc
/mtab
]] ; then
52 ln -sfT /proc
/mounts etc
/mtab
68 $
(printf 'etc/%s ' "${etc[@]}") \
70 if [[ -e /${f} ]] ; then
74 for f
in "${home[@]}" ; do
77 if [[ -e ${f} ]] ; then
82 if [[ ! -d root
/.git
]] ; then
83 f
="${HOME}/.profile.d/aliases.sh"
84 if [[ -e ${f} ]] ; then
85 cat "${f}" > root
/.bash_profile
92 Usage: ${0##*/} [options] [program to run]
94 Sets up common mount points and then chroots in and runs a program.
95 If no program is specified, then launch a login shell.
98 -u Unmount all paths in the chroot
99 -m <path> Add path to mount list
100 -d <dir> Use <dir> as chroot (defaults to ${0%/*})
109 local mounts
=( proc sys tmp dev dev
/pts dev
/shm run usr
/portage usr
/portage
/distfiles usr
/local
/src
)
114 .
/*) chroot
=${PWD}/${chroot#./} ;;
118 while [[ -n $1 ]] ; do
121 -m) mounts
+=( "$2" ); shift ;;
122 -d) chroot
=$
(realpath
"$2"); shift ;;
124 -*) echo "${0##*/}: unknown option $1"; exit 1 ;;
132 umount
) exec "${0%/*}/umount-tree" -y "${chroot}" ;;
136 for m
in "${mounts[@]}" ; do
143 if type -P setarch
&>/dev
/null
; then
144 local bin_dst
=$
(get_type bin
/bash
)
145 if [[ -n ${bin_dst} ]] ; then
146 setarch
="setarch ${bin_dst}"
150 # Doubtful these settings we want to leak into the chroot.
151 unset ROOT PORTAGE_CONFIGROOT LD_LIBRARY_PATH
152 unset LS_COLORS
# format changes over time
153 [[ $# -eq 0 ]] && set -- env HOME
=/root
/bin
/bash
-l