Bug 470455 - test_database_sync_embed_visits.js leaks, r=sdwilsh
[wine-gecko.git] / toolkit / mozapps / installer / makecfgini.pl
blob7aff9ebb07d44c7fec7ef6aff0543e8449ed7ae9
1 #!c:\perl\bin\perl
2 #
3 # ***** BEGIN LICENSE BLOCK *****
4 # Version: MPL 1.1/GPL 2.0/LGPL 2.1
6 # The contents of this file are subject to the Mozilla Public License Version
7 # 1.1 (the "License"); you may not use this file except in compliance with
8 # the License. You may obtain a copy of the License at
9 # http://www.mozilla.org/MPL/
11 # Software distributed under the License is distributed on an "AS IS" basis,
12 # WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
13 # for the specific language governing rights and limitations under the
14 # License.
16 # The Original Code is Mozilla Communicator client code, released
17 # March 31, 1998.
19 # The Initial Developer of the Original Code is
20 # Netscape Communications Corporation.
21 # Portions created by the Initial Developer are Copyright (C) 1998-1999
22 # the Initial Developer. All Rights Reserved.
24 # Contributor(s):
25 # Sean Su <ssu@netscape.com>
26 # Howard Chu <hyc@symas.com>
28 # Alternatively, the contents of this file may be used under the terms of
29 # either the GNU General Public License Version 2 or later (the "GPL"), or
30 # the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
31 # in which case the provisions of the GPL or the LGPL are applicable instead
32 # of those above. If you wish to allow use of your version of this file only
33 # under the terms of either the GPL or the LGPL, and not to allow others to
34 # use your version of this file under the terms of the MPL, indicate your
35 # decision by deleting the provisions above and replace them with the notice
36 # and other provisions required by the GPL or the LGPL. If you do not delete
37 # the provisions above, a recipient may use your version of this file under
38 # the terms of any one of the MPL, the GPL or the LGPL.
40 # ***** END LICENSE BLOCK *****
43 # This perl script parses the input file for special variables
44 # in the format of $Variable$ and replace it with the appropriate
45 # value(s).
47 # Input: .it file
48 # - which is a .ini template
50 # version
51 # - version to display on the blue background
53 # Path to staging area
54 # - path on where the seamonkey built bits are staged to
56 # xpi path
57 # - path on where xpi files will be located at
59 # redirect file url
60 # - url to where the redirect.ini file will be staged at.
61 # Either ftp:// or http:// can be used
62 # ie: ftp://ftp.netscape.com/pub/seamonkey
64 # xpi url
65 # - url to where the .xpi files will be staged at.
66 # Either ftp:// or http:// can be used
67 # ie: ftp://ftp.netscape.com/pub/seamonkey/xpi
69 # ie: perl makecfgini.pl config.it 5.0.0.1999120608 k:\windows\32bit\5.0 d:\builds\mozilla\dist\win32_o.obj\install\xpi ftp://ftp.netscape.com/pub/seamonkey/windows/32bit/x86/1999-09-13-10-M10 ftp://ftp.netscape.com/pub/seamonkey/windows/32bit/x86/1999-09-13-10-M10/xpi
73 # Make sure there are at least two arguments
74 if($#ARGV < 5)
76 die "usage: $0 <.it file> <version> <staging path> <.xpi path> <redirect file url> <xpi url>
78 .it file : input ini template file
80 version : version to be shown in setup. Typically the same version
81 as show in mozilla.exe.
83 staging path : path to where the components are staged at
85 .xpi path : path to where the .xpi files have been built to
86 ie: d:/builds/mozilla/dist/win32_o.obj/install/xpi
88 redirect file : url to where the redirect.ini file will be staged at.
90 xpi url : url to where the .xpi files will be staged at.
91 Either ftp:// or http:// can be used
92 ie: ftp://ftp.netscape.com/pub/seamonkey/xpi
93 \n";
96 $inItFile = $ARGV[0];
97 $inVersion = $ARGV[1];
98 $inStagePath = $ARGV[2];
99 $inXpiPath = $ARGV[3];
100 $inRedirIniUrl = $ARGV[4];
101 $inUrl = $ARGV[5];
103 # get environment vars
104 $userAgent = $ENV{WIZ_userAgent};
105 $userAgentShort = $ENV{WIZ_userAgentShort};
106 $xpinstallVersion = $ENV{WIZ_xpinstallVersion};
107 $nameCompany = $ENV{WIZ_nameCompany};
108 $nameProduct = $ENV{WIZ_nameProduct};
109 $shortNameProduct = $ENV{WIZ_shortNameProduct};
110 $nameProductInternal = $ENV{WIZ_nameProductInternal};
111 $fileMainExe = $ENV{WIZ_fileMainExe};
112 $greBuildID = $ENV{WIZ_greBuildID};
113 $greFileVersion = $ENV{WIZ_greFileVersion};
114 $greUniqueID = $ENV{WIZ_greUniqueID};
116 $inDomain;
117 $inRedirDomain;
118 $inServerPath;
119 $inRedirServerPath;
121 ($inDomain, $inServerPath) = ParseDomainAndPath($inUrl);
122 ($inRedirDomain, $inRedirServerPath) = ParseDomainAndPath($inRedirIniUrl);
124 # Get the name of the file replacing the .it extension with a .ini extension
125 @inItFileSplit = split(/\./,$inItFile);
126 $outIniFile = $inItFileSplit[0];
127 $outIniFile .= ".ini";
129 # Open the input file
130 open(fpInIt, $inItFile) || die "\ncould not open $ARGV[0]: $!\n";
132 # Open the output file
133 open(fpOutIni, ">$outIniFile") || die "\nCould not open $outIniFile: $!\n";
135 print "\n Making $outIniFile...\n";
137 # While loop to read each line from input file
138 while($line = <fpInIt>)
140 # For each line read, search and replace $InstallSize$ with the calculated size
141 if($line =~ /\$InstallSize\$/i)
143 $installSize = 0;
144 $installSizeSystem = 0;
146 # split read line by ":" deliminator
147 @colonSplit = split(/:/, $line);
148 if($#colonSplit >= 0)
150 $componentName = $colonSplit[1];
151 if (substr($componentName, -2, 2) eq "\r\n") {
152 $componentName = substr($componentName, 0, length($componentName) - 2) . "\n";
154 else {
155 chop($componentName);
158 $installSize = OutputInstallSize("$inStagePath/$componentName");
160 # special oji consideration here. Since it's an installer that
161 # seamonkey installer will be calling, the disk space allocation
162 # needs to be adjusted by an expansion factor of 3.62.
163 if($componentName =~ /oji/i)
165 $installSize = int($installSize * 3.62);
168 if($componentName =~ /gre/i)
170 $installSize = int($installSize * 4.48);
174 # Read the next line to calculate for the "Install Size System="
175 if($line = <fpInIt>)
177 if($line =~ /\$InstallSizeSystem\$/i)
179 $installSizeSystem = OutputInstallSizeSystem($line, "$inStagePath/$componentName");
183 $installSize -= $installSizeSystem;
184 print fpOutIni "Install Size=$installSize\n";
185 print fpOutIni "Install Size System=$installSizeSystem\n";
187 elsif($line =~ /\$InstallSizeArchive\$/i)
189 $installSizeArchive = 0;
191 # split read line by ":" deliminator
192 @colonSplit = split(/:/, $line);
193 if($#colonSplit >= 0)
195 $componentName = $colonSplit[1];
196 if (substr($componentName, -2, 2) eq "\r\n") {
197 $componentName = substr($componentName, 0, length($componentName) - 2) . "\n";
199 else {
200 chop($componentName);
202 $installSizeArchive = OutputInstallSizeArchive("$inXpiPath/$componentName");
205 print fpOutIni "Install Size Archive=$installSizeArchive\n";
207 elsif($line =~ /\$FileCount\$/i)
209 if (!($componentName eq ""))
211 $stageDir = "$inStagePath/$componentName";
212 $stageDir =~ s/(.xpi|.zip)\b//i;
213 if (substr($stageDir, -1, 1) eq "\n") {
214 chop($stageDir);
216 $fileCount = `find $stageDir -type f | wc -l`;
217 if (substr($fileCount, -1, 1) eq "\n") {
218 chop($fileCount);
221 $line =~ s/\$FileCount\$/$fileCount/i;
223 print fpOutIni $line;
226 else
228 # For each line read, search and replace $Version$ with the version passed in
229 $line =~ s/\$Version\$/$inVersion/gi;
230 $line =~ s/\$Domain\$/$inDomain/gi;
231 $line =~ s/\$ServerPath\$/$inServerPath/gi;
232 $line =~ s/\$RedirIniUrl\$/$inRedirIniUrl/gi;
233 $line =~ s/\$ArchiveServerPath\$/$inServerPath/gi;
234 $line =~ s/\$ArchiveUrl\$/$inUrl/gi;
235 $line =~ s/\$RedirectServerPath\$/$inRedirServerPath/gi;
236 $line =~ s/\$RedirectUrl\$/$inRedirUrl/gi;
237 $line =~ s/\$UserAgent\$/$userAgent/gi;
238 $line =~ s/\$UserAgentShort\$/$userAgentShort/gi;
239 $line =~ s/\$XPInstallVersion\$/$xpinstallVersion/gi;
240 $line =~ s/\$CompanyName\$/$nameCompany/gi;
241 $line =~ s/\$ProductName\$/$nameProduct/gi;
242 $line =~ s/\$ProductNameInternal\$/$nameProductInternal/gi;
243 $line =~ s/\$ProductShortName\$/$shortNameProduct/gi;
244 $line =~ s/\$MainExeFile\$/$fileMainExe/gi;
245 $line =~ s/\$GreBuildID\$/$greBuildID/gi;
246 $line =~ s/\$GreFileVersion\$/$greFileVersion/gi;
247 $line =~ s/\$GreUniqueID\$/$greUniqueID/gi;
248 print fpOutIni $line;
252 print " done!\n";
254 # end of script
255 exit(0);
257 sub ParseDomainAndPath()
259 my($aUrl) = @_;
260 my($aDomain, $aServerPath);
262 @slashSplit = split(/\//, $aUrl);
263 if($#slashSplit >= 0)
265 for($i = 0; $i <= $#slashSplit; $i++)
267 if($i <= 2)
269 if($aDomain eq "")
271 $aDomain = "$slashSplit[$i]";
273 else
275 $aDomain = "$aDomain/$slashSplit[$i]";
278 else
280 if($aServerPath eq "")
282 $aServerPath = "/$slashSplit[$i]";
284 else
286 $aServerPath = "$aServerPath/$slashSplit[$i]";
292 return($aDomain, $aServerPath);
295 sub OutputInstallSize()
297 my($inPath) = @_;
298 my($installSize);
300 print " calculating size for $inPath\n";
302 my ($inPathWin);
303 if($^O =~ msys)
305 $inPathWin = $inPath;
306 } else {
307 $inPathWin = `cygpath -wa $inPath`;
308 chomp($inPathWin);
309 $inPathWin =~ s/\\/\\\\/g;
311 $installSize = `$ENV{WIZ_distInstallPath}/ds32.exe -D -L0 -A -S -C 32768 $inPathWin`;
312 $installSize += 32768; # take into account install.js
313 $installSize = int($installSize / 1024);
314 $installSize += 1;
315 return($installSize);
318 sub OutputInstallSizeArchive()
320 my($inPath) = @_;
321 my($installSizeArchive);
322 my($dev, $ino, $mode, $nlink, $uid, $gui, $rdev, $size, $atime, $mtime, $ctime, $blksize, $blocks);
324 print " calculating size for $inPath\n";
325 ($dev, $ino, $mode, $nlink, $uid, $gui, $rdev, $size, $atime, $mtime, $ctime, $blksize, $blocks) = stat $inPath;
326 $installSizeArchive += 32768; # take into account install.js
327 $installSizeArchive = int($size / 1024);
328 $installSizeArchive += 1;
329 return($installSizeArchive);
332 sub OutputInstallSizeSystem()
334 my($inLine, $inPath) = @_;
335 my($installSizeSystem) = 0;
337 # split read line by ":" deliminator
338 @colonSplit = split(/:/, $inLine);
339 if($#colonSplit >= 0)
341 # split line by "," deliminator
342 @commaSplit = split(/\,/, $colonSplit[1]);
343 if($#commaSplit >= 0)
345 foreach(@commaSplit)
347 # calculate the size of component installed using ds32.exe in Kbytes
348 print " calculating size for $inPath/$_";
349 $installSizeSystem += `$ENV{WIZ_distInstallPath}/ds32.exe /D /L0 /A /S /C 32768 $inPath/$_`;
354 $installSizeSystem = int($installSizeSystem / 1024);
355 $installSizeSystem += 1;
356 return($installSizeSystem);
359 sub ParseUserAgentShort()
361 my($aUserAgent) = @_;
362 my($aUserAgentShort);
364 @spaceSplit = split(/ /, $aUserAgent);
365 if($#spaceSplit >= 0)
367 $aUserAgentShort = $spaceSplit[0];
370 return($aUserAgentShort);