]>
git.wh0rd.org - home.git/blob - .bin/custom-chroot
4 [[ -w / ]] ||
exec sudo env
-uUNSHARE HOME
="$HOME" "$0" "$@"
6 if [[ -z ${UNSHARE} ]] ; then
8 if type -P unshare
>&/dev
/null
; then
9 UNSHARE
=true
exec unshare
-m -- "$0" "$@"
18 local src
=/$1 dst
=${chroot}/${2:-$1}
19 [[ -d ${src} ]] ||
return 0
20 if ! mkdir
-p "${dst}" ; then
21 [[ -w ${chroot} ]] && exit 1 ||
return 0
23 grep -sq "${dst}" /proc/mounts || mount ${mount_args} --bind "${src}" "${dst}"
28 *x86-64
*) echo x86_64
;;
29 *"Intel 80386"*) echo i386
;;
30 *32-bit*PowerPC
*) echo ppc
;;
31 *64-bit*PowerPC
*) echo ppc64
;;
32 *32-bit*S
/390*) echo s390
;;
33 *64-bit*S
/390*) echo s390x
;;
38 [[ -w .
]] ||
return 0
40 if [[ ! -L etc
/mtab
]] ; then
42 ln -sf /proc
/mounts etc
/mtab
58 $
(printf 'etc/%s ' "${etc[@]}") \
60 if [ -e "/${f}" ] ; then
64 for f
in "${home[@]}" ; do
65 cp "${HOME}/${f}" "root/${f}"
71 Usage: ${0##*/} [options] [program to run]
73 Sets up common mount points and then chroots in and runs a program.
74 If no program is specified, then launch a login shell.
77 -u Unmount all paths in the chroot
78 -m <path> Add path to mount list
79 -d <dir> Use <dir> as chroot (defaults to ${0%/*})
88 local mounts
=( proc sys tmp dev dev
/pts usr
/portage usr
/portage
/distfiles usr
/local
/src
)
93 .
/*) chroot
=${PWD}/${chroot#./} ;;
97 while [[ -n $1 ]] ; do
100 -m) mounts
+=( "$2" ); shift ;;
101 -d) chroot
=$
(realpath
"$2"); shift ;;
103 -*) echo "${0##*/}: unknown option $1"; exit 1 ;;
111 umount
) exec "${0%/*}/umount-tree" -y "${chroot}" ;;
115 for m
in "${mounts[@]}" ; do
122 if type -P setarch
&>/dev
/null
; then
123 local bin_dst
=$
(get_type bin
/bash
)
124 if [[ -n ${bin_dst} ]] ; then
125 setarch
="setarch ${bin_dst}"
129 unset LS_COLORS
# format changes over time
130 [[ $# -eq 0 ]] && set -- env HOME
=/root
/bin
/bash
-l