renommer certaines fonction. retourner 0 si une modification a eu lieu

This commit is contained in:
Jephte CLAIN 2014-02-09 21:55:25 +04:00
parent 226b7aeb62
commit ac63d8456a
1 changed files with 33 additions and 17 deletions

View File

@ -748,47 +748,54 @@ iface $iface inet manual"
bridge_maxwait 0"
}
function __old_network_backup() {
function __network_backup() {
local file="$1"
local backup="$file.orig$(date +%Y%m%d)"
[ -f "$backup" ] || cat "$file" >"$backup" 2>/dev/null
}
function __old_network_hostname() {
function network_fix_hostname() {
local hostname="${1%%.*}"
local modified
[ -f /etc/hostname ] || touch /etc/hostname
if [ -n "$__DEBIAN_NETWORK_DEVEL_SHOW_MODIFS" ]; then
uecho "Setting /etc/hostname to $hostname"
elif [ "$(</etc/hostname)" != "$hostname" ]; then
__old_network_backup /etc/hostname
__network_backup /etc/hostname
if show_debug; then
edebug "Setting /etc/hostname to $hostname"
else
estep /etc/hostname
fi
echo "$hostname" >/etc/hostname
modified=1
fi
[ -n "$modified" ]
}
function __old_network_mailname() {
function network_fix_mailname() {
local host="$1"
local modified
[ -f /etc/mailname ] || touch /etc/mailname
if [ -n "$__DEBIAN_NETWORK_DEVEL_SHOW_MODIFS" ]; then
uecho "Setting /etc/mailname to $host"
elif [ "$(</etc/mailname)" != "$host" ]; then
__old_network_backup /etc/mailname
__network_backup /etc/mailname
if show_debug; then
edebug "Setting /etc/mailname to $host"
else
estep /etc/mailname
fi
echo "$host" >/etc/mailname
modified=1
fi
[ -n "$modified" ]
}
function __old_network_fix_exim4() {
function network_fix_exim4() {
local host="$1" oldhost="$2"
local tmpfile; ac_set_tmpfile tmpfile
local modified
sed </etc/exim4/update-exim4.conf.conf >"$tmpfile" "
/^dc_other_hostnames=/c\\
@ -801,7 +808,7 @@ dc_other_hostnames='$host'"
uecho "/etc/exim4/update-exim4.conf.conf: pas de modifications"
fi
elif testdiff "$tmpfile" /etc/exim4/update-exim4.conf.conf; then
__old_network_backup /etc/exim4/update-exim4.conf.conf
__network_backup /etc/exim4/update-exim4.conf.conf
if show_debug; then
edebug "Setting /etc/exim4/update-exim4.conf.conf to:"
cat "$tmpfile" | sed 's/^/ /g' 1>&2
@ -810,13 +817,16 @@ dc_other_hostnames='$host'"
fi
cat "$tmpfile" >/etc/exim4/update-exim4.conf.conf
update-exim4.conf
modified=1
fi
ac_clean "$tmpfile"
[ -n "$modified" ]
}
function __old_network_fix_postfix() {
function network_fix_postfix() {
local host="$1" oldhost="$2"
local tmpfile; ac_set_tmpfile tmpfile
local modified
awkrun </etc/postfix/main.cf >"$tmpfile" host="$host" oldhost="$oldhost" '
/^myhostname *=/ { $0 = "myhostname = " host }
@ -835,7 +845,7 @@ function __old_network_fix_postfix() {
uecho "/etc/postfix/main.cf: pas de modifications"
fi
elif testdiff "$tmpfile" /etc/postfix/main.cf; then
__old_network_backup /etc/postfix/main.cf
__network_backup /etc/postfix/main.cf
if show_debug; then
edebug "Setting /etc/postfix/main.cf to:"
cat "$tmpfile" | sed 's/^/ /g' 1>&2
@ -843,14 +853,18 @@ function __old_network_fix_postfix() {
estep /etc/postfix/main.cf
fi
cat "$tmpfile" >/etc/postfix/main.cf
modified=1
fi
ac_clean "$tmpfile"
[ -n "$modified" ]
}
function __old_network_hosts() {
function network_fix_hosts() {
local host="$1" hostname="${1%%.*}" ip="$2"
local shost="${host//./\\.}"
local tmpfile; ac_set_tmpfile tmpfile
local modified
awkrun </etc/hosts >"$tmpfile" host="$host" hostname="$hostname" ip="$ip" '
/^[^# \t]/ {
gsub("[ \\t]+" host "[ \\t]*", " ")
@ -874,7 +888,7 @@ $ip$TAB$host $hostname" "$tmpfile"
uecho "/etc/hosts: pas de modifications"
fi
elif testdiff "$tmpfile" /etc/hosts; then
__old_network_backup /etc/hosts
__network_backup /etc/hosts
if show_debug; then
edebug "Setting /etc/hosts to:"
cat "$tmpfile" | sed 's/^/ /g' 1>&2
@ -882,8 +896,10 @@ $ip$TAB$host $hostname" "$tmpfile"
estep /etc/hosts
fi
cat "$tmpfile" >/etc/hosts
modified=1
fi
ac_clean "$tmpfile"
[ -n "$modified" ]
}
function network_config() {
@ -927,8 +943,8 @@ function network_config() {
array_copy confips __nc_confips
array_copy confbrs __nc_confbrs
__old_network_fix_confips confips
__old_network_fix_confbrs confbrs
network_fix_confips confips
network_fix_confbrs confbrs
local mainbr # bridge principal
local mainip # adresse IP principale de l'interface principale
@ -1038,7 +1054,7 @@ iface lo inet loopback
uecho "/etc/network/interfaces: pas de modifications"
fi
elif testdiff "$interfaces" /etc/network/interfaces; then
__old_network_backup /etc/network/interfaces
__network_backup /etc/network/interfaces
if show_debug; then
edebug "Setting /etc/network/interfaces to:"
cat "$interfaces" | sed 's/^/ /g' 1>&2
@ -1072,10 +1088,10 @@ iface lo inet loopback
mainip="${mainips[0]}"
fi
__old_network_hostname "$host"
__old_network_mailname "$host"
network_fix_hostname "$host"
network_fix_mailname "$host"
if [ -n "$mainip" ]; then
__old_network_hosts "$host" "$mainip"
network_fix_hosts "$host" "$mainip"
fi
eend