mhonarc-commits
[Top] [All Lists]

CVS: mharc install.pl,1.2,1.3

2002-09-26 22:12:27
Update of /cvsroot/mhonarc/mharc
In directory subversions:/tmp/cvs-serv6420

Modified Files:
	install.pl 
Log Message:
Numerous changes:
* Try to handle upgrades to installation that have different directory
  locations for HTML_DIR than the default.  CGI_DIR is also handled,
  but this is a new variable.
* Predefine more config.sh variables: PROCMAIL, LOCKFILE, FORMAIL.
* Prompt user if they want to edit config.sh.
* Prompt user if they want to edit lists.def (for new installs).
* Moved some verbose output to debug so screen is not overly cluttered
  with output for normal installs.


Index: install.pl
===================================================================
RCS file: /cvsroot/mhonarc/mharc/install.pl,v
retrieving revision 1.2
retrieving revision 1.3
diff -C2 -r1.2 -r1.3
*** install.pl	24 Sep 2002 06:38:58 -0000	1.2
--- install.pl	27 Sep 2002 05:12:12 -0000	1.3
***************
*** 35,38 ****
--- 35,39 ----
  use Cwd;
  use Getopt::Long;
+ use MHArc::Config;
  use MHArc::Util qw( usage run_prg cmd ch_dir );
  
***************
*** 53,61 ****
  my $Pwd	       = undef;
  
! my @CgiScripts = qw(
!   cgi-bin/extract-mesg.cgi.in.dist
!   cgi-bin/mesg.cgi.in.dist
!   cgi-bin/mnav.cgi.in.dist
! );
  
  my @PerlScripts = (qw(
--- 54,60 ----
  my $Pwd	       = undef;
  
! my $Procmail   = undef;
! my $Formail    = undef;
! my $Lockfile   = undef;
  
  my @PerlScripts = (qw(
***************
*** 73,77 ****
    bin/read-mail
    bin/web-archive
! ), @CgiScripts);
  
  ##--------------------------------------------------------------------------##
--- 72,83 ----
    bin/read-mail
    bin/web-archive
! ));
! 
! # We prepend pathname components during installation
! my @CgiScripts = qw(
!   extract-mesg.cgi.in.dist
!   mesg.cgi.in.dist
!   mnav.cgi.in.dist
! );
  
  ##--------------------------------------------------------------------------##
***************
*** 85,88 ****
--- 91,95 ----
      'url=s'	  => \$Url,
  
+     'debug!'      => \$Debug,
      'verbose!'    => \$Verbose,
  
***************
*** 95,110 ****
  
    $Verbose = 1  if $Debug;
!   $MHArc::Util::ECHO_CMDS = $Verbose;
  
!   ch_dir($Dir) ||
!       die qq/ERROR: Unable to chdir to "$Dir": $!\n/;
!   $Make    = find_make() || 'make';
!   $Tar	   = find_program('tar') || 'tar';
!   $Cp	   = find_program('cp') || 'cp';
!   $Mkdir   = find_program('mkdir') || 'mkdir';
!   $Pwd     = find_program('pwd') || 'pwd';
!   $Perl    = $Config{'perlpath'}  unless defined($Perl);
  
!   my $run_config = 0;
  
    # Create installation directory
--- 102,126 ----
  
    $Verbose = 1  if $Debug;
!   $MHArc::Util::ECHO_CMDS = $Debug;
  
!   ch_dir($Dir) || die qq/ERROR: Unable to chdir to "$Dir": $!\n/;
  
!   $Make     = find_make() || 'make';
!   $Tar	    = find_program('tar') || 'tar';
!   $Cp	    = find_program('cp') || 'cp';
!   $Mkdir    = find_program('mkdir') || 'mkdir';
!   $Pwd      = find_program('pwd') || 'pwd';
!   $Perl     = $Config{'perlpath'}  unless defined($Perl);
! 
!   $Mhonarc  = find_mhonarc();
!   $Mknmz    = find_mknmz();
!   $Nmzcgi   = find_namazu_cgi();
!   $Procmail = find_program('procmail');
!   $Formail  = find_program('formail');
!   $Lockfile = find_program('lockfile');
! 
!   my $run_config     = 0;
!   my $run_procmailrc = 0;
!   my $tar_v	     = 'v'  if $Debug;
  
    # Create installation directory
