Annotation of loncom/build/loncaparestoreconfigurations, revision 1.8

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.1       harris41   47: 			);
                     48: 
1.5       harris41   49: my @perlsetvars=("lonHostID","lonRole","lonAdmEMail","lonDefDomain","lonLoadLim","lonExpire");
1.6       harris41   50: my %pvar;
1.1       harris41   51: foreach (@special_conf_files) {
1.3       harris41   52:     if (/^\/etc\/httpd\/conf\/access.conf$/) {
1.8     ! harris41   53: 	if ($suffixpragma eq 'lasttimestamp') {
        !            54: 	    $suffix=getsuffix('/etc/httpd/conf/access.conf');
        !            55: 	}
1.2       harris41   56: 	my $template=`/bin/cat /etc/httpd/conf/access.conf`;
1.8     ! harris41   57: 	my $rpmsave=`/bin/cat /etc/httpd/conf/access.conf$suffix`;
1.2       harris41   58: 	`/bin/mv /etc/httpd/conf/access.conf /etc/httpd/conf/access.conf.template`;
                     59: 	foreach my $psv (@perlsetvars) {
                     60: 	    $rpmsave=~/\nPerlSetVar\s+$psv\s+(\S+)/;
                     61: 	    my $pval=$1;
                     62: 	    $template=~s/(\nPerlSetVar\s+$psv\s+)\S+/$1$pval/;
1.5       harris41   63: 	    $pvar{$psv}=$pval;
1.2       harris41   64: 	}
                     65: 	open OUT,">/etc/httpd/conf/access.conf";
1.5       harris41   66: 	print OUT $template;
                     67: 	close OUT;
                     68:     }
                     69:     if (/^\/etc\/smb.conf$/) {
1.8     ! harris41   70: 	if ($suffixpragma eq 'lasttimestamp') {
        !            71: 	    $suffix=getsuffix('/etc/smb.conf');
        !            72: 	}
1.7       harris41   73: 	my $template=`/bin/cat /etc/smb.conf`;
1.5       harris41   74: 	foreach my $psv (@perlsetvars) {
                     75: 	    $template=~s/\{\{\{\{\[(.*?)\]\}\}\}\}/$pvar{$1}/ge;
                     76: 	}
                     77: 	open OUT,">/etc/smb.conf";
1.2       harris41   78: 	print OUT $template;
                     79: 	close OUT;
1.1       harris41   80:     }
                     81: }
                     82: 
                     83: foreach (@generic_conf_files) {
1.8     ! harris41   84:     my $file=$_;
        !            85:     if ($suffixpragma eq 'lasttimestamp') {
        !            86: 	$suffix=getsuffix($file);
        !            87:     }
        !            88:     if (-e "$file$suffix") {
        !            89: 	`/bin/mv $file $_.template`;
        !            90: 	`/bin/cp $file$suffix $file`;
1.3       harris41   91:     }
1.8     ! harris41   92: }
        !            93: 
        !            94: sub getsuffix {
        !            95:     my ($file)=@_;
        !            96:     print "$file\n";
        !            97:     my $dir=$file; $dir=~s/([^\/]+)$//;
        !            98:     my $filename=$1;
        !            99:     opendir(DIR,$dir);
        !           100:     my @a=grep {/$filename\.\d{14}/} readdir DIR;
        !           101:     closedir DIR;
        !           102:     map {s/$filename\.//;} @a;
        !           103:     my @b=sort {$a<=>$b} @a;
        !           104:     my $suffix='.'.$b[$#b];
        !           105:     return $suffix;
1.1       harris41  106: }

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