Formatting changes.
[libradsec.git] / tools / naptr-eduroam.sh
index 4aa3c4b..e310812 100755 (executable)
@@ -8,7 +8,7 @@
 # For host command this is column 5, for dig it is column 1.
 
 usage() {
-    /bin/echo "Usage: ${0} <realm>"
+    echo "Usage: ${0} <realm>"
     exit 1
 }
 
@@ -17,20 +17,21 @@ test -n "${1}" || usage
 REALM="${1}"
 DIGCMD=$(command -v dig)
 HOSTCMD=$(command -v host)
+PRINTCMD=$(command -v printf)
 
 dig_it_srv() {
-    ${DIGCMD} +short srv $SRV_HOST | sort -k1 |
+    ${DIGCMD} +short srv $SRV_HOST | sort -n -k1 |
     while read line; do
        set $line ; PORT=$3 ; HOST=$4
-       /bin/echo -e "\thost ${HOST%.}:${PORT}"
+       $PRINTCMD "\thost ${HOST%.}:${PORT}\n"
     done
 }
 
 dig_it_naptr() {
-    ${DIGCMD} +short naptr ${REALM} | grep x-eduroam:radius.tls | sort -k1 |
+    ${DIGCMD} +short naptr ${REALM} | grep x-eduroam:radius.tls | sort -n -k1 |
     while read line; do
        set $line ; TYPE=$3 ; HOST=$6
-       if [ "$TYPE" = "\"s\"" ]; then
+       if [ "$TYPE" = "\"s\"" -o "$TYPE" = "\"S\"" ]; then
            SRV_HOST=${HOST%.}
            dig_it_srv
        fi
@@ -38,18 +39,18 @@ dig_it_naptr() {
 }
 
 host_it_srv() {
-    ${HOSTCMD} -t srv $SRV_HOST | sort -k5 | 
+    ${HOSTCMD} -t srv $SRV_HOST | sort -n -k5 |
     while read line; do
        set $line ; PORT=$7 ; HOST=$8 
-       /bin/echo -e "\thost ${HOST%.}:${PORT}"
+       $PRINTCMD "\thost ${HOST%.}:${PORT}\n"
     done
 }
 
 host_it_naptr() {
-    ${HOSTCMD} -t naptr ${REALM} | grep x-eduroam:radius.tls | sort -k5 | 
+    ${HOSTCMD} -t naptr ${REALM} | grep x-eduroam:radius.tls | sort -n -k5 |
     while read line; do
        set $line ; TYPE=$7 ; HOST=${10}
-       if [ "$TYPE" = "\"s\"" ]; then
+       if [ "$TYPE" = "\"s\"" -o "$TYPE" = "\"S\"" ]; then
            SRV_HOST=${HOST%.}
            host_it_srv
        fi
@@ -61,12 +62,12 @@ if [ -x "${DIGCMD}" ]; then
 elif [ -x "${HOSTCMD}" ]; then
     SERVERS=$(host_it_naptr)
 else
-    /bin/echo "${0} requires either \"dig\" or \"host\" command."
+    echo "${0} requires either \"dig\" or \"host\" command."
     exit 1
 fi
 
 if [ -n "${SERVERS}" ]; then
-    /bin/echo -e "server dynamic_radsec.${REALM} {\n${SERVERS}\n\ttype TLS\n}"
+    $PRINTCMD "server dynamic_radsec.${REALM} {\n${SERVERS}\n\ttype TLS\n}\n"
     exit 0
 fi