-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathgenenter
More file actions
executable file
·58 lines (49 loc) · 1.74 KB
/
genenter
File metadata and controls
executable file
·58 lines (49 loc) · 1.74 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
#!/bin/sh
set -eu
CWD="$(dirname "$0")"
ROOT="${ROOT:-$PWD/broot}"
REPOS="$PWD/repos.squashfs"
DISTDIR="${DISTDIR:-$PWD/distfiles}"
PKGDIR="${PKGDIR:-$PWD/packages}"
modprobe -q loop || true
mkdir -p "$REPOS.wrk"
mkdir -p "$DISTDIR" "$PKGDIR"
tmp="$(mktemp -d -t geniso.XXXXXXXXXX)"
wrk="$REPOS.wrk"
mount -o ro "$REPOS" "$tmp"
mount -o lowerdir="$tmp",upperdir="$ROOT",workdir="$wrk",xino=on -t overlay overlay "$tmp"
# xino=on required to keep python tests from failing due to inode number mismatch
mount -t tmpfs tmpfs "$tmp/mnt"
mkdir "$tmp/mnt/build" "$tmp/mnt/scripts" "$tmp/mnt/distfiles"
mount --bind "$PWD" "$tmp/mnt/build"
mount --bind -o ro "$CWD" "$tmp/mnt/scripts"
mount --bind -o ro "${BDISTDIR:-$(portageq envvar DISTDIR)}" "$tmp/mnt/distfiles"
mkdir -p "$tmp/usr/portage/distfiles"
mkdir -p "$tmp/usr/portage/packages"
mount --bind "$DISTDIR" "$tmp/usr/portage/distfiles"
mount --bind "$PKGDIR" "$tmp/usr/portage/packages"
mount -o nosuid,noexec,nodev -t sysfs sysfs "$tmp/sys"
mount -o nosuid,noexec,nodev -t proc proc "$tmp/proc"
mount -o nosuid,noexec -t devtmpfs devtmpfs "$tmp/dev"
mount -o nosuid,noexec -t devpts devpts "$tmp/dev/pts"
# Use pivot_root to avoid some problems with sandbox in chroot
# https://bugs.gentoo.org/922960
trap true INT QUIT TERM
set +e
#env -i TERM=linux HOME=/root chroot "$tmp" /bin/bash -l "$@"
env -i TERM=linux HOME=/root unshare -m /bin/sh -c '
umask 022
cd "$1"; shift
mount --bind . mnt
pivot_root mnt mnt
exec chroot . /bin/bash -l "$@"
' - "$tmp" "$@"
rc=$?
set -e
umount "$tmp/dev/pts" "$tmp/dev" "$tmp/proc" "$tmp/sys"
umount "$tmp/usr/portage/packages" "$tmp/usr/portage/distfiles"
umount "$tmp/mnt/build" "$tmp/mnt/scripts" "$tmp/mnt/distfiles" "$tmp/mnt"
umount "$tmp"
umount "$tmp"
rm -r "$tmp" "$wrk"
exit $rc