OILS / regtest / aports-common.sh View on Github | oils.pub

109 lines, 62 significant
1# Shared between regtest/aports-*.sh
2
3readonly CHROOT_DIR=_chroot/aports-build
4readonly CHROOT_HOME_DIR=$CHROOT_DIR/home/udu
5
6# For he.oils.pub
7readonly BASE_DIR=_tmp/aports-build
8
9# For localhost
10readonly REPORT_DIR=_tmp/aports-report
11
12readonly INTERACTIVE="${INTERACTIVE:-}"
13
14concat-task-tsv() {
15 local config=${1:-baseline}
16 python3 devtools/tsv_concat.py \
17 $CHROOT_HOME_DIR/oils/_tmp/aports-guest/$config/*.task.tsv
18}
19
20enter-rootfs() {
21 $CHROOT_DIR/enter-chroot "$@"
22}
23
24enter-rootfs-user() {
25 enter-rootfs -u udu "$@"
26}
27
28enter-overlayfs-user() {
29 local name=$1
30 shift
31
32 # output ends up in the upperdir
33 #local upper="$OVERLAY_BASE_DIR/$name"
34 local upper=_chroot/overlay/upper/$name
35
36 # workdir is scratch space
37 local work=_chroot/overlay/work
38 # "$OVERLAY_BASE_DIR/${name}_work"
39
40 # the unified view we chroot into
41 #local merged="$OVERLAY_BASE_DIR/${name}_merged"
42 local merged=_chroot/overlay/merged
43
44 mkdir -p $upper $work $merged
45
46 # myoverlay is the 'source'
47 sudo mount \
48 -t overlay \
49 myoverlay \
50 -o "lowerdir=$CHROOT_DIR,upperdir=$upper,workdir=$work" \
51 "$merged"
52
53 sudo mount \
54 -t proc \
55 "my_chroot_proc" $merged/proc
56
57 sudo mount \
58 -t sysfs \
59 "my_chroot_sysfs" $merged/sys
60
61 sudo mount \
62 -t devtmpfs \
63 "my_chroot_devtmpfs" $merged/dev
64
65 $merged/enter-chroot -u udu "$@"
66
67 unmount-loop $merged/proc
68 unmount-loop $merged/sys
69 unmount-loop $merged/dev
70 unmount-loop $merged
71}
72
73unmount-loop() {
74 local merged=$1
75
76 # unmount it in a loop, to ensure that we can re-mount it later
77 while true; do
78 # Lazy umount seems necessary? Otherwise we get 'target is busy'
79 # I suppose processes started inside the chroot may still be running
80 sudo umount -l "$merged"
81 if ! mountpoint --quiet "$merged"; then
82 break
83 fi
84 echo "Waiting to unmount: $merged"
85 sleep 0.1
86 done
87}
88
89# Note: these functions aren't used. bwrap is problematic when the container
90# has multiple UIDs.
91#
92# We wanted to replace chroot with bwrap, because 'abuild rootbld' uses bwrap,
93# and bwrap can't be run inside a chroot.
94#
95# But bwrap uses mount(), which requires a new user namespace, which creates a
96# host/guest UID mapping problem.
97#
98# See Zulip for details
99
100if false; then
101 enter-rootfs() {
102 $CHROOT_DIR/enter-bwrap.sh '' root '' "$@"
103 }
104
105 enter-rootfs-user() {
106 enter-rootfs -u udu "$@"
107 $CHROOT_DIR/enter-bwrap.sh '' udu '' "$@"
108 }
109fi