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
;;
42 [[ -w .
]] ||
return 0
44 if [[ ! -L etc
/mtab
]] ; then
45 ln -sfT /proc
/mounts etc
/mtab
61 $
(printf 'etc/%s ' "${etc[@]}") \
63 if [[ -e /${f} ]] ; then
67 for f
in "${home[@]}" ; do
70 if [[ -e ${f} ]] ; then
75 if [[ ! -d root
/.git
]] ; then
76 f
="${HOME}/.profile.d/aliases.sh"
77 if [[ -e ${f} ]] ; then
78 cat "${f}" > root
/.bash_profile
85 Usage: ${0##*/} [options] [program to run]
87 Sets up common mount points and then chroots in and runs a program.
88 If no program is specified, then launch a login shell.
91 -u Unmount all paths in the chroot
92 -m <path> Add path to mount list
93 -d <dir> Use <dir> as chroot (defaults to ${0%/*})
102 local mounts
=( proc sys tmp dev dev
/pts dev
/shm run usr
/portage usr
/portage
/distfiles usr
/local
/src
)
107 .
/*) chroot
=${PWD}/${chroot#./} ;;
111 while [[ -n $1 ]] ; do
114 -m) mounts
+=( "$2" ); shift ;;
115 -d) chroot
=$
(realpath
"$2"); shift ;;
117 -*) echo "${0##*/}: unknown option $1"; exit 1 ;;
125 umount
) exec "${0%/*}/umount-tree" -y "${chroot}" ;;
129 for m
in "${mounts[@]}" ; do
136 if type -P setarch
&>/dev
/null
; then
137 local bin_dst
=$
(get_type bin
/bash
)
138 if [[ -n ${bin_dst} ]] ; then
139 setarch
="setarch ${bin_dst}"
143 # Doubtful these settings we want to leak into the chroot.
144 unset ROOT PORTAGE_CONFIGROOT LD_LIBRARY_PATH
145 unset LS_COLORS
# format changes over time
146 [[ $# -eq 0 ]] && set -- env HOME
=/root
/bin
/bash
-l