#!/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