***************
*** 142,201 ****
  
    my $cwd_path = Cwd::abs_path('.');
!   $InstallDir = Cwd::abs_path($InstallDir);
!   print qq/Current working directory: $cwd_path\n/  if $Verbose;
  
!   # Copy files
    if ($InstallDir ne $cwd_path) {
!     run_prg("$Tar cf - . | (cd \"$InstallDir\" && tar xvf -)");
    }
  
!   ch_dir($InstallDir) ||
!       die qq/ERROR: Unable to chdir to "$InstallDir": $!\n/;
  
    # Edit Perl scripts to reference where perl is located
!   edit_perl_scripts($Perl, @PerlScripts);
  
    # Check CGI programs
!   if (check_cgi_scripts(@CgiScripts)) {
      $run_config = 1;
    }
  
!   # If a new install, create lib/config.sh
!   if (! -e 'lib/config.sh') {
!     my @vars = (
!       'SW_ROOT' => $InstallDir,
!     );
!     run_prg($Cp, 'lib/config.sh.dist', 'lib/config.sh');
  
!     # check for mhonarc library
!     $Mhonarc = find_mhonarc();
!     if (defined($Mhonarc)) {
!       my $mha_lib = extract_mhonarc_lib($Mhonarc);
!       if (defined($mha_lib)) {
! 	eval {
! 	  require "$mha_lib/mhamain.pl";
! 	};
! 	if ($@) {
! 	  warn qq/WARNING: Unable to load MHonArc: $(_at_)\n/;
! 	} else {
! 	  push(@vars, 'MHONARC_LIB' => $mha_lib);
! 	}
        }
      }
  
!     # check for mknmz
!     $Mknmz = find_mknmz();
!     if (!defined($Mknmz)) {
!       print '-' x 72, "\n";
        print <<EOT;
! Make sure the MKNMZ variable in
!     $InstallDir/lib/config.sh
! is set to the full pathname of mknmz on your system.
  EOT
-       print '-' x 72, "\n";
      } else {
!       push(@vars, 'MKNMZ' => $Mknmz);
      }
  
      # ask for root url
      if (!defined($Url) && !$Batch) {
--- 158,332 ----
  
    my $cwd_path = Cwd::abs_path('.');
!   $InstallDir  = Cwd::abs_path($InstallDir);
!   print qq/Current working directory: $cwd_path\n/  if $Debug;
! 
!   # Check if doing an upgrade
!   my $cur_config   = undef;
!   my $cur_mbox_dir = undef;
!   my $cur_html_dir = undef;
!   my $cur_cgi_dir  = undef;
!   if (-e "$InstallDir/lib/config.sh") {
!     $cur_config   = MHArc::Config->load("$InstallDir/lib/config.sh");
!     $cur_mbox_dir = Cwd::abs_path($cur_config->{'MBOX_DIR'});
!     $cur_html_dir = Cwd::abs_path($cur_config->{'HTML_DIR'});
!     $cur_cgi_dir  = Cwd::abs_path($cur_config->{'CGI_DIR'});
!   }
!   if (!$cur_mbox_dir) { $cur_mbox_dir = "$InstallDir/mbox"; }
!   if (!$cur_html_dir) { $cur_html_dir = "$InstallDir/html"; }
!   if (!$cur_cgi_dir)  { $cur_cgi_dir  = "$InstallDir/cgi-bin"; }
! 
!   # make sure that html and cgi-bin directories exist
!   run_prg($Mkdir, '-p', $cur_mbox_dir)  unless -e $cur_mbox_dir;
!   run_prg($Mkdir, '-p', $cur_html_dir)  unless -e $cur_html_dir;
!   run_prg($Mkdir, '-p', $cur_cgi_dir)   unless -e $cur_cgi_dir;
! 
!   # Grab list of files to copy
!   local(*DIR);
!   opendir(DIR, '.') || die qq/ERROR: Unable to open "$cwd_path": $!\n/;
!   my @copy_files = grep { !/^\./ &&
! 			  ($_ ne 'install.pl') &&
! 			# ($_ ne 'INSTALL') &&
! 			# ($_ ne 'README') &&
! 			# ($_ ne 'NEWS') &&
! 			# ($_ ne 'TODO') &&
! 			  ($_ ne 'dist') &&
! 			  ($_ ne 'mbox') &&
! 			  ($_ ne 'html') &&
! 			  ($_ ne 'cgi-bin') } readdir(DIR);
!   closedir(DIR);
  
!   # Copy files (nothing for mbox, so we do not mess with it, yet)
    if ($InstallDir ne $cwd_path) {
!     print qq/Copying files into "$InstallDir"...\n/  if $Verbose;
!     run_prg("$Tar cf - @copy_files | (cd \"$InstallDir\" && tar x${tar_v}f -)");
    }
+   if ($cur_html_dir ne "$cwd_path/html") {
+     print qq/Copying files into "$cur_html_dir"...\n/  if $Verbose;
+     ch_dir('html')    || die qq/ERROR: Unable to chdir to "html": $!\n/;
+     run_prg("$Tar cf - . | (cd \"$cur_html_dir\" && tar x${tar_v}f -)");
+     ch_dir($cwd_path) || die qq/ERROR: Unable to chdir to "$cwd_path": $!\n/;
+   }
+   if ($cur_cgi_dir ne "$cwd_path/cgi-bin") {
+     print qq/Copying files into "$cur_cgi_dir"...\n/  if $Verbose;
+     ch_dir('cgi-bin') || die qq/ERROR: Unable to chdir to "cgi-bin": $!\n/;
+     run_prg("$Tar cf - . | (cd \"$cur_cgi_dir\" && tar x${tar_v}f -)");
+     ch_dir($cwd_path) || die qq/ERROR: Unable to chdir to "$cwd_path": $!\n/;
+   }
+ 
+   # We now work in the installation directory
+   ch_dir($InstallDir) || die qq/ERROR: Unable to chdir to "$InstallDir": $!\n/;
  
!   my @cgi_scripts = map { "$cur_cgi_dir/$_" } @CgiScripts;
  
    # Edit Perl scripts to reference where perl is located
!   edit_perl_scripts($Perl, @PerlScripts, @cgi_scripts);
  
    # Check CGI programs
!   if (check_cgi_scripts(@cgi_scripts)) {
      $run_config = 1;
    }
  
!   # config.sh variables we will define if new installation
!   my @vars = ( 'SW_ROOT' => $InstallDir );
  
!   # check for mhonarc library
!   if (defined($cur_config) && $cur_config->{'MHONARC_LIB'}) {
!     eval {
!       require join('/', $cur_config->{'MHONARC_LIB'}, 'mhamain.pl');
!     };
!     if ($@) {
!       warn qq/WARNING: Unable to load MHonArc: $(_at_)\n/;
!     }
! 
!   } elsif (defined($Mhonarc)) {
!     my $mha_lib = extract_mhonarc_lib($Mhonarc);
!     if (defined($mha_lib)) {
!       eval {
! 	require "$mha_lib/mhamain.pl";
!       };
!       if ($@) {
! 	warn qq/WARNING: Unable to load MHonArc: $(_at_)\n/;
!       } else {
! 	push(@vars, 'MHONARC_LIB' => $mha_lib);
        }
      }
+   } else {
+     print <<EOT;
+  ----------------------------------------------------------------------
+ | Make sure the MHONARC_LIB variable in
+ |    $InstallDir/lib/config.sh
+ | is set to the full pathname of the directory containing MHonArc
+ | libraries.
+  ----------------------------------------------------------------------
+ EOT
+   }
  
!   # check for mknmz
!   if (!defined($Mknmz)) {
!     print <<EOT;
!  ----------------------------------------------------------------------
! | Make sure the MKNMZ variable in
! |    $InstallDir/lib/config.sh
! | is set to the full pathname of the mknmz program on your system.
!  ----------------------------------------------------------------------
! EOT
!   } else {
!     push(@vars, 'MKNMZ' => $Mknmz);
!   }
! 
!   # check for procmail
!   if (!defined($Procmail)) {
!     print <<EOT;
!  ----------------------------------------------------------------------
! | Make sure the PROCMAIL variable in
! |    $InstallDir/lib/config.sh
! | is set to the full pathname of the procmail program on your system.
!  ----------------------------------------------------------------------
! EOT
!   } else {
!     push(@vars, 'PROCMAIL' => $Procmail);
!   }
! 
!   # check for formail
!   if (!defined($Formail)) {
!     print <<EOT;
!  ----------------------------------------------------------------------
! | Make sure the FORMAIL variable in
! |    $InstallDir/lib/config.sh
! | is set to the full pathname of the formail program on your system.
!  ----------------------------------------------------------------------
! EOT
!   } else {
!     push(@vars, 'FORMAIL' => $Formail);
!   }
! 
!   # check for lockfile
!   if (!defined($Lockfile)) {
!     print <<EOT;
!  ----------------------------------------------------------------------
! | Make sure the LOCKFILE variable in
! |    $InstallDir/lib/config.sh
! | is set to the full pathname of the lockfile program on your system.
!  ----------------------------------------------------------------------
! EOT
!   } else {
!     push(@vars, 'LOCKFILE' => $Lockfile);
!   }
! 
!   # Check that namazu.cgi exists in cgi-bin
!   if (! -e "$cur_cgi_dir/namazu.cgi") {
!     if (!defined($Nmzcgi)) {
        print <<EOT;
!  -----------------------------------------------------------------------
! | Make sure to copy namazu.cgi into
! |    $cur_cgi_dir
!  -----------------------------------------------------------------------
  EOT
      } else {
!       run_prg($Cp, $Nmzcgi, $cur_cgi_dir);
      }
+   }
  
+   if (!defined($cur_config)) {
      # ask for root url
      if (!defined($Url) && !$Batch) {
***************
*** 207,212 ****
        push(@vars, 'ROOT_URL' => $Url);
      }
  
!     edit_config_sh('lib/config.sh', @vars);
      $run_config = 1;
    }
--- 338,349 ----
        push(@vars, 'ROOT_URL' => $Url);
      }
+   }
  
