19780544fSAndrew Rist#**************************************************************
23c0d14cbSmseidel#
39780544fSAndrew Rist#  Licensed to the Apache Software Foundation (ASF) under one
49780544fSAndrew Rist#  or more contributor license agreements.  See the NOTICE file
59780544fSAndrew Rist#  distributed with this work for additional information
69780544fSAndrew Rist#  regarding copyright ownership.  The ASF licenses this file
79780544fSAndrew Rist#  to you under the Apache License, Version 2.0 (the
89780544fSAndrew Rist#  "License"); you may not use this file except in compliance
99780544fSAndrew Rist#  with the License.  You may obtain a copy of the License at
103c0d14cbSmseidel#
119780544fSAndrew Rist#    http://www.apache.org/licenses/LICENSE-2.0
123c0d14cbSmseidel#
139780544fSAndrew Rist#  Unless required by applicable law or agreed to in writing,
149780544fSAndrew Rist#  software distributed under the License is distributed on an
159780544fSAndrew Rist#  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
169780544fSAndrew Rist#  KIND, either express or implied.  See the License for the
179780544fSAndrew Rist#  specific language governing permissions and limitations
189780544fSAndrew Rist#  under the License.
193c0d14cbSmseidel#
209780544fSAndrew Rist#**************************************************************
219780544fSAndrew Rist
229780544fSAndrew Rist
23cdf0e10cSrcweir
24cdf0e10cSrcweirpackage installer::download;
25cdf0e10cSrcweir
26cdf0e10cSrcweiruse File::Spec;
27cdf0e10cSrcweiruse installer::exiter;
28cdf0e10cSrcweiruse installer::files;
29cdf0e10cSrcweiruse installer::globals;
30cdf0e10cSrcweiruse installer::logger;
31cdf0e10cSrcweiruse installer::pathanalyzer;
32cdf0e10cSrcweiruse installer::remover;
33cdf0e10cSrcweiruse installer::systemactions;
34cdf0e10cSrcweir
350b2dfbacSAndre Fischeruse strict;
360b2dfbacSAndre Fischer
373c0d14cbSmseidelBEGIN { # This is needed so that Cygwin's perl evaluates ACLs
38cdf0e10cSrcweir	# (needed for correctly evaluating the -x test.)
39cdf0e10cSrcweir	if( $^O =~ /cygwin/i ) {
40cdf0e10cSrcweir		require filetest; import filetest "access";
41cdf0e10cSrcweir	}
42cdf0e10cSrcweir}
43cdf0e10cSrcweir
44cdf0e10cSrcweir##################################################################
453c0d14cbSmseidel# Including the lowercase product name into the script template
46cdf0e10cSrcweir##################################################################
47cdf0e10cSrcweir
48cdf0e10cSrcweirsub put_productname_into_script
49cdf0e10cSrcweir{
50cdf0e10cSrcweir	my ($scriptfile, $variableshashref) = @_;
513c0d14cbSmseidel
52cdf0e10cSrcweir	my $productname = $variableshashref->{'PRODUCTNAME'};
53cdf0e10cSrcweir	$productname = lc($productname);
54cdf0e10cSrcweir	$productname =~ s/\.//g;	# openoffice.org -> openofficeorg
55cdf0e10cSrcweir	$productname =~ s/\s*//g;
56b274bc22SAndre Fischer
573c0d14cbSmseidel	$installer::logger::Lang->printf("Adding productname %s into download shell script\n", $productname);
58cdf0e10cSrcweir
59cdf0e10cSrcweir	for ( my $i = 0; $i <= $#{$scriptfile}; $i++ )
60cdf0e10cSrcweir	{
61cdf0e10cSrcweir		${$scriptfile}[$i] =~ s/PRODUCTNAMEPLACEHOLDER/$productname/;
62cdf0e10cSrcweir	}
63cdf0e10cSrcweir}
64cdf0e10cSrcweir
65cdf0e10cSrcweir#########################################################
663c0d14cbSmseidel# Including the linenumber into the script template
67cdf0e10cSrcweir#########################################################
68cdf0e10cSrcweir
69cdf0e10cSrcweirsub put_linenumber_into_script
70cdf0e10cSrcweir{
71cdf0e10cSrcweir	my ( $scriptfile ) = @_;
72cdf0e10cSrcweir
733c0d14cbSmseidel	my $linenumber = $#{$scriptfile} + 2;
743c0d14cbSmseidel
753c0d14cbSmseidel	$installer::logger::Lang->printf("Adding linenumber %d into download shell script\n", $linenumber);
76cdf0e10cSrcweir
77cdf0e10cSrcweir	for ( my $i = 0; $i <= $#{$scriptfile}; $i++ )
78cdf0e10cSrcweir	{
79cdf0e10cSrcweir		${$scriptfile}[$i] =~ s/LINENUMBERPLACEHOLDER/$linenumber/;
803c0d14cbSmseidel	}
81cdf0e10cSrcweir}
82cdf0e10cSrcweir
83cdf0e10cSrcweir#########################################################
843c0d14cbSmseidel# Determining the name of the new scriptfile
85cdf0e10cSrcweir#########################################################
86cdf0e10cSrcweir
87cdf0e10cSrcweirsub determine_scriptfile_name
88cdf0e10cSrcweir{
89cdf0e10cSrcweir	my ( $filename ) = @_;
90cdf0e10cSrcweir
91cdf0e10cSrcweir	$installer::globals::downloadfileextension = ".sh";
92cdf0e10cSrcweir	$filename = $filename . $installer::globals::downloadfileextension;
93cdf0e10cSrcweir	$installer::globals::downloadfilename = $filename;
94cdf0e10cSrcweir
953c0d14cbSmseidel	$installer::logger::Lang->printf("Setting download shell script file name to %s\n", $filename);
96cdf0e10cSrcweir
97cdf0e10cSrcweir	return $filename;
98cdf0e10cSrcweir}
99cdf0e10cSrcweir
100cdf0e10cSrcweir#########################################################
1013c0d14cbSmseidel# Saving the script file in the installation directory
102cdf0e10cSrcweir#########################################################
103cdf0e10cSrcweir
104cdf0e10cSrcweirsub save_script_file
105cdf0e10cSrcweir{
106cdf0e10cSrcweir	my ($directory, $newscriptfilename, $scriptfile) = @_;
1073c0d14cbSmseidel
108cdf0e10cSrcweir	$newscriptfilename = $directory . $installer::globals::separator . $newscriptfilename;
109cdf0e10cSrcweir	installer::files::save_file($newscriptfilename, $scriptfile);
110b274bc22SAndre Fischer
1113c0d14cbSmseidel	$installer::logger::Lang->printf("Saving script file %s\n", $newscriptfilename);
112cdf0e10cSrcweir
113cdf0e10cSrcweir	if ( ! $installer::globals::iswindowsbuild )
114cdf0e10cSrcweir	{
115cdf0e10cSrcweir		my $localcall = "chmod 775 $newscriptfilename \>\/dev\/null 2\>\&1";
116cdf0e10cSrcweir		system($localcall);
117cdf0e10cSrcweir	}
1183c0d14cbSmseidel
119cdf0e10cSrcweir	return $newscriptfilename;
120cdf0e10cSrcweir}
121cdf0e10cSrcweir
122cdf0e10cSrcweir#########################################################
1233c0d14cbSmseidel# Including checksum and size into script file
124cdf0e10cSrcweir#########################################################
125cdf0e10cSrcweir
126cdf0e10cSrcweirsub put_checksum_and_size_into_script
127cdf0e10cSrcweir{
128cdf0e10cSrcweir	my ($scriptfile, $sumout) = @_;
129cdf0e10cSrcweir
130cdf0e10cSrcweir	my $checksum = "";
131cdf0e10cSrcweir	my $size = "";
1323c0d14cbSmseidel
1333c0d14cbSmseidel	if ( $sumout =~ /^\s*(\d+)\s+(\d+)\s*$/ )
134cdf0e10cSrcweir	{
135cdf0e10cSrcweir		$checksum = $1;
1363c0d14cbSmseidel		$size = $2;
137cdf0e10cSrcweir	}
138cdf0e10cSrcweir	else
139cdf0e10cSrcweir	{
140cdf0e10cSrcweir		installer::exiter::exit_program("ERROR: Incorrect return value from /usr/bin/sum: $sumout", "put_checksum_and_size_into_script");
141cdf0e10cSrcweir	}
142cdf0e10cSrcweir
1433c0d14cbSmseidel	$installer::logger::Lang->printf(
1443c0d14cbSmseidel		"Adding checksum %s and size %s into download shell script\n", $checksum, $size);
145cdf0e10cSrcweir
146cdf0e10cSrcweir	for ( my $i = 0; $i <= $#{$scriptfile}; $i++ )
147cdf0e10cSrcweir	{
148cdf0e10cSrcweir		${$scriptfile}[$i] =~ s/CHECKSUMPLACEHOLDER/$checksum/;
149cdf0e10cSrcweir		${$scriptfile}[$i] =~ s/DISCSPACEPLACEHOLDER/$size/;
150cdf0e10cSrcweir	}
1513c0d14cbSmseidel
152cdf0e10cSrcweir}
153cdf0e10cSrcweir
154cdf0e10cSrcweir#########################################################
1553c0d14cbSmseidel# Calling md5sum
156cdf0e10cSrcweir#########################################################
157cdf0e10cSrcweir
158cdf0e10cSrcweirsub call_md5sum
159cdf0e10cSrcweir{
160cdf0e10cSrcweir	my ($filename) = @_;
161cdf0e10cSrcweir
1620b2dfbacSAndre Fischer	my $md5sumfile = "/usr/bin/md5sum";
1633c0d14cbSmseidel
164cdf0e10cSrcweir	if ( ! -f $md5sumfile ) { installer::exiter::exit_program("ERROR: No file /usr/bin/md5sum", "call_md5sum"); }
1653c0d14cbSmseidel
166cdf0e10cSrcweir	my $systemcall = "$md5sumfile $filename |";
1673c0d14cbSmseidel
168cdf0e10cSrcweir	my $md5sumoutput = "";
169cdf0e10cSrcweir
170cdf0e10cSrcweir	open (SUM, "$systemcall");
171cdf0e10cSrcweir	$md5sumoutput = <SUM>;
172cdf0e10cSrcweir	close (SUM);
173cdf0e10cSrcweir
174cdf0e10cSrcweir	my $returnvalue = $?;	# $? contains the return value of the systemcall
175cdf0e10cSrcweir
1763c0d14cbSmseidel	$installer::logger::Lang->printf("Systemcall: %s\n", $systemcall);
1773c0d14cbSmseidel
178cdf0e10cSrcweir	if ($returnvalue)
179cdf0e10cSrcweir	{
1803c0d14cbSmseidel		$installer::logger::Lang->printf("ERROR: Could not execute \"%s\"!\n", $systemcall);
181cdf0e10cSrcweir	}
182cdf0e10cSrcweir	else
183cdf0e10cSrcweir	{
1843c0d14cbSmseidel		$installer::logger::Lang->print("Success: Executed \"%s\" successfully!\n", $systemcall);
185cdf0e10cSrcweir	}
1863c0d14cbSmseidel
1873c0d14cbSmseidel	return $md5sumoutput;
188cdf0e10cSrcweir}
189cdf0e10cSrcweir
190cdf0e10cSrcweir#########################################################
1913c0d14cbSmseidel# Calling md5sum
192cdf0e10cSrcweir#########################################################
193cdf0e10cSrcweir
194cdf0e10cSrcweirsub get_md5sum
195cdf0e10cSrcweir{
1960b2dfbacSAndre Fischer	my ($md5sumoutput) = @_;
1973c0d14cbSmseidel
198cdf0e10cSrcweir	my $md5sum;
1993c0d14cbSmseidel
2003c0d14cbSmseidel	if ( $md5sumoutput =~ /^\s*(\w+?)\s+/ )
201cdf0e10cSrcweir	{
202cdf0e10cSrcweir		$md5sum = $1;
203cdf0e10cSrcweir	}
204cdf0e10cSrcweir	else
205cdf0e10cSrcweir	{
206cdf0e10cSrcweir		installer::exiter::exit_program("ERROR: Incorrect return value from /usr/bin/md5sum: $md5sumoutput", "get_md5sum");
207cdf0e10cSrcweir	}
208cdf0e10cSrcweir
2093c0d14cbSmseidel	$installer::logger::Lang->printf("Setting md5sum: %s\n", $md5sum);
210cdf0e10cSrcweir
211cdf0e10cSrcweir	return $md5sum;
212cdf0e10cSrcweir}
213cdf0e10cSrcweir
214cdf0e10cSrcweir#########################################################
2153c0d14cbSmseidel# Determining checksum and size of tar file
216cdf0e10cSrcweir#########################################################
217cdf0e10cSrcweir
218cdf0e10cSrcweirsub call_sum
219cdf0e10cSrcweir{
220cdf0e10cSrcweir	my ($filename, $getuidlibrary) = @_;
221cdf0e10cSrcweir
222cdf0e10cSrcweir	my $systemcall = "/usr/bin/sum $filename |";
2233c0d14cbSmseidel
224cdf0e10cSrcweir	my $sumoutput = "";
225cdf0e10cSrcweir
226cdf0e10cSrcweir	open (SUM, "$systemcall");
227cdf0e10cSrcweir	$sumoutput = <SUM>;
228cdf0e10cSrcweir	close (SUM);
229cdf0e10cSrcweir
230cdf0e10cSrcweir	my $returnvalue = $?;	# $? contains the return value of the systemcall
231cdf0e10cSrcweir
2323c0d14cbSmseidel	$installer::logger::Lang->printf("Systemcall: %s\n", $systemcall);
2333c0d14cbSmseidel
234cdf0e10cSrcweir	if ($returnvalue)
235cdf0e10cSrcweir	{
2363c0d14cbSmseidel		$installer::logger::Lang->printf("ERROR: Could not execute \"%s\"!\n", $systemcall);
237cdf0e10cSrcweir	}
238cdf0e10cSrcweir	else
239cdf0e10cSrcweir	{
2403c0d14cbSmseidel		$installer::logger::Lang->printf("Success: Executed \"%s\" successfully!\n", $systemcall);
241cdf0e10cSrcweir	}
2423c0d14cbSmseidel
243cdf0e10cSrcweir	$sumoutput =~ s/\s+$filename\s$//;
2443c0d14cbSmseidel	return $sumoutput;
245cdf0e10cSrcweir}
246cdf0e10cSrcweir
247cdf0e10cSrcweir#########################################################
2483c0d14cbSmseidel# Searching for the getuid.so in the solver
249cdf0e10cSrcweir#########################################################
250cdf0e10cSrcweir
251cdf0e10cSrcweirsub get_path_for_library
252cdf0e10cSrcweir{
253cdf0e10cSrcweir	my ($includepatharrayref) = @_;
2543c0d14cbSmseidel
255cdf0e10cSrcweir	my $getuidlibraryname = "getuid.so";
256cdf0e10cSrcweir
257cdf0e10cSrcweir	my $getuidlibraryref = "";
258cdf0e10cSrcweir
259cdf0e10cSrcweir	if ( $installer::globals::include_pathes_read )
260cdf0e10cSrcweir	{
261cdf0e10cSrcweir		$getuidlibraryref = installer::scriptitems::get_sourcepath_from_filename_and_includepath(\$getuidlibraryname, $includepatharrayref, 0);
262cdf0e10cSrcweir	}
263cdf0e10cSrcweir	else
264cdf0e10cSrcweir	{
265cdf0e10cSrcweir		$getuidlibraryref = installer::scriptitems::get_sourcepath_from_filename_and_includepath_classic(\$getuidlibraryname, $includepatharrayref, 0);
266cdf0e10cSrcweir	}
267cdf0e10cSrcweir
268cdf0e10cSrcweir	if ($$getuidlibraryref eq "") { installer::exiter::exit_program("ERROR: Could not find $getuidlibraryname!", "get_path_for_library"); }
2693c0d14cbSmseidel
270cdf0e10cSrcweir	return $$getuidlibraryref;
271cdf0e10cSrcweir}
272cdf0e10cSrcweir
273cdf0e10cSrcweir#########################################################
2743c0d14cbSmseidel# Include the tar file into the script
275cdf0e10cSrcweir#########################################################
276cdf0e10cSrcweir
277cdf0e10cSrcweirsub include_tar_into_script
278cdf0e10cSrcweir{
279cdf0e10cSrcweir	my ($scriptfile, $temporary_tarfile) = @_;
280cdf0e10cSrcweir
281cdf0e10cSrcweir	my $systemcall = "cat $temporary_tarfile >> $scriptfile && rm $temporary_tarfile";
282cdf0e10cSrcweir	my $returnvalue = system($systemcall);
283cdf0e10cSrcweir
2843c0d14cbSmseidel	$installer::logger::Lang->printf("Systemcall: %s\n", $systemcall);
2853c0d14cbSmseidel
286cdf0e10cSrcweir	if ($returnvalue)
287cdf0e10cSrcweir	{
2883c0d14cbSmseidel		$installer::logger::Lang->printf("ERROR: Could not execute \"%s\"!\n", $systemcall);
289cdf0e10cSrcweir	}
290cdf0e10cSrcweir	else
291cdf0e10cSrcweir	{
2923c0d14cbSmseidel		$installer::logger::Lang->printf("Success: Executed \"%s\" successfully!\n", $systemcall);
293cdf0e10cSrcweir	}
294cdf0e10cSrcweir	return $returnvalue;
295cdf0e10cSrcweir}
296cdf0e10cSrcweir
297cdf0e10cSrcweir#########################################################
2983c0d14cbSmseidel# Create a tar file from the binary package
299cdf0e10cSrcweir#########################################################
300cdf0e10cSrcweir
301cdf0e10cSrcweirsub tar_package
302cdf0e10cSrcweir{
303cdf0e10cSrcweir	my ( $installdir, $tarfilename, $getuidlibrary) = @_;
304cdf0e10cSrcweir
305cdf0e10cSrcweir	my $ldpreloadstring = "";
306e250bff1SJim Jagielski
30743c75f1dSJim Jagielski	if (($ENV{'FAKEROOT'} ne "no") && ($ENV{'FAKEROOT'} ne "")) {
308e250bff1SJim Jagielski		$ldpreloadstring = $ENV{'FAKEROOT'};
309e250bff1SJim Jagielski	} else {
310e250bff1SJim Jagielski		if ( $getuidlibrary ne "" ) { $ldpreloadstring = "LD_PRELOAD=" . $getuidlibrary; }
311e250bff1SJim Jagielski	}
312cdf0e10cSrcweir
313cdf0e10cSrcweir	my $systemcall = "cd $installdir; $ldpreloadstring tar -cf - * > $tarfilename";
3143c0d14cbSmseidel
315cdf0e10cSrcweir	my $returnvalue = system($systemcall);
316cdf0e10cSrcweir
3173c0d14cbSmseidel	$installer::logger::Lang->printf("Systemcall: %s\n", $systemcall);
3183c0d14cbSmseidel
319cdf0e10cSrcweir	if ($returnvalue)
320cdf0e10cSrcweir	{
3213c0d14cbSmseidel		$installer::logger::Lang->printf("ERROR: Could not execute \"%s\"!\n", $systemcall);
322cdf0e10cSrcweir	}
323cdf0e10cSrcweir	else
324cdf0e10cSrcweir	{
3253c0d14cbSmseidel		$installer::logger::Lang->printf("Success: Executed \"\" successfully!\n", $systemcall);
326cdf0e10cSrcweir	}
3273c0d14cbSmseidel
328cdf0e10cSrcweir	my $localcall = "chmod 775 $tarfilename \>\/dev\/null 2\>\&1";
329cdf0e10cSrcweir	$returnvalue = system($localcall);
330cdf0e10cSrcweir
331cdf0e10cSrcweir	return ( -s $tarfilename );
332cdf0e10cSrcweir}
333cdf0e10cSrcweir
334cdf0e10cSrcweir#########################################################
335cdf0e10cSrcweir# Creating a tar.gz file
336cdf0e10cSrcweir#########################################################
337cdf0e10cSrcweir
338cdf0e10cSrcweirsub create_tar_gz_file_from_package
339cdf0e10cSrcweir{
340cdf0e10cSrcweir	my ($installdir, $getuidlibrary) = @_;
341cdf0e10cSrcweir
342cdf0e10cSrcweir	my $alldirs = installer::systemactions::get_all_directories($installdir);
343cdf0e10cSrcweir	my $onedir = ${$alldirs}[0];
344cdf0e10cSrcweir	$installdir = $onedir;
345cdf0e10cSrcweir
346cdf0e10cSrcweir	my $allfiles = installer::systemactions::get_all_files_from_one_directory($installdir);
347cdf0e10cSrcweir
348cdf0e10cSrcweir	for ( my $i = 0; $i <= $#{$allfiles}; $i++ )
349cdf0e10cSrcweir	{
350cdf0e10cSrcweir		my $onefile = ${$allfiles}[$i];
351cdf0e10cSrcweir		my $systemcall = "cd $installdir; rm $onefile";
352cdf0e10cSrcweir		my $returnvalue = system($systemcall);
353cdf0e10cSrcweir
3543c0d14cbSmseidel		$installer::logger::Lang->printf("Systemcall: %s\n", $systemcall);
3553c0d14cbSmseidel
356cdf0e10cSrcweir		if ($returnvalue)
357cdf0e10cSrcweir		{
3583c0d14cbSmseidel			$installer::logger::Lang->printf("ERROR: Could not execute \"%s\"!\n", $systemcall);
359cdf0e10cSrcweir		}
360cdf0e10cSrcweir		else
361cdf0e10cSrcweir		{
3623c0d14cbSmseidel			$installer::logger::Lang->printf("Success: Executed \"%s\" successfully!\n", $systemcall);
363cdf0e10cSrcweir		}
364cdf0e10cSrcweir	}
365cdf0e10cSrcweir
366cdf0e10cSrcweir	$alldirs = installer::systemactions::get_all_directories($installdir);
3673c0d14cbSmseidel	my $packagename = ${$alldirs}[0]; # only taking the first Solaris package
3683c0d14cbSmseidel	if ( $packagename eq "" ) { installer::exiter::exit_program("ERROR: Could not find package in directory $installdir!", "determine_packagename"); }
369cdf0e10cSrcweir
370cdf0e10cSrcweir	installer::pathanalyzer::make_absolute_filename_to_relative_filename(\$packagename);
3713c0d14cbSmseidel
372cdf0e10cSrcweir	$installer::globals::downloadfileextension = ".tar.gz";
373cdf0e10cSrcweir	my $targzname = $packagename . $installer::globals::downloadfileextension;
374cdf0e10cSrcweir	$installer::globals::downloadfilename = $targzname;
375e250bff1SJim Jagielski
376cdf0e10cSrcweir	my $ldpreloadstring = "";
377e250bff1SJim Jagielski
37843c75f1dSJim Jagielski	if (($ENV{'FAKEROOT'} ne "no") && ($ENV{'FAKEROOT'} ne "")) {
379e250bff1SJim Jagielski		$ldpreloadstring = $ENV{'FAKEROOT'};
380e250bff1SJim Jagielski	} else {
381e250bff1SJim Jagielski		if ( $getuidlibrary ne "" ) { $ldpreloadstring = "LD_PRELOAD=" . $getuidlibrary; }
382e250bff1SJim Jagielski	}
383cdf0e10cSrcweir
3840b2dfbacSAndre Fischer	my $systemcall = "cd $installdir; $ldpreloadstring tar -cf - $packagename | gzip > $targzname";
3853c0d14cbSmseidel	$installer::logger::Info->printf("... %s ...\n", $systemcall);
386cdf0e10cSrcweir
387cdf0e10cSrcweir	my $returnvalue = system($systemcall);
388cdf0e10cSrcweir
3893c0d14cbSmseidel	$installer::logger::Lang->printf("Systemcall: %s\n", $systemcall);
3903c0d14cbSmseidel
391cdf0e10cSrcweir	if ($returnvalue)
392cdf0e10cSrcweir	{
3933c0d14cbSmseidel		$installer::logger::Lang->printf("ERROR: Could not execute \"%s\"!\n", $systemcall);
394cdf0e10cSrcweir	}
395cdf0e10cSrcweir	else
396cdf0e10cSrcweir	{
3973c0d14cbSmseidel		$installer::logger::Lang->printf("Success: Executed \"%s\" successfully!\n", $systemcall);
398cdf0e10cSrcweir	}
399cdf0e10cSrcweir}
400cdf0e10cSrcweir
401cdf0e10cSrcweir#########################################################
402cdf0e10cSrcweir# Setting type of installation
403cdf0e10cSrcweir#########################################################
404cdf0e10cSrcweir
405cdf0e10cSrcweirsub get_installation_type
406cdf0e10cSrcweir{
407cdf0e10cSrcweir	my $type = "";
4083c0d14cbSmseidel
409cdf0e10cSrcweir	if ( $installer::globals::languagepack ) { $type = "langpack"; }
410cdf0e10cSrcweir	else { $type = "install"; }
4113c0d14cbSmseidel
412cdf0e10cSrcweir	return $type;
413cdf0e10cSrcweir}
414cdf0e10cSrcweir
415cdf0e10cSrcweir#########################################################
416cdf0e10cSrcweir# Setting installation languages
417cdf0e10cSrcweir#########################################################
418cdf0e10cSrcweir
419cdf0e10cSrcweirsub get_downloadname_language
420cdf0e10cSrcweir{
421cdf0e10cSrcweir	my ($languagestringref) = @_;
422cdf0e10cSrcweir
423cdf0e10cSrcweir	my $languages = $$languagestringref;
424cdf0e10cSrcweir
425cdf0e10cSrcweir	if ( $installer::globals::added_english )
426cdf0e10cSrcweir	{
427cdf0e10cSrcweir		$languages =~ s/en-US_//;
428cdf0e10cSrcweir		$languages =~ s/_en-US//;
429cdf0e10cSrcweir	}
430cdf0e10cSrcweir
431cdf0e10cSrcweir	# en-US is default language and can be removed therefore
432cdf0e10cSrcweir	# for one-language installation sets
4333c0d14cbSmseidel
434cdf0e10cSrcweir	# if ( $languages =~ /^\s*en-US\s*$/ )
435cdf0e10cSrcweir	# {
436cdf0e10cSrcweir	#	$languages = "";
4373c0d14cbSmseidel	# }
438cdf0e10cSrcweir
439cdf0e10cSrcweir	if ( length ($languages) > $installer::globals::max_lang_length )
440cdf0e10cSrcweir	{
441cdf0e10cSrcweir		$languages = 'multi';
442cdf0e10cSrcweir	}
443cdf0e10cSrcweir
444cdf0e10cSrcweir	return $languages;
445cdf0e10cSrcweir}
446cdf0e10cSrcweir
447cdf0e10cSrcweir#########################################################
448cdf0e10cSrcweir# Setting download name
449cdf0e10cSrcweir#########################################################
450cdf0e10cSrcweir
451cdf0e10cSrcweirsub get_downloadname_productname
452cdf0e10cSrcweir{
4533c0d14cbSmseidel	my ($allvariables) = @_;
4543c0d14cbSmseidel
4553c0d14cbSmseidel	my $start;
4563c0d14cbSmseidel
4573c0d14cbSmseidel	if ( $allvariables->{'AOODOWNLOADNAMEPREFIX'} )
4583c0d14cbSmseidel	{
4593c0d14cbSmseidel		$start = $allvariables->{'AOODOWNLOADNAMEPREFIX'};
4603c0d14cbSmseidel	}
4613c0d14cbSmseidel	else
4623c0d14cbSmseidel	{
4633c0d14cbSmseidel		$start = "Apache_OpenOffice";
4643c0d14cbSmseidel		if ( $allvariables->{'PRODUCTNAME'} eq "OpenOffice" )
4653c0d14cbSmseidel		{
4663c0d14cbSmseidel			if ( $allvariables->{'POSTVERSIONEXTENSION'} eq "SDK" )
4673c0d14cbSmseidel			{
4683c0d14cbSmseidel				$start .= "-SDK";
4693c0d14cbSmseidel			}
4703c0d14cbSmseidel		}
4713c0d14cbSmseidel
4723c0d14cbSmseidel		if ( $allvariables->{'PRODUCTNAME'} eq "AOO-Developer-Build" )
4733c0d14cbSmseidel		{
4743c0d14cbSmseidel			if ( $allvariables->{'POSTVERSIONEXTENSION'} eq "SDK" )
4753c0d14cbSmseidel			{
4763c0d14cbSmseidel				$start .= "-Dev-SDK";
4773c0d14cbSmseidel			}
4783c0d14cbSmseidel			else
4793c0d14cbSmseidel			{
4803c0d14cbSmseidel				$start .= "-Dev";
4813c0d14cbSmseidel			}
4823c0d14cbSmseidel		}
4833c0d14cbSmseidel
4843c0d14cbSmseidel		if ( $allvariables->{'PRODUCTNAME'} eq "URE" )
4853c0d14cbSmseidel		{
4863c0d14cbSmseidel			$start .= "-URE";
4873c0d14cbSmseidel		}
4883c0d14cbSmseidel	}
4893c0d14cbSmseidel
4903c0d14cbSmseidel	return $start;
491cdf0e10cSrcweir}
492cdf0e10cSrcweir
493cdf0e10cSrcweir#########################################################
494cdf0e10cSrcweir# Setting download version
495cdf0e10cSrcweir#########################################################
496cdf0e10cSrcweir
497cdf0e10cSrcweirsub get_download_version
498cdf0e10cSrcweir{
499cdf0e10cSrcweir	my ($allvariables) = @_;
5003c0d14cbSmseidel
501cdf0e10cSrcweir	my $version = "";
5023c0d14cbSmseidel
503cdf0e10cSrcweir	my $devproduct = 0;
504cdf0e10cSrcweir	if (( $allvariables->{'DEVELOPMENTPRODUCT'} ) && ( $allvariables->{'DEVELOPMENTPRODUCT'} == 1 )) { $devproduct = 1; }
5053c0d14cbSmseidel
506cdf0e10cSrcweir	my $cwsproduct = 0;
507cdf0e10cSrcweir	# the environment variable CWS_WORK_STAMP is set only in CWS
508cdf0e10cSrcweir	if ( $ENV{'CWS_WORK_STAMP'} ) { $cwsproduct = 1; }
509cdf0e10cSrcweir
5103c0d14cbSmseidel	if (( $cwsproduct ) || ( $devproduct )) # use "DEV300m75"
511cdf0e10cSrcweir	{
512cdf0e10cSrcweir		my $source = uc($installer::globals::build); # DEV300
513cdf0e10cSrcweir		my $localminor = "";
514cdf0e10cSrcweir		if ( $installer::globals::minor ne "" ) { $localminor = $installer::globals::minor; }
515cdf0e10cSrcweir		else { $localminor = $installer::globals::lastminor; }
5163c0d14cbSmseidel		$version = $source . $localminor;
517cdf0e10cSrcweir	}
5183c0d14cbSmseidel	else # use 3.2.0rc1
519cdf0e10cSrcweir	{
520cdf0e10cSrcweir		$version = $allvariables->{'PRODUCTVERSION'};
521cdf0e10cSrcweir		if (( $allvariables->{'ABOUTBOXPRODUCTVERSION'} ) && ( $allvariables->{'ABOUTBOXPRODUCTVERSION'} ne "" )) { $version = $allvariables->{'ABOUTBOXPRODUCTVERSION'}; }
5223c0d14cbSmseidel		if (( $allvariables->{'SHORT_PRODUCTEXTENSION'} ) && ( $allvariables->{'SHORT_PRODUCTEXTENSION'} ne "" )) { $version = $version . $allvariables->{'SHORT_PRODUCTEXTENSION'}; }
523cdf0e10cSrcweir	}
5243c0d14cbSmseidel
525cdf0e10cSrcweir	return $version;
526cdf0e10cSrcweir}
527cdf0e10cSrcweir
528cdf0e10cSrcweir###############################################################
529cdf0e10cSrcweir# Set date string, format: yymmdd
530cdf0e10cSrcweir###############################################################
531cdf0e10cSrcweir
532cdf0e10cSrcweirsub set_date_string
533cdf0e10cSrcweir{
534cdf0e10cSrcweir	my ($allvariables) = @_;
535cdf0e10cSrcweir
536cdf0e10cSrcweir	my $datestring = "";
537cdf0e10cSrcweir
538cdf0e10cSrcweir	my $devproduct = 0;
539cdf0e10cSrcweir	if (( $allvariables->{'DEVELOPMENTPRODUCT'} ) && ( $allvariables->{'DEVELOPMENTPRODUCT'} == 1 )) { $devproduct = 1; }
5403c0d14cbSmseidel
541cdf0e10cSrcweir	my $cwsproduct = 0;
542cdf0e10cSrcweir	# the environment variable CWS_WORK_STAMP is set only in CWS
543cdf0e10cSrcweir	if ( $ENV{'CWS_WORK_STAMP'} ) { $cwsproduct = 1; }
544cdf0e10cSrcweir
545cdf0e10cSrcweir	my $releasebuild = 1;
5463c0d14cbSmseidel	if (( $allvariables->{'SHORT_PRODUCTEXTENSION'} ) && ( $allvariables->{'SHORT_PRODUCTEXTENSION'} ne "" )) { $releasebuild = 0; }
547cdf0e10cSrcweir
548cdf0e10cSrcweir	if (( ! $devproduct ) && ( ! $cwsproduct ) && ( ! $releasebuild ))
549cdf0e10cSrcweir	{
550cdf0e10cSrcweir		my @timearray = localtime(time);
551cdf0e10cSrcweir
552cdf0e10cSrcweir		my $day = $timearray[3];
553cdf0e10cSrcweir		my $month = $timearray[4] + 1;
554cdf0e10cSrcweir		my $year = $timearray[5] + 1900;
5553c0d14cbSmseidel
5563c0d14cbSmseidel		if ( $month < 10 ) { $month = "0" . $month; }
5573c0d14cbSmseidel		if ( $day < 10 ) { $day = "0" . $day; }
558cdf0e10cSrcweir
559cdf0e10cSrcweir		$datestring = $year . $month . $day;
560cdf0e10cSrcweir	}
561cdf0e10cSrcweir
562cdf0e10cSrcweir	return $datestring;
563cdf0e10cSrcweir}
564cdf0e10cSrcweir
565cdf0e10cSrcweir#################################################################
566cdf0e10cSrcweir# Setting the platform name for download
567cdf0e10cSrcweir#################################################################
568cdf0e10cSrcweir
569cdf0e10cSrcweirsub get_download_platformname
570cdf0e10cSrcweir{
571cdf0e10cSrcweir	my $platformname = "";
5723c0d14cbSmseidel
573cdf0e10cSrcweir	if ( $installer::globals::islinuxbuild )
574cdf0e10cSrcweir	{
575cdf0e10cSrcweir		$platformname = "Linux";
576cdf0e10cSrcweir	}
577cdf0e10cSrcweir	elsif ( $installer::globals::issolarisbuild )
578cdf0e10cSrcweir	{
579cdf0e10cSrcweir		$platformname = "Solaris";
580cdf0e10cSrcweir	}
581cdf0e10cSrcweir	elsif ( $installer::globals::iswindowsbuild )
582cdf0e10cSrcweir	{
583cdf0e10cSrcweir		$platformname = "Win";
584cdf0e10cSrcweir	}
585cdf0e10cSrcweir	elsif ( $installer::globals::isfreebsdbuild )
586cdf0e10cSrcweir	{
5873c0d14cbSmseidel		$platformname = "FreeBSD";
588cdf0e10cSrcweir	}
589cdf0e10cSrcweir	elsif ( $installer::globals::ismacbuild )
590cdf0e10cSrcweir	{
591cdf0e10cSrcweir		$platformname = "MacOS";
592cdf0e10cSrcweir	}
593cdf0e10cSrcweir	else
594cdf0e10cSrcweir	{
595cdf0e10cSrcweir		# $platformname = $installer::globals::packageformat;
5963c0d14cbSmseidel		$platformname = $installer::globals::compiler;
597cdf0e10cSrcweir	}
5983c0d14cbSmseidel
599cdf0e10cSrcweir	return $platformname;
600cdf0e10cSrcweir}
601cdf0e10cSrcweir
602cdf0e10cSrcweir#########################################################
603cdf0e10cSrcweir# Setting the architecture for the download name
604cdf0e10cSrcweir#########################################################
605cdf0e10cSrcweir
606cdf0e10cSrcweirsub get_download_architecture
607cdf0e10cSrcweir{
608cdf0e10cSrcweir	my $arch = "";
6093c0d14cbSmseidel
6104101619dSHerbert Dürr	if(( $installer::globals::compiler =~ /^unxlngi/ )
6114101619dSHerbert Dürr	|| ( $installer::globals::compiler =~ /^unxmac.i/ )
6124101619dSHerbert Dürr	|| ( $installer::globals::issolarisx86build )
6134101619dSHerbert Dürr	|| ( $installer::globals::iswindowsbuild ))
614cdf0e10cSrcweir	{
615cdf0e10cSrcweir		$arch = "x86";
616cdf0e10cSrcweir	}
6174101619dSHerbert Dürr	elsif(( $installer::globals::compiler =~ /^unxlngx/ )
6184101619dSHerbert Dürr	||    ( $installer::globals::compiler =~ /^unxmaccx/ ))
619cdf0e10cSrcweir	{
620cdf0e10cSrcweir		$arch = "x86-64";
621cdf0e10cSrcweir	}
622cdf0e10cSrcweir	elsif ( $installer::globals::issolarissparcbuild )
623cdf0e10cSrcweir	{
624cdf0e10cSrcweir		$arch = "Sparc";
625cdf0e10cSrcweir	}
6264101619dSHerbert Dürr	elsif(( $installer::globals::compiler =~ /^unxmacxp/ )
6274101619dSHerbert Dürr	||    ( $installer::globals::compiler =~ /^unxlngppc/ ))
628cdf0e10cSrcweir	{
629cdf0e10cSrcweir		$arch = "PPC";
630cdf0e10cSrcweir	}
6313c0d14cbSmseidel
6323c0d14cbSmseidel	return $arch;
633cdf0e10cSrcweir}
634cdf0e10cSrcweir
635cdf0e10cSrcweir#########################################################
636cdf0e10cSrcweir# Setting the installation type for the download name
637cdf0e10cSrcweir#########################################################
638cdf0e10cSrcweir
639cdf0e10cSrcweirsub get_install_type
640cdf0e10cSrcweir{
641cdf0e10cSrcweir	my ($allvariables) = @_;
6423c0d14cbSmseidel
643cdf0e10cSrcweir	my $type = "";
6443c0d14cbSmseidel
645cdf0e10cSrcweir	if ( $installer::globals::languagepack )
646cdf0e10cSrcweir	{
647cdf0e10cSrcweir		$type = "langpack";
648cdf0e10cSrcweir
649cdf0e10cSrcweir		if ( $installer::globals::islinuxrpmbuild )
650cdf0e10cSrcweir		{
651cdf0e10cSrcweir			$type = $type . "-rpm";
652cdf0e10cSrcweir		}
6533c0d14cbSmseidel
654cdf0e10cSrcweir		if ( $installer::globals::islinuxdebbuild )
655cdf0e10cSrcweir		{
656cdf0e10cSrcweir			$type = $type . "-deb";
657cdf0e10cSrcweir		}
6583c0d14cbSmseidel
659cdf0e10cSrcweir		if ( $installer::globals::packageformat eq "archive" )
660cdf0e10cSrcweir		{
6613c0d14cbSmseidel			$type = $type . "-arc";
662cdf0e10cSrcweir		}
663cdf0e10cSrcweir	}
664cdf0e10cSrcweir	else
665cdf0e10cSrcweir	{
666cdf0e10cSrcweir		$type = "install";
667cdf0e10cSrcweir
668cdf0e10cSrcweir		if ( $installer::globals::islinuxrpmbuild )
669cdf0e10cSrcweir		{
670cdf0e10cSrcweir			$type = $type . "-rpm";
671cdf0e10cSrcweir		}
6723c0d14cbSmseidel
673cdf0e10cSrcweir		if ( $installer::globals::islinuxdebbuild )
674cdf0e10cSrcweir		{
675cdf0e10cSrcweir			$type = $type . "-deb";
676cdf0e10cSrcweir		}
6773c0d14cbSmseidel
678cdf0e10cSrcweir		if ( $installer::globals::packageformat eq "archive" )
679cdf0e10cSrcweir		{
6803c0d14cbSmseidel			$type = $type . "-arc";
681cdf0e10cSrcweir		}
682cdf0e10cSrcweir
683cdf0e10cSrcweir		if (( $allvariables->{'WITHJREPRODUCT'} ) && ( $allvariables->{'WITHJREPRODUCT'} == 1 ))
684cdf0e10cSrcweir		{
685cdf0e10cSrcweir			$type = $type . "-wJRE";
686cdf0e10cSrcweir		}
687cdf0e10cSrcweir
688cdf0e10cSrcweir	}
6893c0d14cbSmseidel
690cdf0e10cSrcweir	return $type;
691cdf0e10cSrcweir}
692cdf0e10cSrcweir
693cdf0e10cSrcweir#########################################################
694cdf0e10cSrcweir# Setting installation addons
695cdf0e10cSrcweir#########################################################
696cdf0e10cSrcweir
697cdf0e10cSrcweirsub get_downloadname_addon
698cdf0e10cSrcweir{
699cdf0e10cSrcweir	my $addon = "";
700cdf0e10cSrcweir
701cdf0e10cSrcweir	if ( $installer::globals::islinuxdebbuild ) { $addon = $addon . "_deb"; }
7023c0d14cbSmseidel
703cdf0e10cSrcweir	if ( $installer::globals::product =~ /_wJRE\s*$/ ) { $addon = "_wJRE"; }
7043c0d14cbSmseidel
705cdf0e10cSrcweir	return $addon;
706cdf0e10cSrcweir}
707cdf0e10cSrcweir
708cdf0e10cSrcweir#########################################################
709cdf0e10cSrcweir# Looking for versionstring in version.info
710cdf0e10cSrcweir# This has to be the only content of this file.
711cdf0e10cSrcweir#########################################################
712cdf0e10cSrcweir
713cdf0e10cSrcweirsub get_versionstring
714cdf0e10cSrcweir{
715cdf0e10cSrcweir	my ( $versionfile ) = @_;
7163c0d14cbSmseidel
717cdf0e10cSrcweir	my $versionstring = "";
718cdf0e10cSrcweir
719cdf0e10cSrcweir	for ( my $i = 0; $i <= $#{$versionfile}; $i++ )
720cdf0e10cSrcweir	{
721cdf0e10cSrcweir		my $oneline = ${$versionfile}[$i];
7223c0d14cbSmseidel
723cdf0e10cSrcweir		if ( $oneline =~ /^\s*\#/ ) { next; } # comment line
724cdf0e10cSrcweir		if ( $oneline =~ /^\s*\"\s*(.*?)\s*\"\s*$/ )
725cdf0e10cSrcweir		{
726cdf0e10cSrcweir			$versionstring = $1;
727cdf0e10cSrcweir			last;
728cdf0e10cSrcweir		}
729cdf0e10cSrcweir	}
7303c0d14cbSmseidel
731cdf0e10cSrcweir	return $versionstring;
732cdf0e10cSrcweir}
733cdf0e10cSrcweir
734cdf0e10cSrcweir#########################################################
735cdf0e10cSrcweir# Returning the current product version
736cdf0e10cSrcweir# This has to be defined in file "version.info"
737cdf0e10cSrcweir# in directory $installer::globals::ooouploaddir
738cdf0e10cSrcweir#########################################################
739cdf0e10cSrcweir
740cdf0e10cSrcweirsub get_current_version
741cdf0e10cSrcweir{
742cdf0e10cSrcweir	my $versionstring = "";
743cdf0e10cSrcweir	my $filename = "version.info";
744cdf0e10cSrcweir	# $filename = $installer::globals::ooouploaddir . $installer::globals::separator . $filename;
7453c0d14cbSmseidel
746cdf0e10cSrcweir	if ( -f $filename )
747cdf0e10cSrcweir	{
7483c0d14cbSmseidel		$installer::logger::Lang->printf("File %s exists. Trying to find current version.\n", $filename);
749cdf0e10cSrcweir		my $versionfile = installer::files::read_file($filename);
750cdf0e10cSrcweir		$versionstring = get_versionstring($versionfile);
7513c0d14cbSmseidel		$installer::logger::Lang->printf("Setting version string: %s\n", $versionstring);
752cdf0e10cSrcweir	}
753cdf0e10cSrcweir	else
754cdf0e10cSrcweir	{
7553c0d14cbSmseidel		$installer::logger::Lang->printf("File %s does not exist. No version setting in download file name.\n", $filename);
756cdf0e10cSrcweir	}
757cdf0e10cSrcweir
758cdf0e10cSrcweir	$installer::globals::oooversionstring = $versionstring;
7593c0d14cbSmseidel
760cdf0e10cSrcweir	return $versionstring;
761cdf0e10cSrcweir}
762cdf0e10cSrcweir
763cdf0e10cSrcweir###############################################################################################
764cdf0e10cSrcweir# Setting the download file name
765cdf0e10cSrcweir# Syntax:
766cdf0e10cSrcweir# (PRODUCTNAME)_(VERSION)_(TIMESTAMP)_(OS)_(ARCH)_(INSTALLTYPE)_(LANGUAGE).(FILEEXTENSION)
767cdf0e10cSrcweir# Rules:
768cdf0e10cSrcweir# Timestamp only for Beta and Release Candidate
769cdf0e10cSrcweir###############################################################################################
770cdf0e10cSrcweir
771cdf0e10cSrcweirsub set_download_filename
772cdf0e10cSrcweir{
773cdf0e10cSrcweir	my ($languagestringref, $allvariables) = @_;
7743c0d14cbSmseidel
775cdf0e10cSrcweir	my $start = get_downloadname_productname($allvariables);
776cdf0e10cSrcweir	my $versionstring = get_download_version($allvariables);
777cdf0e10cSrcweir	my $date = set_date_string($allvariables);
778cdf0e10cSrcweir	my $platform = get_download_platformname();
779cdf0e10cSrcweir	my $architecture = get_download_architecture();
780cdf0e10cSrcweir	my $type = get_install_type($allvariables);
781cdf0e10cSrcweir	my $language = get_downloadname_language($languagestringref);
7823c0d14cbSmseidel
783cdf0e10cSrcweir	# Setting the extension happens automatically
784cdf0e10cSrcweir
7853c0d14cbSmseidel	my $filename = $start . "_" . $versionstring . "_" . $date . "_" . $platform . "_" . $architecture . "_" . $type . "_" . $language;
7863c0d14cbSmseidel
787cdf0e10cSrcweir	$filename =~ s/\_\_/\_/g;	# necessary, if $versionstring or $platform or $language are empty
788cdf0e10cSrcweir	$filename =~ s/\_\s*$//;	# necessary, if $language and $addon are empty
7893c0d14cbSmseidel
790cdf0e10cSrcweir	$installer::globals::ooodownloadfilename = $filename;
7913c0d14cbSmseidel
792cdf0e10cSrcweir	return $filename;
793cdf0e10cSrcweir}
794cdf0e10cSrcweir
795cdf0e10cSrcweir#########################################################
796cdf0e10cSrcweir# Creating a tar.gz file
797cdf0e10cSrcweir#########################################################
798cdf0e10cSrcweir
799cdf0e10cSrcweirsub create_tar_gz_file_from_directory
800cdf0e10cSrcweir{
801cdf0e10cSrcweir	my ($installdir, $getuidlibrary, $downloaddir, $downloadfilename) = @_;
802cdf0e10cSrcweir
803cdf0e10cSrcweir	my $packdir = $installdir;
804cdf0e10cSrcweir	installer::pathanalyzer::make_absolute_filename_to_relative_filename(\$packdir);
805cdf0e10cSrcweir	my $changedir = $installdir;
806cdf0e10cSrcweir	installer::pathanalyzer::get_path_from_fullqualifiedname(\$changedir);
807cdf0e10cSrcweir
808cdf0e10cSrcweir	my $ldpreloadstring = "";
809e250bff1SJim Jagielski
81043c75f1dSJim Jagielski	if (($ENV{'FAKEROOT'} ne "no") && ($ENV{'FAKEROOT'} ne "")) {
811e250bff1SJim Jagielski		$ldpreloadstring = $ENV{'FAKEROOT'};
812e250bff1SJim Jagielski	} else {
813e250bff1SJim Jagielski		if ( $getuidlibrary ne "" ) { $ldpreloadstring = "LD_PRELOAD=" . $getuidlibrary; }
814e250bff1SJim Jagielski	}
815cdf0e10cSrcweir
816cdf0e10cSrcweir	$installer::globals::downloadfileextension = ".tar.gz";
817cdf0e10cSrcweir	$installer::globals::downloadfilename = $downloadfilename . $installer::globals::downloadfileextension;
818cdf0e10cSrcweir	my $targzname = $downloaddir . $installer::globals::separator . $installer::globals::downloadfilename;
819cdf0e10cSrcweir
8200b2dfbacSAndre Fischer	my $systemcall = "cd $changedir; $ldpreloadstring tar -cf - $packdir | gzip > $targzname";
8213c0d14cbSmseidel
822cdf0e10cSrcweir	my $returnvalue = system($systemcall);
823cdf0e10cSrcweir
8243c0d14cbSmseidel	$installer::logger::Lang->printf("Systemcall: %s\n", $systemcall);
8253c0d14cbSmseidel
826cdf0e10cSrcweir	if ($returnvalue)
827cdf0e10cSrcweir	{
8283c0d14cbSmseidel		$installer::logger::Lang->printf("ERROR: Could not execute \"%s\"!\n", $systemcall);
829cdf0e10cSrcweir	}
830cdf0e10cSrcweir	else
831cdf0e10cSrcweir	{
8323c0d14cbSmseidel		$installer::logger::Lang->printf("Success: Executed \"%s\" successfully!\n", $systemcall);
833cdf0e10cSrcweir	}
8343c0d14cbSmseidel
835cdf0e10cSrcweir	return $targzname;
836cdf0e10cSrcweir}
837cdf0e10cSrcweir
838cdf0e10cSrcweir#########################################################
839cdf0e10cSrcweir# Setting the variables in the download name
840cdf0e10cSrcweir#########################################################
841cdf0e10cSrcweir
842cdf0e10cSrcweirsub resolve_variables_in_downloadname
843cdf0e10cSrcweir{
844cdf0e10cSrcweir	my ($allvariables, $downloadname, $languagestringref) = @_;
845cdf0e10cSrcweir
846cdf0e10cSrcweir	# Typical name: soa-{productversion}-{extension}-bin-{os}-{languages}
847cdf0e10cSrcweir
848d62abd1aSAndre Fischer	my $productversion = $allvariables->{'PRODUCTVERSION'};
849d62abd1aSAndre Fischer	$productversion = "" unless defined $productversion;
850cdf0e10cSrcweir	$downloadname =~ s/\{productversion\}/$productversion/;
851cdf0e10cSrcweir
852d62abd1aSAndre Fischer	my $packageversion = $allvariables->{'PACKAGEVERSION'};
853d62abd1aSAndre Fischer	$packageversion = "" unless defined $packageversion;
854cdf0e10cSrcweir	$downloadname =~ s/\{packageversion\}/$packageversion/;
855cdf0e10cSrcweir
856d62abd1aSAndre Fischer	my $extension = $allvariables->{'SHORT_PRODUCTEXTENSION'};
857d62abd1aSAndre Fischer	$extension = "" unless defined $extension;
858cdf0e10cSrcweir	$extension = lc($extension);
859cdf0e10cSrcweir	$downloadname =~ s/\{extension\}/$extension/;
860cdf0e10cSrcweir
861cdf0e10cSrcweir	my $os = "";
862cdf0e10cSrcweir	if ( $installer::globals::iswindowsbuild ) { $os = "windows"; }
863cdf0e10cSrcweir	elsif ( $installer::globals::issolarissparcbuild ) { $os = "solsparc"; }
864cdf0e10cSrcweir	elsif ( $installer::globals::issolarisx86build ) { $os = "solia"; }
865cdf0e10cSrcweir	elsif ( $installer::globals::islinuxbuild ) { $os = "linux"; }
8664101619dSHerbert Dürr	elsif ( $installer::globals::compiler =~ /unxmac.i/ ) { $os = "macosi"; }
8674101619dSHerbert Dürr	elsif ( $installer::globals::compiler =~ /unxmac.x/ ) { $os = "macosx"; }
8684101619dSHerbert Dürr	elsif ( $installer::globals::compiler =~ /unxmacxp/ ) { $os = "macosp"; }
8693c0d14cbSmseidel	else { $os = ""; }
870cdf0e10cSrcweir	$downloadname =~ s/\{os\}/$os/;
871cdf0e10cSrcweir
872cdf0e10cSrcweir	my $languages = $$languagestringref;
873cdf0e10cSrcweir	$downloadname =~ s/\{languages\}/$languages/;
8743c0d14cbSmseidel
875cdf0e10cSrcweir	$downloadname =~ s/\-\-\-/\-/g;
876cdf0e10cSrcweir	$downloadname =~ s/\-\-/\-/g;
877cdf0e10cSrcweir	$downloadname =~ s/\-\s*$//;
878cdf0e10cSrcweir
879cdf0e10cSrcweir	return $downloadname;
880cdf0e10cSrcweir}
881cdf0e10cSrcweir
882cdf0e10cSrcweir##################################################################
8833c0d14cbSmseidel# Windows: Replacing one placeholder with the specified value
884cdf0e10cSrcweir##################################################################
885cdf0e10cSrcweir
886cdf0e10cSrcweirsub replace_one_variable
887cdf0e10cSrcweir{
888cdf0e10cSrcweir	my ($templatefile, $placeholder, $value) = @_;
889cdf0e10cSrcweir
8903c0d14cbSmseidel	$installer::logger::Lang->printf("Replacing %s by %s in nsi file\n", $placeholder, $value);
891cdf0e10cSrcweir
892cdf0e10cSrcweir	for ( my $i = 0; $i <= $#{$templatefile}; $i++ )
893cdf0e10cSrcweir	{
894cdf0e10cSrcweir		${$templatefile}[$i] =~ s/$placeholder/$value/g;
895cdf0e10cSrcweir	}
896cdf0e10cSrcweir
897cdf0e10cSrcweir}
898cdf0e10cSrcweir
899cdf0e10cSrcweir########################################################################################
900cdf0e10cSrcweir# Converting a string to a unicode string
901cdf0e10cSrcweir########################################################################################
902cdf0e10cSrcweir
903cdf0e10cSrcweirsub convert_to_unicode
904cdf0e10cSrcweir{
905cdf0e10cSrcweir	my ($string) = @_;
9063c0d14cbSmseidel
907cdf0e10cSrcweir	my $unicodestring = "";
9083c0d14cbSmseidel
909cdf0e10cSrcweir	my $stringlength = length($string);
9103c0d14cbSmseidel
911cdf0e10cSrcweir	for ( my $i = 0; $i < $stringlength; $i++ )
912cdf0e10cSrcweir	{
913cdf0e10cSrcweir		$unicodestring = $unicodestring . substr($string, $i, 1);
914cdf0e10cSrcweir		$unicodestring = $unicodestring . chr(0);
9153c0d14cbSmseidel	}
916cdf0e10cSrcweir
917cdf0e10cSrcweir	return $unicodestring;
918cdf0e10cSrcweir}
919cdf0e10cSrcweir
920cdf0e10cSrcweir##################################################################
9213c0d14cbSmseidel# Windows: Including the product name into nsi template
922cdf0e10cSrcweir##################################################################
923cdf0e10cSrcweir
924cdf0e10cSrcweirsub put_windows_productname_into_template
925cdf0e10cSrcweir{
926cdf0e10cSrcweir	my ($templatefile, $variableshashref) = @_;
9273c0d14cbSmseidel
928cdf0e10cSrcweir	my $productname = $variableshashref->{'PRODUCTNAME'};
929cdf0e10cSrcweir	$productname =~ s/\.//g;	# OpenOffice.org -> OpenOfficeorg
930cdf0e10cSrcweir
931cdf0e10cSrcweir	replace_one_variable($templatefile, "PRODUCTNAMEPLACEHOLDER", $productname);
932cdf0e10cSrcweir}
933cdf0e10cSrcweir
934cdf0e10cSrcweir##################################################################
9353c0d14cbSmseidel# Windows: Including the path to the banner.bmp into nsi template
936cdf0e10cSrcweir##################################################################
937cdf0e10cSrcweir
938cdf0e10cSrcweirsub put_banner_bmp_into_template
939cdf0e10cSrcweir{
940cdf0e10cSrcweir	my ($templatefile, $includepatharrayref, $allvariables) = @_;
9413c0d14cbSmseidel
942cdf0e10cSrcweir	# my $filename = "downloadbanner.bmp";
943cdf0e10cSrcweir	if ( ! $allvariables->{'DOWNLOADBANNER'} ) { installer::exiter::exit_program("ERROR: DOWNLOADBANNER not defined in product definition!", "put_banner_bmp_into_template"); }
944cdf0e10cSrcweir	my $filename = $allvariables->{'DOWNLOADBANNER'};
945cdf0e10cSrcweir
946cdf0e10cSrcweir	my $completefilenameref = "";
947cdf0e10cSrcweir
948cdf0e10cSrcweir	if ( $installer::globals::include_pathes_read )
949cdf0e10cSrcweir	{
9503c0d14cbSmseidel		$completefilenameref = installer::scriptitems::get_sourcepath_from_filename_and_includepath(\$filename, $includepatharrayref, 0);
951cdf0e10cSrcweir	}
952cdf0e10cSrcweir	else
953cdf0e10cSrcweir	{
954cdf0e10cSrcweir		$completefilenameref = installer::scriptitems::get_sourcepath_from_filename_and_includepath_classic(\$filename, $includepatharrayref, 0);
955cdf0e10cSrcweir	}
956cdf0e10cSrcweir
957cdf0e10cSrcweir	if ($$completefilenameref eq "") { installer::exiter::exit_program("ERROR: Could not find download file $filename!", "put_banner_bmp_into_template"); }
958cdf0e10cSrcweir
959cdf0e10cSrcweir	if ( $^O =~ /cygwin/i ) { $$completefilenameref =~ s/\//\\/g; }
960cdf0e10cSrcweir
961cdf0e10cSrcweir	replace_one_variable($templatefile, "BANNERBMPPLACEHOLDER", $$completefilenameref);
962cdf0e10cSrcweir}
963cdf0e10cSrcweir
964cdf0e10cSrcweir##################################################################
9653c0d14cbSmseidel# Windows: Including the path to the welcome.bmp into nsi template
966cdf0e10cSrcweir##################################################################
967cdf0e10cSrcweir
968cdf0e10cSrcweirsub put_welcome_bmp_into_template
969cdf0e10cSrcweir{
970cdf0e10cSrcweir	my ($templatefile, $includepatharrayref, $allvariables) = @_;
971cdf0e10cSrcweir
972cdf0e10cSrcweir	# my $filename = "downloadbitmap.bmp";
973cdf0e10cSrcweir	if ( ! $allvariables->{'DOWNLOADBITMAP'} ) { installer::exiter::exit_program("ERROR: DOWNLOADBITMAP not defined in product definition!", "put_welcome_bmp_into_template"); }
974cdf0e10cSrcweir	my $filename = $allvariables->{'DOWNLOADBITMAP'};
975cdf0e10cSrcweir
976cdf0e10cSrcweir	my $completefilenameref = "";
977cdf0e10cSrcweir
978cdf0e10cSrcweir	if ( $installer::globals::include_pathes_read )
979cdf0e10cSrcweir	{
980cdf0e10cSrcweir		$completefilenameref = installer::scriptitems::get_sourcepath_from_filename_and_includepath(\$filename, $includepatharrayref, 0);
981cdf0e10cSrcweir	}
982cdf0e10cSrcweir	else
983cdf0e10cSrcweir	{
984cdf0e10cSrcweir		$completefilenameref = installer::scriptitems::get_sourcepath_from_filename_and_includepath_classic(\$filename, $includepatharrayref, 0);
985cdf0e10cSrcweir	}
986cdf0e10cSrcweir
987cdf0e10cSrcweir	if ($$completefilenameref eq "") { installer::exiter::exit_program("ERROR: Could not find download file $filename!", "put_welcome_bmp_into_template"); }
988cdf0e10cSrcweir
989cdf0e10cSrcweir	if ( $^O =~ /cygwin/i ) { $$completefilenameref =~ s/\//\\/g; }
990cdf0e10cSrcweir
991cdf0e10cSrcweir	replace_one_variable($templatefile, "WELCOMEBMPPLACEHOLDER", $$completefilenameref);
992cdf0e10cSrcweir}
993cdf0e10cSrcweir
994cdf0e10cSrcweir##################################################################
9953c0d14cbSmseidel# Windows: Including the path to the setup.ico into nsi template
996cdf0e10cSrcweir##################################################################
997cdf0e10cSrcweir
998cdf0e10cSrcweirsub put_setup_ico_into_template
999cdf0e10cSrcweir{
1000cdf0e10cSrcweir	my ($templatefile, $includepatharrayref, $allvariables) = @_;
1001cdf0e10cSrcweir
1002cdf0e10cSrcweir	# my $filename = "downloadsetup.ico";
1003cdf0e10cSrcweir	if ( ! $allvariables->{'DOWNLOADSETUPICO'} ) { installer::exiter::exit_program("ERROR: DOWNLOADSETUPICO not defined in product definition!", "put_setup_ico_into_template"); }
1004cdf0e10cSrcweir	my $filename = $allvariables->{'DOWNLOADSETUPICO'};
1005cdf0e10cSrcweir
1006cdf0e10cSrcweir	my $completefilenameref = "";
1007cdf0e10cSrcweir
1008cdf0e10cSrcweir	if ( $installer::globals::include_pathes_read )
1009cdf0e10cSrcweir	{
1010cdf0e10cSrcweir		$completefilenameref = installer::scriptitems::get_sourcepath_from_filename_and_includepath(\$filename, $includepatharrayref, 0);
1011cdf0e10cSrcweir	}
1012cdf0e10cSrcweir	else
1013cdf0e10cSrcweir	{
1014cdf0e10cSrcweir		$completefilenameref = installer::scriptitems::get_sourcepath_from_filename_and_includepath_classic(\$filename, $includepatharrayref, 0);
1015cdf0e10cSrcweir	}
1016cdf0e10cSrcweir
1017cdf0e10cSrcweir	if ($$completefilenameref eq "") { installer::exiter::exit_program("ERROR: Could not find download file $filename!", "put_setup_ico_into_template"); }
1018cdf0e10cSrcweir
1019cdf0e10cSrcweir	if ( $^O =~ /cygwin/i ) { $$completefilenameref =~ s/\//\\/g; }
1020cdf0e10cSrcweir
1021cdf0e10cSrcweir	replace_one_variable($templatefile, "SETUPICOPLACEHOLDER", $$completefilenameref);
1022cdf0e10cSrcweir}
1023cdf0e10cSrcweir
1024cdf0e10cSrcweir##################################################################
10253c0d14cbSmseidel# Windows: Including the publisher into nsi template
1026cdf0e10cSrcweir##################################################################
1027cdf0e10cSrcweir
10280b2dfbacSAndre Fischersub put_publisher_into_template ($$)
1029cdf0e10cSrcweir{
10303c0d14cbSmseidel	my ($templatefile, $variables) = @_;
10313c0d14cbSmseidel
10323c0d14cbSmseidel	my $publisher = $variables->{'OOOVENDOR'};
10333c0d14cbSmseidel	$publisher = "" unless defined $publisher;
1034cdf0e10cSrcweir
10353c0d14cbSmseidel	replace_one_variable($templatefile, "PUBLISHERPLACEHOLDER", $publisher);
1036cdf0e10cSrcweir}
1037cdf0e10cSrcweir
1038cdf0e10cSrcweir##################################################################
10393c0d14cbSmseidel# Windows: Including the web site into nsi template
1040cdf0e10cSrcweir##################################################################
1041cdf0e10cSrcweir
10420b2dfbacSAndre Fischersub put_website_into_template ($$)
1043cdf0e10cSrcweir{
10443c0d14cbSmseidel	my ($templatefile, $variables) = @_;
1045cdf0e10cSrcweir
10463c0d14cbSmseidel	my $website = $variables->{'STARTCENTER_INFO_URL'};
10473c0d14cbSmseidel	$website = "" unless defined $website;
1048cdf0e10cSrcweir
10493c0d14cbSmseidel	replace_one_variable($templatefile, "WEBSITEPLACEHOLDER", $website);
1050cdf0e10cSrcweir}
1051cdf0e10cSrcweir
1052cdf0e10cSrcweir##################################################################
10533c0d14cbSmseidel# Windows: Including the Java file name into nsi template
1054cdf0e10cSrcweir##################################################################
1055cdf0e10cSrcweir
1056cdf0e10cSrcweirsub put_javafilename_into_template
1057cdf0e10cSrcweir{
1058cdf0e10cSrcweir	my ($templatefile, $variableshashref) = @_;
10593c0d14cbSmseidel
1060cdf0e10cSrcweir	my $javaversion = "";
10613c0d14cbSmseidel
1062cdf0e10cSrcweir	if ( $variableshashref->{'WINDOWSJAVAFILENAME'} ) { $javaversion = $variableshashref->{'WINDOWSJAVAFILENAME'}; }
10633c0d14cbSmseidel
1064cdf0e10cSrcweir	replace_one_variable($templatefile, "WINDOWSJAVAFILENAMEPLACEHOLDER", $javaversion);
1065cdf0e10cSrcweir}
1066cdf0e10cSrcweir
1067cdf0e10cSrcweir##################################################################
10683c0d14cbSmseidel# Windows: Including the product version into nsi template
1069cdf0e10cSrcweir##################################################################
1070cdf0e10cSrcweir
1071cdf0e10cSrcweirsub put_windows_productversion_into_template
1072cdf0e10cSrcweir{
1073cdf0e10cSrcweir	my ($templatefile, $variableshashref) = @_;
10743c0d14cbSmseidel
1075cdf0e10cSrcweir	my $productversion = $variableshashref->{'PRODUCTVERSION'};
10763c0d14cbSmseidel
1077cdf0e10cSrcweir	replace_one_variable($templatefile, "PRODUCTVERSIONPLACEHOLDER", $productversion);
1078cdf0e10cSrcweir}
1079cdf0e10cSrcweir
1080cdf0e10cSrcweir##################################################################
10813c0d14cbSmseidel# Windows: Including the product version into nsi template
1082cdf0e10cSrcweir##################################################################
1083cdf0e10cSrcweir
1084cdf0e10cSrcweirsub put_windows_productpath_into_template
1085cdf0e10cSrcweir{
1086cdf0e10cSrcweir	my ($templatefile, $variableshashref, $languagestringref, $localnsisdir) = @_;
10873c0d14cbSmseidel
1088cdf0e10cSrcweir	my $productpath = $variableshashref->{'PROPERTYTABLEPRODUCTNAME'};
10893c0d14cbSmseidel
1090cdf0e10cSrcweir	my $locallangs = $$languagestringref;
1091cdf0e10cSrcweir	$locallangs =~ s/_/ /g;
1092cdf0e10cSrcweir	if (length($locallangs) > $installer::globals::max_lang_length) { $locallangs = "multi lingual"; }
1093cdf0e10cSrcweir
10943c0d14cbSmseidel	if ( ! $installer::globals::languagepack ) { $productpath = $productpath . " (" . $locallangs . ")"; }
109514ebc950Sarielch
1096cdf0e10cSrcweir	replace_one_variable($templatefile, "PRODUCTPATHPLACEHOLDER", $productpath);
1097cdf0e10cSrcweir}
1098cdf0e10cSrcweir
1099cdf0e10cSrcweir##################################################################
11003c0d14cbSmseidel# Windows: Including download file name into nsi template
1101cdf0e10cSrcweir##################################################################
1102cdf0e10cSrcweir
1103cdf0e10cSrcweirsub put_outputfilename_into_template
1104cdf0e10cSrcweir{
1105cdf0e10cSrcweir	my ($templatefile, $downloadname) = @_;
11063c0d14cbSmseidel
1107cdf0e10cSrcweir	$installer::globals::downloadfileextension = ".exe";
1108cdf0e10cSrcweir	$downloadname = $downloadname . $installer::globals::downloadfileextension;
1109cdf0e10cSrcweir	$installer::globals::downloadfilename = $downloadname;
1110cdf0e10cSrcweir
1111cdf0e10cSrcweir	replace_one_variable($templatefile, "DOWNLOADNAMEPLACEHOLDER", $downloadname);
1112cdf0e10cSrcweir}
1113cdf0e10cSrcweir
1114cdf0e10cSrcweir##################################################################
11153c0d14cbSmseidel# Windows: Generating the file list in nsi file format
1116cdf0e10cSrcweir##################################################################
1117cdf0e10cSrcweir
1118cdf0e10cSrcweirsub get_file_list
1119cdf0e10cSrcweir{
1120cdf0e10cSrcweir	my ( $basedir ) = @_;
1121cdf0e10cSrcweir
1122cdf0e10cSrcweir	my @filelist = ();
1123cdf0e10cSrcweir
1124cdf0e10cSrcweir	my $alldirs = installer::systemactions::get_all_directories($basedir);
1125cdf0e10cSrcweir	unshift(@{$alldirs}, $basedir);	# $basedir is the first directory in $alldirs
11263c0d14cbSmseidel
1127cdf0e10cSrcweir	for ( my $i = 0; $i <= $#{$alldirs}; $i++ )
1128cdf0e10cSrcweir	{
1129cdf0e10cSrcweir		my $onedir = ${$alldirs}[$i];
11303c0d14cbSmseidel
1131cdf0e10cSrcweir		# Syntax:
1132cdf0e10cSrcweir		# SetOutPath "$INSTDIR"
1133cdf0e10cSrcweir
1134cdf0e10cSrcweir		my $relativedir = $onedir;
1135cdf0e10cSrcweir		$relativedir =~ s/\Q$basedir\E//;
1136cdf0e10cSrcweir
1137cdf0e10cSrcweir		my $oneline = " " . "SetOutPath" . " " . "\"\$INSTDIR" . $relativedir . "\"" . "\n";
11383c0d14cbSmseidel
1139cdf0e10cSrcweir		if ( $^O =~ /cygwin/i ) {
1140cdf0e10cSrcweir			$oneline =~ s/\//\\/g;
1141cdf0e10cSrcweir		}
1142cdf0e10cSrcweir		push(@filelist, $oneline);
11433c0d14cbSmseidel
1144cdf0e10cSrcweir		# Collecting all files in the specific directory
11453c0d14cbSmseidel
1146cdf0e10cSrcweir		my $files = installer::systemactions::get_all_files_from_one_directory($onedir);
11473c0d14cbSmseidel
1148cdf0e10cSrcweir		for ( my $j = 0; $j <= $#{$files}; $j++ )
1149cdf0e10cSrcweir		{
1150cdf0e10cSrcweir			my $onefile = ${$files}[$j];
11513c0d14cbSmseidel
1152cdf0e10cSrcweir			my $fileline = "  " . "File" . " " . "\"" . $onefile . "\"" . "\n";
1153cdf0e10cSrcweir
1154cdf0e10cSrcweir			if ( $^O =~ /cygwin/i ) {
1155cdf0e10cSrcweir				$fileline =~ s/\//\\/g;
1156cdf0e10cSrcweir			}
1157cdf0e10cSrcweir			push(@filelist, $fileline);
1158cdf0e10cSrcweir		}
1159cdf0e10cSrcweir	}
1160cdf0e10cSrcweir
1161cdf0e10cSrcweir	return \@filelist;
1162cdf0e10cSrcweir}
1163cdf0e10cSrcweir
1164cdf0e10cSrcweir##################################################################
11653c0d14cbSmseidel# Windows: Including list of all files into nsi template
1166cdf0e10cSrcweir##################################################################
1167cdf0e10cSrcweir
1168cdf0e10cSrcweirsub put_filelist_into_template
1169cdf0e10cSrcweir{
1170cdf0e10cSrcweir	my ($templatefile, $installationdir) = @_;
11713c0d14cbSmseidel
1172cdf0e10cSrcweir	my $filelist = get_file_list($installationdir);
1173cdf0e10cSrcweir
1174cdf0e10cSrcweir	my $filestring = "";
1175cdf0e10cSrcweir
1176cdf0e10cSrcweir	for ( my $i = 0; $i <= $#{$filelist}; $i++ )
1177cdf0e10cSrcweir	{
1178cdf0e10cSrcweir		$filestring = $filestring . ${$filelist}[$i];
1179cdf0e10cSrcweir	}
11803c0d14cbSmseidel
1181cdf0e10cSrcweir	$filestring =~ s/\s*$//;
11823c0d14cbSmseidel
1183cdf0e10cSrcweir	replace_one_variable($templatefile, "ALLFILESPLACEHOLDER", $filestring);
1184cdf0e10cSrcweir}
1185cdf0e10cSrcweir
1186cdf0e10cSrcweir##################################################################
11873c0d14cbSmseidel# Windows: NSIS uses specific language names
1188cdf0e10cSrcweir##################################################################
1189cdf0e10cSrcweir
1190cdf0e10cSrcweirsub nsis_language_converter
1191cdf0e10cSrcweir{
1192cdf0e10cSrcweir	my ($language) = @_;
11933c0d14cbSmseidel
1194cdf0e10cSrcweir	my $nsislanguage = "";
1195cdf0e10cSrcweir
11963c0d14cbSmseidel	# Assign language used by NSIS.
1197cdf0e10cSrcweir	# The files "$nsislanguage.nsh" and "$nsislanguage.nlf"
1198cdf0e10cSrcweir	# are needed in the NSIS environment.
1199cdf0e10cSrcweir	# Directory: <NSIS-Dir>/Contrib/Language files
1200cdf0e10cSrcweir	if ( $language eq "en-US" ) { $nsislanguage = "English"; }
1201404f1323SJim Jagielski	elsif ( $language eq "af" ) { $nsislanguage = "Afrikaans"; }
1202cdf0e10cSrcweir	elsif ( $language eq "sq" ) { $nsislanguage = "Albanian"; }
12034cffc213Smseidel	elsif ( $language eq "ar" ) { $nsislanguage = "Arabic"; }
1204404f1323SJim Jagielski	elsif ( $language eq "hy" ) { $nsislanguage = "Armenian"; }
1205404f1323SJim Jagielski	elsif ( $language eq "ast" ) { $nsislanguage = "Asturian"; }
1206404f1323SJim Jagielski	elsif ( $language eq "eu" ) { $nsislanguage = "Basque"; }
1207cdf0e10cSrcweir	elsif ( $language eq "bg" ) { $nsislanguage = "Bulgarian"; }
1208cdf0e10cSrcweir	elsif ( $language eq "ca" ) { $nsislanguage = "Catalan"; }
1209cdf0e10cSrcweir	elsif ( $language eq "hr" ) { $nsislanguage = "Croatian"; }
1210cdf0e10cSrcweir	elsif ( $language eq "cs" ) { $nsislanguage = "Czech"; }
1211cdf0e10cSrcweir	elsif ( $language eq "da" ) { $nsislanguage = "Danish"; }
1212cdf0e10cSrcweir	elsif ( $language eq "nl" ) { $nsislanguage = "Dutch"; }
1213404f1323SJim Jagielski	elsif ( $language eq "en-GB" ) { $nsislanguage = "English"; }
1214*d7e3b64dSmseidel	elsif ( $language eq "eo" ) { $nsislanguage = "Esperanto"; }
1215cdf0e10cSrcweir	elsif ( $language eq "et" ) { $nsislanguage = "Estonian"; }
1216cdf0e10cSrcweir	elsif ( $language eq "fa" ) { $nsislanguage = "Farsi"; }
1217cdf0e10cSrcweir	elsif ( $language eq "fi" ) { $nsislanguage = "Finnish"; }
1218cdf0e10cSrcweir	elsif ( $language eq "fr" ) { $nsislanguage = "French"; }
1219404f1323SJim Jagielski	elsif ( $language eq "gl" ) { $nsislanguage = "Galician"; }
1220404f1323SJim Jagielski	elsif ( $language eq "de" ) { $nsislanguage = "German"; }
1221404f1323SJim Jagielski	elsif ( $language eq "el" ) { $nsislanguage = "Greek"; }
1222cdf0e10cSrcweir	elsif ( $language eq "he" ) { $nsislanguage = "Hebrew"; }
1223392e01b2Smseidel	elsif ( $language eq "hi" ) { $nsislanguage = "Hindi"; }
1224404f1323SJim Jagielski	elsif ( $language eq "hu" ) { $nsislanguage = "Hungarian"; }
1225cdf0e10cSrcweir	elsif ( $language eq "is" ) { $nsislanguage = "Icelandic"; }
1226cdf0e10cSrcweir	elsif ( $language eq "id" ) { $nsislanguage = "Indonesian"; }
1227cdf0e10cSrcweir	elsif ( $language eq "it" ) { $nsislanguage = "Italian"; }
1228404f1323SJim Jagielski	elsif ( $language eq "ja" ) { $nsislanguage = "Japanese"; }
1229404f1323SJim Jagielski	elsif ( $language eq "ko" ) { $nsislanguage = "Korean"; }
1230cdf0e10cSrcweir	elsif ( $language eq "lv" ) { $nsislanguage = "Latvian"; }
1231cdf0e10cSrcweir	elsif ( $language eq "lt" ) { $nsislanguage = "Lithuanian"; }
1232404f1323SJim Jagielski	elsif ( $language eq "de-LU" ) { $nsislanguage = "Luxembourgish"; }
1233cdf0e10cSrcweir	elsif ( $language eq "mk" ) { $nsislanguage = "Macedonian"; }
1234cdf0e10cSrcweir	elsif ( $language eq "mn" ) { $nsislanguage = "Mongolian"; }
1235fdcb970cSJim Jagielski	elsif ( $language eq "nb" ) { $nsislanguage = "Norwegian"; }
1236cdf0e10cSrcweir	elsif ( $language eq "no" ) { $nsislanguage = "Norwegian"; }
1237cdf0e10cSrcweir	elsif ( $language eq "no-NO" ) { $nsislanguage = "Norwegian"; }
1238404f1323SJim Jagielski	elsif ( $language eq "nn" ) { $nsislanguage = "NorwegianNynorsk"; }
1239cdf0e10cSrcweir	elsif ( $language eq "pl" ) { $nsislanguage = "Polish"; }
1240cdf0e10cSrcweir	elsif ( $language eq "pt" ) { $nsislanguage = "Portuguese"; }
1241404f1323SJim Jagielski	elsif ( $language eq "pt-BR" ) { $nsislanguage = "PortugueseBR"; }
1242cdf0e10cSrcweir	elsif ( $language eq "ro" ) { $nsislanguage = "Romanian"; }
1243cdf0e10cSrcweir	elsif ( $language eq "ru" ) { $nsislanguage = "Russian"; }
1244404f1323SJim Jagielski	elsif ( $language eq "gd" ) { $nsislanguage = "ScotsGaelic"; }
1245cdf0e10cSrcweir	elsif ( $language eq "sr" ) { $nsislanguage = "Serbian"; }
1246cdf0e10cSrcweir	elsif ( $language eq "sr-SP" ) { $nsislanguage = "Serbian"; }
1247404f1323SJim Jagielski	elsif ( $language eq "sh" ) { $nsislanguage = "SerbianLatin"; }
1248cdf0e10cSrcweir	elsif ( $language eq "zh-CN" ) { $nsislanguage = "SimpChinese"; }
1249404f1323SJim Jagielski	elsif ( $language eq "sk" ) { $nsislanguage = "Slovak"; }
1250*d7e3b64dSmseidel	elsif ( $language eq "sl" ) { $nsislanguage = "Slovenian"; }
1251404f1323SJim Jagielski	elsif ( $language eq "es" ) { $nsislanguage = "Spanish"; }
1252404f1323SJim Jagielski	elsif ( $language eq "sv" ) { $nsislanguage = "Swedish"; }
1253404f1323SJim Jagielski	elsif ( $language eq "th" ) { $nsislanguage = "Thai"; }
1254cdf0e10cSrcweir	elsif ( $language eq "zh-TW" ) { $nsislanguage = "TradChinese"; }
1255404f1323SJim Jagielski	elsif ( $language eq "tr" ) { $nsislanguage = "Turkish"; }
12564cffc213Smseidel	elsif ( $language eq "uk" ) { $nsislanguage = "Ukrainian"; }
1257404f1323SJim Jagielski	elsif ( $language eq "vi" ) { $nsislanguage = "Vietnamese"; }
1258404f1323SJim Jagielski	elsif ( $language eq "cy" ) { $nsislanguage = "Welsh"; }
1259b274bc22SAndre Fischer	else
12603c0d14cbSmseidel	{
12613c0d14cbSmseidel		$installer::logger::Lang->printf("NSIS language_converter : Could not find nsis language for %s!\n", $language);
1262cdf0e10cSrcweir		$nsislanguage = "English";
1263cdf0e10cSrcweir	}
1264cdf0e10cSrcweir
1265cdf0e10cSrcweir	return $nsislanguage;
1266cdf0e10cSrcweir}
1267cdf0e10cSrcweir
1268cdf0e10cSrcweir##################################################################
12693c0d14cbSmseidel# Windows: Including list of all languages into nsi template
1270cdf0e10cSrcweir##################################################################
1271cdf0e10cSrcweir
1272cdf0e10cSrcweirsub put_language_list_into_template
1273cdf0e10cSrcweir{
1274cdf0e10cSrcweir	my ($templatefile, $languagesarrayref) = @_;
1275cdf0e10cSrcweir
1276cdf0e10cSrcweir	my $alllangstring = "";
1277cdf0e10cSrcweir	my %nsislangs;
12783c0d14cbSmseidel
1279cdf0e10cSrcweir	for ( my $i = 0; $i <= $#{$languagesarrayref}; $i++ )
1280cdf0e10cSrcweir	{
1281cdf0e10cSrcweir		my $onelanguage = ${$languagesarrayref}[$i];
1282cdf0e10cSrcweir		my $nsislanguage = nsis_language_converter($onelanguage);
1283cdf0e10cSrcweir		$nsislangs{$nsislanguage}++;
1284cdf0e10cSrcweir	}
1285cdf0e10cSrcweir
1286cdf0e10cSrcweir	foreach my $nsislanguage ( keys(%nsislangs) )
1287cdf0e10cSrcweir	{
1288cdf0e10cSrcweir		# Syntax: !insertmacro MUI_LANGUAGE "English"
1289cdf0e10cSrcweir		my $langstring = "\!insertmacro MUI_LANGUAGE_PACK " . $nsislanguage . "\n";
1290cdf0e10cSrcweir		if ( $nsislanguage eq "English" )
1291cdf0e10cSrcweir		{
1292cdf0e10cSrcweir			$alllangstring = $langstring . $alllangstring;
1293cdf0e10cSrcweir		}
1294cdf0e10cSrcweir		else
1295cdf0e10cSrcweir		{
12963c0d14cbSmseidel			$alllangstring = $alllangstring . $langstring;
1297cdf0e10cSrcweir		}
1298cdf0e10cSrcweir	}
1299cdf0e10cSrcweir
1300cdf0e10cSrcweir	$alllangstring =~ s/\s*$//;
13013c0d14cbSmseidel
1302cdf0e10cSrcweir	replace_one_variable($templatefile, "ALLLANGUAGESPLACEHOLDER", $alllangstring);
1303cdf0e10cSrcweir}
1304cdf0e10cSrcweir
1305cdf0e10cSrcweir##################################################################
13063c0d14cbSmseidel# Windows: Collecting all identifier from mlf file
1307cdf0e10cSrcweir##################################################################
1308cdf0e10cSrcweir
1309cdf0e10cSrcweirsub get_identifier
1310cdf0e10cSrcweir{
1311cdf0e10cSrcweir	my ( $mlffile ) = @_;
13123c0d14cbSmseidel
1313cdf0e10cSrcweir	my @identifier = ();
13143c0d14cbSmseidel
1315cdf0e10cSrcweir	for ( my $i = 0; $i <= $#{$mlffile}; $i++ )
1316cdf0e10cSrcweir	{
1317cdf0e10cSrcweir		my $oneline = ${$mlffile}[$i];
1318cdf0e10cSrcweir
1319cdf0e10cSrcweir		if ( $oneline =~ /^\s*\[(.+)\]\s*$/ )
1320cdf0e10cSrcweir		{
1321cdf0e10cSrcweir			my $identifier = $1;
1322cdf0e10cSrcweir			push(@identifier, $identifier);
1323cdf0e10cSrcweir		}
1324cdf0e10cSrcweir	}
1325cdf0e10cSrcweir
1326cdf0e10cSrcweir	return \@identifier;
1327cdf0e10cSrcweir}
1328cdf0e10cSrcweir
1329cdf0e10cSrcweir##############################################################
1330cdf0e10cSrcweir# Returning the complete block in all languages
1331cdf0e10cSrcweir# for a specified string
1332cdf0e10cSrcweir##############################################################
1333cdf0e10cSrcweir
1334cdf0e10cSrcweirsub get_language_block_from_language_file
1335cdf0e10cSrcweir{
1336cdf0e10cSrcweir	my ($searchstring, $languagefile) = @_;
1337cdf0e10cSrcweir
1338cdf0e10cSrcweir	my @language_block = ();
1339cdf0e10cSrcweir
1340cdf0e10cSrcweir	for ( my $i = 0; $i <= $#{$languagefile}; $i++ )
13413c0d14cbSmseidel	{
1342cdf0e10cSrcweir		if ( ${$languagefile}[$i] =~ /^\s*\[\s*$searchstring\s*\]\s*$/ )
1343cdf0e10cSrcweir		{
1344cdf0e10cSrcweir			my $counter = $i;
1345cdf0e10cSrcweir
1346cdf0e10cSrcweir			push(@language_block, ${$languagefile}[$counter]);
1347cdf0e10cSrcweir			$counter++;
13483c0d14cbSmseidel
1349cdf0e10cSrcweir			while (( $counter <= $#{$languagefile} ) && (!( ${$languagefile}[$counter] =~ /^\s*\[/ )))
1350cdf0e10cSrcweir			{
1351cdf0e10cSrcweir				push(@language_block, ${$languagefile}[$counter]);
1352cdf0e10cSrcweir				$counter++;
1353cdf0e10cSrcweir			}
13543c0d14cbSmseidel
1355cdf0e10cSrcweir			last;
1356cdf0e10cSrcweir		}
13573c0d14cbSmseidel	}
13583c0d14cbSmseidel
1359cdf0e10cSrcweir	return \@language_block;
1360cdf0e10cSrcweir}
1361cdf0e10cSrcweir
1362cdf0e10cSrcweir##############################################################
1363cdf0e10cSrcweir# Returning a specific language string from the block
1364cdf0e10cSrcweir# of all translations
1365cdf0e10cSrcweir##############################################################
1366cdf0e10cSrcweir
1367cdf0e10cSrcweirsub get_language_string_from_language_block
1368cdf0e10cSrcweir{
1369cdf0e10cSrcweir	my ($language_block, $language) = @_;
13703c0d14cbSmseidel
1371cdf0e10cSrcweir	my $newstring = "";
1372cdf0e10cSrcweir
1373cdf0e10cSrcweir	for ( my $i = 0; $i <= $#{$language_block}; $i++ )
1374cdf0e10cSrcweir	{
1375cdf0e10cSrcweir		if ( ${$language_block}[$i] =~ /^\s*$language\s*\=\s*\"(.*)\"\s*$/ )
1376cdf0e10cSrcweir		{
1377cdf0e10cSrcweir			$newstring = $1;
1378cdf0e10cSrcweir			last;
13793c0d14cbSmseidel		}
13803c0d14cbSmseidel	}
13813c0d14cbSmseidel
1382cdf0e10cSrcweir	if ( $newstring eq "" )
1383cdf0e10cSrcweir	{
13843c0d14cbSmseidel		$language = "en-US"; 	# defaulting to English
1385cdf0e10cSrcweir
1386cdf0e10cSrcweir		for ( my $i = 0; $i <= $#{$language_block}; $i++ )
13873c0d14cbSmseidel		{
1388cdf0e10cSrcweir			if ( ${$language_block}[$i] =~ /^\s*$language\s*\=\s*\"(.*)\"\s*$/ )
1389cdf0e10cSrcweir			{
1390cdf0e10cSrcweir				$newstring = $1;
1391cdf0e10cSrcweir				last;
1392cdf0e10cSrcweir			}
1393cdf0e10cSrcweir		}
1394cdf0e10cSrcweir	}
13953c0d14cbSmseidel
1396cdf0e10cSrcweir	return $newstring;
1397cdf0e10cSrcweir}
1398cdf0e10cSrcweir
1399cdf0e10cSrcweir##################################################################
14003c0d14cbSmseidel# Windows: Replacing strings in NSIS nsh file
1401cdf0e10cSrcweir# nsh file syntax:
1402fdcb970cSJim Jagielski# !define MUI_TEXT_DIRECTORY_TITLE "Zielverzeichnis auswählen"
1403cdf0e10cSrcweir##################################################################
1404cdf0e10cSrcweir
1405cdf0e10cSrcweirsub replace_identifier_in_nshfile
1406cdf0e10cSrcweir{
1407cdf0e10cSrcweir	my ( $nshfile, $identifier, $newstring, $nshfilename, $onelanguage ) = @_;
1408cdf0e10cSrcweir
14093c0d14cbSmseidel	$newstring =~ s/\\r/\$\\r/g; # \r -> $\r in modern nsis versions
14103c0d14cbSmseidel	$newstring =~ s/\\n/\$\\n/g; # \n -> $\n in modern nsis versions
14113c0d14cbSmseidel
1412b4e95e96Smseidel	for ( my $i = 0; $i <= $#{$nshfile}; $i++ )
1413cdf0e10cSrcweir	{
1414cdf0e10cSrcweir		if ( ${$nshfile}[$i] =~ /\s+\Q$identifier\E\s+\"(.+)\"\s*$/ )
1415cdf0e10cSrcweir		{
1416cdf0e10cSrcweir			my $oldstring = $1;
1417cdf0e10cSrcweir			${$nshfile}[$i] =~ s/\Q$oldstring\E/$newstring/;
14183c0d14cbSmseidel			$installer::logger::Lang->printf("NSIS replacement in %s (%s): \-\> %s\n",
14193c0d14cbSmseidel				$nshfilename,
14203c0d14cbSmseidel				$onelanguage,
14213c0d14cbSmseidel				$oldstring,
14223c0d14cbSmseidel				$newstring);
1423cdf0e10cSrcweir		}
1424cdf0e10cSrcweir	}
1425cdf0e10cSrcweir}
1426cdf0e10cSrcweir
1427cdf0e10cSrcweir##################################################################
14283c0d14cbSmseidel# Windows: Replacing strings in NSIS nlf file
1429cdf0e10cSrcweir# nlf file syntax (2 lines):
1430cdf0e10cSrcweir# # ^DirSubText
14313c0d14cbSmseidel# Zielverzeichnis
1432cdf0e10cSrcweir##################################################################
1433cdf0e10cSrcweir
1434cdf0e10cSrcweirsub replace_identifier_in_nlffile
1435cdf0e10cSrcweir{
1436cdf0e10cSrcweir	my ( $nlffile, $identifier, $newstring, $nlffilename, $onelanguage ) = @_;
1437cdf0e10cSrcweir
1438cdf0e10cSrcweir	for ( my $i = 0; $i <= $#{$nlffile}; $i++ )
1439cdf0e10cSrcweir	{
1440cdf0e10cSrcweir		if ( ${$nlffile}[$i] =~ /^\s*\#\s+\^\s*\Q$identifier\E\s*$/ )
1441cdf0e10cSrcweir		{
1442cdf0e10cSrcweir			my $next = $i+1;
1443cdf0e10cSrcweir			my $oldstring = ${$nlffile}[$next];
1444cdf0e10cSrcweir			${$nlffile}[$next] = $newstring . "\n";
1445cdf0e10cSrcweir			$oldstring =~ s/\s*$//;
14463c0d14cbSmseidel			$installer::logger::Lang->printf("NSIS replacement in %s (%s): %s \-\> %s\n",
14473c0d14cbSmseidel				$nlffilename,
14483c0d14cbSmseidel				$onelanguage,
14493c0d14cbSmseidel				$oldstring,
14503c0d14cbSmseidel				$newstring);
1451cdf0e10cSrcweir		}
14523c0d14cbSmseidel	}
1453cdf0e10cSrcweir}
1454cdf0e10cSrcweir
1455cdf0e10cSrcweir##################################################################
14563c0d14cbSmseidel# Windows: Translating the NSIS nsh and nlf file
1457cdf0e10cSrcweir##################################################################
1458cdf0e10cSrcweir
1459cdf0e10cSrcweirsub translate_nsh_nlf_file
1460cdf0e10cSrcweir{
1461cdf0e10cSrcweir	my ($nshfile, $nlffile, $mlffile, $onelanguage, $nshfilename, $nlffilename, $nsislanguage) = @_;
1462cdf0e10cSrcweir
1463cdf0e10cSrcweir	# Analyzing the mlf file, collecting all Identifier
1464cdf0e10cSrcweir	my $allidentifier = get_identifier($mlffile);
14653c0d14cbSmseidel
1466cdf0e10cSrcweir	$onelanguage = "en-US" if ( $nsislanguage eq "English" && $onelanguage ne "en-US");
1467cdf0e10cSrcweir	for ( my $i = 0; $i <= $#{$allidentifier}; $i++ )
1468cdf0e10cSrcweir	{
1469cdf0e10cSrcweir		my $identifier = ${$allidentifier}[$i];
1470cdf0e10cSrcweir		my $language_block = get_language_block_from_language_file($identifier, $mlffile);
1471cdf0e10cSrcweir		my $newstring = get_language_string_from_language_block($language_block, $onelanguage);
14723c0d14cbSmseidel
1473cdf0e10cSrcweir		# removing mask
1474cdf0e10cSrcweir		$newstring =~ s/\\\'/\'/g;
14753c0d14cbSmseidel
1476cdf0e10cSrcweir		replace_identifier_in_nshfile($nshfile, $identifier, $newstring, $nshfilename, $onelanguage);
14773c0d14cbSmseidel		replace_identifier_in_nlffile($nlffile, $identifier, $newstring, $nlffilename, $onelanguage);
1478cdf0e10cSrcweir	}
1479cdf0e10cSrcweir}
1480cdf0e10cSrcweir
1481cdf0e10cSrcweir##################################################################
14823c0d14cbSmseidel# Converting utf 16 file to utf 8
1483cdf0e10cSrcweir##################################################################
1484cdf0e10cSrcweir
1485cdf0e10cSrcweirsub convert_utf16_to_utf8
1486cdf0e10cSrcweir{
1487cdf0e10cSrcweir	my ( $filename ) = @_;
1488cdf0e10cSrcweir
1489cdf0e10cSrcweir	my @localfile = ();
1490cdf0e10cSrcweir
1491cdf0e10cSrcweir	my $savfilename = $filename . "_before.utf16";
1492cdf0e10cSrcweir	installer::systemactions::copy_one_file($filename, $savfilename);
1493cdf0e10cSrcweir
1494cdf0e10cSrcweir#	open( IN, "<:utf16", $filename ) || installer::exiter::exit_program("ERROR: Cannot open file $filename for reading", "convert_utf16_to_utf8");
1495cdf0e10cSrcweir#	open( IN, "<:para:crlf:uni", $filename ) || installer::exiter::exit_program("ERROR: Cannot open file $filename for reading", "convert_utf16_to_utf8");
1496cdf0e10cSrcweir	open( IN, "<:encoding(UTF16-LE)", $filename ) || installer::exiter::exit_program("ERROR: Cannot open file $filename for reading", "convert_utf16_to_utf8");
14970b2dfbacSAndre Fischer	while ( my $line = <IN> )
14983c0d14cbSmseidel	{
1499cdf0e10cSrcweir		push @localfile, $line;
1500cdf0e10cSrcweir	}
1501cdf0e10cSrcweir	close( IN );
1502cdf0e10cSrcweir
1503cdf0e10cSrcweir	if ( open( OUT, ">:utf8", $filename ) )
1504cdf0e10cSrcweir	{
1505cdf0e10cSrcweir		print OUT @localfile;
15063c0d14cbSmseidel		close(OUT);
1507cdf0e10cSrcweir	}
1508cdf0e10cSrcweir
1509cdf0e10cSrcweir	$savfilename = $filename . "_before.utf8";
1510cdf0e10cSrcweir	installer::systemactions::copy_one_file($filename, $savfilename);
1511cdf0e10cSrcweir}
1512cdf0e10cSrcweir
1513cdf0e10cSrcweir##################################################################
15143c0d14cbSmseidel# Converting utf 8 file to utf 16
1515cdf0e10cSrcweir##################################################################
1516cdf0e10cSrcweir
1517cdf0e10cSrcweirsub convert_utf8_to_utf16
1518cdf0e10cSrcweir{
15193c0d14cbSmseidel	my ( $filename ) = @_;
1520cdf0e10cSrcweir
1521cdf0e10cSrcweir	my @localfile = ();
1522cdf0e10cSrcweir
1523cdf0e10cSrcweir	my $savfilename = $filename . "_after.utf8";
1524cdf0e10cSrcweir	installer::systemactions::copy_one_file($filename, $savfilename);
1525cdf0e10cSrcweir
1526cdf0e10cSrcweir	open( IN, "<:utf8", $filename ) || installer::exiter::exit_program("ERROR: Cannot open file $filename for reading", "convert_utf8_to_utf16");
15273c0d14cbSmseidel	while (my $line = <IN>)
15283c0d14cbSmseidel	{
1529cdf0e10cSrcweir		push @localfile, $line;
1530cdf0e10cSrcweir	}
1531cdf0e10cSrcweir	close( IN );
1532cdf0e10cSrcweir
1533cdf0e10cSrcweir	if ( open( OUT, ">:raw:encoding(UTF16-LE):crlf:utf8", $filename ) )
1534cdf0e10cSrcweir	{
1535cdf0e10cSrcweir		print OUT @localfile;
15363c0d14cbSmseidel		close(OUT);
1537cdf0e10cSrcweir	}
1538cdf0e10cSrcweir
1539cdf0e10cSrcweir	$savfilename = $filename . "_after.utf16";
1540cdf0e10cSrcweir	installer::systemactions::copy_one_file($filename, $savfilename);
1541cdf0e10cSrcweir}
1542cdf0e10cSrcweir
1543cdf0e10cSrcweir##################################################################
15443c0d14cbSmseidel# Converting text string to utf 16
1545cdf0e10cSrcweir##################################################################
1546cdf0e10cSrcweir
1547cdf0e10cSrcweirsub convert_textstring_to_utf16
1548cdf0e10cSrcweir{
15493c0d14cbSmseidel	my ( $textstring, $localnsisdir, $shortfilename ) = @_;
1550cdf0e10cSrcweir
1551cdf0e10cSrcweir	my $filename = $localnsisdir . $installer::globals::separator . $shortfilename;
1552cdf0e10cSrcweir	my @filecontent = ();
1553cdf0e10cSrcweir	push(@filecontent, $textstring);
1554cdf0e10cSrcweir	installer::files::save_file($filename, \@filecontent);
1555cdf0e10cSrcweir	convert_utf8_to_utf16($filename);
1556cdf0e10cSrcweir	my $newfile = installer::files::read_file($filename);
1557cdf0e10cSrcweir	my $utf16string = "";
1558cdf0e10cSrcweir	if ( ${$newfile}[0] ne "" ) { $utf16string = ${$newfile}[0]; }
1559cdf0e10cSrcweir
1560cdf0e10cSrcweir	return $utf16string;
1561cdf0e10cSrcweir}
1562cdf0e10cSrcweir
1563cdf0e10cSrcweir##################################################################
15643c0d14cbSmseidel# Windows: Copying NSIS language files to local nsis directory
1565cdf0e10cSrcweir##################################################################
1566cdf0e10cSrcweir
1567cdf0e10cSrcweirsub copy_and_translate_nsis_language_files
1568cdf0e10cSrcweir{
1569cdf0e10cSrcweir	my ($nsispath, $localnsisdir, $languagesarrayref, $allvariables) = @_;
15703c0d14cbSmseidel
1571cdf0e10cSrcweir	my $nlffilepath = $nsispath . $installer::globals::separator . "Contrib" . $installer::globals::separator . "Language\ files" . $installer::globals::separator;
1572cdf0e10cSrcweir	my $nshfilepath = $nsispath . $installer::globals::separator . "Contrib" . $installer::globals::separator . "Modern\ UI" . $installer::globals::separator . "Language files" . $installer::globals::separator;
1573cdf0e10cSrcweir
1574cdf0e10cSrcweir	for ( my $i = 0; $i <= $#{$languagesarrayref}; $i++ )
1575cdf0e10cSrcweir	{
1576cdf0e10cSrcweir		my $onelanguage = ${$languagesarrayref}[$i];
1577cdf0e10cSrcweir		my $nsislanguage = nsis_language_converter($onelanguage);
1578cdf0e10cSrcweir
1579cdf0e10cSrcweir		# Copying the nlf file
1580cdf0e10cSrcweir		my $sourcepath = $nlffilepath . $nsislanguage . "\.nlf";
1581cdf0e10cSrcweir		if ( ! -f $sourcepath ) { installer::exiter::exit_program("ERROR: Could not find nsis file: $sourcepath!", "copy_and_translate_nsis_language_files"); }
1582cdf0e10cSrcweir		my $nlffilename = $localnsisdir . $installer::globals::separator . $nsislanguage . "_pack.nlf";
1583cdf0e10cSrcweir		if ( $^O =~ /cygwin/i ) { $nlffilename =~ s/\//\\/g; }
1584cdf0e10cSrcweir		installer::systemactions::copy_one_file($sourcepath, $nlffilename);
15853c0d14cbSmseidel
1586cdf0e10cSrcweir		# Copying the nsh file
1587cdf0e10cSrcweir		# In newer nsis versions, the nsh file is located next to the nlf file
1588cdf0e10cSrcweir		$sourcepath = $nshfilepath . $nsislanguage . "\.nsh";
1589cdf0e10cSrcweir		if ( ! -f $sourcepath )
1590cdf0e10cSrcweir		{
1591cdf0e10cSrcweir			# trying to find the nsh file next to the nlf file
1592cdf0e10cSrcweir			$sourcepath = $nlffilepath . $nsislanguage . "\.nsh";
1593cdf0e10cSrcweir			if ( ! -f $sourcepath )
1594cdf0e10cSrcweir			{
1595cdf0e10cSrcweir				installer::exiter::exit_program("ERROR: Could not find nsis file: $sourcepath!", "copy_and_translate_nsis_language_files");
1596cdf0e10cSrcweir			}
1597cdf0e10cSrcweir		}
1598cdf0e10cSrcweir		my $nshfilename = $localnsisdir . $installer::globals::separator . $nsislanguage . "_pack.nsh";
1599cdf0e10cSrcweir		if ( $^O =~ /cygwin/i ) { $nshfilename =~ s/\//\\/g; }
16003c0d14cbSmseidel		installer::systemactions::copy_one_file($sourcepath, $nshfilename);
1601cdf0e10cSrcweir
1602cdf0e10cSrcweir		# Changing the macro name in nsh file: MUI_LANGUAGEFILE_BEGIN -> MUI_LANGUAGEFILE_PACK_BEGIN
16033c0d14cbSmseidel		#convert_utf16_to_utf8($nshfilename);
16043c0d14cbSmseidel		#convert_utf16_to_utf8($nlffilename);
16053c0d14cbSmseidel		my $nshfile = installer::files::read_file($nshfilename);
1606cdf0e10cSrcweir		replace_one_variable($nshfile, "MUI_LANGUAGEFILE_BEGIN", "MUI_LANGUAGEFILE_PACK_BEGIN");
1607cdf0e10cSrcweir
1608cdf0e10cSrcweir		# find the ulf file for translation
1609cdf0e10cSrcweir		my $mlffile = get_translation_file($allvariables);
16103c0d14cbSmseidel
1611cdf0e10cSrcweir		# Translate the files
1612cdf0e10cSrcweir		my $nlffile = installer::files::read_file($nlffilename);
1613cdf0e10cSrcweir		translate_nsh_nlf_file($nshfile, $nlffile, $mlffile, $onelanguage, $nshfilename, $nlffilename, $nsislanguage);
16143c0d14cbSmseidel
1615cdf0e10cSrcweir		installer::files::save_file($nshfilename, $nshfile);
1616cdf0e10cSrcweir		installer::files::save_file($nlffilename, $nlffile);
1617cdf0e10cSrcweir
16183c0d14cbSmseidel		#convert_utf8_to_utf16($nshfilename);
16193c0d14cbSmseidel		#convert_utf8_to_utf16($nlffilename);
1620cdf0e10cSrcweir	}
1621cdf0e10cSrcweir
1622cdf0e10cSrcweir}
1623cdf0e10cSrcweir
1624cdf0e10cSrcweir##################################################################
16253c0d14cbSmseidel# Windows: Including the nsis path into the nsi template
1626cdf0e10cSrcweir##################################################################
1627cdf0e10cSrcweir
1628cdf0e10cSrcweirsub put_nsis_path_into_template
1629cdf0e10cSrcweir{
1630cdf0e10cSrcweir	my ($templatefile, $nsisdir) = @_;
1631cdf0e10cSrcweir
1632cdf0e10cSrcweir	replace_one_variable($templatefile, "NSISPATHPLACEHOLDER", $nsisdir);
1633cdf0e10cSrcweir}
1634cdf0e10cSrcweir
1635cdf0e10cSrcweir##################################################################
16363c0d14cbSmseidel# Windows: Including the output path into the nsi template
1637cdf0e10cSrcweir##################################################################
1638cdf0e10cSrcweir
1639cdf0e10cSrcweirsub put_output_path_into_template
1640cdf0e10cSrcweir{
1641cdf0e10cSrcweir	my ($templatefile, $downloaddir) = @_;
1642cdf0e10cSrcweir
1643cdf0e10cSrcweir	if ( $^O =~ /cygwin/i ) { $downloaddir =~ s/\//\\/g; }
1644cdf0e10cSrcweir
1645cdf0e10cSrcweir	replace_one_variable($templatefile, "OUTPUTDIRPLACEHOLDER", $downloaddir);
1646cdf0e10cSrcweir}
1647cdf0e10cSrcweir
1648cdf0e10cSrcweir##################################################################
16493c0d14cbSmseidel# Windows: Finding the path to the nsis SDK
1650cdf0e10cSrcweir##################################################################
1651cdf0e10cSrcweir
1652cdf0e10cSrcweirsub get_path_to_nsis_sdk
1653cdf0e10cSrcweir{
1654cdf0e10cSrcweir	my $nsispath = "";
1655cdf0e10cSrcweir
16560b2dfbacSAndre Fischer	if ( $ENV{'NSIS_PATH'} )
16573c0d14cbSmseidel	{
1658cdf0e10cSrcweir		$nsispath = $ENV{'NSIS_PATH'};
16590b2dfbacSAndre Fischer	}
1660cdf0e10cSrcweir	if ( $nsispath eq "" )
1661cdf0e10cSrcweir	{
16623c0d14cbSmseidel		$installer::logger::Info->print("... no Environment variable \"NSIS_PATH\"!\n");
1663b274bc22SAndre Fischer	}
16643c0d14cbSmseidel	elsif ( ! -d $nsispath )
1665cdf0e10cSrcweir	{
1666cdf0e10cSrcweir		installer::exiter::exit_program("ERROR: NSIS path $nsispath does not exist!", "get_path_to_nsis_sdk");
1667cdf0e10cSrcweir	}
16683c0d14cbSmseidel
1669cdf0e10cSrcweir	return $nsispath;
1670cdf0e10cSrcweir}
1671cdf0e10cSrcweir
1672cdf0e10cSrcweir##################################################################
16733c0d14cbSmseidel# Windows: Executing NSIS to create the installation set
1674cdf0e10cSrcweir##################################################################
1675cdf0e10cSrcweir
1676cdf0e10cSrcweirsub call_nsis
1677cdf0e10cSrcweir{
1678cdf0e10cSrcweir	my ( $nsispath, $nsifile ) = @_;
16793c0d14cbSmseidel
1680cdf0e10cSrcweir	my $makensisexe = $nsispath . $installer::globals::separator . "makensis.exe";
1681cdf0e10cSrcweir
16823c0d14cbSmseidel	$installer::logger::Info->printf("... starting %s ... \n", $makensisexe);
1683cdf0e10cSrcweir
1684cdf0e10cSrcweir	if( $^O =~ /cygwin/i ) { $nsifile =~ s/\\/\//g;	}
1685cdf0e10cSrcweir
1686cdf0e10cSrcweir	my $systemcall = "$makensisexe $nsifile |";
1687cdf0e10cSrcweir
16883c0d14cbSmseidel	$installer::logger::Lang->printf("Systemcall: %s\n", $systemcall);
1689cdf0e10cSrcweir
1690cdf0e10cSrcweir	my @nsisoutput = ();
1691cdf0e10cSrcweir
1692cdf0e10cSrcweir	open (NSI, "$systemcall");
1693cdf0e10cSrcweir	while (<NSI>) {push(@nsisoutput, $_); }
1694cdf0e10cSrcweir	close (NSI);
1695cdf0e10cSrcweir
1696cdf0e10cSrcweir	my $returnvalue = $?;	# $? contains the return value of the systemcall
1697cdf0e10cSrcweir
1698cdf0e10cSrcweir	if ($returnvalue)
1699cdf0e10cSrcweir	{
17003c0d14cbSmseidel		$installer::logger::Lang->printf("ERROR: %s !\n", $systemcall);
1701cdf0e10cSrcweir	}
1702cdf0e10cSrcweir	else
1703cdf0e10cSrcweir	{
17043c0d14cbSmseidel		$installer::logger::Lang->printf("Success: %s\n", $systemcall);
17053c0d14cbSmseidel	}
1706cdf0e10cSrcweir
1707b274bc22SAndre Fischer	foreach my $line (@nsisoutput)
17083c0d14cbSmseidel	{
17093c0d14cbSmseidel		$installer::logger::Lang->print($line);
17103c0d14cbSmseidel	}
1711cdf0e10cSrcweir}
1712cdf0e10cSrcweir
1713cdf0e10cSrcweir#################################################################################
1714cdf0e10cSrcweir# Replacing one variable in one files
1715cdf0e10cSrcweir#################################################################################
1716cdf0e10cSrcweir
1717cdf0e10cSrcweirsub replace_one_variable_in_translationfile
1718cdf0e10cSrcweir{
1719cdf0e10cSrcweir	my ($translationfile, $variable, $searchstring) = @_;
17203c0d14cbSmseidel
1721cdf0e10cSrcweir	for ( my $i = 0; $i <= $#{$translationfile}; $i++ )
1722cdf0e10cSrcweir	{
1723cdf0e10cSrcweir		${$translationfile}[$i] =~ s/\%$searchstring/$variable/g;
17243c0d14cbSmseidel	}
1725cdf0e10cSrcweir}
1726cdf0e10cSrcweir
1727cdf0e10cSrcweir#################################################################################
1728cdf0e10cSrcweir# Replacing the variables in the translation file
1729cdf0e10cSrcweir#################################################################################
1730cdf0e10cSrcweir
1731cdf0e10cSrcweirsub replace_variables
1732cdf0e10cSrcweir{
1733cdf0e10cSrcweir	my ($translationfile, $variableshashref) = @_;
1734cdf0e10cSrcweir
17350b2dfbacSAndre Fischer	foreach my $key (keys %{$variableshashref})
1736cdf0e10cSrcweir	{
1737cdf0e10cSrcweir		my $value = $variableshashref->{$key};
1738cdf0e10cSrcweir
1739cdf0e10cSrcweir		# special handling for PRODUCTVERSION, if $allvariables->{'POSTVERSIONEXTENSION'}
1740cdf0e10cSrcweir		if (( $key eq "PRODUCTVERSION" ) && ( $variableshashref->{'POSTVERSIONEXTENSION'} )) { $value = $value . " " . $variableshashref->{'POSTVERSIONEXTENSION'}; }
1741cdf0e10cSrcweir
1742cdf0e10cSrcweir		replace_one_variable_in_translationfile($translationfile, $value, $key);
1743cdf0e10cSrcweir	}
1744cdf0e10cSrcweir}
1745cdf0e10cSrcweir
1746cdf0e10cSrcweir#########################################################
1747cdf0e10cSrcweir# Getting the translation file for the nsis installer
1748cdf0e10cSrcweir#########################################################
1749cdf0e10cSrcweir
1750cdf0e10cSrcweirsub get_translation_file
1751cdf0e10cSrcweir{
1752cdf0e10cSrcweir	my ($allvariableshashref) = @_;
175314ebc950Sarielch	my $translationfilename = $installer::globals::idtlanguagepath . $installer::globals::separator . $installer::globals::nsisfilename . ".uulf";
1754cdf0e10cSrcweir	if ( ! -f $translationfilename ) { installer::exiter::exit_program("ERROR: Could not find language file $translationfilename!", "get_translation_file"); }
1755cdf0e10cSrcweir	my $translationfile = installer::files::read_file($translationfilename);
1756cdf0e10cSrcweir	replace_variables($translationfile, $allvariableshashref);
1757cdf0e10cSrcweir
17583c0d14cbSmseidel	$installer::logger::Lang->printf("Reading translation file: %s\n", $translationfilename);
17593c0d14cbSmseidel
1760cdf0e10cSrcweir	return $translationfile;
1761cdf0e10cSrcweir}
1762cdf0e10cSrcweir
1763cdf0e10cSrcweir####################################################
17643c0d14cbSmseidel# Removing English, if it was added before
1765cdf0e10cSrcweir####################################################
1766cdf0e10cSrcweir
1767cdf0e10cSrcweirsub remove_english_for_nsis_installer
1768cdf0e10cSrcweir{
1769cdf0e10cSrcweir	my ($languagestringref, $languagesarrayref) = @_;
1770cdf0e10cSrcweir
1771cdf0e10cSrcweir	# $$languagestringref =~ s/en-US_//;
1772cdf0e10cSrcweir	# shift(@{$languagesarrayref});
1773cdf0e10cSrcweir
17743c0d14cbSmseidel	@{$languagesarrayref} = ("en-US");	# only English for NSIS installer!
1775cdf0e10cSrcweir}
1776cdf0e10cSrcweir
1777cdf0e10cSrcweir####################################################
1778cdf0e10cSrcweir# Creating link tree for upload
1779cdf0e10cSrcweir####################################################
1780cdf0e10cSrcweir
1781cdf0e10cSrcweirsub create_link_tree
1782cdf0e10cSrcweir{
1783cdf0e10cSrcweir	my ($sourcedownloadfile, $destfilename, $versionstring) = @_;
17843c0d14cbSmseidel
1785957116b7SHerbert Dürr	if ( ! $installer::globals::ooouploaddir ) { installer::exiter::exit_program("ERROR: Directory for AOO upload not defined!", "create_link_tree"); }
1786cdf0e10cSrcweir	my $versiondir = $installer::globals::ooouploaddir . $installer::globals::separator . $versionstring;
17873c0d14cbSmseidel	$installer::logger::Lang->printf("Directory for the link: %s\n", $versiondir);
17883c0d14cbSmseidel
1789cdf0e10cSrcweir	if ( ! -d $versiondir ) { installer::systemactions::create_directory_structure($versiondir); }
17903c0d14cbSmseidel
17913c0d14cbSmseidel	# inside directory $versiondir all links have to be created
1792cdf0e10cSrcweir	my $linkdestination = $versiondir . $installer::globals::separator . $destfilename;
1793cdf0e10cSrcweir
1794cdf0e10cSrcweir	# If there is an older version of this file (link), it has to be removed
1795cdf0e10cSrcweir	if ( -f $linkdestination ) { unlink($linkdestination); }
1796cdf0e10cSrcweir
17973c0d14cbSmseidel	$installer::logger::Lang->printf("Creating hard link from %s to %s\n", $sourcedownloadfile, $linkdestination);
17983c0d14cbSmseidel	installer::systemactions::hardlink_one_file($sourcedownloadfile, $linkdestination);
1799cdf0e10cSrcweir}
1800cdf0e10cSrcweir
1801cdf0e10cSrcweir#######################################################
1802cdf0e10cSrcweir# Setting supported platform for Sun OpenOffice.org
1803cdf0e10cSrcweir# builds
1804cdf0e10cSrcweir#######################################################
1805cdf0e10cSrcweir
1806cdf0e10cSrcweirsub is_supported_platform
1807cdf0e10cSrcweir{
1808cdf0e10cSrcweir	my $is_supported = 0;
18093c0d14cbSmseidel
1810cdf0e10cSrcweir	if (( $installer::globals::islinuxrpmbuild ) ||
1811cdf0e10cSrcweir		( $installer::globals::issolarissparcbuild ) ||
1812cdf0e10cSrcweir		( $installer::globals::issolarisx86build ) ||
1813cdf0e10cSrcweir		( $installer::globals::iswindowsbuild ))
1814cdf0e10cSrcweir	{
1815cdf0e10cSrcweir		$is_supported = 1;
1816cdf0e10cSrcweir	}
1817cdf0e10cSrcweir
1818cdf0e10cSrcweir	return $is_supported;
1819cdf0e10cSrcweir}
1820cdf0e10cSrcweir
1821cdf0e10cSrcweir####################################################
1822cdf0e10cSrcweir# Creating download installation sets
1823cdf0e10cSrcweir####################################################
1824cdf0e10cSrcweir
1825cdf0e10cSrcweirsub create_download_sets
1826cdf0e10cSrcweir{
1827cdf0e10cSrcweir	my ($installationdir, $includepatharrayref, $allvariableshashref, $downloadname, $languagestringref, $languagesarrayref) = @_;
18283c0d14cbSmseidel
18293c0d14cbSmseidel	$installer::logger::Info->print("\n");
18303c0d14cbSmseidel	$installer::logger::Info->print("******************************************\n");
18313c0d14cbSmseidel	$installer::logger::Info->print("... creating download installation set ...\n", 1);
18323c0d14cbSmseidel	$installer::logger::Info->print("******************************************\n");
1833cdf0e10cSrcweir
1834cdf0e10cSrcweir	installer::logger::include_header_into_logfile("Creating download installation sets:");
1835cdf0e10cSrcweir
18363c0d14cbSmseidel	# special handling for installation sets, to which English was added automatically
1837cdf0e10cSrcweir	if ( $installer::globals::added_english ) { remove_english_for_nsis_installer($languagestringref, $languagesarrayref); }
1838cdf0e10cSrcweir
1839cdf0e10cSrcweir	my $firstdir = $installationdir;
1840cdf0e10cSrcweir	installer::pathanalyzer::get_path_from_fullqualifiedname(\$firstdir);
18413c0d14cbSmseidel
1842cdf0e10cSrcweir	my $lastdir = $installationdir;
1843cdf0e10cSrcweir	installer::pathanalyzer::make_absolute_filename_to_relative_filename(\$lastdir);
1844cdf0e10cSrcweir
1845cdf0e10cSrcweir	if ( $lastdir =~ /\./ ) { $lastdir =~ s/\./_download_inprogress\./ }
1846cdf0e10cSrcweir	else { $lastdir = $lastdir . "_download_inprogress"; }
1847cdf0e10cSrcweir
1848cdf0e10cSrcweir	# removing existing directory "_native_packed_inprogress" and "_native_packed_witherror" and "_native_packed"
1849cdf0e10cSrcweir
1850cdf0e10cSrcweir	my $downloaddir = $firstdir . $lastdir;
18513c0d14cbSmseidel
1852cdf0e10cSrcweir	if ( -d $downloaddir ) { installer::systemactions::remove_complete_directory($downloaddir); }
18533c0d14cbSmseidel
1854cdf0e10cSrcweir	my $olddir = $downloaddir;
1855cdf0e10cSrcweir	$olddir =~ s/_inprogress/_witherror/;
1856cdf0e10cSrcweir	if ( -d $olddir ) { installer::systemactions::remove_complete_directory($olddir); }
1857cdf0e10cSrcweir
1858cdf0e10cSrcweir	$olddir = $downloaddir;
1859cdf0e10cSrcweir	$olddir =~ s/_inprogress//;
1860cdf0e10cSrcweir	if ( -d $olddir ) { installer::systemactions::remove_complete_directory($olddir); }
1861cdf0e10cSrcweir
1862cdf0e10cSrcweir	# creating the new directory
18633c0d14cbSmseidel
1864cdf0e10cSrcweir	installer::systemactions::create_directory($downloaddir);
1865cdf0e10cSrcweir
1866cdf0e10cSrcweir	$installer::globals::saveinstalldir = $downloaddir;
1867cdf0e10cSrcweir
1868cdf0e10cSrcweir	# evaluating the name of the download file
1869cdf0e10cSrcweir
18703c0d14cbSmseidel	if ( $allvariableshashref->{'AOODOWNLOADNAME'} )
18713c0d14cbSmseidel	{
18723c0d14cbSmseidel		$downloadname = set_download_filename($languagestringref, $allvariableshashref);
18733c0d14cbSmseidel	}
18743c0d14cbSmseidel	else
18753c0d14cbSmseidel	{
18763c0d14cbSmseidel		$downloadname = resolve_variables_in_downloadname($allvariableshashref, $downloadname, $languagestringref);
18773c0d14cbSmseidel	}
1878cdf0e10cSrcweir
1879cdf0e10cSrcweir	if ( ! $installer::globals::iswindowsbuild )	# Unix specific part
1880cdf0e10cSrcweir	{
1881cdf0e10cSrcweir
1882cdf0e10cSrcweir		# getting the path of the getuid.so (only required for Solaris and Linux)
1883cdf0e10cSrcweir		my $getuidlibrary = "";
1884cdf0e10cSrcweir		if (( $installer::globals::issolarisbuild ) || ( $installer::globals::islinuxbuild )) {	$getuidlibrary = get_path_for_library($includepatharrayref); }
1885cdf0e10cSrcweir
1886ff3f4ebcSOliver-Rainer Wittmann		if ( $allvariableshashref->{'AOODOWNLOADNAME'} )
1887cdf0e10cSrcweir		{
1888cdf0e10cSrcweir			my $downloadfile = create_tar_gz_file_from_directory($installationdir, $getuidlibrary, $downloaddir, $downloadname);
1889cdf0e10cSrcweir		}
1890cdf0e10cSrcweir		else
1891cdf0e10cSrcweir		{
1892cdf0e10cSrcweir			# find and read setup script template
1893cdf0e10cSrcweir			my $scriptfilename = "downloadscript.sh";
1894cdf0e10cSrcweir
1895cdf0e10cSrcweir			my $scriptref = "";
1896cdf0e10cSrcweir
1897cdf0e10cSrcweir			if ( $installer::globals::include_pathes_read )
1898cdf0e10cSrcweir			{
1899cdf0e10cSrcweir				$scriptref = installer::scriptitems::get_sourcepath_from_filename_and_includepath(\$scriptfilename, $includepatharrayref, 0);
1900cdf0e10cSrcweir			}
1901cdf0e10cSrcweir			else
1902cdf0e10cSrcweir			{
1903cdf0e10cSrcweir				$scriptref = installer::scriptitems::get_sourcepath_from_filename_and_includepath_classic(\$scriptfilename, $includepatharrayref, 0);
1904cdf0e10cSrcweir			}
1905cdf0e10cSrcweir
1906cdf0e10cSrcweir			if ($$scriptref eq "") { installer::exiter::exit_program("ERROR: Could not find script file $scriptfilename!", "create_download_sets"); }
1907cdf0e10cSrcweir			my $scriptfile = installer::files::read_file($$scriptref);
1908cdf0e10cSrcweir
19093c0d14cbSmseidel			$installer::logger::Lang->printf("Found script file %s: %s \n", $scriptfilename, $$scriptref);
19103c0d14cbSmseidel
1911cdf0e10cSrcweir			# add product name into script template
1912cdf0e10cSrcweir			put_productname_into_script($scriptfile, $allvariableshashref);
1913cdf0e10cSrcweir
1914cdf0e10cSrcweir			# replace linenumber in script template
1915cdf0e10cSrcweir			put_linenumber_into_script($scriptfile);
1916cdf0e10cSrcweir
1917cdf0e10cSrcweir			# create tar file
1918cdf0e10cSrcweir			my $temporary_tarfile_name = $downloaddir . $installer::globals::separator . 'installset.tar';
19193c0d14cbSmseidel			my $size = tar_package($installationdir, $temporary_tarfile_name, $getuidlibrary);
19203c0d14cbSmseidel			installer::exiter::exit_program("ERROR: Could not create tar file $temporary_tarfile_name!", "create_download_sets") unless $size;
1921cdf0e10cSrcweir
1922cdf0e10cSrcweir			# calling sum to determine checksum and size of the tar file
1923cdf0e10cSrcweir			my $sumout = call_sum($temporary_tarfile_name);
19243c0d14cbSmseidel
1925cdf0e10cSrcweir			# writing checksum and size into scriptfile
1926cdf0e10cSrcweir			put_checksum_and_size_into_script($scriptfile, $sumout);
19273c0d14cbSmseidel
1928cdf0e10cSrcweir			# saving the script file
1929cdf0e10cSrcweir			my $newscriptfilename = determine_scriptfile_name($downloadname);
1930cdf0e10cSrcweir			$newscriptfilename = save_script_file($downloaddir, $newscriptfilename, $scriptfile);
1931cdf0e10cSrcweir
19323c0d14cbSmseidel			$installer::logger::Info->printf("... including installation set into %s ... \n", $newscriptfilename);
19333c0d14cbSmseidel			# Append tar file to script
19343c0d14cbSmseidel			include_tar_into_script($newscriptfilename, $temporary_tarfile_name);
1935cdf0e10cSrcweir		}
1936cdf0e10cSrcweir	}
1937cdf0e10cSrcweir	else	# Windows specific part
1938cdf0e10cSrcweir	{
1939cdf0e10cSrcweir		my $localnsisdir = installer::systemactions::create_directories("nsis", $languagestringref);
1940cdf0e10cSrcweir		# push(@installer::globals::removedirs, $localnsisdir);
1941cdf0e10cSrcweir
1942cdf0e10cSrcweir		# find nsis in the system
1943cdf0e10cSrcweir		my $nsispath = get_path_to_nsis_sdk();
1944cdf0e10cSrcweir
1945cdf0e10cSrcweir		if ( $nsispath eq "" ) {
1946cdf0e10cSrcweir			# If nsis is not found just skip the rest of this function
1947cdf0e10cSrcweir			# and do not create the NSIS file.
19483c0d14cbSmseidel			$installer::logger::Lang->print("\n");
19493c0d14cbSmseidel			$installer::logger::Lang->printf("No NSIS SDK found. Skipping the generation of NSIS file.\n");
19503c0d14cbSmseidel			$installer::logger::Info->print("... no NSIS SDK found. Skipping the generation of NSIS file ... \n");
1951cdf0e10cSrcweir			return $downloaddir;
1952cdf0e10cSrcweir		}
1953cdf0e10cSrcweir
1954cdf0e10cSrcweir		# copy language files into nsis directory and translate them
1955cdf0e10cSrcweir		copy_and_translate_nsis_language_files($nsispath, $localnsisdir, $languagesarrayref, $allvariableshashref);
19563c0d14cbSmseidel
1957cdf0e10cSrcweir		# find and read the nsi file template
1958cdf0e10cSrcweir		my $templatefilename = "downloadtemplate.nsi";
1959cdf0e10cSrcweir
1960cdf0e10cSrcweir		my $templateref = "";
1961cdf0e10cSrcweir
1962cdf0e10cSrcweir		if ( $installer::globals::include_pathes_read )
1963cdf0e10cSrcweir		{
1964cdf0e10cSrcweir			$templateref = installer::scriptitems::get_sourcepath_from_filename_and_includepath(\$templatefilename, $includepatharrayref, 0);
1965cdf0e10cSrcweir		}
1966cdf0e10cSrcweir		else
1967cdf0e10cSrcweir		{
1968cdf0e10cSrcweir			$templateref = installer::scriptitems::get_sourcepath_from_filename_and_includepath_classic(\$templatefilename, $includepatharrayref, 0);
1969cdf0e10cSrcweir		}
1970cdf0e10cSrcweir
1971cdf0e10cSrcweir		if ($$templateref eq "") { installer::exiter::exit_program("ERROR: Could not find nsi template file $templatefilename!", "create_download_sets"); }
1972cdf0e10cSrcweir		my $templatefile = installer::files::read_file($$templateref);
1973cdf0e10cSrcweir
1974cdf0e10cSrcweir		# add product name into script template
1975cdf0e10cSrcweir		put_windows_productname_into_template($templatefile, $allvariableshashref);
1976cdf0e10cSrcweir		put_banner_bmp_into_template($templatefile, $includepatharrayref, $allvariableshashref);
1977cdf0e10cSrcweir		put_welcome_bmp_into_template($templatefile, $includepatharrayref, $allvariableshashref);
1978cdf0e10cSrcweir		put_setup_ico_into_template($templatefile, $includepatharrayref, $allvariableshashref);
19790b2dfbacSAndre Fischer		put_publisher_into_template($templatefile, $allvariableshashref);
19800b2dfbacSAndre Fischer		put_website_into_template($templatefile, $allvariableshashref);
1981cdf0e10cSrcweir		put_javafilename_into_template($templatefile, $allvariableshashref);
1982cdf0e10cSrcweir		put_windows_productversion_into_template($templatefile, $allvariableshashref);
1983cdf0e10cSrcweir		put_windows_productpath_into_template($templatefile, $allvariableshashref, $languagestringref, $localnsisdir);
1984cdf0e10cSrcweir		put_outputfilename_into_template($templatefile, $downloadname);
1985cdf0e10cSrcweir		put_filelist_into_template($templatefile, $installationdir);
1986cdf0e10cSrcweir		put_language_list_into_template($templatefile, $languagesarrayref);
1987cdf0e10cSrcweir		put_nsis_path_into_template($templatefile, $localnsisdir);
1988cdf0e10cSrcweir		put_output_path_into_template($templatefile, $downloaddir);
19893c0d14cbSmseidel
1990cdf0e10cSrcweir		my $nsifilename = save_script_file($localnsisdir, $templatefilename, $templatefile);
1991b274bc22SAndre Fischer
19923c0d14cbSmseidel		$installer::logger::Info->printf("... created NSIS file %s ... \n", $nsifilename);
19933c0d14cbSmseidel
1994cdf0e10cSrcweir		# starting the NSIS SDK to create the download file
19953c0d14cbSmseidel		call_nsis($nsispath, $nsifilename);
1996cdf0e10cSrcweir	}
19973c0d14cbSmseidel
1998cdf0e10cSrcweir	return $downloaddir;
1999cdf0e10cSrcweir}
2000cdf0e10cSrcweir
2001cdf0e10cSrcweir####################################################
2002957116b7SHerbert Dürr# Creating AOO upload tree
2003cdf0e10cSrcweir####################################################
2004cdf0e10cSrcweir
2005cdf0e10cSrcweirsub create_download_link_tree
2006cdf0e10cSrcweir{
2007cdf0e10cSrcweir	my ($downloaddir, $languagestringref, $allvariableshashref) = @_;
2008cdf0e10cSrcweir
20093c0d14cbSmseidel	$installer::logger::Info->print("\n");
20103c0d14cbSmseidel	$installer::logger::Info->print("******************************************\n"); #
20113c0d14cbSmseidel	$installer::logger::Info->print("... creating download hard link ...\n");
20123c0d14cbSmseidel	$installer::logger::Info->print("******************************************\n");
2013cdf0e10cSrcweir
2014cdf0e10cSrcweir	installer::logger::include_header_into_logfile("Creating download hard link:");
2015b274bc22SAndre Fischer	$installer::logger::Lang->print("\n");
2016b274bc22SAndre Fischer	$installer::logger::Lang->add_timestamp("Performance Info: Creating hard link, start");
2017cdf0e10cSrcweir
2018cdf0e10cSrcweir	if ( is_supported_platform() )
2019cdf0e10cSrcweir	{
2020cdf0e10cSrcweir		my $versionstring = "";
2021cdf0e10cSrcweir		# Already defined $installer::globals::oooversionstring and $installer::globals::ooodownloadfilename ?
20223c0d14cbSmseidel
2023cdf0e10cSrcweir		if ( ! $installer::globals::oooversionstring ) { $versionstring = get_current_version(); }
20243c0d14cbSmseidel		else { $versionstring = $installer::globals::oooversionstring; }
20253c0d14cbSmseidel
20263c0d14cbSmseidel		# Is $versionstring empty? If yes, there is nothing to do now.
20273c0d14cbSmseidel
20283c0d14cbSmseidel		$installer::logger::Lang->printf("Version string is set to: %s\n", $versionstring);
2029cdf0e10cSrcweir
2030cdf0e10cSrcweir		if ( $versionstring )
2031cdf0e10cSrcweir		{
2032cdf0e10cSrcweir			# Now the downloadfilename has to be set (if not already done)
2033cdf0e10cSrcweir			my $destdownloadfilename = "";
2034cdf0e10cSrcweir			if ( ! $installer::globals::ooodownloadfilename ) { $destdownloadfilename = set_download_filename($languagestringref, $versionstring, $allvariableshashref); }
2035cdf0e10cSrcweir			else { $destdownloadfilename = $installer::globals::ooodownloadfilename; }
2036cdf0e10cSrcweir
2037cdf0e10cSrcweir			if ( $destdownloadfilename )
2038cdf0e10cSrcweir			{
2039cdf0e10cSrcweir				$destdownloadfilename = $destdownloadfilename . $installer::globals::downloadfileextension;
2040b274bc22SAndre Fischer
20413c0d14cbSmseidel				$installer::logger::Lang->printf("Setting destination download file name: %s\n", $destdownloadfilename);
2042cdf0e10cSrcweir
2043cdf0e10cSrcweir				my $sourcedownloadfile = $downloaddir . $installer::globals::separator . $installer::globals::downloadfilename;
2044cdf0e10cSrcweir
20453c0d14cbSmseidel				$installer::logger::Lang->printf("Setting source download file name: %s\n", $sourcedownloadfile);
2046cdf0e10cSrcweir
2047cdf0e10cSrcweir				create_link_tree($sourcedownloadfile, $destdownloadfilename, $versionstring);
2048cdf0e10cSrcweir				# my $md5sumoutput = call_md5sum($downloadfile);
2049cdf0e10cSrcweir				# my $md5sum = get_md5sum($md5sumoutput);
20503c0d14cbSmseidel
2051cdf0e10cSrcweir			}
2052cdf0e10cSrcweir		}
2053cdf0e10cSrcweir		else
2054cdf0e10cSrcweir		{
20553c0d14cbSmseidel			$installer::logger::Lang->printf("Version string is empty. Nothing to do!\n");
20563c0d14cbSmseidel		}
20573c0d14cbSmseidel	}
2058cdf0e10cSrcweir	else
2059cdf0e10cSrcweir	{
20603c0d14cbSmseidel		$installer::logger::Lang->printf("Platform not used for hard linking. Nothing to do!\n");
2061cdf0e10cSrcweir	}
2062cdf0e10cSrcweir
2063b274bc22SAndre Fischer	$installer::logger::Lang->add_timestamp("Performance Info: Creating hard link, stop");
2064cdf0e10cSrcweir}
2065cdf0e10cSrcweir
2066cdf0e10cSrcweir1;
2067