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 $ARGV[1]=~/^[\.\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 $lpmlnew=`/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: $template=~/\nPerlSetVar\s+$psv\s+(\S+)/;
63: my $pval=$1;
64: $lpmlnew=~s/(\nPerlSetVar\s+$psv\s+)\S+/$1$pval/;
65: $pvar{$psv}=$pval;
66: }
67: open OUT,">/etc/httpd/conf/access.conf$suffix";
68: print OUT $lpmlnew;
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$suffix`;
76: foreach my $psv (@perlsetvars) {
77: $template=~s/\{\{\{\{\[(.*?)\]\}\}\}\}/$pvar{$1}/ge;
78: }
79: open OUT,">/etc/smb.conf$suffix";
80: print OUT $template;
81: close OUT;
82: }
83: }
84:
85: exit; # Just because this is only about restoring configuration to
86: # new files
87:
88: foreach (@generic_conf_files) {
89: my $file=$_;
90: if ($suffixpragma eq 'lasttimestamp') {
91: $suffix=getsuffix($file);
92: }
93: if (-e "$file$suffix") {
94: `/bin/mv $file $_.template`;
95: `/bin/cp $file$suffix $file`;
96: }
97: }
98:
99: sub getsuffix {
100: my ($file)=@_;
101: print "$file\n";
102: my $dir=$file; $dir=~s/([^\/]+)$//;
103: my $filename=$1;
104: opendir(DIR,$dir);
105: my @a=grep {/$filename\.\d{14}/} readdir DIR;
106: closedir DIR;
107: map {s/$filename\.//;} @a;
108: my @b=sort {$a<=>$b} @a;
109: my $suffix='.'.$b[$#b];
110: return $suffix;
111: }
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>