Release openresolv-1.7
[openresolv] / resolvconf.in
index e975ad4b88676d7b4f3fac180cdffe296324444a..1512c6fd2c7bc49d5ca3fe9e7e3724950e7c844f 100755 (executable)
@@ -65,9 +65,15 @@ usage()
 
 echo_resolv()
 {
+       local LINE=
        [ -n "$1" -a -e "${IFACEDIR}/$1" ] || return 1
-       echo "# resolv.conf for interface $1"
-       cat "${IFACEDIR}/$1"
+       echo "# resolv.conf from $1"
+       # Our variable maker works of the fact each resolv.conf per interface
+       # is separated by blank lines.
+       # So we remove them when echoing them.
+       while read LINE; do
+               [ -n "${LINE}" ] && echo "${LINE}"
+       done < "${IFACEDIR}/$1"
        echo
 }
 
@@ -310,7 +316,7 @@ if [ ! -d "${IFACEDIR}" ]; then
                error_exit "Failed to create needed directory ${IFACEDIR}"
 else
        # Delete any existing information about the interface
-       if [ "${CMD}" = "a" -o "${CMD}" = "d" ]; then
+       if [ "${CMD}" = "d" ]; then
                cd "${IFACEDIR}"
                for ARG in ${ARGS}; do
                        if [ "${CMD}" = "d" -a ! -e "${ARG}" ]; then
@@ -323,8 +329,17 @@ else
 fi
 
 if [ "${CMD}" = "a" ]; then
-       # Create our resolv.conf file
-       cat >"${IFACEDIR}"/"${IFACE}" || exit $?
+       # Read resolv.conf from stdin
+       RESOLV="$(cat)\n"
+       # If what we are given matches what we have, then do nothing
+       if [ -e "${IFACEDIR}/${IFACE}" ]; then
+               if [ "$(printf "${RESOLV}")" = "$(cat "${IFACEDIR}/${IFACE}")" ]
+               then
+                       exit 0
+               fi
+               rm "${IFACEDIR}/${IFACE}"
+       fi
+       printf "${RESOLV}" >"${IFACEDIR}/${IFACE}" || exit $?
 fi
 
 RETVAL=0