!   edit_config_sh('lib/config.sh.dist', @vars);
!   if (!defined($cur_config)) {
!     run_prg($Cp, 'lib/config.sh.dist', 'lib/config.sh');
!     $run_config = 1;
!   }
!   if (manual_file_edit('lib/config.sh', 1)) {
      $run_config = 1;
    }
***************
*** 215,233 ****
    if (! -e 'lib/lists.def') {
      run_prg($Cp, 'lib/lists.def.dist', 'lib/lists.def');
!   }
! 
!   # Check that namazu.cgi exists in cgi-bin
!   if (! -e 'cgi-bin/namazu.cgi') {
!     $Nmzcgi = find_namazu_cgi();
!     if (!defined($Nmzcgi)) {
!       print '-' x 72, "\n";
!       print <<EOT;
! Make sure to copy namazu.cgi into
!     $InstallDir/cgi-bin
! or edit SEARCH_CGI variable in
!     $InstallDir/lib/config.sh
! to reflect URL location of namazu.cgi.
! EOT
!       print '-' x 72, "\n";
      }
    }
--- 352,357 ----
    if (! -e 'lib/lists.def') {
      run_prg($Cp, 'lib/lists.def.dist', 'lib/lists.def');
!     if (manual_file_edit('lib/lists.def', 1)) {
!       $run_procmailrc = 1;
      }
    }
