summaryrefslogtreecommitdiffstats
path: root/retiolum/scripts/adv_graphgen/find_super
blob: e971e204ce699802354d2efcf93d4c4d0dabb299 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
#! /bin/dash
set -euf
case "${1-all}" in
  (all)
    find /etc/tinc/retiolum/hosts -type f |
    xargs -P 423 -n 1 "$0" one
    ;;
  (one)
    hosts_file=$2
    name=$(basename $hosts_file)

    if grep -q Address $hosts_file; then
      script="$(sed -n '
        s/[[:space:]]*//g
        s/^\(Address\|Port\)=\(.*\)/\1="${\1+$\1 }\2"/p
      ' $hosts_file)"
      eval "$script"
      for address in ${Address-}; do
        if nc -zw 2 $address 655 2>/dev/null; then
          echo $name - $address reachable
        fi &
      done
      wait
    fi
esac