home *** CD-ROM | disk | FTP | other *** search
/ PC World 2003 March / PCWorld_2003-03_cd.bin / Software / Topware / activeperl / ActivePerl / Perl / bin / configPPM.pl < prev    next >
Encoding:
Perl Script  |  2002-11-07  |  1.3 KB  |  52 lines

  1. #!perl -w
  2. #
  3. # Copyright ⌐ 2002 ActiveState
  4. #
  5. use XML::Simple;
  6. use strict;
  7. use File::Copy;
  8.  
  9. my $ppmConfigFile = $ARGV[0];    # full path of ppm.xml on target install tree
  10. my $sdir          = $ARGV[1];   # directory where install package is located
  11. my $repository;
  12.  
  13. if ($sdir) {
  14.     # this path sets up the ActiveCD repository if a PPMPackages directory
  15.     # exists two levels up from where the MSI package is located
  16.     $sdir =~ s#\\#/#g;
  17.  
  18.     # weak series of regex to strip off two levels of extra dirs
  19.     $sdir =~ s#/$##;
  20.     $sdir =~ s#(.*/).*$#$1#;
  21.  
  22.     $sdir =~ s#/$##;
  23.     $sdir =~ s#(.*/).*$#$1#;
  24.     if (-d $sdir ."PPMPackages") {
  25.     $repository = {
  26.       'NAME' => 'ActiveCD Repository',
  27.       'LOCATION' => $sdir .'PPMPackages/5.8-cd',
  28.       'SUMMARYFILE' => 'package.lst'
  29.     };
  30.     }
  31. }
  32.  
  33. exit unless $sdir && $repository;
  34.  
  35. print "Configuring PPM ...\n";
  36. chmod(0666, $ppmConfigFile)
  37.     or warn "Unable to chmod $ppmConfigFile: $!\n";
  38.  
  39. File::Copy::copy($ppmConfigFile, "$ppmConfigFile~") || die;
  40.  
  41.  
  42. my $ppmxml = XMLin ($ppmConfigFile, forcearray => 'REPOSITORY', keeproot => 1 );
  43. unshift (@{$ppmxml->{PPMCONFIG}->[0]->{REPOSITORY}}, $repository);
  44. #use Data::Dumper; print Dumper $ppmxml;
  45.  
  46. open (my $f, ">$ppmConfigFile") || die;
  47.  
  48. print $f XMLout ($ppmxml, rootname => undef );
  49.  
  50. close $f;
  51.  
  52.