1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51
|
#!/bin/sh
#
# This script copies havp.config.default to havp.config,
# while keeping user set values
#
# Command: update-conf /usr/local/etc/havp/havp.config
#
# Default config must be found: /usr/local/etc/havp/havp.config.default
#
if [ ! -f "$1" ]; then exit 0; fi
if [ ! -f "$1.default" ]; then exit 0; fi
cp "$1" "$1.old"
perl -e '
open(OLDCONF, "$ARGV[0]") or die;
while (<OLDCONF>)
{
chomp;
unless ( /^\s*?#/ || /^\s*$/ )
{
if ( /\s*?(\S+?)\s+?(.+)\s*$/ )
{
$conf{$1} = $2;
}
}
}
close(OLDCONF);
open(NEWCONF, "$ARGV[0].default") or die;
open(REPCONF, ">$ARGV[0].tmp") or die;
while (<NEWCONF>)
{
foreach $key (keys %conf)
{
if ( /^(\# )?$key / )
{
print REPCONF "$key $conf{$key}\n" or die;
goto END;
}
}
print REPCONF $_ or die;
END:
}
close(REPCONF);
close(NEWCONF);
rename("$ARGV[0].tmp", "$ARGV[0]") or die;
' $1
|