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" "$@"
24 local src
=/$1 dst
=${chroot}/${2:-$1}
25 [[ -d ${src} ]] ||
return 0
26 if ! mkdir
-p "${dst}" ; then
27 [[ -w ${chroot} ]] && exit 1 ||
return 0
29 grep -sq "${dst}" /proc/mounts || mount ${mount_args} --bind "${src}" "${dst}"
34 *x86-64
*) echo x86_64
;;
35 *"Intel 80386"*) echo i386
;;
36 *32-bit*PowerPC
*) echo ppc
;;
37 *64-bit*PowerPC
*) echo ppc64
;;
38 *32-bit*S
/390*) echo s390
;;
39 *64-bit*S
/390*) echo s390x
;;
40 *64-bit*MIPS
*) echo mips64
;;
41 *32-bit*MIPS
*N32
*)echo mips64
;;
42 *32-bit*MIPS
*) echo mips
;;
43 *32-bit*PA-RISC
*) echo parisc
;;
44 *64-bit*PA-RISC
*) echo parisc64
;;
45 *32-bit*SPARC
*) echo sparc
;;
46 *64-bit*SPARC
*) echo sparc64
;;
51 [[ -w .
]] ||
return 0
53 if [[ ! -L etc
/mtab
]] ; then
54 ln -sfT /proc
/mounts etc
/mtab
70 $
(printf 'etc/%s ' "${etc[@]}") \
72 if [[ -e /${f} ]] ; then
76 for f
in "${home[@]}" ; do
79 if [[ -e ${f} ]] ; then
84 if [[ ! -d root
/.git
]] ; then
85 f
="${HOME}/.profile.d/aliases.sh"
86 if [[ -e ${f} ]] ; then
87 cat "${f}" > root
/.bash_profile
94 Usage: ${0##*/} [options] [program to run]
96 Sets up common mount points and then chroots in and runs a program.
97 If no program is specified, then launch a login shell.
100 -u Unmount all paths in the chroot
101 -m <path> Add path to mount list
102 -d <dir> Use <dir> as chroot (defaults to ${0%/*})
111 local mounts
=( proc sys tmp dev dev
/pts dev
/shm run usr
/portage usr
/portage
/distfiles usr
/local
/src
)
116 .
/*) chroot
=${PWD}/${chroot#./} ;;
120 while [[ -n $1 ]] ; do
123 -m) mounts
+=( "$2" ); shift ;;
124 -d) chroot
=$
(realpath
"$2"); shift ;;
126 -*) echo "${0##*/}: unknown option $1"; exit 1 ;;
134 umount
) exec "${0%/*}/umount-tree" -y "${chroot}" ;;
138 for m
in "${mounts[@]}" ; do
145 if type -P setarch
&>/dev
/null
; then
146 local bin_dst
=$
(get_type bin
/bash
)
147 if [[ -n ${bin_dst} ]] ; then
148 setarch
="setarch ${bin_dst}"
152 # Doubtful these settings we want to leak into the chroot.
153 unset ROOT PORTAGE_CONFIGROOT LD_LIBRARY_PATH
154 unset LS_COLORS
# format changes over time
155 [[ $# -eq 0 ]] && set -- env HOME
=/root
/bin
/bash
-l