diff options
Diffstat (limited to 'resolvconf.in')
| -rw-r--r-- | resolvconf.in | 84 |
1 files changed, 77 insertions, 7 deletions
diff --git a/resolvconf.in b/resolvconf.in index e7b0ffe..d1ec074 100644 --- a/resolvconf.in +++ b/resolvconf.in @@ -64,6 +64,7 @@ IFACEDIR="$VARDIR/interfaces" METRICDIR="$VARDIR/metrics" PRIVATEDIR="$VARDIR/private" EXCLUSIVEDIR="$VARDIR/exclusive" +INACTIVEDIR="$VARDIR/inactive" LOCKDIR="$VARDIR/lock" _PWD="$PWD" @@ -88,6 +89,8 @@ usage() Commands: -a \$INTERFACE Add DNS information to the specified interface (DNS supplied via stdin in resolv.conf format) + -C \$PATTERN Deprecate DNS information for matched interfaces + -c \$PATTERN Configure DNS information for matched interfaces -d \$INTERFACE Delete DNS information from the specified interface -h Show this help cruft -i [\$PATTERN] Show interfaces that have supplied DNS information @@ -407,6 +410,22 @@ echo_resolv() IFS="$OIFS" } +inactive_interface() +{ + [ -d "$INACTIVEDIR" ] || return 1 + + cd "$INACTIVEDIR" + for ia; do + for iaf in *; do + [ -f "$iaf" ] || continue + case "$ia" in + $iaf) return 0;; + esac + done + done + return 1 +} + list_resolv() { [ -d "$IFACEDIR" ] || return 0 @@ -474,12 +493,25 @@ list_resolv() list="$list $i" fi done + if [ -d "$METRICDIR" ]; then cd "$METRICDIR" for i in *; do [ -f "$i" ] && list="$list ${i#* }" done fi + + # Move inactive interfaces to the back + active= + inactive= + for i in $list; do + if inactive_interface "$i"; then + inactive="$inactive $i" + else + active="$active $i" + fi + done + list="$active $inactive" fi cd "$IFACEDIR" @@ -678,7 +710,7 @@ make_vars() force=false VFLAG= -while getopts a:Dd:fhIilm:pRruvVx OPT; do +while getopts a:C:c:Dd:fhIilm:pRruvVx OPT; do case "$OPT" in f) force=true;; h) usage;; @@ -693,7 +725,7 @@ while getopts a:Dd:fhIilm:pRruvVx OPT; do fi ;; x) IF_EXCLUSIVE=1;; - '?') ;; + '?') exit 1;; *) cmd="$OPT"; iface="$OPTARG";; esac done @@ -742,14 +774,20 @@ if [ "$cmd" = v ] || [ -n "$VFLAG" ]; then fi # Test that we have valid options -if [ "$cmd" = a ] || [ "$cmd" = d ]; then +case "$cmd" in +a|d|C|c) if [ -z "$iface" ]; then - usage "Interface not specified" + error_exit "Interface not specified" + fi + ;; +u) ;; +*) + if [ -n "$cmd" ] && [ "$cmd" != h ]; then + error_exit "Unknown option $cmd" fi -elif [ "$cmd" != u ]; then - [ -n "$cmd" ] && [ "$cmd" != h ] && usage "Unknown option $cmd" usage -fi + ;; +esac if [ "$cmd" = a ]; then for x in '/' \\ ' ' '*'; do @@ -945,6 +983,7 @@ d) "$PRIVATEDIR/$i" \ "$EXCLUSIVEDIR/"*" $i" || exit $? done + if ! $changed; then # Set the return code based on the forced flag $force @@ -952,6 +991,37 @@ d) fi unset changed i ;; + +C) + # Mark interface as inactive + [ ! -d "$INACTIVEDIR" ] && mkdir "$INACTIVEDIR" + cd "$INACTIVEDIR" + changed=false + for i in $args; do + if [ ! -e "$i" ]; then + changed=true + echo " " >"$i" || exit $? + fi + done + $changed || exit 0 + unset changed i + ;; + +c) + # Mark interface as active + if [ -d "$INACTIVEDIR" ]; then + cd "$INACTIVEDIR" + changed=false + for i in $args; do + if [ -e "$i" ]; then + changed=true + rm "$i" || exit $? + fi + done + $changed || exit 0 + unset changed i + fi + ;; esac case "${resolvconf:-YES}" in |
