File:  [LON-CAPA] / loncom / build / loncaparestoreconfigurations
Revision 1.9: download - view: text, annotated - select for diffs
Wed May 9 16:50:53 2001 UTC (23 years, 1 month ago) by harris41
Branches: MAIN
CVS tags: HEAD
causing lonSqlAccess and lonExpire to be preserved..

    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 $suffix=~/^[\.\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: 			);
   48: 
   49: my @perlsetvars=("lonHostID","lonRole","lonAdmEMail","lonDefDomain","lonLoadLim","lonExpire","lonReceipt","lonSqlAccess");
   50: my %pvar;
   51: foreach (@special_conf_files) {
   52:     if (/^\/etc\/httpd\/conf\/access.conf$/) {
   53: 	if ($suffixpragma eq 'lasttimestamp') {
   54: 	    $suffix=getsuffix('/etc/httpd/conf/access.conf');
   55: 	}
   56: 	my $template=`/bin/cat /etc/httpd/conf/access.conf`;
   57: 	my $rpmsave=`/bin/cat /etc/httpd/conf/access.conf$suffix`;
   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/;
   63: 	    $pvar{$psv}=$pval;
   64: 	}
   65: 	open OUT,">/etc/httpd/conf/access.conf";
   66: 	print OUT $template;
   67: 	close OUT;
   68:     }
   69:     if (/^\/etc\/smb.conf$/) {
   70: 	if ($suffixpragma eq 'lasttimestamp') {
   71: 	    $suffix=getsuffix('/etc/smb.conf');
   72: 	}
   73: 	my $template=`/bin/cat /etc/smb.conf`;
   74: 	foreach my $psv (@perlsetvars) {
   75: 	    $template=~s/\{\{\{\{\[(.*?)\]\}\}\}\}/$pvar{$1}/ge;
   76: 	}
   77: 	open OUT,">/etc/smb.conf";
   78: 	print OUT $template;
   79: 	close OUT;
   80:     }
   81: }
   82: 
   83: foreach (@generic_conf_files) {
   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`;
   91:     }
   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;
  106: }

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