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