Annotation of loncom/build/loncaparestoreconfigurations, revision 1.11

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') {
1.11    ! harris41   28:     $suffix=$ARGV[1] if $ARGV[1]=~/^[\.\w]+$/;
1.8       harris41   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.11    ! harris41   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`;
1.2       harris41   61: 	foreach my $psv (@perlsetvars) {
1.11    ! harris41   62: 	    $template=~/\nPerlSetVar\s+$psv\s+(\S+)/;
1.2       harris41   63: 	    my $pval=$1;
1.11    ! harris41   64: 	    $lpmlnew=~s/(\nPerlSetVar\s+$psv\s+)\S+/$1$pval/;
1.5       harris41   65: 	    $pvar{$psv}=$pval;
1.2       harris41   66: 	}
1.11    ! harris41   67: 	open OUT,">/etc/httpd/conf/access.conf$suffix";
        !            68: 	print OUT $lpmlnew;
1.5       harris41   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.11    ! harris41   75: 	my $template=`/bin/cat /etc/smb.conf$suffix`;
1.5       harris41   76: 	foreach my $psv (@perlsetvars) {
                     77: 	    $template=~s/\{\{\{\{\[(.*?)\]\}\}\}\}/$pvar{$1}/ge;
                     78: 	}
1.11    ! harris41   79: 	open OUT,">/etc/smb.conf$suffix";
1.2       harris41   80: 	print OUT $template;
                     81: 	close OUT;
1.1       harris41   82:     }
                     83: }
1.11    ! harris41   84: 
        !            85: exit; # Just because this is only about restoring configuration to
        !            86:       # new files
1.1       harris41   87: 
                     88: foreach (@generic_conf_files) {
1.8       harris41   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`;
1.3       harris41   96:     }
1.8       harris41   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;
1.1       harris41  111: }

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>