summaryrefslogtreecommitdiffstats
path: root/retiolum/bin
diff options
context:
space:
mode:
Diffstat (limited to 'retiolum/bin')
-rwxr-xr-xretiolum/bin/apply-custom-hosts-patches8
-rwxr-xr-xretiolum/bin/list-known-public-addresses38
-rwxr-xr-xretiolum/bin/patch-retiolum-hosts13
-rwxr-xr-xretiolum/bin/update-retiolum-hosts6
-rwxr-xr-xretiolum/bin/update_tinc_hosts8
5 files changed, 59 insertions, 14 deletions
diff --git a/retiolum/bin/apply-custom-hosts-patches b/retiolum/bin/apply-custom-hosts-patches
deleted file mode 100755
index 2b2fda80..00000000
--- a/retiolum/bin/apply-custom-hosts-patches
+++ /dev/null
@@ -1,8 +0,0 @@
-#! /bin/sh
-set -euf
-
-patch=/etc/tinc/retiolum/hosts.patch
-
-if test -e $patch; then
- patch -N -d /etc/tinc/retiolum/hosts -r - < $patch
-fi
diff --git a/retiolum/bin/list-known-public-addresses b/retiolum/bin/list-known-public-addresses
new file mode 100755
index 00000000..21b1c389
--- /dev/null
+++ b/retiolum/bin/list-known-public-addresses
@@ -0,0 +1,38 @@
+#! /bin/sh
+#
+# printf '%s %s\n' hostname IP-address for each known public retiolum address
+#
+set -eu
+
+_list_hostname_address() {
+ cd /etc/tinc/retiolum/hosts
+ grep --with-filename '^Address' * |
+ sed -n '
+ s/: */ /
+ s/ *= */ /
+ s/ Address \([a-zA-Z0-9.:_]*\) \?.*/ \1/p'
+}
+_lookup_address() {
+ sed '
+ /:/!{/ [0-9.]*$/!{s/ / `dig +short /;s/$/` \&/}}
+ s/^/echo /
+ $s/$/\nwait/
+ ' | sh
+}
+_filter_public() {
+ sed '
+ # drop private IPv4 addresses
+ / 10\./d
+ / 172\.\(1[6-9]\|2[0-9]\|3[01]\)\./d
+ / 192\.168\./d
+ # TODO drop private IPv6 addresses
+ '
+}
+_filter_online() {
+ awk '
+ {print"nc -zw 2 "$2" 655 2>/dev/null && echo "$1" "$2" &"}
+ END {print"wait"}
+ ' | sh
+}
+
+_list_hostname_address | _lookup_address | _filter_public
diff --git a/retiolum/bin/patch-retiolum-hosts b/retiolum/bin/patch-retiolum-hosts
new file mode 100755
index 00000000..69d7b92c
--- /dev/null
+++ b/retiolum/bin/patch-retiolum-hosts
@@ -0,0 +1,13 @@
+#! /bin/sh
+#
+# Apply custom retiolum hosts patches, if any.
+#
+# usage: patch-retiolum-hosts [--reverse]
+#
+set -euf
+
+patch=/etc/tinc/retiolum/hosts.patch
+
+if test -e $patch; then
+ patch -N -d /etc/tinc/retiolum/hosts -r - "$@" < $patch
+fi
diff --git a/retiolum/bin/update-retiolum-hosts b/retiolum/bin/update-retiolum-hosts
index 2a379459..214ac205 100755
--- a/retiolum/bin/update-retiolum-hosts
+++ b/retiolum/bin/update-retiolum-hosts
@@ -1,5 +1,5 @@
#! /bin/sh
-set -eu
+set -euf
if test "${nosudo-false}" != true -a `id -u` != 0; then
echo "we're going sudo..." >&2
@@ -11,6 +11,4 @@ fi
cd $(dirname $(readlink -f $0))/..
mkdir -p /etc/tinc/retiolum/hosts
-cp -v -r hosts/* /etc/tinc/retiolum/hosts
-pkill -HUP tincd
-pkill -ALRM tincd
+rsync -va --delete hosts/ /etc/tinc/retiolum/hosts/
diff --git a/retiolum/bin/update_tinc_hosts b/retiolum/bin/update_tinc_hosts
index 7be30c2a..ce1be497 100755
--- a/retiolum/bin/update_tinc_hosts
+++ b/retiolum/bin/update_tinc_hosts
@@ -7,8 +7,12 @@ if test "${nosudo-false}" != true -a `id -u` != 0; then
exit 23 # go to hell
fi
-DIRNAME=`dirname $0`
-export PATH="`readlink -f $DIRNAME`:$PATH"
+list_hosts="$(
+ basename="`readlink -f "$0"`"
+ bindir="`dirname "$basename"`"
+ echo "$bindir/hosts"
+)"
+hosts() { "$list_hosts"; }
hosts="${hosts-/etc/hosts}"