From ff12d6752047becb6c3aa120f20cbb283c9b2780 Mon Sep 17 00:00:00 2001 From: Erich Eckner Date: Sat, 1 Jan 2022 22:14:35 +0100 Subject: initial commit --- save-graph | 68 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 68 insertions(+) create mode 100755 save-graph 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 -- cgit v1.2.3-70-g09d2