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.

232 lines
5.0 KiB

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