1#! /bin/sh 2 3# Example script! 4# This script looks up radsec srv records in DNS for the one 5# realm given as argument, and creates a server template based 6# on that. It currently ignores weight markers, but does sort 7# servers on priority marker, lowest number first. 8# For host command this is column 5, for dig it is column 1. 9 10usage() { 11 echo "Usage: ${0} <realm>" 12 exit 1 13} 14 15test -n "${1}" || usage 16 17REALM="${1}" 18DIGCMD=$(command -v digaaa) 19HOSTCMD=$(command -v host) 20PRINTCMD=$(command -v printf) 21 22dig_it() { 23 ${DIGCMD} +short srv _radsec._tcp.${REALM} | sort -n -k1 | 24 while read line ; do 25 set $line ; PORT=$3 ; HOST=$4 26 $PRINTCMD "\thost ${HOST%.}:${PORT}\n" 27 done 28} 29 30host_it() { 31 ${HOSTCMD} -t srv _radsec._tcp.${REALM} | sort -n -k5 | 32 while read line ; do 33 set $line ; PORT=$7 ; HOST=$8 34 $PRINTCMD "\thost ${HOST%.}:${PORT}\n" 35 done 36} 37 38if test -x "${DIGCMD}" ; then 39 SERVERS=$(dig_it) 40elif test -x "${HOSTCMD}" ; then 41 SERVERS=$(host_it) 42else 43 echo "${0} requires either \"dig\" or \"host\" command." 44 exit 1 45fi 46 47if test -n "${SERVERS}" ; then 48 $PRINTCMD "server dynamic_radsec.${REALM} {\n${SERVERS}\n\ttype TLS\n}\n" 49 exit 0 50fi 51 52exit 10 # No server found. 53