chiark / gitweb /
contrib/: New directory for random occasionally-useful stuff.
[tripe] / contrib / ipif-peers
diff --git a/contrib/ipif-peers b/contrib/ipif-peers
new file mode 100755 (executable)
index 0000000..c976238
--- /dev/null
@@ -0,0 +1,59 @@
+#! /bin/sh
+###
+### Start up peers registered in tripe-ipif's table
+###
+### (c) 2012 Mark Wooding
+###
+
+###----- Licensing notice ---------------------------------------------------
+###
+### This file is part of Trivial IP Encryption (TrIPE).
+###
+### TrIPE is free software; you can redistribute it and/or modify
+### it under the terms of the GNU General Public License as published by
+### the Free Software Foundation; either version 2 of the License, or
+### (at your option) any later version.
+###
+### TrIPE is distributed in the hope that it will be useful,
+### but WITHOUT ANY WARRANTY; without even the implied warranty of
+### MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+### GNU General Public License for more details.
+###
+### You should have received a copy of the GNU General Public License
+### along with TrIPE; if not, write to the Free Software Foundation,
+### Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+
+###--------------------------------------------------------------------------
+### Instructions.
+###
+### This script will tell a tripe server to associate with all of the peers
+### named in the $TRIPEDIR/ipif.tab file.  See `tripe-ipif' for a description
+### of the configuration file.
+
+set -e
+quis=${0##*/}
+case ${TRIPEDIR+t} in
+  t) ;;
+  *) echo >&2 "$quis: \`TRIPEDIR' unset"; exit 1 ;;
+esac
+
+## Trundle through the table.
+while read name remote_ext local_int remote_int routes; do
+
+  ## Ignore comments, and unknown remote-external addresses.
+  case "$name" in "" | "#"*) continue ;; esac
+  case "$remote_ext" in -) continue ;; esac
+
+  ## Parse the address.
+  fam=INET port=4070
+  case "$remote_ext" in
+    *:*) port=${remote_ext#*:}; addr=${remote_ext%:*} ;;
+    *) addr=$remote_ext ;
+  esac
+
+  ## Add the peer.
+  tripectl ADD "$name" "$fam" "$addr" "$port"
+
+done <$TRIPEDIR/ipif.tab
+
+###----- That's all, folks --------------------------------------------------