# ISC License # # Copyright 2025 xs # # Permission to use, copy, modify, and/or distribute this software for any # purpose with or without fee is hereby granted, provided that the above # copyright notice and this permission notice appear in all copies. # # THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH # REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND # FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, # INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM # LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR # OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR # PERFORMANCE OF THIS SOFTWARE. .POSIX: PREFIX:=/usr/local SHELLS=ksh93 ksh yash sh UTILITY_VERSION=0.1.3 UTILITY=$(PWD)/r7 # To use the test suite, please edit or use environment for SSH parameters # SSH_ID=/path/to/.ssh/id_ed25519 # SSH_TEST_NODES=nodeA nodeB .DEFAULT: all all: tests release: r7.1 make tests whoami rm -fr _release/r7-$(UTILITY_VERSION) mkdir -p _release/r7-$(UTILITY_VERSION) cp LICENSE r7 r7.1 Makefile README.md _release/r7-$(UTILITY_VERSION) cp -r groups/ _release/r7-$(UTILITY_VERSION) cd _release && tar cfv r7-$(UTILITY_VERSION).tar r7-$(UTILITY_VERSION) gzip -9 _release/r7-$(UTILITY_VERSION).tar cp _release/r7-$(UTILITY_VERSION).tar.gz _release/r7-latest.tar.gz html: index.md documentation.html pandoc --template=./r7doc.html \ -s --toc=false \ --metadata title='R7' \ --from markdown+smart \ -t html -o index.html index.md documentation.html: README.md ./r7 pandoc --template=./r7doc.html \ -s --toc=true \ --metadata title='R7 Documentation' \ --metadata date="Tue Jun 3 2025" \ --from markdown+smart \ -t html -o documentation.html README.md r7.1: README.md r7 Makefile pandoc --from markdown+smart \ --metadata section=1 \ --metadata title="R7" \ --metadata header="User Manual" \ --metadata date="Tue Jun 3 2025" \ --metadata footer="v$(UTILITY_VERSION)" \ -s -t man -o r7.1 README.md r7.1.pdf: README.md pandoc --from markdown+smart \ -s -t pdf -o r7.1.pdf README.md install: cp ./r7 $(PREFIX)/bin/ chmod 755 $(PREFIX)/bin/r7 cp ./r7.1 $(PREFIX)/man/man1/ chmod 644 $(PREFIX)/man/man1/r7.1 # Test suite for r7 R=${SHELL} ${UTILITY} test_arguments: usage version debug test_workdirs: \ workdir0-arguments \ workdir0-digraph \ workdir1-init \ workdir1-populate \ workdir2-init \ workdir2-ssh \ workdir2-grouplib \ workdir2-goodby \ workdir2-r7doc \ workdir2-source \ workdir2-importer tests: @echo make test_arguments make test_workdirs @echo == ALL TESTS PASSED poly: @for shell in ${SHELLS}; do \ ashell=$$(command -v $$shell || true); \ if test -x "$$ashell"; then \ if time make tests SHELL=$$ashell SH=$$ashell; then \ : \ else \ failed="$$(basename "$$ashell") $$failed"; \ fi; \ else \ notfound="$$shell $$notfound"; \ fi; \ done; \ echo; \ echo "== POLY TESTS RESULTS"; \ echo " spec: $(SHELLS)"; \ echo "not-found: $$notfound"; \ echo " failed: $$failed"; \ test -z "$$failed" -a -z "$$notfound" || (echo; false;) usage: @echo _________________________________________________________ $R -h $R -h 2>&1 | grep -q -e usage: -e '\[' @echo _________________________________________________________ version: @echo _________________________________________________________ $R -h 2>&1 | grep -q -e "$(UTILITY_VERSION)" @echo _________________________________________________________ debug: @echo _________________________________________________________ $R -dn 2>&1 run-config | grep -q "R7 DEBUG $(UTILITY_VERSION)" @echo _________________________________________________________ workdir0-arguments: @echo _________________________________________________________ rm -fr testdir/workdir0/_run $R -w testdir/workdir0 -dn run-config 2>&1 | tee testdir/wd01.produced grep -q -e '^LOADING $(PWD)/testdir/workdir0/site-config' testdir/wd01.produced grep -q -e '^PROCESSING GROUP common' testdir/wd01.produced grep -q -e '^PROCESSING GROUP test0' testdir/wd01.produced @echo _________________________________________________________ workdir0-digraph: @echo _________________________________________________________ $R -w testdir/workdir0 -dn digraph-host 2>/dev/null | \ tee testdir/wd01.dot.produced cmp testdir/wd01.dot testdir/wd01.dot.produced @echo _________________________________________________________ workdir1-init: @echo _________________________________________________________ rm -fr testdir/workdir1 $R -dw testdir/workdir1 init test -d testdir/workdir1 find testdir/workdir1 | tee testdir/wd1-init-find.produced cmp testdir/wd1-init-find testdir/wd1-init-find.produced @echo _________________________________________________________ workdir1-populate: workdir1-init @echo _________________________________________________________ { cd testdir/workdir1 && \ $R && \ $R run-config && \ $R output-dump && \ $R output && \ $R group && \ $R -s group ;} | wc -c | grep -q 0 @echo _________________________________________________________ workdir2-init: @echo _________________________________________________________ rm -fr testdir/workdir2 $R -dw testdir/workdir2 init test -d testdir/workdir2 cd testdir/workdir2 && $R | wc -c | grep -q 0 cd testdir/workdir2 && \ cp "$(SSH_ID)" .ssh/id_ed25519_r7 && \ cp "$(SSH_ID).pub" .ssh/id_ed25519_r7.pub && \ . $(UTILITY) && for node in $(SSH_TEST_NODES); do \ mkdir "nodes/$$node" && \ ssh_accept_new "$$node"; \ done; @echo _________________________________________________________ workdir2-ssh: workdir2-init @echo _________________________________________________________ cd testdir/workdir2 && . $(UTILITY) && \ cat site-config && \ echo 'state_hello() { echo Hi! ; }' > groups/common && \ echo 'state_hello() { echo Hey! ; }' > groups/heyo && \ echo 'dummy_hello() { echo Heyo! ; }' >> groups/heyo && \ echo 'group heyo $(SSH_TEST_NODES)' >> site-config && export R7_DEBUG=yes && \ digraph_host && \ run_config && \ output_dump && \ output | grep Hey! && \ output && \ info && \ digraph_ssh_id_hosts && \ ssh_known_hosts && \ nodes && \ prefix dummy && group heyo '.*' && output_dump && \ output | grep Heyo! && \ trace_id_last && \ output_duration | grep 0 && \ output_status && \ summary && \ output_errors && \ output_permissions && \ output_diffs @echo _________________________________________________________ workdir2-grouplib: workdir2-init @echo _________________________________________________________ cp testdir/grouplib testdir/workdir2/groups/ mkdir -p testdir/workdir2/groups/grouplib.dir/subdir touch testdir/workdir2/groups/grouplib.dir/item echo 'aaa' > testdir/workdir2/groups/grouplib.dir/subdir/subitem echo 'bbb' > testdir/workdir2/groups/grouplib.dir/subdir/subitem2 cp testdir/testfile2 testdir/workdir2/groups/grouplib.dir/ cd testdir/workdir2 && set -e && . $(UTILITY) && \ echo 'prefix grouplib' > site-config && \ echo "group grouplib '.*'" >> site-config && \ $R run-config && $R output-dump && $R info && \ for node in $(SSH_TEST_NODES); do \ ssh "$$node" ls -la /tmp/item\* | grep item; \ ssh "$$node" ls -la /tmp/r7/my-empty-file | grep empty | grep -e '-rw-r-----' ; \ ssh "$$node" ls -la /tmp/newdir/newdir2/null | grep -e '-rw-r-----' ; \ done && $R output tools0 grouplib @echo _________________________________________________________ workdir2-goodby: workdir2-grouplib @echo _________________________________________________________ cd testdir/workdir2 && \ rm -fr _output && \ $R -P grouplib -se group grouplib $(SSH_TEST_NODES) @echo _________________________________________________________ workdir2-r7doc: workdir2-init @echo _________________________________________________________ rm -fr testdir/workdir2/_output cp testdir/example1 testdir/workdir2/groups/ cd testdir/workdir2/ && $R -a group example1 $(SSH_TEST_NODES) cd testdir/workdir2/ && $R -ea group example1 $(SSH_TEST_NODES) rm -fr testdir/workdir2/_output cp testdir/example2 testdir/workdir2/groups/ cd testdir/workdir2/ && $R -sea group example2 $(SSH_TEST_NODES) @echo _________________________________________________________ workdir2-source: workdir2-init @echo _________________________________________________________ rm -fr testdir/workdir2/_output rm -fr testdir/workdir2/_run cp testdir/source testdir/workdir2/groups/ mkdir testdir/workdir2/groups/source.dir echo : > testdir/workdir2/groups/source.dir/my-source for node in $(SSH_TEST_NODES); do \ echo myvar=3333 > "testdir/workdir2/nodes/$$node/my-source" ; \ done cd testdir/workdir2/ && $R -sea group source $(SSH_TEST_NODES) sleep 1 cd testdir/workdir2/ && $R -sda group source $(SSH_TEST_NODES) cd testdir/workdir2/ && $R output \* source source_nodesource2 | grep 3333 @echo _________________________________________________________ workdir2-importer: workdir2-init @echo _________________________________________________________ rm -fr testdir/workdir2/_output rm -fr testdir/workdir2/_run cd testdir/workdir2/ && \ for node in $(SSH_TEST_NODES); do \ . $(UTILITY) && import "$$node"; \ done find testdir/workdir2/nodes | grep sshd_config find testdir/workdir2/nodes cd testdir/workdir2/ && . $(UTILITY) && import notfound || : @echo _________________________________________________________