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

95 lines, 50 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 $merged/enter-chroot -u udu "$@"
54
55 unmount-loop $merged
56
57}
58
59unmount-loop() {
60 local merged=$1
61
62 # unmount it in a loop, to ensure that we can re-mount it later
63 while true; do
64 # Lazy umount seems necessary? Otherwise we get 'target is busy'
65 # I suppose processes started inside the chroot may still be running
66 sudo umount -l "$merged"
67 if ! mountpoint --quiet "$merged"; then
68 break
69 fi
70 echo "Waiting to unmount: $merged"
71 sleep 0.1
72 done
73}
74
75# Note: these functions aren't used. bwrap is problematic when the container
76# has multiple UIDs.
77#
78# We wanted to replace chroot with bwrap, because 'abuild rootbld' uses bwrap,
79# and bwrap can't be run inside a chroot.
80#
81# But bwrap uses mount(), which requires a new user namespace, which creates a
82# host/guest UID mapping problem.
83#
84# See Zulip for details
85
86if false; then
87 enter-rootfs() {
88 $CHROOT_DIR/enter-bwrap.sh '' root '' "$@"
89 }
90
91 enter-rootfs-user() {
92 enter-rootfs -u udu "$@"
93 $CHROOT_DIR/enter-bwrap.sh '' udu '' "$@"
94 }
95fi