Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

137 lines
3.5 KiB

  1. ###############################################################################
  2. #
  3. # Script: configPPM.pl
  4. # Author: Michael Smith
  5. # Description: Setup 'ppm.xml' for first use by inserting path strings
  6. # consistent with the installation we are performing.
  7. #
  8. # Copyright � 1999,2001 ActiveState Tool Corp.
  9. #
  10. ###############################################################################
  11. use Config;
  12. use PPM::XML::PPMConfig;
  13. use XML::Parser;
  14. my $ppmConfigFile = $ARGV[0];
  15. my $srcDir = $ARGV[1] || '';
  16. my $oldConfig = $ARGV[2];
  17. my $repository = $ARGV[3];
  18. my $sitelib = $Config{'sitelib'};
  19. my $perldir = $Config{'prefix'};
  20. my $osname = $Config{'osname'};
  21. my $archname = $Config{'archname'};
  22. my @ppmConfig;
  23. my $osversion = join ",", (split (/\./, $Config{'osvers'}), (0) x 4) [0 .. 3];
  24. $tmp = $ENV{'TEMP'} || $ENV{'tmp'};
  25. if ($^O =~ /MSWin/) {
  26. $tmp ||= 'c:/temp';
  27. }
  28. else {
  29. $tmp ||= '/tmp';
  30. }
  31. #if $repository is undef, leave it
  32. if ($repository) {
  33. $repository =~ s#\\#/#g;
  34. # weak series of regex to strip off extra dirs.
  35. $repository =~ s#/$##;
  36. $repository =~ s#(.*/).*$#$1#;
  37. $repository =~ s#/$##;
  38. $repository =~ s#(.*/).*$#$1#;
  39. if (-d $repository ."PPMPackages") {
  40. $repository = '<REPOSITORY LOCATION="'. $repository .'PPMPackages/5.6plus" NAME="ActiveCD" PASSWORD="" SUMMARYFILE="package.lst" USERNAME="" />';
  41. }
  42. else {
  43. $repository = '';
  44. }
  45. }
  46. else {
  47. $repository = '';
  48. }
  49. print "Configuring PPM ...\n";
  50. chmod(0666, $ppmConfigFile)
  51. or warn "Unable to chmod $ppmConfigFile: $!\n";
  52. if(open(FILE, "+<$ppmConfigFile")) {
  53. while(<FILE>) {
  54. s/%SITELIB%/$sitelib/g;
  55. s/%PERLDIR%/$perldir/g;
  56. s/%SRCDIR%/$srcDir/g;
  57. s/%OSNAME%/$osname/g;
  58. s/%OSVERSION%/$osversion/g;
  59. s/%TEMP%/$tmp/g;
  60. s/%REPOSITORY%/$repository/g;
  61. s/%ARCHNAME%/$archname/g;
  62. push(@ppmConfig, $_);
  63. }
  64. seek(FILE, 0, 0);
  65. truncate(FILE, 0);
  66. foreach my $line (@ppmConfig) {
  67. print FILE $line;
  68. }
  69. close(FILE);
  70. sleep(1);
  71. }
  72. else {
  73. print "Unable to open $ppmConfigFile: $!\n";
  74. print "Press [Enter] to continue\n";
  75. <STDIN>;
  76. }
  77. if ($oldConfig and -f $oldConfig) {
  78. mergePPMConfig($oldConfig, $ppmConfigFile);
  79. }
  80. ###############################################################################
  81. #
  82. ###############################################################################
  83. sub mergePPMConfig {
  84. my $file1 = shift;
  85. my $file2 = shift;
  86. my $parser = new XML::Parser(Style => 'Objects',
  87. Pkg => 'PPM::XML::PPMConfig');
  88. my $Config1 = $parser->parsefile($file1);
  89. my $Config2 = $parser->parsefile($file2);
  90. my $i = 0;
  91. foreach my $elem (@{$Config1->[0]->{Kids}}) {
  92. if((ref $elem) =~ /.*::PACKAGE$/) {
  93. if (! existsInConfig('PACKAGE', $elem->{NAME}, $Config2)) {
  94. splice(@{$Config2->[0]->{Kids}}, $i, 0, $elem);
  95. }
  96. }
  97. ++$i;
  98. }
  99. open(FILE, ">$file2")
  100. || return "Error: Could not open $file2 : $!";
  101. select(FILE);
  102. my $Config_ref = bless($Config2->[0], "PPM::XML::PPMConfig::PPMCONFIG");
  103. $Config_ref->output();
  104. close(FILE);
  105. return;
  106. }
  107. ###############################################################################
  108. #
  109. ###############################################################################
  110. sub existsInConfig {
  111. my $element = shift;
  112. my $name = shift;
  113. my $config = shift;
  114. foreach my $elem (@{$config->[0]->{Kids}}) {
  115. return 1
  116. if ((ref $elem) =~ /.*::$element$/ && $elem->{NAME} eq $name);
  117. }
  118. return 0;
  119. }