X-Git-Url: https://git.wh0rd.org/?a=blobdiff_plain;f=.bin%2Fcustom-chroot;h=08d76ada03bfa4aedf7429ab16893cb924858bdd;hb=HEAD;hp=8a3fc619c763c8d0eaad824284082d63db06d6e1;hpb=8b6a28cd3292932beaafc6fd8bc1382f34a4d191;p=home.git diff --git a/.bin/custom-chroot b/.bin/custom-chroot index 8a3fc61..08d76ad 100755 --- a/.bin/custom-chroot +++ b/.bin/custom-chroot @@ -6,9 +6,12 @@ bootstrap() { if [[ -z ${UNSHARE} ]] ; then mount_args= if type -P unshare >&/dev/null ; then + test_arg() { unshare "$@" -- true >&/dev/null && uargs+=( "$@" ) || :; } uargs=( -m ) - unshare -u -- true >&/dev/null && uargs+=( -u ) - unshare -p -- true >&/dev/null && uargs+=( -p -f --mount-proc ) + test_arg -u + test_arg -i + test_arg -p -f --mount-proc + test_arg --propagation=private UNSHARE=true exec unshare "${uargs[@]}" -- "$0" "$@" fi else @@ -17,23 +20,37 @@ bootstrap() { unset UNSHARE } +is_mounted() { + local dst=$1 + grep -sq "${dst}" /proc/mounts +} + maybe_mount() { local src=/$1 dst=${chroot}/${2:-$1} [[ -d ${src} ]] || return 0 if ! mkdir -p "${dst}" ; then [[ -w ${chroot} ]] && exit 1 || return 0 fi - grep -sq "${dst}" /proc/mounts || mount ${mount_args} --bind "${src}" "${dst}" + is_mounted "${dst}" || mount ${mount_args} --bind "${src}" "${dst}" } get_type() { case $(file "$1") in - *x86-64*) echo x86_64;; - *"Intel 80386"*) echo i386;; - *32-bit*PowerPC*) echo ppc;; - *64-bit*PowerPC*) echo ppc64;; - *32-bit*S/390*) echo s390;; - *64-bit*S/390*) echo s390x;; + *x86-64*) echo x86_64;; + *"Intel 80386"*) echo i386;; + *32-bit*PowerPC*MSB*) echo ppc;; + *64-bit*PowerPC*MSB*) echo ppc64;; + *32-bit*PowerPC*LSB*) echo ppcle;; + *64-bit*PowerPC*LSB*) echo ppc64le;; + *32-bit*S/390*) echo s390;; + *64-bit*S/390*) echo s390x;; + *64-bit*MIPS*) echo mips64;; + *32-bit*MIPS*N32*) echo mips64;; + *32-bit*MIPS*) echo mips;; + *32-bit*PA-RISC*) echo parisc;; + *64-bit*PA-RISC*) echo parisc64;; + *32-bit*SPARC*) echo sparc;; + *64-bit*SPARC*) echo sparc64;; esac } @@ -71,9 +88,11 @@ init_chroot() { fi done - f="${HOME}/.profile.d/aliases.sh" - if [[ -e ${f} ]] ; then - cat "${f}" > root/.bash_profile + if [[ ! -d root/.git ]] ; then + f="${HOME}/.profile.d/aliases.sh" + if [[ -e ${f} ]] ; then + cat "${f}" > root/.bash_profile + fi fi } @@ -96,7 +115,12 @@ usage() { main() { bootstrap "$@" - local mounts=( proc sys tmp dev dev/pts dev/shm usr/portage usr/portage/distfiles usr/local/src ) + local mounts=( + proc sys tmp dev dev/shm run + usr/portage usr/portage/distfiles + var/db/repos/gentoo var/cache/distfiles + usr/local/src + ) local chroot=${0%/*} case ${chroot} in @@ -124,8 +148,15 @@ main() { local m for m in "${mounts[@]}" ; do - maybe_mount ${m} + maybe_mount "${m}" done + # Handle special mounts that we don't want to just bind mount. + if ! is_mounted "${chroot}/dev/pts" ; then + # Option order matters: on older kernels that don't recognize newinstance, + # parsing stops as soon as it hits that. + mount -t devpts devpts "${chroot}/dev/pts" \ + -o nosuid,noexec,mode=0620,gid=5,ptmxmode=0666,newinstance + fi init_chroot