home *** CD-ROM | disk | FTP | other *** search
/ Australian Personal Computer 2004 July / APC0407D2.iso / workshop / apache / files / ActivePerl-5.6.1.638-MSWin32-x86.msi / _1e88b6658f6f978088b0eba873f06720 < prev    next >
Encoding:
Text File  |  2004-04-13  |  5.3 KB  |  242 lines

  1. ###############################################################################
  2. #
  3. # Script:    config.pl
  4. # Purpose:    Fix up Config.pm after a binary installation
  5. #
  6. # Copyright (c) 1999-2003 ActiveState Corp.  All rights reserved.
  7. #
  8. ###############################################################################
  9.  
  10. my $prefix = shift;
  11. # get prefix from script location, ignoring the last two components
  12. $prefix = $1 if !$prefix and $0 =~ m#^(.*)([\\/][^\\/]+){2}$#;
  13. $prefix =~ s{[\\/]$}{};
  14. my $libpth = $ENV{LIB};
  15. my $user   = $ENV{USERNAME};
  16. my $file   = $prefix . '\lib\Config.pm';
  17. my $oldfile = $prefix . '\lib\Config.pm~';
  18.  
  19. $tmp = $ENV{'TEMP'} || $ENV{'tmp'};
  20. if ($^O =~ /MSWin/) {
  21.     $tmp ||= 'c:/temp';
  22. }
  23. else {
  24.     $tmp ||= '/tmp';
  25. }
  26.  
  27. print 'Configuring Perl ... ' . "\n";
  28.  
  29. # Remove the "command" value from the file association to prevent the MSI
  30. # "Repair" feature from triggering once an included extension has been
  31. # upgraded by PPM.
  32. if ($^O =~ /MSWin/) {
  33.     require Win32::Registry;
  34.     $::HKEY_CLASSES_ROOT->Open('Perl\shell\Open\command', my $command);
  35.     $command->DeleteValue('command') if $command;
  36. }
  37.  
  38. my %replacements = (
  39.     archlib            => "'$prefix\\lib'",
  40.     archlibexp        => "'$prefix\\lib'",
  41.     bin            => "'$prefix\\bin'",
  42.     binexp            => "'$prefix\\bin'",
  43.     cf_by            => "'ActiveState'",
  44.     installarchlib        => "'$prefix\\lib'",
  45.     installbin        => "'$prefix\\bin'",
  46.     installhtmldir        => "'$prefix\\html'",
  47.     installhtmlhelpdir     => "'$prefix\\htmlhelp'",
  48.     installman1dir        => "''",
  49.     installman3dir        => "''",
  50.     installprefix        => "'$prefix'",
  51.     installprefixexp    => "'$prefix'",
  52.     installprivlib        => "'$prefix\\lib'",
  53.     installscript        => "'$prefix\\bin'",
  54.     installsitearch        => "'$prefix\\site\\lib'",
  55.     installsitebin        => "'$prefix\\bin'",
  56.     installsitelib        => "'$prefix\\site\\lib'",
  57.     libpth            => q('") . join(q(" "), split(/;/, $libpth), $prefix . "\\lib\\CORE") . q("'),
  58.     man1dir            => "''",
  59.     man1direxp        => "''",
  60.     man3dir            => "''",
  61.     man3direxp        => "''",
  62.     perlpath        => "'$prefix\\bin\\perl.exe'",
  63.     prefix            => "'$prefix'",
  64.     prefixexp        => "'$prefix'",
  65.     privlib            => "'$prefix\\lib'",
  66.     privlibexp        => "'$prefix\\lib'",
  67.     scriptdir        => "'$prefix\\bin'",
  68.     scriptdirexp        => "'$prefix\\bin'",
  69.     sitearch        => "'$prefix\\site\\lib'",
  70.     sitearchexp        => "'$prefix\\site\\lib'",
  71.     sitebin            => "'$prefix\\site\\bin'",
  72.     sitebinexp        => "'$prefix\\site\\bin'",
  73.     sitelib            => "'$prefix\\site\\lib'",
  74.     sitelibexp        => "'$prefix\\site\\lib'",
  75.     siteprefix        => "'$prefix\\site'",
  76.     siteprefixexp        => "'$prefix\\site'",
  77. );
  78.  
  79. my $pattern = '^(' . join('|', keys %replacements) . ')=.*';
  80.  
  81. chmod(0644, $file)
  82.     or warn "Unable to chmod(0644, $file) : $!";
  83.     
  84. if(open(FILE, "+<$file")) {
  85.     my @Config;
  86.     while(<FILE>) {
  87.     s/$pattern/$1=$replacements{$1}/;
  88.     push(@Config, $_); 
  89.     }
  90.  
  91.     seek(FILE, 0, 0);
  92.     truncate(FILE, 0);
  93.     print FILE @Config;
  94.     close(FILE);
  95. }
  96. else {
  97.     print "Unable to open $file : $!\n\n";
  98.     print "Press [Enter] to continue:\n";
  99.     <STDIN>;
  100.     exit 1;
  101. }
  102.  
  103. ###############################################################################
  104. # Config.pm values to propogate when doing an upgrade installation
  105. ###############################################################################
  106. my @propagateThese = qw(
  107.     ar
  108.     awk
  109.     bash
  110.     bin
  111.     binexp
  112.     bison
  113.     byacc
  114.     cat
  115.     cc
  116.     cp
  117.     cryptlib
  118.     csh
  119.     date
  120.     echo
  121.     egrep
  122.     emacs
  123.     expr
  124.     find
  125.     flex
  126.     full_csh
  127.     full_sed
  128.     gccversion
  129.     glibpth
  130.     gzip
  131.     incpath
  132.     inews
  133.     ksh
  134.     ld
  135.     lddlflags
  136.     ldflags
  137.     less
  138.     libc
  139.     libpth
  140.     ln
  141.     lns
  142.     loincpth
  143.     lolibpth
  144.     lp
  145.     lpr
  146.     ls
  147.     mail
  148.     mailx
  149.     make
  150.     mkdir
  151.     more
  152.     mv
  153.     mydomain
  154.     myhostname
  155.     myuname
  156.     pager
  157.     rm
  158.     rmail
  159.     sed
  160.     sendmail
  161.     sh
  162.     tar
  163.     touch
  164.     tr
  165.     usrinc
  166.     vi
  167.     xlibpth
  168.     zcat
  169.     zip
  170. );
  171.  
  172. if(-f $oldfile) {
  173.     mergeConfig($oldfile, $file);
  174. }
  175.  
  176. ###############################################################################
  177. #
  178. ###############################################################################
  179. sub mergeConfig {
  180.     my $file1 = shift;
  181.     my $file2 = shift;
  182.  
  183.     open(FILE1, "<$file1")
  184.     || do {
  185.         warn "Could not open file $file1 : $!";
  186.         return -1;
  187.     };
  188.     
  189.     my $foundConfigBegin = 0;
  190.     my $foundConfigEnd = 0;
  191.     my %Config1 = ();
  192.     while(<FILE1>) {
  193.     chomp;
  194.     if (!$foundConfigBegin && /^my \$config_sh = <<'!END!';$/) {
  195.         $foundConfigBegin = 1;
  196.         next;
  197.     } 
  198.     elsif (!$foundConfigEnd && /^!END!$/) {
  199.         last;
  200.     }
  201.     next if(!$foundConfigBegin);
  202.     my ($name, $value) = split(/=/, $_, 2);
  203.     if(grep(/$name/, @propagateThese)) {
  204.         $Config1{$name} = $value;
  205.     }
  206.     }
  207.     close(FILE1);
  208.  
  209.     open(FILE2, "+<$file2")
  210.     || do {
  211.         warn "Could not open file $file2 : $!";
  212.         return -1;
  213.     };
  214.  
  215.     $foundConfigBegin = 0;
  216.     $foundConfigEnd = 0;
  217.     my @Config2 = ();
  218.     while(<FILE2>) {
  219.     my $line = $_;
  220.     chomp($line);
  221.     if (!$foundConfigBegin && $line =~ /^my \$config_sh = <<'!END!';$/) {
  222.         $foundConfigBegin = 1;
  223.     } 
  224.     elsif (!$foundConfigEnd && $line =~ /^!END!$/) {
  225.         $foundConfigEnd = 1;
  226.     }
  227.     elsif ($foundConfigBegin && !$foundConfigEnd) {
  228.         my ($name, $value) = split(/=/, $line, 2);
  229.         if(exists $Config1{$name} && length($Config1{$name}) > 0) {
  230.         $line = "$name=$Config1{$name}";
  231.         }
  232.     }
  233.     push(@Config2, $line . "\n");
  234.     }
  235.     truncate(FILE2, 0);
  236.     seek(FILE2, 0, 0);
  237.     print FILE2 (@Config2);
  238.     close(FILE2);
  239.     return; 
  240. }
  241.  
  242.