summaryrefslogtreecommitdiff
path: root/save-graph
diff options
context:
space:
mode:
authorErich Eckner <git@eckner.net>2022-01-01 22:14:35 +0100
committerErich Eckner <git@eckner.net>2022-01-01 22:14:35 +0100
commitff12d6752047becb6c3aa120f20cbb283c9b2780 (patch)
tree36c21439f13ce219c8b86eab4faa367c2daf5642 /save-graph
downloadtinc-graph-ff12d6752047becb6c3aa120f20cbb283c9b2780.tar.xz
initial commit
Diffstat (limited to 'save-graph')
-rwxr-xr-xsave-graph68
1 files changed, 68 insertions, 0 deletions
diff --git a/save-graph b/save-graph
new file mode 100755
index 0000000..005e6be
--- /dev/null
+++ b/save-graph
@@ -0,0 +1,68 @@
+#!/bin/bash
+
+graph=$(
+ tinc --net=$1 dump digraph
+)
+
+pre=$(
+ printf '%s\n' "${graph}" \
+ | sed '
+ / -> /,$ d
+ '
+)
+post=$(
+ printf '%s\n' "${graph}" \
+ | sed '
+ 1,/ -> /d
+ / -> /d
+ '
+)
+inter=$(
+ printf '%s\n' "${graph}" \
+ | sed -n '
+ / -> /p
+ ' \
+ | while read -r a b c d; do
+ mapfile -t e < <(
+ printf '%s\n' "$a" "$c" \
+ | sort
+ )
+ b4=$(
+ printf '%s\n' "$d" \
+ | base64 -w0
+ )
+ printf '%s %s %s %s %s\n' \
+ "${a}" "${c}" "${b4}" "${e[0]}" "${e[1]}"
+ done \
+ | sort -k4,4 -k5,5 -k3,3 \
+ | uniq -cf2 \
+ | while read -r c a b b4 _ _; do
+ printf '%s -> %s ' "${a}" "${b}"
+ printf '%s\n' "${b4}" \
+ | base64 -d \
+ | if [ "${c}" = '1' ]; then
+ cat
+ else
+ sed 's@];$@, dir=both\0@'
+ fi
+ done
+)
+
+if printf '%s\n' "${graph}" \
+| grep -qwF backup \
+&& printf '%s\n' "${graph}" \
+| greo -qwF backup_lo; then
+ extra='
+"backup" -> "backup_lo" [style=dashed, constraint=false, dir=none];'
+else
+ extra=''
+fi
+
+{
+ printf '%s\n' "${pre}" "${inter}" "${extra}" "${post}"
+} \
+| if [ $# -eq 0 ]; then
+ /usr/bin/dot -Tpng
+else
+ cat
+fi