Annotation of loncom/build/loncaparestoreconfigurations, revision 1.12

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",
1.12    ! harris41   39: 			"/etc/smb.conf",
        !            40: 			"/etc/samba/smb.conf"
1.1       harris41   41: 			);
                     42: 
                     43: my @generic_conf_files=(
                     44: 			"/home/httpd/lonTabs/hosts.tab",
                     45: 			"/home/httpd/lonTabs/spare.tab",
                     46: 			"/etc/krb.conf",
1.4       harris41   47: 			"/etc/ntp.conf",
1.10      harris41   48: 			"/etc/httpd/conf/srm.conf",
                     49: 			"/etc/httpd/conf/httpd.conf",
1.1       harris41   50: 			);
                     51: 
1.9       harris41   52: my @perlsetvars=("lonHostID","lonRole","lonAdmEMail","lonDefDomain","lonLoadLim","lonExpire","lonReceipt","lonSqlAccess");
1.6       harris41   53: my %pvar;
1.1       harris41   54: foreach (@special_conf_files) {
1.3       harris41   55:     if (/^\/etc\/httpd\/conf\/access.conf$/) {
1.8       harris41   56: 	if ($suffixpragma eq 'lasttimestamp') {
                     57: 	    $suffix=getsuffix('/etc/httpd/conf/access.conf');
                     58: 	}
1.2       harris41   59: 	my $template=`/bin/cat /etc/httpd/conf/access.conf`;
1.11      harris41   60: 	my $lpmlnew=`/bin/cat /etc/httpd/conf/access.conf$suffix`;
                     61: #	`/bin/mv /etc/httpd/conf/access.conf /etc/httpd/conf/access.conf.template`;
1.2       harris41   62: 	foreach my $psv (@perlsetvars) {
1.12    ! harris41   63: 	    if ($template=~/\nPerlSetVar\s+$psv\s+(\S+)/) {
        !            64: 		my $pval=$1;
        !            65: 		$lpmlnew=~s/(\nPerlSetVar\s+$psv\s+)\S+/$1$pval/;
        !            66: 		$pvar{$psv}=$pval;
        !            67: 	    }
1.2       harris41   68: 	}
1.11      harris41   69: 	open OUT,">/etc/httpd/conf/access.conf$suffix";
                     70: 	print OUT $lpmlnew;
1.5       harris41   71: 	close OUT;
                     72:     }
1.12    ! harris41   73:     if (/^\/etc\/smb.conf$/ and -e "/etc/smb.conf$suffix") {
1.8       harris41   74: 	if ($suffixpragma eq 'lasttimestamp') {
                     75: 	    $suffix=getsuffix('/etc/smb.conf');
                     76: 	}
1.11      harris41   77: 	my $template=`/bin/cat /etc/smb.conf$suffix`;
1.5       harris41   78: 	foreach my $psv (@perlsetvars) {
                     79: 	    $template=~s/\{\{\{\{\[(.*?)\]\}\}\}\}/$pvar{$1}/ge;
                     80: 	}
1.11      harris41   81: 	open OUT,">/etc/smb.conf$suffix";
1.12    ! harris41   82: 	print OUT $template;
        !            83: 	close OUT;
        !            84:     }
        !            85:     if (/^\/etc\/samba\/smb.conf$/ and -e "/etc/samba/smb.conf$suffix") {
        !            86: 	if ($suffixpragma eq 'lasttimestamp') {
        !            87: 	    $suffix=getsuffix('/etc/samba/smb.conf');
        !            88: 	}
        !            89: 	my $template=`/bin/cat /etc/samba/smb.conf$suffix`;
        !            90: 	foreach my $psv (@perlsetvars) {
        !            91: 	    $template=~s/\{\{\{\{\[(.*?)\]\}\}\}\}/$pvar{$1}/ge;
        !            92: 	}
        !            93: 	open OUT,">/etc/samba/smb.conf$suffix";
1.2       harris41   94: 	print OUT $template;
                     95: 	close OUT;
1.1       harris41   96:     }
                     97: }
1.11      harris41   98: 
                     99: exit; # Just because this is only about restoring configuration to
                    100:       # new files
1.1       harris41  101: 
                    102: foreach (@generic_conf_files) {
1.8       harris41  103:     my $file=$_;
                    104:     if ($suffixpragma eq 'lasttimestamp') {
                    105: 	$suffix=getsuffix($file);
                    106:     }
                    107:     if (-e "$file$suffix") {
                    108: 	`/bin/mv $file $_.template`;
                    109: 	`/bin/cp $file$suffix $file`;
1.3       harris41  110:     }
1.8       harris41  111: }
                    112: 
                    113: sub getsuffix {
                    114:     my ($file)=@_;
                    115:     print "$file\n";
                    116:     my $dir=$file; $dir=~s/([^\/]+)$//;
                    117:     my $filename=$1;
                    118:     opendir(DIR,$dir);
                    119:     my @a=grep {/$filename\.\d{14}/} readdir DIR;
                    120:     closedir DIR;
                    121:     map {s/$filename\.//;} @a;
                    122:     my @b=sort {$a<=>$b} @a;
                    123:     my $suffix='.'.$b[$#b];
                    124:     return $suffix;
1.1       harris41  125: }

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