1: #!/usr/bin/perl
2:
3: # loncaparestoreconfigurations
4:
5: # Scott Harrison, 10/25/2000
6: # Scott Harrison, 12/14/2000
7:
8: # This tool helps in updating a system. It restores backed-up
9: # configuration files (.rpmsave or other backup notations).
10:
11: # By default, the .rpmsave suffix is used.
12: # Alternatively, there can be two other invocations
13: # Invocation #1:
14: # ARGV[0]=suffix
15: # ARGV[1]=.bak
16: # Invocation #2:
17: # ARGV[0]=lasttimestamp
18:
19: # The criteria for the lasttimestamp is that the
20: # file suffix is a '.' followed by a 14-digit
21: # time-stamp (YYYYMMDDhhmmss).
22: # The time-stamp with the greatest value is
23: # taken as the backup file.
24:
25: my $suffix=".rpmsave";
26: my $suffixpragma="";
27: if ($ARGV[0] eq 'suffix') {
28: $suffix=$ARGV[1] if $suffix=~/^[\.\w]+$/;
29: }
30: elsif ($ARGV[0] eq 'lasttimestamp') {
31: $suffixpragma="lasttimestamp";
32: }
33:
34:
35: use strict;
36:
37: my @special_conf_files=(
38: "/etc/httpd/conf/access.conf",
39: "/etc/smb.conf"
40: );
41:
42: my @generic_conf_files=(
43: "/home/httpd/lonTabs/hosts.tab",
44: "/home/httpd/lonTabs/spare.tab",
45: "/etc/krb.conf",
46: "/etc/ntp.conf",
47: "/etc/httpd/conf/srm.conf",
48: "/etc/httpd/conf/httpd.conf",
49: );
50:
51: my @perlsetvars=("lonHostID","lonRole","lonAdmEMail","lonDefDomain","lonLoadLim","lonExpire","lonReceipt","lonSqlAccess");
52: my %pvar;
53: foreach (@special_conf_files) {
54: if (/^\/etc\/httpd\/conf\/access.conf$/) {
55: if ($suffixpragma eq 'lasttimestamp') {
56: $suffix=getsuffix('/etc/httpd/conf/access.conf');
57: }
58: my $template=`/bin/cat /etc/httpd/conf/access.conf`;
59: my $rpmsave=`/bin/cat /etc/httpd/conf/access.conf$suffix`;
60: `/bin/mv /etc/httpd/conf/access.conf /etc/httpd/conf/access.conf.template`;
61: foreach my $psv (@perlsetvars) {
62: $rpmsave=~/\nPerlSetVar\s+$psv\s+(\S+)/;
63: my $pval=$1;
64: $template=~s/(\nPerlSetVar\s+$psv\s+)\S+/$1$pval/;
65: $pvar{$psv}=$pval;
66: }
67: open OUT,">/etc/httpd/conf/access.conf";
68: print OUT $template;
69: close OUT;
70: }
71: if (/^\/etc\/smb.conf$/) {
72: if ($suffixpragma eq 'lasttimestamp') {
73: $suffix=getsuffix('/etc/smb.conf');
74: }
75: my $template=`/bin/cat /etc/smb.conf`;
76: foreach my $psv (@perlsetvars) {
77: $template=~s/\{\{\{\{\[(.*?)\]\}\}\}\}/$pvar{$1}/ge;
78: }
79: open OUT,">/etc/smb.conf";
80: print OUT $template;
81: close OUT;
82: }
83: }
84:
85: foreach (@generic_conf_files) {
86: my $file=$_;
87: if ($suffixpragma eq 'lasttimestamp') {
88: $suffix=getsuffix($file);
89: }
90: if (-e "$file$suffix") {
91: `/bin/mv $file $_.template`;
92: `/bin/cp $file$suffix $file`;
93: }
94: }
95:
96: sub getsuffix {
97: my ($file)=@_;
98: print "$file\n";
99: my $dir=$file; $dir=~s/([^\/]+)$//;
100: my $filename=$1;
101: opendir(DIR,$dir);
102: my @a=grep {/$filename\.\d{14}/} readdir DIR;
103: closedir DIR;
104: map {s/$filename\.//;} @a;
105: my @b=sort {$a<=>$b} @a;
106: my $suffix='.'.$b[$#b];
107: return $suffix;
108: }
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>