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