#!/bin/bash # -*- Mode: shell-script -*- # Copyright (C) 2003 by Chmouel Boudjnah <chmouel@mandrakesoft.com> # Redistribution of this file is permitted under the terms of the GNU # Public License (GPL) resolv_conf=/etc/resolv.conf tmpfile=$(mktemp /tmp/.resolv.conf.XXXXXX) opt= function usage() { cat << EOF >&2 ${0##*/}: -f=RESOLV_CONF -r: Remove local entries -f: Another resolv.conf file [Default: /etc/resolv.conf] EOF exit 1; } while getopts "rf:" opt;do case $opt in r) remove=1;; f) resolv_conf=$OPTARG;resolv_conf=${resolv_conf/=/};; *) usage esac done shift $((OPTIND - 1)) [[ -w $resolv_conf ]] || { echo "Can't update $resolv_conf, you don't have the rights to do it."; exit 1; } if [ -z "$remove" ]; then while true;do if [[ -e /var/run/tmdns.pid ]];then if [[ -n "$(/bin/ps --no-header -p $(cat /var/run/tmdns.pid))" ]];then break; fi fi exit 1 #do nothing since tmdns seems like not launched done needname= needsearch= if ! egrep -q "^nameserver 127.0.0.1" $resolv_conf;then needname=yes fi if ! egrep -q "^search.* local($| )" $resolv_conf;then needsearch=yes fi name_done= search_done= while read entry;do if [[ -n $needname && "$entry" == nameserver* && -z $name_done ]];then echo "nameserver 127.0.0.1" name_done="yes" fi if [[ -n $needsearch && "$entry" == search* && -z $search_done ]];then echo "$entry local" search_done="yes" continue fi echo $entry done < $resolv_conf > $tmpfile else grep -v '^nameserver *127.0.0.1' < $resolv_conf | sed 's/ local//' > $tmpfile fi mv $tmpfile $resolv_conf chmod 644 $resolv_conf