version 1.13, 2002/05/16 00:20:30
|
version 1.16, 2003/02/03 18:03:52
|
Line 4
|
Line 4
|
# |
# |
# $Id$ |
# $Id$ |
# |
# |
# YEAR=2000 |
|
# 10/25, 12/14 Scott Harrison |
|
# YEAR=2002 |
|
# Scott Harrison, 05/15 |
|
# |
|
### |
### |
|
|
# This tool helps in updating a system. It restores information for |
# This tool helps in updating a system. It restores information for |
# configuration files (.lpmlsave or other backup notations). |
# configuration files (.lpmlnew or other backup notations). |
|
|
# By default, the .lpmlsave suffix is used. |
# By default, the .lpmlsave suffix is used. |
# Alternatively, there can be two other invocations |
# Alternatively, there can be two other invocations |
Line 46 use strict; # restrict unsafe and poorly
|
Line 41 use strict; # restrict unsafe and poorly
|
# ------------------------------------ Configuration files to be concerned with |
# ------------------------------------ Configuration files to be concerned with |
my @special_conf_files=( |
my @special_conf_files=( |
'/etc/httpd/conf/loncapa.conf', |
'/etc/httpd/conf/loncapa.conf', |
'/etc/httpd/conf/access.conf', |
|
'/etc/smb.conf', |
|
'/etc/samba/smb.conf' |
|
); |
); |
|
|
my %pvar; # store the PerlSetVar variable key/value combinations |
my %pvar; # store the PerlSetVar variable key/value combinations |
Line 65 CONFLOOP: foreach (@special_conf_files)
|
Line 57 CONFLOOP: foreach (@special_conf_files)
|
|
|
my $lpmlnew_file; # file location of information that needs to be modified |
my $lpmlnew_file; # file location of information that needs to be modified |
|
|
# ------------------------------------------- access.conf (becoming deprecated) |
|
if (/^\/etc\/httpd\/conf\/access.conf$/ and |
|
-e '/etc/httpd/conf/access.conf') { |
|
if ($suffixpragma eq 'lasttimestamp' and |
|
-e '/etc/httpd/conf/access.conf'.$suffix) { |
|
$suffix=&getsuffix('/etc/httpd/conf/access.conf'); |
|
unless (-e '/etc/httpd/conf/access.conf'.$suffix) { |
|
next CONFLOOP; |
|
} |
|
$lpmlold="\n".&readfile('/etc/httpd/conf/access.conf'.$suffix); |
|
$lpmlnew_file='/etc/httpd/conf/access.conf'; |
|
$lpmlnew=&readfile($lpmlnew_file); |
|
} |
|
else { |
|
$lpmlold="\n".&readfile('/etc/httpd/conf/access.conf'); |
|
$lpmlnew_file='/etc/httpd/conf/access.conf'.$suffix; |
|
unless (-e $lpmlnew_file) { |
|
next CONFLOOP; |
|
} |
|
$lpmlnew=&readfile($lpmlnew_file); |
|
} |
|
while($lpmlold=~/\n\s*PerlSetVar\s+(\S+)\s+(\S+)/mcg) { |
|
my $pkey=$1; my $pval=$2; |
|
$lpmlnew=~s/(\n\s*PerlSetVar\s+$pkey\s+)\S+/$1$pval/; |
|
$pvar{$pkey}=$pval; |
|
} |
|
} |
|
|
|
# ---------------------------------------------------------------- loncapa.conf |
# ---------------------------------------------------------------- loncapa.conf |
elsif (/^\/etc\/httpd\/conf\/loncapa.conf$/ and |
if (/^\/etc\/httpd\/conf\/loncapa.conf$/ and |
-e '/etc/httpd/conf/loncapa.conf') { |
-e '/etc/httpd/conf/loncapa.conf') |
|
{ |
if ($suffixpragma eq 'lasttimestamp' and |
if ($suffixpragma eq 'lasttimestamp' and |
-e '/etc/httpd/conf/loncapa.conf') { |
-e '/etc/httpd/conf/loncapa.conf') |
|
{ |
$suffix=&getsuffix('/etc/httpd/conf/loncapa.conf'); |
$suffix=&getsuffix('/etc/httpd/conf/loncapa.conf'); |
unless (-e '/etc/httpd/conf/loncapa.conf'.$suffix) { |
unless (-e '/etc/httpd/conf/loncapa.conf'.$suffix) |
|
{ |
next CONFLOOP; |
next CONFLOOP; |
} |
} |
$lpmlold="\n".&readfile('/etc/httpd/conf/loncapa.conf'.$suffix); |
$lpmlold="\n".&readfile('/etc/httpd/conf/loncapa.conf'.$suffix); |
$lpmlnew_file='/etc/httpd/conf/loncapa.conf'; |
$lpmlnew_file='/etc/httpd/conf/loncapa.conf'; |
$lpmlnew=&readfile($lpmlnew_file); |
$lpmlnew=&readfile($lpmlnew_file); |
} |
} |
else { |
else |
|
{ |
$lpmlold="\n".&readfile('/etc/httpd/conf/loncapa.conf'); |
$lpmlold="\n".&readfile('/etc/httpd/conf/loncapa.conf'); |
$lpmlnew_file='/etc/httpd/conf/loncapa.conf'.$suffix; |
$lpmlnew_file='/etc/httpd/conf/loncapa.conf'.$suffix; |
unless (-e $lpmlnew_file) { |
unless (-e $lpmlnew_file) |
|
{ |
next CONFLOOP; |
next CONFLOOP; |
} |
} |
$lpmlnew=&readfile($lpmlnew_file); |
$lpmlnew=&readfile($lpmlnew_file); |
} |
} |
while($lpmlold=~/\n\s*PerlSetVar\s+(\S+)\s+(\S+)/mcg) { |
while($lpmlold=~/\n\s*PerlSetVar\s+(\S+)\s+(\S+)/mcg) |
|
{ |
my $pkey=$1; my $pval=$2; |
my $pkey=$1; my $pval=$2; |
$pvar{$pkey}=$pval; |
$pvar{$pkey}=$pval; |
} |
} |
foreach my $pkey (keys %pvar) { |
foreach my $pkey (keys %pvar) |
|
{ |
my $pval=$pvar{$pkey}; |
my $pval=$pvar{$pkey}; |
$lpmlnew=~s/(\n\s*PerlSetVar\s+$pkey\s+)\S+/$1$pval/; |
$lpmlnew=~s/(\n\s*PerlSetVar\s+$pkey\s+)\S+/$1$pval/; |
} |
} |
open(OUT,'>'.$lpmlnew_file) or |
open(OUT,'>'.$lpmlnew_file) or |
die('Cannot open '.$lpmlnew_file.' for output'."\n"); |
die('Cannot open '.$lpmlnew_file.' for output'."\n"); |
print(OUT $lpmlnew); |
print(OUT $lpmlnew); |
close(OUT); |
close(OUT); |
} |
} |
|
|
# -------------------------------------------------------------------- smb.conf |
# ---------------------- smb.conf (probably will be deprecated in 2004 or 2005) |
elsif (/^\/etc\/smb.conf$/ and -e "/etc/smb.conf$suffix") { |
elsif (/^\/etc\/smb.conf$/ and -e "/etc/smb.conf$suffix") |
if ($suffixpragma eq 'lasttimestamp') { |
{ |
|
if ($suffixpragma eq 'lasttimestamp') |
|
{ |
$suffix=&getsuffix('/etc/smb.conf'); |
$suffix=&getsuffix('/etc/smb.conf'); |
unless (-e '/etc/httpd/conf/loncapa.conf'.$suffix) { |
unless (-e '/etc/httpd/conf/loncapa.conf'.$suffix) |
|
{ |
next CONFLOOP; |
next CONFLOOP; |
} |
} |
$lpmlnew=&readfile('/etc/smb.conf'); |
$lpmlnew = &readfile('/etc/smb.conf'); |
$lpmlnew_file='/etc/smb.conf'; |
$lpmlnew_file = '/etc/smb.conf'; |
} |
} |
else { |
else |
$lpmlnew=&readfile('/etc/smb.conf'.$suffix); |
{ |
$lpmlnew_file='/etc/smb.conf'.$suffix; |
$lpmlnew = &readfile('/etc/smb.conf'.$suffix); |
} |
$lpmlnew_file = '/etc/smb.conf'.$suffix; |
$lpmlnew=~s/\{\{\{\{\[(.*?)\]\}\}\}\}/$pvar{$1}/ge; |
} |
|
$lpmlnew =~ s/\{\{\{\{\[(.*?)\]\}\}\}\}/$pvar{$1}/ge; |
open(OUT,'>'.$lpmlnew_file) or |
open(OUT,'>'.$lpmlnew_file) or |
die('Cannot open '.$lpmlnew_file.' for output'."\n"); |
die('Cannot open '.$lpmlnew_file.' for output'."\n"); |
print(OUT $lpmlnew); |
print(OUT $lpmlnew); |
close(OUT); |
close(OUT); |
} |
} |
elsif (/^\/etc\/samba\/smb.conf$/ and -e "/etc/samba/smb.conf$suffix") { |
elsif (/^\/etc\/samba\/smb.conf$/ and -e "/etc/samba/smb.conf$suffix") |
if ($suffixpragma eq 'lasttimestamp') { |
{ |
$suffix=&getsuffix('/etc/samba/smb.conf'); |
if ($suffixpragma eq 'lasttimestamp') |
unless (-e '/etc/samba/smb.conf'.$suffix) { |
{ |
|
$suffix = &getsuffix('/etc/samba/smb.conf'); |
|
unless (-e '/etc/samba/smb.conf'.$suffix) |
|
{ |
next CONFLOOP; |
next CONFLOOP; |
} |
} |
$lpmlnew=&readfile('/etc/samba/smb.conf'); |
$lpmlnew = &readfile('/etc/samba/smb.conf'); |
$lpmlnew_file='/etc/samba/smb.conf'; |
$lpmlnew_file = '/etc/samba/smb.conf'; |
} |
} |
else { |
else |
$lpmlnew=&readfile('/etc/samba/smb.conf'.$suffix); |
{ |
$lpmlnew_file='/etc/samba/smb.conf'.$suffix; |
$lpmlnew = &readfile('/etc/samba/smb.conf'.$suffix); |
} |
$lpmlnew_file = '/etc/samba/smb.conf'.$suffix; |
$lpmlnew=~s/\{\{\{\{\[(.*?)\]\}\}\}\}/$pvar{$1}/ge; |
} |
|
$lpmlnew =~ s/\{\{\{\{\[(.*?)\]\}\}\}\}/$pvar{$1}/ge; |
open(OUT,'>'.$lpmlnew_file) or |
open(OUT,'>'.$lpmlnew_file) or |
die('Cannot open '.$lpmlnew_file.' for output'."\n"); |
die('Cannot open '.$lpmlnew_file.' for output'."\n"); |
print(OUT $lpmlnew); |
print(OUT $lpmlnew); |
close(OUT); |
close(OUT); |
} |
} |
} |
} |
|
|
# --------------------------------- getsuffix: get the latest time stamp suffix |
# --------------------------------- getsuffix: get the latest time stamp suffix |
# === INPUT: filename without suffix |
# === INPUT: filename without suffix |
# === OUTPUT: the latest time stamp suffix; 14 digits YYYYMMDDhhmmss |
# === OUTPUT: the latest time stamp suffix; 14 digits YYYYMMDDhhmmss |
# === ERROR: cannot read the directory in which the filenames reside |
# === ERROR: cannot read the directory in which the filenames reside |
sub getsuffix { |
sub getsuffix ($) |
my ($file)=@_; |
{ |
|
my ($file) = @_; |
print("$file\n"); |
print("$file\n"); |
my $dir=$file; $dir=~s/([^\/]+)$//; |
my $dir = $file; $dir =~ s/([^\/]+)$//; |
my $filename=$1; |
my $filename = $1; |
opendir(DIR,$dir) or |
opendir(DIR,$dir) or |
die('Cannot open directory '.$dir.' for viewing'."\n"); |
die('Cannot open directory '.$dir.' for viewing'."\n"); |
my @a=grep {/$filename\.\d{14}/} readdir(DIR); |
my @a = grep {/$filename\.\d{14}/} readdir(DIR); |
closedir(DIR); |
closedir(DIR); |
map {s/$filename\.//;} @a; |
map {s/$filename\.//;} @a; |
my @b=sort {$a<=>$b} @a; |
my @b = sort {$a<=>$b} @a; |
my $suffix='.'.$b[$#b]; |
my $suffix = '.'.$b[$#b]; |
return($suffix); |
return($suffix); |
} |
} |
|
|
# -------------------------- readfile: get the file contents in a scalar string |
# -------------------------- readfile: get the file contents in a scalar string |
# === INPUT: filename |
# === INPUT: filename |
# === OUTPUT: the filename's contents |
# === OUTPUT: the filename's contents |
# === ERROR: cannot read the file |
# === ERROR: cannot read the file |
# === NOTE: big files will hog computer memory |
# === NOTE: big files will hog computer memory |
sub readfile { |
sub readfile ($) |
my ($filename)=@_; |
{ |
my $contents=''; |
my ($filename) = @_; |
|
my $contents = ''; |
open(IN,'<'.$filename) or die ('Cannot read '.$filename."\n"); |
open(IN,'<'.$filename) or die ('Cannot read '.$filename."\n"); |
while(<IN>) {$contents.=$_;} |
while(<IN>) {$contents .= $_;} |
close(IN); |
close(IN); |
return($contents); |
return($contents); |
} |
} |
|
|
=pod |
=pod |
|
|
Line 311 invokes this script in B<aggressive upda
|
Line 292 invokes this script in B<aggressive upda
|
|
|
=head1 AUTHORS |
=head1 AUTHORS |
|
|
Scott Harrison |
|
|
|
This module is free software; you can redistribute it |
This script is free software; you can redistribute it |
and/or modify it under the same terms as LON-CAPA itself. |
and/or modify it under the same terms as LON-CAPA itself. |
|
|
=cut |
=cut |