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