traiter les anciennes occurences de host, même si pas localhost

This commit is contained in:
Jephté Clain 2014-01-28 07:48:33 +04:00
parent a0130ab206
commit 445bbe90ff
1 changed files with 9 additions and 2 deletions

View File

@ -163,9 +163,16 @@ function __network_fix_exim4() {
function __network_hosts() {
local host="$1" hostname="${1%%.*}" ip="$2"
local shost="${host//./\\.}"
local tmpfile; ac_set_tmpfile tmpfile
</etc/hosts sed "/^127\\./s/$hostname\\(\\.[^ $TAB]*\\)\\?[ $TAB]*//g;
/^127\\.[0-9]\\+\\.[0-9]\\+\\.[0-9]\\+[ $TAB]*\$/d" >"$tmpfile"
awkrun </etc/hosts >"$tmpfile" host="$host" hostname="$hostname" ip="$ip" '
/^[^# \t]/ {
gsub("[ \\t]+" host "[ \\t]*", " ")
gsub("[ \\t]+" hostname "[ \\t]*", " ")
if ($0 ~ /^[^ \t]+[ \t]*$/) next
gsub(/[ \t]*$/, "")
}
{ print }'
local sip="${ip//./\\.}" shost="${host//./\\.}"
if ! quietgrep "^$sip[ $TAB]\\+$shost[ $TAB]\\+$hostname" "$tmpfile"; then
sed -i "/^$sip[ $TAB]/d" "$tmpfile"