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

112 lines, 45 significant
1#!/usr/bin/env bash
2#
3# Misc tests
4#
5# Usage:
6# regtest/aports-test.sh <function name>
7
8: ${LIB_OSH=stdlib/osh}
9source $LIB_OSH/bash-strict.sh
10source $LIB_OSH/task-five.sh
11
12source regtest/aports-common.sh
13
14test-unshare() {
15 # These work (at least on Debian, but it may not work on Red Hat)
16 unshare --map-root-user whoami
17 unshare --map-root-user /usr/sbin/chroot $CHROOT_DIR ls
18
19 # Hm multiple problems with enter-chroot
20
21 # su: can't set groups: Operation not permitted
22 # mv: cannot move '/tmp/tmp.6FHJHwbdMd' to 'env.sh': Permission denied
23
24 unshare --map-root-user \
25 sh -x enter-rootfs sh -c 'echo hi; whoami'
26
27 unshare --map-root-user \
28 enter-rootfs -u udu sh -c 'echo hi; whoami'
29}
30
31test-timeout() {
32 ### syntax of timeout command
33
34
35 # doesn't accept --
36 # lame!
37
38 # give 10 second grace period
39
40 # TODO: osh doesn't properly fix this
41
42 local -a cmd=( sh -c 'trap "echo TERM" TERM; sleep 5' )
43
44 # Give it 1 second to respond to SIGTERM, then SIGKILL
45 local -a timeout_cmd=( timeout -k 1 0.5 "${cmd[@]}" )
46
47 set +o errexit
48
49 "${timeout_cmd[@]}"
50
51 #return
52
53 # Hm this one doesn't return for 5 seconds? With either busybox or OSH. Is
54 # that a busybox issue?
55 # It falls back on KILL?
56 # Could be something in enter-chroot
57 # - chroot
58 # - env
59 # - su
60 # - sh -c
61
62 echo
63 echo 'CHROOT'
64
65 # alpine uses busybox
66 # my version doesn't have -k, but the one in the chroot should
67 enter-rootfs-user "${timeout_cmd[@]}"
68}
69
70# Note:
71# - /var/cache is 5.8 GB after fetching all sources for Alpine main
72# - All APKG packages are 6.9 GB, according to APKINDEX
73
74download-apk-index() {
75 wget --no-clobber --directory-prefix _tmp \
76 http://dl-cdn.alpinelinux.org/alpine/v3.22/main/x86_64/APKINDEX.tar.gz
77}
78
79apk-stats() {
80 #tar --list -z < _tmp/APKINDEX.tar.gz
81
82 # 5650 packages
83 grep 'S:' _tmp/APKINDEX | wc -l
84
85 gawk -f regtest/aports/stats.awk < _tmp/APKINDEX
86}
87
88count-lines() {
89 for f in regtest/aports-* regtest/aports/*; do
90 echo $f
91 done | egrep -v 'old|notes' | xargs wc -l | sort -n
92}
93
94test-bind-mount() {
95 local host_dir=_tmp/bind-test
96 mkdir -p $host_dir
97 touch $host_dir/foo.txt
98
99 local chroot_dir=$PWD/$CHROOT_DIR
100 local guest_dir=$chroot_dir/home/oils/bind-test
101
102 # OK this works; it's a bit awkward
103
104 sudo mkdir -p $guest_dir
105 sudo mount --bind $PWD/$host_dir $guest_dir
106 sudo chroot $chroot_dir sh -c 'ls /home/oils/bind-test'
107 sudo umount $guest_dir
108
109 #mount
110}
111
112task-five "$@"