***************
*** 239,250 ****
    apply_config()  if $run_config;
  
!   print '-' x 72, "\n";
    print <<EOT;
! Please read the document
!     $InstallDir/doc/install.html
!     (Text Version: $InstallDir/INSTALL)
! to finish the installation process.
  EOT
-   print '-' x 72, "\n";
  
  } # End: MAIN
--- 363,376 ----
    apply_config()  if $run_config;
  
!   # Create procmailrc
!   run_prg('bin/mk-procmailrc')  if $run_procmailrc;
! 
    print <<EOT;
!  -----------------------------------------------------------------------
! | Please read the mharc installation document for instructions on
! | finishing the installation process.  A copy is located at:
! | $InstallDir/doc/install.html
!  -----------------------------------------------------------------------
  EOT
  
  } # End: MAIN
***************
*** 253,262 ****
  
  sub apply_config {
!   print "Applying configuration (this may take awhile)...\n"
!       if $Verbose;
!   # XXX: Should we show what is going, could be cause important messages
!   #      to scroll off screen.
!   local $MHArc::Util::ECHO_CMDS = 0;
!   run_prg('bin/apply-config');
  }
  
--- 379,386 ----
  
  sub apply_config {
!   print "Applying configuration (this may take awhile)...\n" if $Verbose;
!   my @cmd = ( 'bin/apply-config' );
!   push(@cmd, '-verbose')  if $Debug;
!   run_prg(@cmd);
  }
  
