Annotation of loncom/build/loncaparestoreconfigurations, revision 1.10
1.1 harris41 1: #!/usr/bin/perl
2:
3: # loncaparestoreconfigurations
4:
1.8 harris41 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: }
1.1 harris41 33:
34:
35: use strict;
36:
37: my @special_conf_files=(
1.5 harris41 38: "/etc/httpd/conf/access.conf",
39: "/etc/smb.conf"
1.1 harris41 40: );
41:
42: my @generic_conf_files=(
43: "/home/httpd/lonTabs/hosts.tab",
44: "/home/httpd/lonTabs/spare.tab",
45: "/etc/krb.conf",
1.4 harris41 46: "/etc/ntp.conf",
1.10 ! harris41 47: "/etc/httpd/conf/srm.conf",
! 48: "/etc/httpd/conf/httpd.conf",
1.1 harris41 49: );
50:
1.9 harris41 51: my @perlsetvars=("lonHostID","lonRole","lonAdmEMail","lonDefDomain","lonLoadLim","lonExpire","lonReceipt","lonSqlAccess");
1.6 harris41 52: my %pvar;
1.1 harris41 53: foreach (@special_conf_files) {
1.3 harris41 54: if (/^\/etc\/httpd\/conf\/access.conf$/) {
1.8 harris41 55: if ($suffixpragma eq 'lasttimestamp') {
56: $suffix=getsuffix('/etc/httpd/conf/access.conf');
57: }
1.2 harris41 58: my $template=`/bin/cat /etc/httpd/conf/access.conf`;
1.8 harris41 59: my $rpmsave=`/bin/cat /etc/httpd/conf/access.conf$suffix`;
1.2 harris41 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/;
1.5 harris41 65: $pvar{$psv}=$pval;
1.2 harris41 66: }
67: open OUT,">/etc/httpd/conf/access.conf";
1.5 harris41 68: print OUT $template;
69: close OUT;
70: }
71: if (/^\/etc\/smb.conf$/) {
1.8 harris41 72: if ($suffixpragma eq 'lasttimestamp') {
73: $suffix=getsuffix('/etc/smb.conf');
74: }
1.7 harris41 75: my $template=`/bin/cat /etc/smb.conf`;
1.5 harris41 76: foreach my $psv (@perlsetvars) {
77: $template=~s/\{\{\{\{\[(.*?)\]\}\}\}\}/$pvar{$1}/ge;
78: }
79: open OUT,">/etc/smb.conf";
1.2 harris41 80: print OUT $template;
81: close OUT;
1.1 harris41 82: }
83: }
84:
85: foreach (@generic_conf_files) {
1.8 harris41 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`;
1.3 harris41 93: }
1.8 harris41 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;
1.1 harris41 108: }
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>