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		$installer::logger::Lang->print($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		$installer::logger::Lang->print($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		$installer::logger::Lang->print($infoline);
115	}
116
117	if ( $unopkgexists )
118	{
119		my $currentdir = cwd();
120		$installer::logger::Info->printf("... current dir: %s ...\n", $currentdir);
121		$infoline = "Current dir: $currentdir\n";
122		$installer::logger::Lang->print($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		$installer::logger::Info->printf("... %s ...\n", $systemcall);
129
130		$infoline = "Systemcall: $systemcall\n";
131		$installer::logger::Lang->print($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			foreach my $line (@unopkgoutput)
151            {
152                $installer::logger::Lang->printf($line);
153            }
154
155			$infoline = "ERROR: Could not execute \"$systemcall\"!\nExitcode: '$returnvalue'\n";
156			$installer::logger::Lang->print($infoline);
157			installer::exiter::exit_program("ERROR: $systemcall failed!", "register_extensions");
158		}
159		else
160		{
161			$infoline = "Success: Executed \"$systemcall\" successfully!\n";
162			$installer::logger::Lang->print($infoline);
163		}
164	}
165
166	chdir($from);
167}
168
169########################################################################
170# Getting the translation file for the Mac Language Pack installer
171########################################################################
172
173sub get_mac_translation_file
174{
175	my $translationfilename = $installer::globals::maclangpackfilename;
176	# my $translationfilename = $installer::globals::idtlanguagepath . $installer::globals::separator . $installer::globals::maclangpackfilename;
177	# if ( $installer::globals::unicodensis ) { $translationfilename = $translationfilename . ".uulf"; }
178	# else { $translationfilename = $translationfilename . ".mlf"; }
179	if ( ! -f $translationfilename ) { installer::exiter::exit_program("ERROR: Could not find language file $translationfilename!", "get_mac_translation_file"); }
180	my $translationfile = installer::files::read_file($translationfilename);
181
182	my $infoline = "Reading translation file: $translationfilename\n";
183	$installer::logger::Lang->print($infoline);
184
185	return $translationfile;
186}
187
188##################################################################
189# Collecting all identifier from ulf file
190##################################################################
191
192sub get_identifier
193{
194	my ( $translationfile ) = @_;
195
196	my @identifier = ();
197
198	for ( my $i = 0; $i <= $#{$translationfile}; $i++ )
199	{
200		my $oneline = ${$translationfile}[$i];
201
202		if ( $oneline =~ /^\s*\[(.+)\]\s*$/ )
203		{
204			my $identifier = $1;
205			push(@identifier, $identifier);
206		}
207	}
208
209	return \@identifier;
210}
211
212##############################################################
213# Returning the complete block in all languages
214# for a specified string
215##############################################################
216
217sub get_language_block_from_language_file
218{
219	my ($searchstring, $languagefile) = @_;
220
221	my @language_block = ();
222
223	for ( my $i = 0; $i <= $#{$languagefile}; $i++ )
224	{
225		if ( ${$languagefile}[$i] =~ /^\s*\[\s*$searchstring\s*\]\s*$/ )
226		{
227			my $counter = $i;
228
229			push(@language_block, ${$languagefile}[$counter]);
230			$counter++;
231
232			while (( $counter <= $#{$languagefile} ) && (!( ${$languagefile}[$counter] =~ /^\s*\[/ )))
233			{
234				push(@language_block, ${$languagefile}[$counter]);
235				$counter++;
236			}
237
238			last;
239		}
240	}
241
242	return \@language_block;
243}
244
245##############################################################
246# Returning a specific language string from the block
247# of all translations
248##############################################################
249
250sub get_language_string_from_language_block
251{
252	my ($language_block, $language) = @_;
253
254	my $newstring = "";
255
256	for ( my $i = 0; $i <= $#{$language_block}; $i++ )
257	{
258		if ( ${$language_block}[$i] =~ /^\s*$language\s*\=\s*\"(.*)\"\s*$/ )
259		{
260			$newstring = $1;
261			last;
262		}
263	}
264
265	if ( $newstring eq "" )
266	{
267		$language = "en-US"; 	# defaulting to english
268
269		for ( my $i = 0; $i <= $#{$language_block}; $i++ )
270		{
271			if ( ${$language_block}[$i] =~ /^\s*$language\s*\=\s*\"(.*)\"\s*$/ )
272			{
273				$newstring = $1;
274				last;
275			}
276		}
277	}
278
279	return $newstring;
280}
281
282########################################################################
283# Localizing the script for the Mac Language Pack installer
284########################################################################
285
286sub localize_scriptfile
287{
288	my ($scriptfile, $translationfile, $languagestringref) = @_;
289
290	# my $translationfile = get_mac_translation_file();
291
292	my $onelanguage = $$languagestringref;
293	if ( $onelanguage =~ /^\s*(.*?)_/ ) { $onelanguage = $1; }
294
295	# Analyzing the ulf file, collecting all Identifier
296	my $allidentifier = get_identifier($translationfile);
297
298	for ( my $i = 0; $i <= $#{$allidentifier}; $i++ )
299	{
300		my $identifier = ${$allidentifier}[$i];
301		my $language_block = get_language_block_from_language_file($identifier, $translationfile);
302		my $newstring = get_language_string_from_language_block($language_block, $onelanguage);
303
304		# removing mask
305		$newstring =~ s/\\\'/\'/g;
306
307		replace_one_variable_in_shellscript($scriptfile, $newstring, $identifier);
308	}
309}
310
311#################################################################################
312# Replacing one variable in Mac shell script
313#################################################################################
314
315sub replace_one_variable_in_shellscript
316{
317	my ($scriptfile, $variable, $searchstring) = @_;
318
319	for ( my $i = 0; $i <= $#{$scriptfile}; $i++ )
320	{
321		${$scriptfile}[$i] =~ s/\[$searchstring\]/$variable/g;
322	}
323}
324
325#############################################
326# Replacing variables in Mac shell script
327#############################################
328
329sub replace_variables_in_scriptfile
330{
331	my ($scriptfile, $volume_name, $volume_name_app, $allvariables) = @_;
332
333	replace_one_variable_in_shellscript($scriptfile, $volume_name, "FULLPRODUCTNAME" );
334	replace_one_variable_in_shellscript($scriptfile, $volume_name_app, "FULLAPPPRODUCTNAME" );
335	replace_one_variable_in_shellscript($scriptfile, $allvariables->{'PRODUCTNAME'}, "PRODUCTNAME" );
336	replace_one_variable_in_shellscript($scriptfile, $allvariables->{'PRODUCTVERSION'}, "PRODUCTVERSION" );
337
338	my $scriptname = lc($allvariables->{'PRODUCTNAME'}) . "\.script";
339	if ( $allvariables->{'PRODUCTNAME'} eq "OpenOffice" )
340    {
341        $scriptname = "org.openoffice.script";
342    }
343
344	replace_one_variable_in_shellscript($scriptfile, $scriptname, "SEARCHSCRIPTNAME" );
345}
346
347#############################################
348# Creating the "simple" package.
349# "zip" for Windows
350# "tar.gz" for all other platforms
351# additionally "dmg" on Mac OS X
352#############################################
353
354sub create_package
355{
356	my ( $installdir, $archivedir, $packagename, $allvariables, $includepatharrayref, $languagestringref, $format ) = @_;
357
358    $installer::logger::Info->printf("... creating %s file ...\n", $installer::globals::packageformat);
359    installer::logger::include_header_into_logfile("Creating $installer::globals::packageformat file:");
360
361	# moving dir into temporary directory
362	my $pid = $$; # process id
363	my $tempdir = $installdir . "_temp" . "." . $pid;
364	my $systemcall = "";
365	my $from = "";
366	my $makesystemcall = 1;
367	my $return_to_start = 0;
368	installer::systemactions::rename_directory($installdir, $tempdir);
369
370	# creating new directory with original name
371	installer::systemactions::create_directory($archivedir);
372
373	my $archive = $archivedir . $installer::globals::separator . $packagename . $format;
374
375	if ( $archive =~ /zip$/ )
376	{
377		$from = cwd();
378		$return_to_start = 1;
379		chdir($tempdir);
380		if ( $^O =~ /os2/i )
381		{
382			my $zip = Cwd::realpath($archive);
383			$systemcall = "$installer::globals::zippath -qr $zip .";
384		}
385	 	else
386		{
387			$systemcall = "$installer::globals::zippath -qr $archive .";
388		}
389
390		# Using Archive::Zip fails because of very long path names below "share/uno_packages/cache"
391		# my $packzip = Archive::Zip->new();
392		# $packzip->addTree(".");	# after changing into $tempdir
393		# $packzip->writeToFileNamed($archive);
394		# $makesystemcall = 0;
395	}
396 	elsif ( $archive =~ /dmg$/ )
397	{
398		my $folder = (( -l "$tempdir/$packagename/Applications" ) or ( -l "$tempdir/$packagename/opt" )) ? $packagename : "\.";
399
400		if ( $allvariables->{'PACK_INSTALLED'} ) {
401		    $folder = $packagename;
402		}
403
404		# my $volume_name = $allvariables->{'PRODUCTNAME'} . ' ' . $allvariables->{'PRODUCTVERSION'}; # Adding PRODUCTVERSION makes this difficult to maintain!
405		my $volume_name = $allvariables->{'PRODUCTNAME'};
406		my $volume_name_classic = $allvariables->{'PRODUCTNAME'} . ' ' . $allvariables->{'PRODUCTVERSION'};
407		my $volume_name_classic_app = $volume_name;  # "app" should not contain version number
408		# $volume_name = $volume_name . ' ' . $allvariables->{'PRODUCTEXTENSION'} if $allvariables->{'PRODUCTEXTENSION'}; # Adding PRODUCTEXTENSION makes this difficult to maintain!
409		$volume_name_classic = $volume_name_classic . ' ' . $allvariables->{'PRODUCTEXTENSION'} if $allvariables->{'PRODUCTEXTENSION'};
410		$volume_name_classic_app = $volume_name_classic_app . ' ' . $allvariables->{'PRODUCTEXTENSION'} if $allvariables->{'PRODUCTEXTENSION'};
411		if ( $allvariables->{'DMG_VOLUMEEXTENSION'} ) {
412		    $volume_name = $volume_name . ' ' . $allvariables->{'DMG_VOLUMEEXTENSION'};
413		    $volume_name_classic = $volume_name_classic . ' ' . $allvariables->{'DMG_VOLUMEEXTENSION'};
414		    $volume_name_classic_app = $volume_name_classic_app . ' ' . $allvariables->{'DMG_VOLUMEEXTENSION'};
415		}
416
417		my $sla = 'sla.r';
418		my $ref = "";
419
420		if ( ! $allvariables->{'HIDELICENSEDIALOG'} )
421		{
422			installer::scriptitems::get_sourcepath_from_filename_and_includepath( \$sla, $includepatharrayref, 0);
423		}
424
425		my $localtempdir = $tempdir;
426
427		if (( $installer::globals::languagepack ) || ( $installer::globals::patch ))
428		{
429			$localtempdir = "$tempdir/$packagename";
430			if ( $installer::globals::languagepack )
431			{
432				$volume_name = "$volume_name Language Pack";
433				$volume_name_classic = "$volume_name_classic Language Pack";
434				$volume_name_classic_app = "$volume_name_classic_app Language Pack";
435			}
436			if ( $installer::globals::patch )
437			{
438				$volume_name = "$volume_name Patch";
439				$volume_name_classic = "$volume_name_classic Patch";
440				$volume_name_classic_app = "$volume_name_classic_app Patch";
441			}
442
443			# Create tar ball named tarball.tar.bz2
444			# my $appfolder = $localtempdir . "/" . $volume_name . "\.app";
445			my $appfolder = $localtempdir . "/" . $volume_name_classic_app . "\.app";
446			my $contentsfolder = $appfolder . "/Contents";
447			my $tarballname = "tarball.tar.bz2";
448
449			my $localfrom = cwd();
450			chdir $appfolder;
451
452			$systemcall = "tar -cjf $tarballname Contents/";
453
454			$installer::logger::Info->printf("... %s ...\n", $systemcall);
455			my $localreturnvalue = system($systemcall);
456			$infoline = "Systemcall: $systemcall\n";
457			$installer::logger::Lang->print($infoline);
458
459			if ($localreturnvalue)
460			{
461				$infoline = "ERROR: Could not execute \"$systemcall\"!\n";
462				$installer::logger::Lang->print($infoline);
463			}
464			else
465			{
466				$infoline = "Success: Executed \"$systemcall\" successfully!\n";
467				$installer::logger::Lang->print($infoline);
468			}
469
470			my $sourcefile = $appfolder . "/" . $tarballname;
471			my $destfile = $contentsfolder . "/" . $tarballname;
472
473			installer::systemactions::remove_complete_directory($contentsfolder);
474			installer::systemactions::create_directory($contentsfolder);
475
476			installer::systemactions::copy_one_file($sourcefile, $destfile);
477			unlink($sourcefile);
478
479			# Copy two files into installation set next to the tar ball
480			# 1. "osx_install.applescript"
481			# 2 "OpenOffice.org Languagepack"
482
483			my $scriptrealfilename = "osx_install.applescript";
484			my $scriptfilename = "";
485			if ( $installer::globals::languagepack ) { $scriptfilename = "osx_install_languagepack.applescript"; }
486			if ( $installer::globals::patch ) { $scriptfilename = "osx_install_patch.applescript"; }
487			my $scripthelpersolverfilename = "mac_install.script";
488			# my $scripthelperrealfilename = $volume_name;
489			my $scripthelperrealfilename = $volume_name_classic_app;
490			my $translationfilename = $installer::globals::macinstallfilename;
491
492			# Finding both files in solver
493
494			my $scriptref = installer::scriptitems::get_sourcepath_from_filename_and_includepath( \$scriptfilename, $includepatharrayref, 0);
495			if ($$scriptref eq "") { installer::exiter::exit_program("ERROR: Could not find Apple script $scriptfilename!", "create_package"); }
496			my $scripthelperref = installer::scriptitems::get_sourcepath_from_filename_and_includepath( \$scripthelpersolverfilename, $includepatharrayref, 0);
497			if ($$scripthelperref eq "") { installer::exiter::exit_program("ERROR: Could not find Apple script $scripthelpersolverfilename!", "create_package"); }
498			my $translationfileref = installer::scriptitems::get_sourcepath_from_filename_and_includepath( \$translationfilename, $includepatharrayref, 0);
499			if ($$translationfileref eq "") { installer::exiter::exit_program("ERROR: Could not find Apple script translation file $translationfilename!", "create_package"); }
500
501			$scriptfilename = $contentsfolder . "/" . $scriptrealfilename;
502			$scripthelperrealfilename = $contentsfolder . "/" . $scripthelperrealfilename;
503
504			installer::systemactions::copy_one_file($$scriptref, $scriptfilename);
505			installer::systemactions::copy_one_file($$scripthelperref, $scripthelperrealfilename);
506
507			# Replacing variables in script $scriptfilename
508			# Localizing script $scriptfilename
509			my $scriptfilecontent = installer::files::read_file($scriptfilename);
510			my $translationfilecontent = installer::files::read_file($$translationfileref);
511			localize_scriptfile($scriptfilecontent, $translationfilecontent, $languagestringref);
512			# replace_variables_in_scriptfile($scriptfilecontent, $volume_name, $allvariables);
513			replace_variables_in_scriptfile($scriptfilecontent, $volume_name_classic, $volume_name_classic_app, $allvariables);
514			installer::files::save_file($scriptfilename, $scriptfilecontent);
515
516			$systemcall = "chmod 775 " . "\"" . $scriptfilename . "\"";
517			system($systemcall);
518			$systemcall = "chmod 775 " . "\"" . $scripthelperrealfilename . "\"";
519			system($systemcall);
520
521			# Copy also Info.plist and icon file
522			# Finding both files in solver
523			my $iconfile = "ooo3_installer.icns";
524			my $iconfileref = installer::scriptitems::get_sourcepath_from_filename_and_includepath( \$iconfile, $includepatharrayref, 0);
525			if ($$iconfileref eq "") { installer::exiter::exit_program("ERROR: Could not find Apple script icon file $iconfile!", "create_package"); }
526			my $subdir = $contentsfolder . "/" . "Resources";
527			if ( ! -d $subdir ) { installer::systemactions::create_directory($subdir); }
528			$destfile = $subdir . "/" . $iconfile;
529			installer::systemactions::copy_one_file($$iconfileref, $destfile);
530
531			my $infoplistfile = "Info.plist.langpack";
532			my $installname = "Info.plist";
533			my $infoplistfileref = installer::scriptitems::get_sourcepath_from_filename_and_includepath( \$infoplistfile, $includepatharrayref, 0);
534			if ($$infoplistfileref eq "") { installer::exiter::exit_program("ERROR: Could not find Apple script Info.plist: $infoplistfile!", "create_package"); }
535			$destfile = $contentsfolder . "/" . $installname;
536			installer::systemactions::copy_one_file($$infoplistfileref, $destfile);
537
538			# Replacing variables in Info.plist
539			$scriptfilecontent = installer::files::read_file($destfile);
540			# replace_one_variable_in_shellscript($scriptfilecontent, $volume_name, "FULLPRODUCTNAME" );
541			replace_one_variable_in_shellscript($scriptfilecontent, $volume_name_classic_app, "FULLAPPPRODUCTNAME" ); # OpenOffice.org Language Pack
542			installer::files::save_file($destfile, $scriptfilecontent);
543
544			chdir $localfrom;
545		}
546
547		$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 && ";
548        if (( $ref ne "" ) && ( $$ref ne "" )) {
549			$systemcall .= "hdiutil unflatten $archive && Rez -a $$ref -o $archive && hdiutil flatten $archive &&";
550		}
551		$systemcall .= "rm -f $installdir/tmp.dmg";
552	}
553	else
554	{
555		# getting the path of the getuid.so (only required for Solaris and Linux)
556		my $getuidlibrary = "";
557		my $ldpreloadstring = "";
558		if (( $installer::globals::issolarisbuild ) || ( $installer::globals::islinuxbuild ))
559		{
560			$getuidlibrary = installer::download::get_path_for_library($includepatharrayref);
561			if ( $getuidlibrary ne "" ) { $ldpreloadstring = "LD_PRELOAD=" . $getuidlibrary; }
562		}
563
564		$systemcall = "cd $tempdir; $ldpreloadstring tar -cf - . | gzip > $archive";
565	}
566
567	if ( $makesystemcall )
568	{
569		$installer::logger::Info->printf("... %s ...\n", $systemcall);
570		my $returnvalue = system($systemcall);
571		my $infoline = "Systemcall: $systemcall\n";
572		$installer::logger::Lang->print($infoline);
573
574		if ($returnvalue)
575		{
576			$infoline = "ERROR: Could not execute \"$systemcall\"!\n";
577			$installer::logger::Lang->print($infoline);
578		}
579		else
580		{
581			$infoline = "Success: Executed \"$systemcall\" successfully!\n";
582			$installer::logger::Lang->print($infoline);
583		}
584	}
585
586	if ( $return_to_start ) { chdir($from); }
587
588	$installer::logger::Info->printf("... removing %s ...\n", $tempdir);
589	installer::systemactions::remove_complete_directory($tempdir);
590}
591
592####################################################
593# Main method for creating the simple package
594# installation sets
595####################################################
596
597sub create_simple_package
598{
599	my ( $filesref, $dirsref, $scpactionsref, $linksref, $unixlinksref, $loggingdir, $languagestringref, $shipinstalldir, $allsettingsarrayref, $allvariables, $includepatharrayref ) = @_;
600
601	# Creating directories
602
603	my $current_install_number = "";
604	my $infoline = "";
605
606	$installer::logger::Info->print( "... creating installation directory ...\n" );
607	installer::logger::include_header_into_logfile("Creating installation directory");
608
609	$installer::globals::csp_installdir = installer::worker::create_installation_directory($shipinstalldir, $languagestringref, \$current_install_number);
610	$installer::globals::csp_installlogdir = installer::systemactions::create_directory_next_to_directory($installer::globals::csp_installdir, "log");
611
612	my $installdir = $installer::globals::csp_installdir;
613	my $installlogdir = $installer::globals::csp_installlogdir;
614
615	# Setting package name (similar to the download name)
616	my $packagename = "";
617
618	if ( $installer::globals::packageformat eq "archive"  ||
619		$installer::globals::packageformat eq "dmg" )
620	{
621		$installer::globals::csp_languagestring = $$languagestringref;
622
623		my $locallanguage = $installer::globals::csp_languagestring;
624
625		if ( $allvariables->{'AOODOWNLOADNAME'} )
626		{
627			$packagename = installer::download::set_download_filename(\$locallanguage, $allvariables);
628		}
629		else
630		{
631			$downloadname = installer::ziplist::getinfofromziplist($allsettingsarrayref, "downloadname");
632			if ( $installer::globals::languagepack ) { $downloadname = installer::ziplist::getinfofromziplist($allsettingsarrayref, "langpackdownloadname"); }
633			if ( $installer::globals::patch ) { $downloadname = installer::ziplist::getinfofromziplist($allsettingsarrayref, "patchdownloadname"); }
634			$packagename = installer::download::resolve_variables_in_downloadname($allvariables, $$downloadname, \$locallanguage);
635		}
636	}
637
638    # Work around Windows problems with long pathnames (see issue 50885) by
639    # putting the to-be-archived installation tree into the temp directory
640    # instead of the module output tree (unless LOCALINSTALLDIR dictates
641    # otherwise, anyway); can be removed once issue 50885 is fixed:
642    my $tempinstalldir = $installdir;
643    if ( $installer::globals::iswindowsbuild &&
644         $installer::globals::packageformat eq "archive" &&
645         !$installer::globals::localinstalldirset )
646    {
647        $tempinstalldir = File::Temp::tempdir;
648    }
649
650	# Creating subfolder in installdir, which shall become the root of package or zip file
651	my $subfolderdir = "";
652	if ( $packagename ne "" ) { $subfolderdir = $tempinstalldir . $installer::globals::separator . $packagename; }
653	else { $subfolderdir = $tempinstalldir; }
654
655	if ( ! -d $subfolderdir ) { installer::systemactions::create_directory($subfolderdir); }
656
657	# Create directories, copy files and ScpActions
658
659	$installer::logger::Info->print("... creating directories ...\n");
660	installer::logger::include_header_into_logfile("Creating directories:");
661
662	for ( my $i = 0; $i <= $#{$dirsref}; $i++ )
663	{
664		my $onedir = ${$dirsref}[$i];
665
666		if ( $onedir->{'HostName'} )
667		{
668			my $destdir = $subfolderdir . $installer::globals::separator . $onedir->{'HostName'};
669
670			if ( ! -d $destdir )
671			{
672				if ( $^O =~ /cygwin/i || $^O =~ /os2/i ) # Cygwin performance check
673				{
674                    $installer::logger::Lang->printf("Try to create directory %s\n", $destdir);
675					# Directories in $dirsref are sorted and all parents were added -> "mkdir" works without parent creation!
676					if ( ! ( -d $destdir )) { mkdir($destdir, 0775); }
677				}
678				else
679				{
680					installer::systemactions::create_directory_structure($destdir);
681				}
682			}
683		}
684	}
685
686	# stripping files ?!
687	if (( $installer::globals::strip ) && ( ! $installer::globals::iswindowsbuild ) && ( ! $installer::globals::isos2 )) { installer::strip::strip_libraries($filesref, $languagestringref); }
688
689	# copy Files
690	$installer::logger::Info->print("... copying files ...\n");
691	installer::logger::include_header_into_logfile("Copying files:");
692
693	for ( my $i = 0; $i <= $#{$filesref}; $i++ )
694	{
695		my $onefile = ${$filesref}[$i];
696
697		if (( $onefile->{'Styles'} ) && ( $onefile->{'Styles'} =~ /\bBINARYTABLE_ONLY\b/ )) { next; }
698		if (( $installer::globals::patch ) && ( $onefile->{'Styles'} ) && ( ! ( $onefile->{'Styles'} =~ /\bPATCH\b/ ))) { next; }
699		if (( $installer::globals::patch ) && ( $installer::globals::packageformat eq "dmg" )) { push(@installer::globals::patchfilecollector, "$onefile->{'destination'}\n"); }
700
701		my $source = $onefile->{'sourcepath'};
702		my $destination = $onefile->{'destination'};
703		$destination = $subfolderdir . $installer::globals::separator . $destination;
704
705		# Replacing $$ by $ is necessary to install files with $ in its name (back-masquerading)
706		# Otherwise, the following shell command does not work and the file list is not correct
707		$source =~ s/\$\$/\$/;
708		$destination =~ s/\$\$/\$/;
709
710		if ( $^O =~ /cygwin/i || $^O =~ /os2/i )	# Cygwin performance, do not use copy_one_file. "chmod -R" at the end
711		{
712			my $copyreturn = copy($source, $destination);
713
714			if ($copyreturn)
715			{
716                $installer::logger::Lang->printf("Copy: $source to %s\n", $destination);
717				$returnvalue = 1;
718			}
719			else
720			{
721                $installer::logger::Lang->printf("ERROR: Could not copy %s to %s\n", $source, $destination);
722				$returnvalue = 0;
723			}
724		}
725		else
726		{
727			installer::systemactions::copy_one_file($source, $destination);
728
729			if ( ! $installer::globals::iswindowsbuild )
730			{
731				# see issue 102274
732				my $unixrights = "";
733				if ( $onefile->{'UnixRights'} )
734				{
735					$unixrights = $onefile->{'UnixRights'};
736
737					my $localcall = "$installer::globals::wrapcmd chmod $unixrights \'$destination\' \>\/dev\/null 2\>\&1";
738					system($localcall);
739				}
740			}
741		}
742	}
743
744	# creating Links
745
746	$installer::logger::Info->print("... creating links ...\n");
747	installer::logger::include_header_into_logfile("Creating links:");
748
749	for ( my $i = 0; $i <= $#{$linksref}; $i++ )
750	{
751		my $onelink = ${$linksref}[$i];
752
753		if (( $installer::globals::patch ) && ( $onelink->{'Styles'} ) && ( ! ( $onelink->{'Styles'} =~ /\bPATCH\b/ ))) { next; }
754
755		my $destination = $onelink->{'destination'};
756		$destination = $subfolderdir . $installer::globals::separator . $destination;
757		my $destinationfile = $onelink->{'destinationfile'};
758
759		my $localcall = "ln -sf \'$destinationfile\' \'$destination\' \>\/dev\/null 2\>\&1";
760		system($localcall);
761
762        $installer::logger::Lang->printf("Creating link: \"ln -sf %s %s\"\n",
763            $destinationfile,
764            $destination);
765	}
766
767	for ( my $i = 0; $i <= $#{$unixlinksref}; $i++ )
768	{
769		my $onelink = ${$unixlinksref}[$i];
770
771		if (( $installer::globals::patch ) && ( $onelink->{'Styles'} ) && ( ! ( $onelink->{'Styles'} =~ /\bPATCH\b/ ))) { next; }
772
773		my $target = $onelink->{'Target'};
774		my $destination = $subfolderdir . $installer::globals::separator . $onelink->{'destination'};
775
776		my $localcall = "ln -sf \'$target\' \'$destination\' \>\/dev\/null 2\>\&1";
777		system($localcall);
778
779        $installer::logger::Lang->printf("Creating Unix link: \"ln -sf %s %s\"\n",
780            $target,
781            $destination);
782	}
783
784	# Setting privileges for cygwin globally
785
786	if ( $^O =~ /cygwin/i )
787	{
788		$installer::logger::Lang->print( "... changing privileges in $subfolderdir ...\n" );
789		installer::logger::include_header_into_logfile("Changing privileges in $subfolderdir:");
790
791		my $localcall = "chmod -R 755 " . "\"" . $subfolderdir . "\"";
792		system($localcall);
793	}
794
795	$installer::logger::Lang->print( "... removing superfluous directories ...\n" );
796	installer::logger::include_header_into_logfile("Removing superfluous directories:");
797
798	my ( $extensionfolder, $preregdir ) = get_extensions_dir($subfolderdir);
799	installer::systemactions::remove_empty_dirs_in_folder($extensionfolder);
800
801	# Registering the extensions
802
803	$installer::logger::Lang->print( "... registering extensions ...\n" );
804	installer::logger::include_header_into_logfile("Registering extensions:");
805	register_extensions($subfolderdir, $languagestringref, $preregdir);
806
807	if ( $installer::globals::compiler =~ /^unxmacx/ )
808	{
809		installer::worker::put_scpactions_into_installset("$installdir/$packagename");
810	}
811
812	# Creating archive file
813    if ( $installer::globals::packageformat eq "archive" )
814    {
815        create_package($tempinstalldir, $installdir, $packagename, $allvariables, $includepatharrayref, $languagestringref, $installer::globals::archiveformat);
816    }
817    elsif ( $installer::globals::packageformat eq "dmg" )
818    {
819        create_package($installdir, $installdir, $packagename, $allvariables, $includepatharrayref, $languagestringref, ".dmg");
820    }
821
822	# Analyzing the log file
823
824	installer::worker::clean_output_tree();	# removing directories created in the output tree
825	installer::worker::analyze_and_save_logfile($loggingdir, $installdir, $installlogdir, $allsettingsarrayref, $languagestringref, $current_install_number);
826}
827
8281;
829