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.1.3
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
26 all: tests
28 release: r7.1
29 make tests
30 whoami
31 rm -fr _release/r7-$(UTILITY_VERSION)
32 mkdir -p _release/r7-$(UTILITY_VERSION)
33 cp LICENSE r7 r7.1 Makefile README.md _release/r7-$(UTILITY_VERSION)
34 cp -r groups/ _release/r7-$(UTILITY_VERSION)
35 cd _release && tar cfv r7-$(UTILITY_VERSION).tar r7-$(UTILITY_VERSION)
36 gzip -9 _release/r7-$(UTILITY_VERSION).tar
37 cp _release/r7-$(UTILITY_VERSION).tar.gz _release/r7-latest.tar.gz
39 html: index.md documentation.html
40 pandoc --template=./r7doc.html \
41 -s --toc=false \
42 --metadata title='R7' \
43 --from markdown+smart \
44 -t html -o index.html index.md
46 documentation.html: README.md ./r7
47 pandoc --template=./r7doc.html \
48 -s --toc=true \
49 --metadata title='R7 Documentation' \
50 --metadata date="Tue Jun 3 2025" \
51 --from markdown+smart \
52 -t html -o documentation.html README.md
54 r7.1: README.md r7 Makefile
55 pandoc --from markdown+smart \
56 --metadata section=1 \
57 --metadata title="R7" \
58 --metadata header="User Manual" \
59 --metadata date="Tue Jun 3 2025" \
60 --metadata footer="v$(UTILITY_VERSION)" \
61 -s -t man -o r7.1 README.md
63 r7.1.pdf: README.md
64 pandoc --from markdown+smart \
65 -s -t pdf -o r7.1.pdf README.md
67 install:
68 cp ./r7 $(PREFIX)/bin/
69 chmod 755 $(PREFIX)/bin/r7
70 cp ./r7.1 $(PREFIX)/man/man1/
71 chmod 644 $(PREFIX)/man/man1/r7.1
73 # Test suite for r7
74 R=${SHELL} ${UTILITY}
75 test_arguments: usage version debug
76 test_workdirs: \
77 workdir0-arguments \
78 workdir0-digraph \
79 workdir1-init \
80 workdir1-populate \
81 workdir2-init \
82 workdir2-ssh \
83 workdir2-grouplib \
84 workdir2-goodby \
85 workdir2-r7doc \
86 workdir2-source \
87 workdir2-importer
89 tests:
90 @echo
91 make test_arguments
92 make test_workdirs
93 @echo == ALL TESTS PASSED
95 poly:
96 @for shell in ${SHELLS}; do \
97 ashell=$$(command -v $$shell || true); \
98 if test -x "$$ashell"; then \
99 if time make tests SHELL=$$ashell SH=$$ashell; then \
100 : \
101 else \
102 failed="$$(basename "$$ashell") $$failed"; \
103 fi; \
104 else \
105 notfound="$$shell $$notfound"; \
106 fi; \
107 done; \
108 echo; \
109 echo "== POLY TESTS RESULTS"; \
110 echo " spec: $(SHELLS)"; \
111 echo "not-found: $$notfound"; \
112 echo " failed: $$failed"; \
113 test -z "$$failed" -a -z "$$notfound" || (echo; false;)
115 usage:
116 @echo _________________________________________________________
117 $R -h
118 $R -h 2>&1 | grep -q -e usage: -e '\['
119 @echo _________________________________________________________
121 version:
122 @echo _________________________________________________________
123 $R -h 2>&1 | grep -q -e "$(UTILITY_VERSION)"
124 @echo _________________________________________________________
126 debug:
127 @echo _________________________________________________________
128 $R -dn 2>&1 run-config | grep -q "R7 DEBUG $(UTILITY_VERSION)"
129 @echo _________________________________________________________
131 workdir0-arguments:
132 @echo _________________________________________________________
133 rm -fr testdir/workdir0/_run
134 $R -w testdir/workdir0 -dn run-config 2>&1 | tee testdir/wd01.produced
135 grep -q -e '^LOADING $(PWD)/testdir/workdir0/site-config' testdir/wd01.produced
136 grep -q -e '^PROCESSING GROUP common' testdir/wd01.produced
137 grep -q -e '^PROCESSING GROUP test0' testdir/wd01.produced
138 @echo _________________________________________________________
140 workdir0-digraph:
141 @echo _________________________________________________________
142 $R -w testdir/workdir0 -dn digraph-host 2>/dev/null | \
143 tee testdir/wd01.dot.produced
144 cmp testdir/wd01.dot testdir/wd01.dot.produced
145 @echo _________________________________________________________
147 workdir1-init:
148 @echo _________________________________________________________
149 rm -fr testdir/workdir1
150 $R -dw testdir/workdir1 init
151 test -d testdir/workdir1
152 find testdir/workdir1 | tee testdir/wd1-init-find.produced
153 cmp testdir/wd1-init-find testdir/wd1-init-find.produced
154 @echo _________________________________________________________
156 workdir1-populate: workdir1-init
157 @echo _________________________________________________________
158 { cd testdir/workdir1 && \
159 $R && \
160 $R run-config && \
161 $R output-dump && \
162 $R output && \
163 $R group && \
164 $R -s group ;} | wc -c | grep -q 0
165 @echo _________________________________________________________
167 workdir2-init:
168 @echo _________________________________________________________
169 rm -fr testdir/workdir2
170 $R -dw testdir/workdir2 init
171 test -d testdir/workdir2
172 cd testdir/workdir2 && $R | wc -c | grep -q 0
173 cd testdir/workdir2 && \
174 cp "$(SSH_ID)" .ssh/id_ed25519_r7 && \
175 cp "$(SSH_ID).pub" .ssh/id_ed25519_r7.pub && \
176 . $(UTILITY) && for node in $(SSH_TEST_NODES); do \
177 mkdir "nodes/$$node" && \
178 ssh_accept_new "$$node"; \
179 done;
180 @echo _________________________________________________________
182 workdir2-ssh: workdir2-init
183 @echo _________________________________________________________
184 cd testdir/workdir2 && . $(UTILITY) && \
185 cat site-config && \
186 echo 'state_hello() { echo Hi! ; }' > groups/common && \
187 echo 'state_hello() { echo Hey! ; }' > groups/heyo && \
188 echo 'dummy_hello() { echo Heyo! ; }' >> groups/heyo && \
189 echo 'group heyo $(SSH_TEST_NODES)' >> site-config && export R7_DEBUG=yes && \
190 digraph_host && \
191 run_config && \
192 output_dump && \
193 output | grep Hey! && \
194 output && \
195 info && \
196 digraph_ssh_id_hosts && \
197 ssh_known_hosts && \
198 nodes && \
199 prefix dummy && group heyo '.*' && output_dump && \
200 output | grep Heyo! && \
201 trace_id_last && \
202 output_duration | grep 0 && \
203 output_status && \
204 summary && \
205 output_errors && \
206 output_permissions && \
207 output_diffs
208 @echo _________________________________________________________
210 workdir2-grouplib: workdir2-init
211 @echo _________________________________________________________
212 cp testdir/grouplib testdir/workdir2/groups/
213 mkdir -p testdir/workdir2/groups/grouplib.dir/subdir
214 touch testdir/workdir2/groups/grouplib.dir/item
215 echo 'aaa' > testdir/workdir2/groups/grouplib.dir/subdir/subitem
216 echo 'bbb' > testdir/workdir2/groups/grouplib.dir/subdir/subitem2
217 cp testdir/testfile2 testdir/workdir2/groups/grouplib.dir/
218 cd testdir/workdir2 && set -e && . $(UTILITY) && \
219 echo 'prefix grouplib' > site-config && \
220 echo "group grouplib '.*'" >> site-config && \
221 $R run-config && $R output-dump && $R info && \
222 for node in $(SSH_TEST_NODES); do \
223 ssh "$$node" ls -la /tmp/item\* | grep item; \
224 ssh "$$node" ls -la /tmp/r7/my-empty-file | grep empty | grep -e '-rw-r-----' ; \
225 ssh "$$node" ls -la /tmp/newdir/newdir2/null | grep -e '-rw-r-----' ; \
226 done && $R output tools0 grouplib
227 @echo _________________________________________________________
229 workdir2-goodby: workdir2-grouplib
230 @echo _________________________________________________________
231 cd testdir/workdir2 && \
232 rm -fr _output && \
233 $R -P grouplib -se group grouplib $(SSH_TEST_NODES)
234 @echo _________________________________________________________
236 workdir2-r7doc: workdir2-init
237 @echo _________________________________________________________
238 rm -fr testdir/workdir2/_output
239 cp testdir/example1 testdir/workdir2/groups/
240 cd testdir/workdir2/ && $R -a group example1 $(SSH_TEST_NODES)
241 cd testdir/workdir2/ && $R -ea group example1 $(SSH_TEST_NODES)
242 rm -fr testdir/workdir2/_output
243 cp testdir/example2 testdir/workdir2/groups/
244 cd testdir/workdir2/ && $R -sea group example2 $(SSH_TEST_NODES)
245 @echo _________________________________________________________
247 workdir2-source: workdir2-init
248 @echo _________________________________________________________
249 rm -fr testdir/workdir2/_output
250 rm -fr testdir/workdir2/_run
251 cp testdir/source testdir/workdir2/groups/
252 mkdir testdir/workdir2/groups/source.dir
253 echo : > testdir/workdir2/groups/source.dir/my-source
254 for node in $(SSH_TEST_NODES); do \
255 echo myvar=3333 > "testdir/workdir2/nodes/$$node/my-source" ; \
256 done
257 cd testdir/workdir2/ && $R -sea group source $(SSH_TEST_NODES)
258 sleep 1
259 cd testdir/workdir2/ && $R -sda group source $(SSH_TEST_NODES)
260 cd testdir/workdir2/ && $R output \* source source_nodesource2 | grep 3333
261 @echo _________________________________________________________
263 workdir2-importer: workdir2-init
264 @echo _________________________________________________________
265 rm -fr testdir/workdir2/_output
266 rm -fr testdir/workdir2/_run
267 cd testdir/workdir2/ && \
268 for node in $(SSH_TEST_NODES); do \
269 . $(UTILITY) && import "$$node"; \
270 done
271 find testdir/workdir2/nodes | grep sshd_config
272 find testdir/workdir2/nodes
273 cd testdir/workdir2/ && . $(UTILITY) && import notfound || :
274 @echo _________________________________________________________