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
;;
45 [[ -w .
]] ||
return 0
47 if [[ ! -L etc
/mtab
]] ; then
48 ln -sfT /proc
/mounts etc
/mtab
64 $
(printf 'etc/%s ' "${etc[@]}") \
66 if [[ -e /${f} ]] ; then
70 for f
in "${home[@]}" ; do
73 if [[ -e ${f} ]] ; then
78 if [[ ! -d root
/.git
]] ; then
79 f
="${HOME}/.profile.d/aliases.sh"
80 if [[ -e ${f} ]] ; then
81 cat "${f}" > root
/.bash_profile
88 Usage: ${0##*/} [options] [program to run]
90 Sets up common mount points and then chroots in and runs a program.
91 If no program is specified, then launch a login shell.
94 -u Unmount all paths in the chroot
95 -m <path> Add path to mount list
96 -d <dir> Use <dir> as chroot (defaults to ${0%/*})
105 local mounts
=( proc sys tmp dev dev
/pts dev
/shm run usr
/portage usr
/portage
/distfiles usr
/local
/src
)
110 .
/*) chroot
=${PWD}/${chroot#./} ;;
114 while [[ -n $1 ]] ; do
117 -m) mounts
+=( "$2" ); shift ;;
118 -d) chroot
=$
(realpath
"$2"); shift ;;
120 -*) echo "${0##*/}: unknown option $1"; exit 1 ;;
128 umount
) exec "${0%/*}/umount-tree" -y "${chroot}" ;;
132 for m
in "${mounts[@]}" ; do
139 if type -P setarch
&>/dev
/null
; then
140 local bin_dst
=$
(get_type bin
/bash
)
141 if [[ -n ${bin_dst} ]] ; then
142 setarch
="setarch ${bin_dst}"
146 # Doubtful these settings we want to leak into the chroot.
147 unset ROOT PORTAGE_CONFIGROOT LD_LIBRARY_PATH
148 unset LS_COLORS
# format changes over time
149 [[ $# -eq 0 ]] && set -- env HOME
=/root
/bin
/bash
-l