File:  [LON-CAPA] / loncom / build / loncaparestoreconfigurations
Revision 1.12: download - view: text, annotated - select for diffs
Sun Mar 3 00:21:23 2002 UTC (22 years, 4 months ago) by harris41
Branches: MAIN
CVS tags: stable_2002_april, HEAD
should process samba.conf on redhat7.* systems now...
also fixes weird formatting problem by only substituting
when there is something to substitute

    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: 			"/etc/samba/smb.conf"
   41: 			);
   42: 
   43: my @generic_conf_files=(
   44: 			"/home/httpd/lonTabs/hosts.tab",
   45: 			"/home/httpd/lonTabs/spare.tab",
   46: 			"/etc/krb.conf",
   47: 			"/etc/ntp.conf",
   48: 			"/etc/httpd/conf/srm.conf",
   49: 			"/etc/httpd/conf/httpd.conf",
   50: 			);
   51: 
   52: my @perlsetvars=("lonHostID","lonRole","lonAdmEMail","lonDefDomain","lonLoadLim","lonExpire","lonReceipt","lonSqlAccess");
   53: my %pvar;
   54: foreach (@special_conf_files) {
   55:     if (/^\/etc\/httpd\/conf\/access.conf$/) {
   56: 	if ($suffixpragma eq 'lasttimestamp') {
   57: 	    $suffix=getsuffix('/etc/httpd/conf/access.conf');
   58: 	}
   59: 	my $template=`/bin/cat /etc/httpd/conf/access.conf`;
   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`;
   62: 	foreach my $psv (@perlsetvars) {
   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: 	    }
   68: 	}
   69: 	open OUT,">/etc/httpd/conf/access.conf$suffix";
   70: 	print OUT $lpmlnew;
   71: 	close OUT;
   72:     }
   73:     if (/^\/etc\/smb.conf$/ and -e "/etc/smb.conf$suffix") {
   74: 	if ($suffixpragma eq 'lasttimestamp') {
   75: 	    $suffix=getsuffix('/etc/smb.conf');
   76: 	}
   77: 	my $template=`/bin/cat /etc/smb.conf$suffix`;
   78: 	foreach my $psv (@perlsetvars) {
   79: 	    $template=~s/\{\{\{\{\[(.*?)\]\}\}\}\}/$pvar{$1}/ge;
   80: 	}
   81: 	open OUT,">/etc/smb.conf$suffix";
   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";
   94: 	print OUT $template;
   95: 	close OUT;
   96:     }
   97: }
   98: 
   99: exit; # Just because this is only about restoring configuration to
  100:       # new files
  101: 
  102: foreach (@generic_conf_files) {
  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`;
  110:     }
  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;
  125: }

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