1#**************************************************************
2#
3#  Licensed to the Apache Software Foundation (ASF) under one
4#  or more contributor license agreements.  See the NOTICE file
5#  distributed with this work for additional information
6#  regarding copyright ownership.  The ASF licenses this file
7#  to you under the Apache License, Version 2.0 (the
8#  "License"); you may not use this file except in compliance
9#  with the License.  You may obtain a copy of the License at
10#
11#    http://www.apache.org/licenses/LICENSE-2.0
12#
13#  Unless required by applicable law or agreed to in writing,
14#  software distributed under the License is distributed on an
15#  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16#  KIND, either express or implied.  See the License for the
17#  specific language governing permissions and limitations
18#  under the License.
19#
20#**************************************************************
21
22
23
24package installer::simplepackage;
25
26# use Archive::Zip qw( :ERROR_CODES :CONSTANTS );
27use Cwd;
28use File::Copy;
29use installer::download;
30use installer::exiter;
31use installer::globals;
32use installer::logger;
33use installer::strip;
34use installer::systemactions;
35use installer::worker;
36
37####################################################
38# Checking if the simple packager is required.
39# This can be achieved by setting the global
40# variable SIMPLE_PACKAGE in *.lst file or by
41# setting the environment variable SIMPLE_PACKAGE.
42####################################################
43
44sub check_simple_packager_project
45{
46	my ( $allvariables ) = @_;
47
48	if (( $installer::globals::packageformat eq "installed" ) ||
49		( $installer::globals::packageformat eq "archive" ))
50	{
51		$installer::globals::is_simple_packager_project = 1;
52		$installer::globals::patch_user_dir = 1;
53	}
54	elsif( $installer::globals::packageformat eq "dmg" )
55	{
56		$installer::globals::is_simple_packager_project = 1;
57	}
58}
59
60####################################################
61# Detecting the directory with extensions
62####################################################
63
64sub get_extensions_dir
65{
66	my ( $subfolderdir ) = @_;
67
68	my $extensiondir = $subfolderdir . $installer::globals::separator;
69	if ( $installer::globals::officedirhostname ne "" ) { $extensiondir = $extensiondir . $installer::globals::officedirhostname . $installer::globals::separator; }
70	my $extensionsdir = $extensiondir . "share" . $installer::globals::separator . "extensions";
71	my $preregdir = $extensiondir . "share" . $installer::globals::separator . "prereg" . $installer::globals::separator . "bundled";
72
73	return ( $extensionsdir, $preregdir );
74}
75
76####################################################
77# Registering extensions
78####################################################
79
80sub register_extensions
81{
82	my ($officedir, $languagestringref, $preregdir) = @_;
83
84	my $infoline = "";
85
86	if ( $preregdir eq "" )
87	{
88		$infoline = "ERROR: Failed to determine directory \"prereg\" for extension registration! Please check your installation set.\n";
89		push( @installer::globals::logfileinfo, $infoline);
90		installer::exiter::exit_program($infoline, "register_extensions");
91	}
92
93	my $programdir = $officedir . $installer::globals::separator;
94	if ( $installer::globals::officedirhostname ne "" ) { $programdir = $programdir . $installer::globals::officedirhostname . $installer::globals::separator; }
95	$programdir = $programdir . "program";
96
97	my $from = cwd();
98	chdir($programdir);
99
100	my $unopkgfile = $installer::globals::unopkgfile;
101
102	my $unopkgexists = 1;
103	if (( $installer::globals::languagepack ) && ( ! -f $unopkgfile ))
104	{
105		$unopkgexists = 0;
106		$infoline = "Language packs do not contain unopkg!\n";
107		push( @installer::globals::logfileinfo, $infoline);
108	}
109
110	if ( ! -f $unopkgfile )
111	{
112		$unopkgexists = 0;
113		$infoline = "Info: File $unopkgfile does not exist! Extensions cannot be registered.\n";
114		push( @installer::globals::logfileinfo, $infoline);
115	}
116
117	if ( $unopkgexists )
118	{
119		my $currentdir = cwd();
120		print "... current dir: $currentdir ...\n";
121		$infoline = "Current dir: $currentdir\n";
122		push( @installer::globals::logfileinfo, $infoline);
123
124		if ( ! -f $unopkgfile ) { installer::exiter::exit_program("ERROR: $unopkgfile not found!", "register_extensions"); }
125
126		my $systemcall = $unopkgfile . " sync --verbose" . " -env:UNO_JAVA_JFW_ENV_JREHOME=true 2\>\&1 |";
127
128		print "... $systemcall ...\n";
129
130		$infoline = "Systemcall: $systemcall\n";
131		push( @installer::globals::logfileinfo, $infoline);
132
133		my @unopkgoutput = ();
134
135		open (UNOPKG, $systemcall);
136		while (<UNOPKG>)
137		{
138			my $lastline = $_;
139			push(@unopkgoutput, $lastline);
140		}
141		close (UNOPKG);
142
143		my $returnvalue = $?;	# $? contains the return value of the systemcall
144
145		if ($returnvalue)
146		{
147			# Writing content of @unopkgoutput only in the error case into the log file. Sometimes it
148			# contains strings like "Error" even in the case of success. This causes a packaging error
149			# when the log file is analyzed at the end, even if there is no real error.
150			for ( my $j = 0; $j <= $#unopkgoutput; $j++ ) { push( @installer::globals::logfileinfo, "$unopkgoutput[$j]"); }
151
152			$infoline = "ERROR: Could not execute \"$systemcall\"!\nExitcode: '$returnvalue'\n";
153			push( @installer::globals::logfileinfo, $infoline);
154			installer::exiter::exit_program("ERROR: $systemcall failed!", "register_extensions");
155		}
156		else
157		{
158			$infoline = "Success: Executed \"$systemcall\" successfully!\n";
159			push( @installer::globals::logfileinfo, $infoline);
160		}
161	}
162
163	chdir($from);
164}
165
166########################################################################
167# Getting the translation file for the Mac Language Pack installer
168########################################################################
169
170sub get_mac_translation_file
171{
172	my $translationfilename = $installer::globals::maclangpackfilename;
173	# my $translationfilename = $installer::globals::idtlanguagepath . $installer::globals::separator . $installer::globals::maclangpackfilename;
174	# if ( $installer::globals::unicodensis ) { $translationfilename = $translationfilename . ".uulf"; }
175	# else { $translationfilename = $translationfilename . ".mlf"; }
176	if ( ! -f $translationfilename ) { installer::exiter::exit_program("ERROR: Could not find language file $translationfilename!", "get_mac_translation_file"); }
177	my $translationfile = installer::files::read_file($translationfilename);
178
179	my $infoline = "Reading translation file: $translationfilename\n";
180	push( @installer::globals::logfileinfo, $infoline);
181
182	return $translationfile;
183}
184
185##################################################################
186# Collecting all identifier from ulf file
187##################################################################
188
189sub get_identifier
190{
191	my ( $translationfile ) = @_;
192
193	my @identifier = ();
194
195	for ( my $i = 0; $i <= $#{$translationfile}; $i++ )
196	{
197		my $oneline = ${$translationfile}[$i];
198
199		if ( $oneline =~ /^\s*\[(.+)\]\s*$/ )
200		{
201			my $identifier = $1;
202			push(@identifier, $identifier);
203		}
204	}
205
206	return \@identifier;
207}
208
209##############################################################
210# Returning the complete block in all languages
211# for a specified string
212##############################################################
213
214sub get_language_block_from_language_file
215{
216	my ($searchstring, $languagefile) = @_;
217
218	my @language_block = ();
219
220	for ( my $i = 0; $i <= $#{$languagefile}; $i++ )
221	{
222		if ( ${$languagefile}[$i] =~ /^\s*\[\s*$searchstring\s*\]\s*$/ )
223		{
224			my $counter = $i;
225
226			push(@language_block, ${$languagefile}[$counter]);
227			$counter++;
228
229			while (( $counter <= $#{$languagefile} ) && (!( ${$languagefile}[$counter] =~ /^\s*\[/ )))
230			{
231				push(@language_block, ${$languagefile}[$counter]);
232				$counter++;
233			}
234
235			last;
236		}
237	}
238
239	return \@language_block;
240}
241
242##############################################################
243# Returning a specific language string from the block
244# of all translations
245##############################################################
246
247sub get_language_string_from_language_block
248{
249	my ($language_block, $language) = @_;
250
251	my $newstring = "";
252
253	for ( my $i = 0; $i <= $#{$language_block}; $i++ )
254	{
255		if ( ${$language_block}[$i] =~ /^\s*$language\s*\=\s*\"(.*)\"\s*$/ )
256		{
257			$newstring = $1;
258			last;
259		}
260	}
261
262	if ( $newstring eq "" )
263	{
264		$language = "en-US"; 	# defaulting to english
265
266		for ( my $i = 0; $i <= $#{$language_block}; $i++ )
267		{
268			if ( ${$language_block}[$i] =~ /^\s*$language\s*\=\s*\"(.*)\"\s*$/ )
269			{
270				$newstring = $1;
271				last;
272			}
273		}
274	}
275
276	return $newstring;
277}
278
279########################################################################
280# Localizing the script for the Mac Language Pack installer
281########################################################################
282
283sub localize_scriptfile
284{
285	my ($scriptfile, $translationfile, $languagestringref) = @_;
286
287	# my $translationfile = get_mac_translation_file();
288
289	my $onelanguage = $$languagestringref;
290	if ( $onelanguage =~ /^\s*(.*?)_/ ) { $onelanguage = $1; }
291
292	# Analyzing the ulf file, collecting all Identifier
293	my $allidentifier = get_identifier($translationfile);
294
295	for ( my $i = 0; $i <= $#{$allidentifier}; $i++ )
296	{
297		my $identifier = ${$allidentifier}[$i];
298		my $language_block = get_language_block_from_language_file($identifier, $translationfile);
299		my $newstring = get_language_string_from_language_block($language_block, $onelanguage);
300
301		# removing mask
302		$newstring =~ s/\\\'/\'/g;
303
304		replace_one_variable_in_shellscript($scriptfile, $newstring, $identifier);
305	}
306}
307
308#################################################################################
309# Replacing one variable in Mac shell script
310#################################################################################
311
312sub replace_one_variable_in_shellscript
313{
314	my ($scriptfile, $variable, $searchstring) = @_;
315
316	for ( my $i = 0; $i <= $#{$scriptfile}; $i++ )
317	{
318		${$scriptfile}[$i] =~ s/\[$searchstring\]/$variable/g;
319	}
320}
321
322#############################################
323# Replacing variables in Mac shell script
324#############################################
325
326sub replace_variables_in_scriptfile
327{
328	my ($scriptfile, $volume_name, $volume_name_app, $allvariables) = @_;
329
330	replace_one_variable_in_shellscript($scriptfile, $volume_name, "FULLPRODUCTNAME" );
331	replace_one_variable_in_shellscript($scriptfile, $volume_name_app, "FULLAPPPRODUCTNAME" );
332	replace_one_variable_in_shellscript($scriptfile, $allvariables->{'PRODUCTNAME'}, "PRODUCTNAME" );
333	replace_one_variable_in_shellscript($scriptfile, $allvariables->{'PRODUCTVERSION'}, "PRODUCTVERSION" );
334
335	my $scriptname = lc($allvariables->{'PRODUCTNAME'}) . "\.script";
336	if ( $allvariables->{'PRODUCTNAME'} eq "OpenOffice.org" ) { $scriptname = "org.openoffice.script"; }
337
338	replace_one_variable_in_shellscript($scriptfile, $scriptname, "SEARCHSCRIPTNAME" );
339}
340
341#############################################
342# Creating the "simple" package.
343# "zip" for Windows
344# "tar.gz" for all other platforms
345# additionally "dmg" on Mac OS X
346#############################################
347
348sub create_package
349{
350	my ( $installdir, $archivedir, $packagename, $allvariables, $includepatharrayref, $languagestringref, $format ) = @_;
351
352    installer::logger::print_message( "... creating $installer::globals::packageformat file ...\n" );
353    installer::logger::include_header_into_logfile("Creating $installer::globals::packageformat file:");
354
355	# moving dir into temporary directory
356	my $pid = $$; # process id
357	my $tempdir = $installdir . "_temp" . "." . $pid;
358	my $systemcall = "";
359	my $from = "";
360	my $makesystemcall = 1;
361	my $return_to_start = 0;
362	installer::systemactions::rename_directory($installdir, $tempdir);
363
364	# creating new directory with original name
365	installer::systemactions::create_directory($archivedir);
366
367	my $archive = $archivedir . $installer::globals::separator . $packagename . $format;
368
369	if ( $archive =~ /zip$/ )
370	{
371		$from = cwd();
372		$return_to_start = 1;
373		chdir($tempdir);
374		$systemcall = "$installer::globals::zippath -qr $archive .";
375
376		# Using Archive::Zip fails because of very long path names below "share/uno_packages/cache"
377		# my $packzip = Archive::Zip->new();
378		# $packzip->addTree(".");	# after changing into $tempdir
379		# $packzip->writeToFileNamed($archive);
380		# $makesystemcall = 0;
381	}
382 	elsif ( $archive =~ /dmg$/ )
383	{
384		my $folder = (( -l "$tempdir/$packagename/Applications" ) or ( -l "$tempdir/$packagename/opt" )) ? $packagename : "\.";
385
386		if ( $allvariables->{'PACK_INSTALLED'} ) {
387		    $folder = $packagename;
388		}
389
390		# my $volume_name = $allvariables->{'PRODUCTNAME'} . ' ' . $allvariables->{'PRODUCTVERSION'}; # Adding PRODUCTVERSION makes this difficult to maintain!
391		my $volume_name = $allvariables->{'PRODUCTNAME'};
392		my $volume_name_classic = $allvariables->{'PRODUCTNAME'} . ' ' . $allvariables->{'PRODUCTVERSION'};
393		my $volume_name_classic_app = $volume_name;  # "app" should not contain version number
394		# $volume_name = $volume_name . ' ' . $allvariables->{'PRODUCTEXTENSION'} if $allvariables->{'PRODUCTEXTENSION'}; # Adding PRODUCTEXTENSION makes this difficult to maintain!
395		$volume_name_classic = $volume_name_classic . ' ' . $allvariables->{'PRODUCTEXTENSION'} if $allvariables->{'PRODUCTEXTENSION'};
396		$volume_name_classic_app = $volume_name_classic_app . ' ' . $allvariables->{'PRODUCTEXTENSION'} if $allvariables->{'PRODUCTEXTENSION'};
397		if ( $allvariables->{'DMG_VOLUMEEXTENSION'} ) {
398		    $volume_name = $volume_name . ' ' . $allvariables->{'DMG_VOLUMEEXTENSION'};
399		    $volume_name_classic = $volume_name_classic . ' ' . $allvariables->{'DMG_VOLUMEEXTENSION'};
400		    $volume_name_classic_app = $volume_name_classic_app . ' ' . $allvariables->{'DMG_VOLUMEEXTENSION'};
401		}
402
403		my $sla = 'sla.r';
404		my $ref = "";
405
406		if ( ! $allvariables->{'HIDELICENSEDIALOG'} )
407		{
408			installer::scriptitems::get_sourcepath_from_filename_and_includepath( \$sla, $includepatharrayref, 0);
409		}
410
411		my $localtempdir = $tempdir;
412
413		if (( $installer::globals::languagepack ) || ( $installer::globals::patch ))
414		{
415			$localtempdir = "$tempdir/$packagename";
416			if ( $installer::globals::languagepack )
417			{
418				$volume_name = "$volume_name Language Pack";
419				$volume_name_classic = "$volume_name_classic Language Pack";
420				$volume_name_classic_app = "$volume_name_classic_app Language Pack";
421			}
422			if ( $installer::globals::patch )
423			{
424				$volume_name = "$volume_name Patch";
425				$volume_name_classic = "$volume_name_classic Patch";
426				$volume_name_classic_app = "$volume_name_classic_app Patch";
427			}
428
429			# Create tar ball named tarball.tar.bz2
430			# my $appfolder = $localtempdir . "/" . $volume_name . "\.app";
431			my $appfolder = $localtempdir . "/" . $volume_name_classic_app . "\.app";
432			my $contentsfolder = $appfolder . "/Contents";
433			my $tarballname = "tarball.tar.bz2";
434
435			my $localfrom = cwd();
436			chdir $appfolder;
437
438			$systemcall = "tar -cjf $tarballname Contents/";
439
440			print "... $systemcall ...\n";
441			my $localreturnvalue = system($systemcall);
442			$infoline = "Systemcall: $systemcall\n";
443			push( @installer::globals::logfileinfo, $infoline);
444
445			if ($localreturnvalue)
446			{
447				$infoline = "ERROR: Could not execute \"$systemcall\"!\n";
448				push( @installer::globals::logfileinfo, $infoline);
449			}
450			else
451			{
452				$infoline = "Success: Executed \"$systemcall\" successfully!\n";
453				push( @installer::globals::logfileinfo, $infoline);
454			}
455
456			my $sourcefile = $appfolder . "/" . $tarballname;
457			my $destfile = $contentsfolder . "/" . $tarballname;
458
459			installer::systemactions::remove_complete_directory($contentsfolder);
460			installer::systemactions::create_directory($contentsfolder);
461
462			installer::systemactions::copy_one_file($sourcefile, $destfile);
463			unlink($sourcefile);
464
465			# Copy two files into installation set next to the tar ball
466			# 1. "osx_install.applescript"
467			# 2 "OpenOffice.org Languagepack"
468
469			my $scriptrealfilename = "osx_install.applescript";
470			my $scriptfilename = "";
471			if ( $installer::globals::languagepack ) { $scriptfilename = "osx_install_languagepack.applescript"; }
472			if ( $installer::globals::patch ) { $scriptfilename = "osx_install_patch.applescript"; }
473			my $scripthelpersolverfilename = "mac_install.script";
474			# my $scripthelperrealfilename = $volume_name;
475			my $scripthelperrealfilename = $volume_name_classic_app;
476			my $translationfilename = $installer::globals::macinstallfilename;
477
478			# Finding both files in solver
479
480			my $scriptref = installer::scriptitems::get_sourcepath_from_filename_and_includepath( \$scriptfilename, $includepatharrayref, 0);
481			if ($$scriptref eq "") { installer::exiter::exit_program("ERROR: Could not find Apple script $scriptfilename!", "create_package"); }
482			my $scripthelperref = installer::scriptitems::get_sourcepath_from_filename_and_includepath( \$scripthelpersolverfilename, $includepatharrayref, 0);
483			if ($$scripthelperref eq "") { installer::exiter::exit_program("ERROR: Could not find Apple script $scripthelpersolverfilename!", "create_package"); }
484			my $translationfileref = installer::scriptitems::get_sourcepath_from_filename_and_includepath( \$translationfilename, $includepatharrayref, 0);
485			if ($$translationfileref eq "") { installer::exiter::exit_program("ERROR: Could not find Apple script translation file $translationfilename!", "create_package"); }
486
487			$scriptfilename = $contentsfolder . "/" . $scriptrealfilename;
488			$scripthelperrealfilename = $contentsfolder . "/" . $scripthelperrealfilename;
489
490			installer::systemactions::copy_one_file($$scriptref, $scriptfilename);
491			installer::systemactions::copy_one_file($$scripthelperref, $scripthelperrealfilename);
492
493			# Replacing variables in script $scriptfilename
494			# Localizing script $scriptfilename
495			my $scriptfilecontent = installer::files::read_file($scriptfilename);
496			my $translationfilecontent = installer::files::read_file($$translationfileref);
497			localize_scriptfile($scriptfilecontent, $translationfilecontent, $languagestringref);
498			# replace_variables_in_scriptfile($scriptfilecontent, $volume_name, $allvariables);
499			replace_variables_in_scriptfile($scriptfilecontent, $volume_name_classic, $volume_name_classic_app, $allvariables);
500			installer::files::save_file($scriptfilename, $scriptfilecontent);
501
502			$systemcall = "chmod 775 " . "\"" . $scriptfilename . "\"";
503			system($systemcall);
504			$systemcall = "chmod 775 " . "\"" . $scripthelperrealfilename . "\"";
505			system($systemcall);
506
507			# Copy also Info.plist and icon file
508			# Finding both files in solver
509			my $iconfile = "ooo3_installer.icns";
510			my $iconfileref = installer::scriptitems::get_sourcepath_from_filename_and_includepath( \$iconfile, $includepatharrayref, 0);
511			if ($$iconfileref eq "") { installer::exiter::exit_program("ERROR: Could not find Apple script icon file $iconfile!", "create_package"); }
512			my $subdir = $contentsfolder . "/" . "Resources";
513			if ( ! -d $subdir ) { installer::systemactions::create_directory($subdir); }
514			$destfile = $subdir . "/" . $iconfile;
515			installer::systemactions::copy_one_file($$iconfileref, $destfile);
516
517			my $infoplistfile = "Info.plist.langpack";
518			my $installname = "Info.plist";
519			my $infoplistfileref = installer::scriptitems::get_sourcepath_from_filename_and_includepath( \$infoplistfile, $includepatharrayref, 0);
520			if ($$infoplistfileref eq "") { installer::exiter::exit_program("ERROR: Could not find Apple script Info.plist: $infoplistfile!", "create_package"); }
521			$destfile = $contentsfolder . "/" . $installname;
522			installer::systemactions::copy_one_file($$infoplistfileref, $destfile);
523
524			# Replacing variables in Info.plist
525			$scriptfilecontent = installer::files::read_file($destfile);
526			# replace_one_variable_in_shellscript($scriptfilecontent, $volume_name, "FULLPRODUCTNAME" );
527			replace_one_variable_in_shellscript($scriptfilecontent, $volume_name_classic_app, "FULLAPPPRODUCTNAME" ); # OpenOffice.org Language Pack
528			installer::files::save_file($destfile, $scriptfilecontent);
529
530			chdir $localfrom;
531		}
532
533		$systemcall = "cd $localtempdir && hdiutil makehybrid -hfs -hfs-openfolder $folder $folder -hfs-volume-name \"$volume_name\" -ov -o $installdir/tmp && hdiutil convert -ov -format UDZO $installdir/tmp.dmg -o $archive && ";
534        if (( $ref ne "" ) && ( $$ref ne "" )) {
535			$systemcall .= "hdiutil unflatten $archive && Rez -a $$ref -o $archive && hdiutil flatten $archive &&";
536		}
537		$systemcall .= "rm -f $installdir/tmp.dmg";
538	}
539	else
540	{
541		# getting the path of the getuid.so (only required for Solaris and Linux)
542		my $getuidlibrary = "";
543		my $ldpreloadstring = "";
544		if (( $installer::globals::issolarisbuild ) || ( $installer::globals::islinuxbuild ))
545		{
546			$getuidlibrary = installer::download::get_path_for_library($includepatharrayref);
547			if ( $getuidlibrary ne "" ) { $ldpreloadstring = "LD_PRELOAD=" . $getuidlibrary; }
548		}
549
550		$systemcall = "cd $tempdir; $ldpreloadstring tar -cf - . | gzip > $archive";
551	}
552
553	if ( $makesystemcall )
554	{
555		print "... $systemcall ...\n";
556		my $returnvalue = system($systemcall);
557		my $infoline = "Systemcall: $systemcall\n";
558		push( @installer::globals::logfileinfo, $infoline);
559
560		if ($returnvalue)
561		{
562			$infoline = "ERROR: Could not execute \"$systemcall\"!\n";
563			push( @installer::globals::logfileinfo, $infoline);
564		}
565		else
566		{
567			$infoline = "Success: Executed \"$systemcall\" successfully!\n";
568			push( @installer::globals::logfileinfo, $infoline);
569		}
570	}
571
572	if ( $return_to_start ) { chdir($from); }
573
574	print "... removing $tempdir ...\n";
575	installer::systemactions::remove_complete_directory($tempdir);
576}
577
578####################################################
579# Main method for creating the simple package
580# installation sets
581####################################################
582
583sub create_simple_package
584{
585	my ( $filesref, $dirsref, $scpactionsref, $linksref, $unixlinksref, $loggingdir, $languagestringref, $shipinstalldir, $allsettingsarrayref, $allvariables, $includepatharrayref ) = @_;
586
587	# Creating directories
588
589	my $current_install_number = "";
590	my $infoline = "";
591
592	installer::logger::print_message( "... creating installation directory ...\n" );
593	installer::logger::include_header_into_logfile("Creating installation directory");
594
595	$installer::globals::csp_installdir = installer::worker::create_installation_directory($shipinstalldir, $languagestringref, \$current_install_number);
596	$installer::globals::csp_installlogdir = installer::systemactions::create_directory_next_to_directory($installer::globals::csp_installdir, "log");
597
598	my $installdir = $installer::globals::csp_installdir;
599	my $installlogdir = $installer::globals::csp_installlogdir;
600
601	# Setting package name (similar to the download name)
602	my $packagename = "";
603
604	if ( $installer::globals::packageformat eq "archive"  ||
605		$installer::globals::packageformat eq "dmg" )
606	{
607		$installer::globals::csp_languagestring = $$languagestringref;
608
609		my $locallanguage = $installer::globals::csp_languagestring;
610
611		if ( $allvariables->{'OOODOWNLOADNAME'} )
612		{
613			$packagename = installer::download::set_download_filename(\$locallanguage, $allvariables);
614		}
615		else
616		{
617			$downloadname = installer::ziplist::getinfofromziplist($allsettingsarrayref, "downloadname");
618			if ( $installer::globals::languagepack ) { $downloadname = installer::ziplist::getinfofromziplist($allsettingsarrayref, "langpackdownloadname"); }
619			if ( $installer::globals::patch ) { $downloadname = installer::ziplist::getinfofromziplist($allsettingsarrayref, "patchdownloadname"); }
620			$packagename = installer::download::resolve_variables_in_downloadname($allvariables, $$downloadname, \$locallanguage);
621		}
622	}
623
624    # Work around Windows problems with long pathnames (see issue 50885) by
625    # putting the to-be-archived installation tree into the temp directory
626    # instead of the module output tree (unless LOCALINSTALLDIR dictates
627    # otherwise, anyway); can be removed once issue 50885 is fixed:
628    my $tempinstalldir = $installdir;
629    if ( $installer::globals::iswindowsbuild &&
630         $installer::globals::packageformat eq "archive" &&
631         !$installer::globals::localinstalldirset )
632    {
633        $tempinstalldir = File::Temp::tempdir;
634    }
635
636	# Creating subfolder in installdir, which shall become the root of package or zip file
637	my $subfolderdir = "";
638	if ( $packagename ne "" ) { $subfolderdir = $tempinstalldir . $installer::globals::separator . $packagename; }
639	else { $subfolderdir = $tempinstalldir; }
640
641	if ( ! -d $subfolderdir ) { installer::systemactions::create_directory($subfolderdir); }
642
643	# Create directories, copy files and ScpActions
644
645	installer::logger::print_message( "... creating directories ...\n" );
646	installer::logger::include_header_into_logfile("Creating directories:");
647
648	for ( my $i = 0; $i <= $#{$dirsref}; $i++ )
649	{
650		my $onedir = ${$dirsref}[$i];
651
652		if ( $onedir->{'HostName'} )
653		{
654			my $destdir = $subfolderdir . $installer::globals::separator . $onedir->{'HostName'};
655
656			if ( ! -d $destdir )
657			{
658				if ( $^O =~ /cygwin/i ) # Cygwin performance check
659				{
660					$infoline = "Try to create directory $destdir\n";
661					push(@installer::globals::logfileinfo, $infoline);
662					# Directories in $dirsref are sorted and all parents were added -> "mkdir" works without parent creation!
663					if ( ! ( -d $destdir )) { mkdir($destdir, 0775); }
664				}
665				else
666				{
667					installer::systemactions::create_directory_structure($destdir);
668				}
669			}
670		}
671	}
672
673	# stripping files ?!
674	if (( $installer::globals::strip ) && ( ! $installer::globals::iswindowsbuild )) { installer::strip::strip_libraries($filesref, $languagestringref); }
675
676	# copy Files
677	installer::logger::print_message( "... copying files ...\n" );
678	installer::logger::include_header_into_logfile("Copying files:");
679
680	for ( my $i = 0; $i <= $#{$filesref}; $i++ )
681	{
682		my $onefile = ${$filesref}[$i];
683
684		if (( $onefile->{'Styles'} ) && ( $onefile->{'Styles'} =~ /\bBINARYTABLE_ONLY\b/ )) { next; }
685		if (( $installer::globals::patch ) && ( $onefile->{'Styles'} ) && ( ! ( $onefile->{'Styles'} =~ /\bPATCH\b/ ))) { next; }
686		if (( $installer::globals::patch ) && ( $installer::globals::packageformat eq "dmg" )) { push(@installer::globals::patchfilecollector, "$onefile->{'destination'}\n"); }
687
688		my $source = $onefile->{'sourcepath'};
689		my $destination = $onefile->{'destination'};
690		$destination = $subfolderdir . $installer::globals::separator . $destination;
691
692		# Replacing $$ by $ is necessary to install files with $ in its name (back-masquerading)
693		# Otherwise, the following shell command does not work and the file list is not correct
694		$source =~ s/\$\$/\$/;
695		$destination =~ s/\$\$/\$/;
696
697		if ( $^O =~ /cygwin/i )	# Cygwin performance, do not use copy_one_file. "chmod -R" at the end
698		{
699			my $copyreturn = copy($source, $destination);
700
701			if ($copyreturn)
702			{
703				$infoline = "Copy: $source to $destination\n";
704				$returnvalue = 1;
705			}
706			else
707			{
708				$infoline = "ERROR: Could not copy $source to $destination\n";
709				$returnvalue = 0;
710			}
711
712			push(@installer::globals::logfileinfo, $infoline);
713		}
714		else
715		{
716			installer::systemactions::copy_one_file($source, $destination);
717
718			if ( ! $installer::globals::iswindowsbuild )
719			{
720				# see issue 102274
721				my $unixrights = "";
722				if ( $onefile->{'UnixRights'} )
723				{
724					$unixrights = $onefile->{'UnixRights'};
725
726					my $localcall = "$installer::globals::wrapcmd chmod $unixrights \'$destination\' \>\/dev\/null 2\>\&1";
727					system($localcall);
728				}
729			}
730		}
731	}
732
733	# creating Links
734
735	installer::logger::print_message( "... creating links ...\n" );
736	installer::logger::include_header_into_logfile("Creating links:");
737
738	for ( my $i = 0; $i <= $#{$linksref}; $i++ )
739	{
740		my $onelink = ${$linksref}[$i];
741
742		if (( $installer::globals::patch ) && ( $onelink->{'Styles'} ) && ( ! ( $onelink->{'Styles'} =~ /\bPATCH\b/ ))) { next; }
743
744		my $destination = $onelink->{'destination'};
745		$destination = $subfolderdir . $installer::globals::separator . $destination;
746		my $destinationfile = $onelink->{'destinationfile'};
747
748		my $localcall = "ln -sf \'$destinationfile\' \'$destination\' \>\/dev\/null 2\>\&1";
749		system($localcall);
750
751		$infoline = "Creating link: \"ln -sf $destinationfile $destination\"\n";
752		push(@installer::globals::logfileinfo, $infoline);
753	}
754
755	for ( my $i = 0; $i <= $#{$unixlinksref}; $i++ )
756	{
757		my $onelink = ${$unixlinksref}[$i];
758
759		if (( $installer::globals::patch ) && ( $onelink->{'Styles'} ) && ( ! ( $onelink->{'Styles'} =~ /\bPATCH\b/ ))) { next; }
760
761		my $target = $onelink->{'Target'};
762		my $destination = $subfolderdir . $installer::globals::separator . $onelink->{'destination'};
763
764		my $localcall = "ln -sf \'$target\' \'$destination\' \>\/dev\/null 2\>\&1";
765		system($localcall);
766
767		$infoline = "Creating Unix link: \"ln -sf $target $destination\"\n";
768		push(@installer::globals::logfileinfo, $infoline);
769	}
770
771	# Setting privileges for cygwin globally
772
773	if ( $^O =~ /cygwin/i )
774	{
775		installer::logger::print_message( "... changing privileges in $subfolderdir ...\n" );
776		installer::logger::include_header_into_logfile("Changing privileges in $subfolderdir:");
777
778		my $localcall = "chmod -R 755 " . "\"" . $subfolderdir . "\"";
779		system($localcall);
780	}
781
782	installer::logger::print_message( "... removing superfluous directories ...\n" );
783	installer::logger::include_header_into_logfile("Removing superfluous directories:");
784
785	my ( $extensionfolder, $preregdir ) = get_extensions_dir($subfolderdir);
786	installer::systemactions::remove_empty_dirs_in_folder($extensionfolder);
787
788	# Registering the extensions
789
790	installer::logger::print_message( "... registering extensions ...\n" );
791	installer::logger::include_header_into_logfile("Registering extensions:");
792	register_extensions($subfolderdir, $languagestringref, $preregdir);
793
794	if ( $installer::globals::compiler =~ /^unxmacx/ )
795	{
796		installer::worker::put_scpactions_into_installset("$installdir/$packagename");
797	}
798
799	# Creating archive file
800    if ( $installer::globals::packageformat eq "archive" )
801    {
802        create_package($tempinstalldir, $installdir, $packagename, $allvariables, $includepatharrayref, $languagestringref, $installer::globals::archiveformat);
803    }
804    elsif ( $installer::globals::packageformat eq "dmg" )
805    {
806        create_package($installdir, $installdir, $packagename, $allvariables, $includepatharrayref, $languagestringref, ".dmg");
807    }
808
809	# Analyzing the log file
810
811	installer::worker::clean_output_tree();	# removing directories created in the output tree
812	installer::worker::analyze_and_save_logfile($loggingdir, $installdir, $installlogdir, $allsettingsarrayref, $languagestringref, $current_install_number);
813}
814
8151;
816