supprimer ancien nom d'hôte

This commit is contained in:
Jephte CLAIN 2014-02-09 23:05:42 +04:00
parent 390b550f19
commit 43bf3e379c
1 changed files with 19 additions and 7 deletions

View File

@ -860,20 +860,34 @@ function network_fix_postfix() {
}
function network_fix_hosts() {
local host="$1" hostname="${1%%.*}" ip="$2"
local shost="${host//./\\.}"
local host="$1" hostname="${1%%.*}"; local shost="${host//./\\.}"
local ip="$2"; local sip="${ip//./\\.}"
local oldhost="$3" oldhostname="${3%%.*}"; soldhost="${host//./\\.}"
local tmpfile; ac_set_tmpfile tmpfile
local modified
awkrun </etc/hosts >"$tmpfile" host="$host" hostname="$hostname" ip="$ip" '
awkrun </etc/hosts >"$tmpfile" \
host="$host" hostname="$hostname" \
ip="$ip" \
oldhost="$oldhost" oldhostname="$oldhostname" \
'
/^[^# \t]/ {
gsub("[ \\t]+" host "[ \\t]*", " ")
gsub("[ \\t]+" hostname "[ \\t]*", " ")
gsub("[ \\t]+" oldhost "[ \\t]*", " ")
gsub("[ \\t]+" oldhostname "[ \\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 "\
s/\$/ /
/^[ $TAB]$oldhost[ $TAB]/d
/^[ $TAB]$oldhostname[ $TAB]/d
s/ \$//
" "$tmpfile"
fi
if ! quietgrep "^$sip[ $TAB]\\+$shost[ $TAB]\\+$hostname" "$tmpfile"; then
sed -i "/^$sip[ $TAB]/d" "$tmpfile"
sed -i "1i\\
@ -1079,9 +1093,7 @@ iface lo inet loopback
network_fix_hostname "$host"
network_fix_mailname "$host"
if [ -n "$mainip" ]; then
network_fix_hosts "$host" "$mainip"
fi
network_fix_hosts "$host" "$mainip" "$oldhost"
eend
fi