***************
*** 492,495 ****
--- 616,620 ----
    }
  
+   my %found = ( );
    local $_;
    while (<CFG_IN>) {
***************
*** 498,506 ****
  	my $var = $1;
  	my $val = $vars{$var};
! 	if ($val =~ /\s/) {
! 	  $val = '"' . $val . '"';
! 	}
  	#print CFG_OUT '#', $_;
  	print CFG_OUT $var, '=', $val, "\n";
  	next;
        }
--- 623,630 ----
  	my $var = $1;
  	my $val = $vars{$var};
! 	if ($val =~ /\s/) { $val = '"' . $val . '"'; }
  	#print CFG_OUT '#', $_;
  	print CFG_OUT $var, '=', $val, "\n";
+ 	$found{$var} = 1;
  	next;
        }
***************
*** 508,511 ****
--- 632,647 ----
      print CFG_OUT $_;
    }
+   foreach (sort keys %vars) {
+     next  if $found{$_};
+     print CFG_OUT "\n", '# Added by install.pl', "\n";
+     print CFG_OUT $_, '=';
+     if ($vars{$_} =~ /\s/) {
+       print CFG_OUT '"', $vars{$_}, '"';
+     } else {
+       print CFG_OUT $vars{$_};
+     }
+     print CFG_OUT "\n";
+   }
+ 
    close CFG_OUT;
    close CFG_IN;
***************
*** 515,518 ****
--- 651,669 ----
  }
  
+ sub manual_file_edit {
+   return 0  if $Batch;
+   my $file = shift;
+   my $default = shift;
+   my $editor = $ENV{'EDITOR'} || 'vi';
+   if (prompt_user_yn(qq/Would like to edit "$file" with "$editor"?/,
+ 		     $default)) {
+     if (cmd($editor, $file) != 0) {
+       warn qq/WARNING: "$editor" exited with non-zero status: $?\n/;
+     }
+     return 1;
+   }
+   0;
+ }
+ 
  sub prompt_user_yn {
    my $prompt = shift;
***************
*** 564,571 ****
  =item C<-batch>
  
! Do not prompt for anything.  All confirmations prompts default to 'y'
! and all other prompts will use whatever the default value is.
  
  If this option is specified, then C<-path> must also be specified.
  
  =item C<-help>
--- 715,727 ----
  =item C<-batch>
  
! Do not prompt for anything.  All prompts will default to the default
! choice (which may not be what you want).
  
  If this option is specified, then C<-path> must also be specified.
+ 
+ =item C<-debug>
+ 
+ Generate more output than C<-verbose>.  This option can generate
+ alot of output.
  
  =item C<-help>

---------------------------------------------------------------------
To sign-off this list, send email to majordomo(_at_)mhonarc(_dot_)org with the
message text UNSUBSCRIBE MHONARC-DEV