1 | #!/usr/bin/env bash
|
2 | #
|
3 | # Make an Alpine Linux chroot and run Oil within it.
|
4 | #
|
5 | # Usage:
|
6 | # test/alpine.sh <function name>
|
7 | #
|
8 | # Use Cases:
|
9 | # - _chroot/alpine-oil-tar
|
10 | # Test if the oil tarball can be configured/compiled/installed inside a
|
11 | # minimal Linux distro. This is tested with EACH RELEASE.
|
12 | # - _chroot/alpine-oil-spec
|
13 | # Test how the spec tests run (gawk and zip deps)
|
14 | # - _chroot/alpine-distro-build
|
15 | # Test if Oil can run Alpine's own package manager and scripts (not done yet)
|
16 | #
|
17 | # Examples:
|
18 | #
|
19 | # 1. To make oil-tar env:
|
20 | #
|
21 | # $0 download
|
22 | # $0 extract-oil-tar
|
23 | # $0 setup-dns _chroot/alpine-oil-tar
|
24 | # $0 add-oil-tar-deps
|
25 | # $0 copy-tar
|
26 | # $0 test-tar
|
27 | #
|
28 | # 1. To make a spec test env:
|
29 | #
|
30 | # $0 download
|
31 | # $0 extract-oil-spec
|
32 | # $0 setup-dns _chroot/alpine-oil-spec
|
33 | # $0 add-oil-spec-deps
|
34 | #
|
35 | # $0 copy-tar _chroot/alpine-oil-spec # TODO: copy arbitrary tarball
|
36 | # TODO: set up non-root user
|
37 | #
|
38 | # $0 make-oil-spec
|
39 | # $0 copy-oil-spec
|
40 | #
|
41 | # Now enter the chroot:
|
42 | #
|
43 | # test/alpine.sh interactive _chroot/alpine-oil-spec
|
44 | # bash # if you prefer, use bash inside
|
45 | #
|
46 | # cd src/
|
47 | # tar -x -z < oil-$VERSION.tar.gz
|
48 | # cd oil-$VERSION/
|
49 | # ./configure && make && sudo ./install
|
50 | #
|
51 | # cd ~/src/oil-spec
|
52 | # tar -x < oil-spec.tar
|
53 | #
|
54 | # test/spec-alpine.sh all
|
55 | # test/spec-alpine.sh archive-results
|
56 | #
|
57 | # TODO: Automate this more with an arbitrary tarball.
|
58 | #
|
59 | # Now again OUTSIDE:
|
60 | #
|
61 | # test/alpine.sh copy-wwz
|
62 | # test/alpine.sh publish
|
63 |
|
64 | set -o nounset
|
65 | set -o pipefail
|
66 | set -o errexit
|
67 |
|
68 | readonly ROOTFS_URL='http://dl-cdn.alpinelinux.org/alpine/v3.11/releases/x86_64/alpine-minirootfs-3.11.3-x86_64.tar.gz'
|
69 |
|
70 | readonly CHROOT_OIL_TAR=_chroot/alpine-oil-tar
|
71 | readonly CHROOT_OIL_SPEC=_chroot/alpine-oil-spec
|
72 | readonly CHROOT_DISTRO_BUILD=_chroot/alpine-distro-build
|
73 |
|
74 | download() {
|
75 | wget --no-clobber --directory _tmp $ROOTFS_URL
|
76 | }
|
77 |
|
78 | _extract() {
|
79 | local dest=$1
|
80 |
|
81 | local tarball=_tmp/$(basename $ROOTFS_URL)
|
82 |
|
83 | mkdir -p $dest
|
84 | # Must be run as root
|
85 | tar --extract --gzip --verbose --directory $dest < $tarball
|
86 |
|
87 | du --si -s $dest
|
88 | }
|
89 | extract-oil-tar() { sudo $0 _extract $CHROOT_OIL_TAR; }
|
90 | extract-oil-spec() { sudo $0 _extract $CHROOT_OIL_SPEC; }
|
91 | extract-distro-build() { sudo $0 _extract $CHROOT_DISTRO_BUILD; }
|
92 |
|
93 | # Without this, you can't 'su myusername'. It won't be able to execute bash.
|
94 | chmod-chroot() {
|
95 | local dest=${1:-$CHROOT_OIL_TAR}
|
96 | sudo chmod 755 $dest
|
97 | }
|
98 |
|
99 | # add DNS -- for package manager
|
100 |
|
101 | _setup-dns() {
|
102 | local chroot_dir=$1
|
103 | cat >$chroot_dir/etc/resolv.conf <<EOF
|
104 | nameserver 8.8.8.8
|
105 | nameserver 8.8.4.4
|
106 | EOF
|
107 | }
|
108 | setup-dns() { sudo $0 _setup-dns "$@"; }
|
109 |
|
110 | #
|
111 | # Deps for different chroots
|
112 | #
|
113 |
|
114 | # 106 MiB as of 7/7/2017.
|
115 | add-oil-tar-deps() {
|
116 | local chroot_dir=${1:-$CHROOT_OIL_TAR}
|
117 | sudo chroot $chroot_dir /bin/sh <<EOF
|
118 | apk update
|
119 | apk add bash make gcc g++ musl-dev
|
120 | EOF
|
121 | }
|
122 |
|
123 | # Additions:
|
124 | # python2, gawk: to run spec tests
|
125 | # zip: for publishing it
|
126 |
|
127 | # 3/6/2020: 154 MiB
|
128 | add-oil-spec-deps() {
|
129 | local chroot_dir=${1:-$CHROOT_OIL_SPEC}
|
130 | sudo chroot $chroot_dir /bin/sh <<EOF
|
131 | apk update
|
132 | apk add bash make gcc musl-dev python2 gawk zip
|
133 | EOF
|
134 | }
|
135 |
|
136 | # alpine-sdk scripts are /bin/sh busybox scripts!
|
137 | # Executing busybox-1.26.2-r5.trigger
|
138 | # Executing ca-certificates-20161130-r2.trigger
|
139 | # OK: 195 MiB in 72 packages
|
140 | #
|
141 | # Hm they still have triggers...
|
142 | # 72 packages. bash/readline are installed!
|
143 |
|
144 | add-alpine-sdk() {
|
145 | local chroot_dir=${1:-$CHROOT_DISTRO_BUILD}
|
146 | sudo chroot $chroot_dir /bin/sh <<EOF
|
147 | apk update
|
148 | apk add bash alpine-sdk
|
149 | EOF
|
150 | }
|
151 |
|
152 | #
|
153 | # Admin
|
154 | #
|
155 |
|
156 | list-packages() {
|
157 | local chroot_dir=${1:-$CHROOT_DISTRO_BUILD}
|
158 | sudo chroot $chroot_dir apk info
|
159 | }
|
160 |
|
161 | destroy-chroot() {
|
162 | local chroot_dir=${1:-$CHROOT_OIL_TAR}
|
163 | sudo rm -r -rf $chroot_dir
|
164 | }
|
165 |
|
166 | # Interactive /bin/sh.
|
167 | enter-chroot() {
|
168 | local chroot_dir=${1:-$CHROOT_OIL_TAR}
|
169 | shift
|
170 | sudo chroot $chroot_dir "$@"
|
171 | }
|
172 |
|
173 | interactive() {
|
174 | local chroot_dir=${1:-$CHROOT_OIL_TAR}
|
175 | enter-chroot $chroot_dir /bin/sh
|
176 | }
|
177 |
|
178 | #
|
179 | # oil-tar functions
|
180 | #
|
181 |
|
182 | readonly OIL_VERSION=$(head -n 1 oil-version.txt)
|
183 |
|
184 | _copy-tar() {
|
185 | local chroot_dir=${1:-$CHROOT_OIL_TAR}
|
186 | local name=${2:-oil}
|
187 | local version=${3:-$OIL_VERSION}
|
188 |
|
189 | local dest=$chroot_dir/src
|
190 | rm -r -f $dest # make sure it's empty
|
191 | mkdir -p $dest
|
192 | cp -v _release/$name-$version.tar.gz $dest
|
193 | }
|
194 |
|
195 | copy-tar() {
|
196 | sudo $0 _copy-tar "$@"
|
197 | }
|
198 |
|
199 | _test-tar() {
|
200 | local chroot_dir=${1:-$CHROOT_OIL_TAR}
|
201 | local name=${2:-oil}
|
202 | local version=${3:-$OIL_VERSION}
|
203 |
|
204 | local target=_bin/${name}.ovm
|
205 |
|
206 | #local target=_bin/${name}.ovm-dbg
|
207 |
|
208 | enter-chroot "$chroot_dir" /bin/sh <<EOF
|
209 | set -e
|
210 | cd src
|
211 | tar --extract -z < $name-$version.tar.gz
|
212 | cd $name-$version
|
213 | ./configure
|
214 |
|
215 | if test $name = oil; then
|
216 | time make $target
|
217 | else
|
218 | time _build/oils.sh
|
219 | fi
|
220 |
|
221 | echo
|
222 | echo "*** Running $target"
|
223 |
|
224 | if test $name = oil; then
|
225 | $target --version
|
226 | else
|
227 | _bin/cxx-opt-sh/osh --version
|
228 | fi
|
229 |
|
230 | ./install
|
231 | echo
|
232 | echo "*** Running osh"
|
233 | osh --version
|
234 | echo status=$?
|
235 | echo DONE
|
236 | EOF
|
237 | }
|
238 |
|
239 | test-tar() {
|
240 | sudo $0 _test-tar "$@"
|
241 | }
|
242 |
|
243 | #
|
244 | # cpp tarball
|
245 | #
|
246 |
|
247 | copy-cpp-tar() {
|
248 | copy-tar '' oils-for-unix
|
249 | }
|
250 |
|
251 | test-cpp-tar() {
|
252 | test-tar '' oils-for-unix
|
253 | }
|
254 |
|
255 | #
|
256 | # oil-spec functions
|
257 | #
|
258 |
|
259 | # Spec tests
|
260 | make-oil-spec() {
|
261 | # TODO: maybe get rid of doctools
|
262 | # test/spec.sh is just for reference
|
263 | # web/*.css dir because we want the end user to be able to see it
|
264 | find \
|
265 | benchmarks/time_.py \
|
266 | test/sh_spec.py doctools/{html_head,doc_html,__init__}.py \
|
267 | test/{common,spec-common,spec,spec-alpine,spec-runner}.sh \
|
268 | spec/ \
|
269 | web/*.css \
|
270 | -type f \
|
271 | | xargs tar --create > _tmp/oil-spec.tar
|
272 | }
|
273 |
|
274 | _copy-oil-spec() {
|
275 | local dest=$CHROOT_OIL_SPEC/src/oil-spec
|
276 | mkdir -p $dest
|
277 | cp -v _tmp/oil-spec.tar $dest
|
278 | }
|
279 | copy-oil-spec() { sudo $0 _copy-oil-spec "$@"; }
|
280 |
|
281 |
|
282 | copy-wwz() {
|
283 | ### Take results out of chroot
|
284 |
|
285 | local out=_tmp/spec-results
|
286 | mkdir -p $out
|
287 | cp -v _chroot/alpine-oil-spec/src/oil-spec/*.wwz $out
|
288 | ls -l $out
|
289 | }
|
290 |
|
291 | publish() {
|
292 | ### Publish results to oilshell.org/spec-results
|
293 | # similar to web/publish.sh
|
294 |
|
295 | local user=$1
|
296 | local host=$user.org
|
297 |
|
298 | local path=$2
|
299 |
|
300 | local dest='oilshell.org/spec-results'
|
301 | ssh $user@$host mkdir --verbose -p $dest
|
302 | scp $path $user@$host:$dest
|
303 |
|
304 | echo "Visit http://$dest/$(basename $path)/"
|
305 | }
|
306 |
|
307 | "$@"
|