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