Blob


1 # ISC License
2 #
3 # Copyright 2025 xs <xs@inda.re>
4 #
5 # Permission to use, copy, modify, and/or distribute this software for any
6 # purpose with or without fee is hereby granted, provided that the above
7 # copyright notice and this permission notice appear in all copies.
8 #
9 # THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
10 # REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
11 # FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
12 # INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
13 # LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
14 # OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
15 # PERFORMANCE OF THIS SOFTWARE.
16 .POSIX:
17 PREFIX:=/usr/local
18 SHELLS=ksh93 ksh yash sh
19 UTILITY_VERSION=0.2.0
20 UTILITY=$(PWD)/r7
21 # To use the test suite, please edit or use environment for SSH parameters
22 # SSH_ID=/path/to/.ssh/id_ed25519
23 # SSH_TEST_NODES=nodeA nodeB
24 .DEFAULT: all all: tests
26 release: r7.1
27 make tests
28 whoami
29 rm -fr _release/r7-$(UTILITY_VERSION)
30 mkdir -p _release/r7-$(UTILITY_VERSION)
31 cp LICENSE r7 r7.1 Makefile README.md _release/r7-$(UTILITY_VERSION)
32 cp -r groups/ _release/r7-$(UTILITY_VERSION)
33 cd _release && tar cfv r7-$(UTILITY_VERSION).tar r7-$(UTILITY_VERSION)
34 gzip -9 _release/r7-$(UTILITY_VERSION).tar
35 cp _release/r7-$(UTILITY_VERSION).tar.gz _release/r7-latest.tar.gz
37 html: index.md documentation.html
38 pandoc --template=./r7doc.html \
39 -s --toc=false \
40 --metadata title='R7' \
41 --from markdown+smart \
42 -t html -o index.html index.md
44 documentation.html: README.md ./r7
45 pandoc --template=./r7doc.html \
46 -s --toc=true \
47 --metadata title='R7 Documentation' \
48 --metadata date="Tue Jun 3 2025" \
49 --from markdown+smart \
50 -t html -o documentation.html README.md
52 r7.1: README.md r7 Makefile
53 pandoc --from markdown+smart \
54 --metadata section=1 \
55 --metadata title="R7" \
56 --metadata header="User Manual" \
57 --metadata date="Tue Jun 3 2025" \
58 --metadata footer="v$(UTILITY_VERSION)" \
59 -s -t man -o r7.1 README.md
61 r7.1.pdf: README.md
62 pandoc --from markdown+smart \
63 -s -t pdf -o r7.1.pdf README.md
65 install:
66 cp ./r7 $(PREFIX)/bin/
67 chmod 755 $(PREFIX)/bin/r7
68 cp ./r7.1 $(PREFIX)/man/man1/
69 chmod 644 $(PREFIX)/man/man1/r7.1
71 # Test suite for r7
72 R=${SHELL} ${UTILITY}
73 test_arguments: usage version debug
74 test_workdirs: workdir3-init \
75 workdir0-arguments \
76 workdir0-digraph \
77 workdir1-init \
78 workdir1-populate \
79 workdir2-init \
80 workdir2-ssh \
81 workdir2-grouplib \
82 workdir2-goodby \
83 workdir2-r7doc \
84 workdir2-source \
85 workdir2-importer
87 tests:
88 @echo
89 make test_arguments
90 make test_workdirs
91 @echo == ALL TESTS PASSED
93 poly:
94 @for shell in ${SHELLS}; do \
95 ashell=$$(command -v $$shell || true); \
96 if test -x "$$ashell"; then \
97 if time make tests SHELL=$$ashell SH=$$ashell; then \
98 : \
99 else \
100 failed="$$(basename "$$ashell") $$failed"; \
101 fi; \
102 else \
103 notfound="$$shell $$notfound"; \
104 fi; \
105 done; \
106 echo; \
107 echo "== POLY TESTS RESULTS"; \
108 echo " spec: $(SHELLS)"; \
109 echo "not-found: $$notfound"; \
110 echo " failed: $$failed"; \
111 test -z "$$failed" -a -z "$$notfound" || (echo; false;)
113 usage:
114 @echo _________________________________________________________
115 @echo USAGE
116 @echo _________________________________________________________
117 $R -h
118 $R -h 2>&1 | grep -q -e usage: -e '\['
119 @echo _________________________________________________________
121 version:
122 @echo _________________________________________________________
123 @echo VERSION
124 @echo _________________________________________________________
125 $R -h 2>&1 | grep -q -e "$(UTILITY_VERSION)"
126 @echo _________________________________________________________
128 debug:
129 @echo _________________________________________________________
130 @echo DEBUG
131 @echo _________________________________________________________
132 $R -dn 2>&1 run-config | grep -q "R7 DEBUG $(UTILITY_VERSION)"
133 @echo _________________________________________________________
135 workdir0-arguments:
136 @echo _________________________________________________________
137 rm -fr testdir/workdir0/_run
138 $R -w testdir/workdir0 -dn run-config 2>&1 | tee testdir/wd01.produced
139 grep -q -e '^LOADING $(PWD)/testdir/workdir0/site-config' testdir/wd01.produced
140 grep -q -e '^PROCESSING GROUP common' testdir/wd01.produced
141 grep -q -e '^PROCESSING GROUP test0' testdir/wd01.produced
142 @echo _________________________________________________________
144 workdir0-digraph:
145 @echo _________________________________________________________
146 $R -w testdir/workdir0 -dn digraph-host 2>/dev/null | \
147 tee testdir/wd01.dot.produced
148 cmp testdir/wd01.dot testdir/wd01.dot.produced
149 @echo _________________________________________________________
151 workdir1-init:
152 @echo _________________________________________________________
153 rm -fr testdir/workdir1
154 $R -dw testdir/workdir1 init
155 test -d testdir/workdir1
156 find testdir/workdir1 | tee testdir/wd1-init-find.produced
157 cmp testdir/wd1-init-find testdir/wd1-init-find.produced
158 @echo _________________________________________________________
160 workdir1-populate: workdir1-init
161 @echo _________________________________________________________
162 { cd testdir/workdir1 && \
163 $R && \
164 $R run-config && \
165 $R output-dump && \
166 $R output && \
167 $R group && \
168 $R -s group ;} | wc -c | grep -q 0
169 @echo _________________________________________________________
171 workdir2-init:
172 @echo _________________________________________________________
173 rm -fr testdir/workdir2
174 $R -dw testdir/workdir2 init
175 test -d testdir/workdir2
176 cd testdir/workdir2 && $R | wc -c | grep -q 0
177 cd testdir/workdir2 && \
178 cp "$(SSH_ID)" .ssh/id_ed25519_r7 && \
179 cp "$(SSH_ID).pub" .ssh/id_ed25519_r7.pub && \
180 . $(UTILITY) && for node in $(SSH_TEST_NODES); do \
181 mkdir "nodes/$$node" && \
182 ssh_accept_new "$$node"; \
183 done;
184 @echo _________________________________________________________
186 workdir2-ssh: workdir2-init
187 @echo _________________________________________________________
188 cd testdir/workdir2 && . $(UTILITY) && \
189 cat site-config && \
190 echo 'state_hello() { echo Hi! ; }' > groups/common && \
191 echo 'state_hello() { echo Hey! ; }' > groups/heyo && \
192 echo 'dummy_hello() { echo Heyo! ; }' >> groups/heyo && \
193 echo 'group heyo $(SSH_TEST_NODES)' >> site-config && export R7_DEBUG=yes && \
194 . $(UTILITY) && \
195 prefix install state doc dummy && \
196 digraph_host && \
197 run_config && \
198 output_dump && \
199 output | grep Hey! && \
200 output && \
201 info && \
202 digraph_ssh_id_hosts && \
203 ssh_known_hosts && \
204 nodes && \
205 prefix dummy && group heyo '.*' && output_dump && \
206 output | grep Heyo! && \
207 group_functions_all && \
208 trace_id_last && \
209 output_duration | grep 0 && \
210 output_status && \
211 summary && \
212 output_errors && \
213 output_permissions && \
214 output_diffs
215 @echo _________________________________________________________
217 workdir2-grouplib: workdir2-init
218 @echo _________________________________________________________
219 cp testdir/grouplib testdir/workdir2/groups/
220 mkdir -p testdir/workdir2/groups/grouplib.dir/subdir
221 touch testdir/workdir2/groups/grouplib.dir/item
222 echo 'aaa' > testdir/workdir2/groups/grouplib.dir/subdir/subitem
223 echo 'bbb' > testdir/workdir2/groups/grouplib.dir/subdir/subitem2
224 cp testdir/testfile2 testdir/workdir2/groups/grouplib.dir/
225 cd testdir/workdir2 && set -e && . $(UTILITY) && \
226 echo 'prefix grouplib' > site-config && \
227 echo "group grouplib '.*'" >> site-config && \
228 $R run-config && $R output-dump && $R info && \
229 for node in $(SSH_TEST_NODES); do \
230 ssh "$$node" ls -la /tmp/item\* | grep item; \
231 ssh "$$node" ls -la /tmp/r7/my-empty-file | grep empty | grep -e '-rw-r-----' ; \
232 ssh "$$node" ls -la /tmp/newdir/newdir2/null | grep -e '-rw-r-----' ; \
233 done && $R output tools0 grouplib
234 @echo _________________________________________________________
236 workdir2-goodby: workdir2-grouplib
237 @echo _________________________________________________________
238 cd testdir/workdir2 && \
239 rm -fr _output && \
240 $R -P grouplib -se group grouplib $(SSH_TEST_NODES)
241 @echo _________________________________________________________
243 workdir2-r7doc: workdir2-init
244 @echo _________________________________________________________
245 rm -fr testdir/workdir2/_output
246 cp testdir/example1 testdir/workdir2/groups/
247 cd testdir/workdir2/ && $R -a group example1 $(SSH_TEST_NODES)
248 cd testdir/workdir2/ && $R -ea group example1 $(SSH_TEST_NODES)
249 rm -fr testdir/workdir2/_output
250 cp testdir/example2 testdir/workdir2/groups/
251 cd testdir/workdir2/ && $R -sea group example2 $(SSH_TEST_NODES)
252 @echo _________________________________________________________
254 workdir2-source: workdir2-init
255 @echo _________________________________________________________
256 rm -fr testdir/workdir2/_output
257 rm -fr testdir/workdir2/_run
258 cp testdir/source testdir/workdir2/groups/
259 mkdir testdir/workdir2/groups/source.dir
260 for node in $(SSH_TEST_NODES); do \
261 echo myvar=3333 > "testdir/workdir2/nodes/$$node/my-source" ; \
262 done
263 cd testdir/workdir2/ && $R -sea group source $(SSH_TEST_NODES)
264 sleep 1
265 cd testdir/workdir2/ && $R -sda group source $(SSH_TEST_NODES)
266 cd testdir/workdir2/ && $R output \* source source_nodesource2 | grep 3333
267 cd testdir/workdir2/ && . $(UTILITY) && group_functions_all
268 @echo _________________________________________________________
270 workdir2-importer: workdir2-init
271 @echo _________________________________________________________
272 rm -fr testdir/workdir2/_output
273 rm -fr testdir/workdir2/_run
274 cd testdir/workdir2/ && \
275 for node in $(SSH_TEST_NODES); do \
276 . $(UTILITY) && import "$$node"; \
277 done
278 cd testdir/workdir2/ && . $(UTILITY) && import notfound || :
279 find testdir/workdir2/nodes | grep hosts
280 find testdir/workdir2/nodes
281 @echo _________________________________________________________
283 workdir3-init:
284 @echo _________________________________________________________
285 @echo WORKDIR3-INIT
286 @echo _________________________________________________________
287 rm -fr testdir/workdir3
288 $R -dw testdir/workdir3 init
289 test -d testdir/workdir3
290 cd testdir/workdir3 && $R | wc -c | grep -q 0
291 cd testdir/workdir3 && \
292 cp .ssh/config .sshtmp && \
293 echo 'Host test-haiku-b5' > .ssh/config && \
294 echo ' User user' >> .ssh/config && \
295 echo >>.ssh/.config && \
296 cat .sshtmp >>.ssh/config && \
297 sleep 1 && \
298 cp -p "$(SSH_ID)" .ssh/id_ed25519_r7 && \
299 cp -p "$(SSH_ID).pub" .ssh/id_ed25519_r7.pub && \
300 . $(UTILITY) && for node in $(SSH_TEST_NODES); do \
301 mkdir "nodes/$$node" && \
302 ssh_accept_new "$$node"; \
303 done;
304 @echo _________________________________________________________