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.

157 lines
3.8 KiB

  1. ###############################################################################
  2. #
  3. # Script: configPPM3.pl
  4. # Author: Neil Watkiss
  5. # Description: Setup 'ppm3' by expanding '%TEMP%' placeholders. If extra
  6. # arguments are given, it also runs ppm3 to set up those
  7. # options.
  8. #
  9. # Copyright � 1999,2001 ActiveState Tool Corp.
  10. #
  11. ###############################################################################
  12. use Config;
  13. use Data::Dumper;
  14. use Getopt::Long;
  15. # Accept options which control whether or not to call PPM3 with more
  16. # configuration options.
  17. GetOptions (
  18. 'ppm-conf=s' => \$ppm_conf,
  19. 'image-conf=s' => \$img_conf,
  20. # These options are for configuring PPM3 on windows; on Unix, the
  21. # installer script does this by itself.
  22. 'ppm3=s' => \$ppm3_exe,
  23. 'shared=s' => \$shared,
  24. 'fixpath=s' => \@fixpath,
  25. 'generate-inst-key' => \$gen_inst_key,
  26. 'set-profile=s' => \$set_profile,
  27. );
  28. if ($^O eq 'MSWin32') {
  29. for ($ppm_conf, $image_conf, $shared, @fixpath) {
  30. s{\\}{/}g;
  31. chop $_ while substr($_, -1) eq '/';
  32. }
  33. }
  34. my $sitelib = $Config{'sitelib'};
  35. my $perldir = $Config{'prefix'};
  36. my $osname = $Config{'osname'};
  37. my $archname = $Config{'archname'};
  38. my $osversion = join ",", (split (/\./, $Config{'osvers'}), (0) x 4) [0 .. 3];
  39. $tmp = $ENV{'TEMP'} || $ENV{'tmp'};
  40. if ($^O =~ /MSWin/) {
  41. $tmp ||= 'c:/temp';
  42. }
  43. else {
  44. $tmp ||= '/tmp';
  45. }
  46. # Edit ppm-conf/* and image/conf/*:
  47. my @files;
  48. if (-d $ppm_conf) {
  49. opendir(CONF, $ppm_conf) or die "can't opendir $ppm_conf: $!";
  50. push @files, grep { -f } map { "$ppm_conf/$_" } readdir(CONF);
  51. closedir(CONF) or die "can't closedir $ppm_conf: $!";
  52. }
  53. if (-d $img_conf) {
  54. opendir(IMG, $img_conf) or die "can't opendir $img_conf: $!";
  55. push @files, grep { -f } map { "$img_conf/$_" } readdir(IMG);
  56. closedir(IMG) or die "can't closedir $img_conf: $!";
  57. }
  58. {
  59. local $^I = '.~1~';
  60. local *ARGV;
  61. @ARGV = @files;
  62. while (<>) {
  63. s/%SITELIB%/$sitelib/g;
  64. s/%PERLDIR%/$perldir/g;
  65. s/%SRCDIR%/$srcDir/g;
  66. s/%OSNAME%/$osname/g;
  67. s/%OSVERSION%/$osversion/g;
  68. s/%TEMP%/$tmp/g;
  69. s/%REPOSITORY%/$repository/g;
  70. s/%ARCHNAME%/$archname/g;
  71. print;
  72. close ARGV if eof;
  73. }
  74. unlink "$_.~1~" for @files;
  75. }
  76. exit unless $ppm3_exe;
  77. exit unless -d $shared;
  78. if (@fixpath == 2) {
  79. opendir (GLOB, $shared) or die "Can't opendir $shared: $!";
  80. my @files = grep { -f } map { "$shared/$_" } readdir(GLOB);
  81. closedir(GLOB) or die "closedir $shared: $!";
  82. local $^I = '.~1~';
  83. local *ARGV;
  84. @ARGV = @files;
  85. my ($from, $to) = @fixpath;
  86. if ($^O eq 'MSWin32') {
  87. require Win32;
  88. $to = Win32::GetShortPathName($to);
  89. }
  90. while (<>) {
  91. s{\\}{/}g;
  92. s/\Q$from\E/$to/gi;
  93. print;
  94. close ARGV if eof;
  95. }
  96. unlink "$_.~1~" for @files;
  97. }
  98. if (defined $gen_inst_key) {
  99. my $date = localtime;
  100. my $rand = rand;
  101. my $os = $^O;
  102. my $hostname;
  103. if ($^O eq 'MSWin32') {
  104. $hostname = (gethostbyname('localhost'))[0];
  105. }
  106. elsif (eval { require Net::Domain }) {
  107. $hostname = Net::Domain::hostfqdn();
  108. }
  109. else {
  110. require Sys::Hostname;
  111. $hostname = Sys::Hostname::hostname();
  112. }
  113. use Digest::MD5 qw(md5_hex);
  114. my $inst_id = md5_hex(join ':', ($rand, $hostname, $os, $date));
  115. my $instkey = "$shared/instkey.cfg";
  116. open (my $INST, "> $instkey") or die "can't open $instkey: $!";
  117. print $INST <<END;
  118. date: $date
  119. hostname: $hostname
  120. inst_id: $inst_id
  121. os: $os
  122. rand: $rand
  123. END
  124. close $INST or die "can't close $instkey: $!";
  125. }
  126. if (defined $set_profile) {
  127. my $clientlib = "$shared/clientlib.cfg";
  128. local *ARGV;
  129. local $^I = '.~1~';
  130. @ARGV = ($clientlib);
  131. while (<>) {
  132. s/(profile_enable:) \d+/$1 $set_profile/;
  133. print;
  134. close ARGV if eof;
  135. }
  136. unlink "$_.~1~" for ($clientlib);
  137. }