Comments
[radsecproxy.git] / radsec-dynsrv.sh
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
9 usage() {
10    echo "Usage: ${0} <realm>"
11    exit 1
12 }
13
14 test -n "${1}" || usage
15
16 REALM="${1}"
17 DIGCMD=$(command -v digaaa)
18 HOSTCMD=$(command -v host)
19
20 dig_it() {
21    ${DIGCMD} +short srv _radsec._tcp.${REALM} | sort -k1 |
22    while read line ; do
23       set $line ; PORT=$3 ; HOST=$4 
24       echo "\thost ${HOST%.}:${PORT}"
25    done
26 }
27
28 host_it() {
29    ${HOSTCMD} -t srv _radsec._tcp.${REALM} | sort -k5 | 
30    while read line ; do
31       set $line ; PORT=$7 ; HOST=$8 
32       echo "\thost ${HOST%.}:${PORT}"
33    done
34 }
35
36 if test -x "${DIGCMD}" ; then
37    SERVERS=$(dig_it)
38 elif test -x "${HOSTCMD}" ; then
39    SERVERS=$(host_it)
40 else
41    echo "${0} requires either \"dig\" or \"host\" command."
42    exit 1
43 fi
44
45 if test -n "${SERVERS}" ; then
46         echo "server dynamic_radsec.${REALM} {\n${SERVERS}\n\ttype TLS\n}"
47         exit 0
48 fi
49
50 exit 0