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 = $programdir . $installer::globals::separator . $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	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	$installer::logger::Lang->print($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" )
337    {
338        $scriptname = "org.openoffice.script";
339    }
340
341	replace_one_variable_in_shellscript($scriptfile, $scriptname, "SEARCHSCRIPTNAME" );
342}
343
344#############################################
345# Creating the "simple" package.
346# "zip" for Windows
347# "tar.gz" for all other platforms
348# additionally "dmg" on Mac OS X
349#############################################
350
351sub create_package
352{
353	my ( $installdir, $archivedir, $packagename, $allvariables, $includepatharrayref, $languagestringref, $format ) = @_;
354
355    $installer::logger::Info->printf("... creating %s file ...\n", $installer::globals::packageformat);
356    installer::logger::include_header_into_logfile("Creating $installer::globals::packageformat file:");
357
358	# moving dir into temporary directory
359	my $pid = $$; # process id
360	my $tempdir = $installdir . "_temp" . "." . $pid;
361	my $systemcall = "";
362	my $from = "";
363	my $makesystemcall = 1;
364	my $return_to_start = 0;
365	installer::systemactions::rename_directory($installdir, $tempdir);
366
367	# creating new directory with original name
368	installer::systemactions::create_directory($archivedir);
369
370	my $archive = $archivedir . $installer::globals::separator . $packagename . $format;
371
372	if ( $archive =~ /zip$/ )
373	{
374		$from = cwd();
375		$return_to_start = 1;
376		chdir($tempdir);
377		if ( $^O =~ /os2/i )
378		{
379			my $zip = Cwd::realpath($archive);
380			$systemcall = "$installer::globals::zippath -qr $zip .";
381		}
382	 	else
383		{
384			$systemcall = "$installer::globals::zippath -qr $archive .";
385		}
386
387		# Using Archive::Zip fails because of very long path names below "share/uno_packages/cache"
388		# my $packzip = Archive::Zip->new();
389		# $packzip->addTree(".");	# after changing into $tempdir
390		# $packzip->writeToFileNamed($archive);
391		# $makesystemcall = 0;
392	}
393 	elsif ( $archive =~ /dmg$/ )
394	{
395		my $folder = (( -l "$tempdir/$packagename/Applications" ) or ( -l "$tempdir/$packagename/opt" )) ? $packagename : "\.";
396
397		if ( $allvariables->{'PACK_INSTALLED'} ) {
398		    $folder = $packagename;
399		}
400
401		# my $volume_name = $allvariables->{'PRODUCTNAME'} . ' ' . $allvariables->{'PRODUCTVERSION'}; # Adding PRODUCTVERSION makes this difficult to maintain!
402		my $volume_name = $allvariables->{'PRODUCTNAME'};
403		my $volume_name_classic = $allvariables->{'PRODUCTNAME'} . ' ' . $allvariables->{'PRODUCTVERSION'};
404		my $volume_name_classic_app = $volume_name;  # "app" should not contain version number
405		# $volume_name = $volume_name . ' ' . $allvariables->{'PRODUCTEXTENSION'} if $allvariables->{'PRODUCTEXTENSION'}; # Adding PRODUCTEXTENSION makes this difficult to maintain!
406		$volume_name_classic = $volume_name_classic . ' ' . $allvariables->{'PRODUCTEXTENSION'} if $allvariables->{'PRODUCTEXTENSION'};
407		$volume_name_classic_app = $volume_name_classic_app . ' ' . $allvariables->{'PRODUCTEXTENSION'} if $allvariables->{'PRODUCTEXTENSION'};
408		if ( $allvariables->{'DMG_VOLUMEEXTENSION'} ) {
409		    $volume_name = $volume_name . ' ' . $allvariables->{'DMG_VOLUMEEXTENSION'};
410		    $volume_name_classic = $volume_name_classic . ' ' . $allvariables->{'DMG_VOLUMEEXTENSION'};
411		    $volume_name_classic_app = $volume_name_classic_app . ' ' . $allvariables->{'DMG_VOLUMEEXTENSION'};
412		}
413
414		my $sla = 'sla.r';
415		my $ref = "";
416
417		if ( ! $allvariables->{'HIDELICENSEDIALOG'} )
418		{
419			installer::scriptitems::get_sourcepath_from_filename_and_includepath( \$sla, $includepatharrayref, 0);
420		}
421
422		my $localtempdir = $tempdir;
423
424		if (( $installer::globals::languagepack ) || ( $installer::globals::patch ))
425		{
426			$localtempdir = "$tempdir/$packagename";
427			if ( $installer::globals::languagepack )
428			{
429				$volume_name = "$volume_name Language Pack";
430				$volume_name_classic = "$volume_name_classic Language Pack";
431				$volume_name_classic_app = "$volume_name_classic_app Language Pack";
432			}
433			if ( $installer::globals::patch )
434			{
435				$volume_name = "$volume_name Patch";
436				$volume_name_classic = "$volume_name_classic Patch";
437				$volume_name_classic_app = "$volume_name_classic_app Patch";
438			}
439
440			# Create tar ball named tarball.tar.bz2
441			# my $appfolder = $localtempdir . "/" . $volume_name . "\.app";
442			my $appfolder = $localtempdir . "/" . $volume_name_classic_app . "\.app";
443			my $contentsfolder = $appfolder . "/Contents";
444			my $tarballname = "tarball.tar.bz2";
445
446			my $localfrom = cwd();
447			chdir $appfolder;
448
449			$systemcall = "tar -cjf $tarballname Contents/";
450
451			$installer::logger::Info->printf("... %s ...\n", $systemcall);
452			my $localreturnvalue = system($systemcall);
453			$infoline = "Systemcall: $systemcall\n";
454			$installer::logger::Lang->print($infoline);
455
456			if ($localreturnvalue)
457			{
458				$infoline = "ERROR: Could not execute \"$systemcall\"!\n";
459				$installer::logger::Lang->print($infoline);
460			}
461			else
462			{
463				$infoline = "Success: Executed \"$systemcall\" successfully!\n";
464				$installer::logger::Lang->print($infoline);
465			}
466
467			my $sourcefile = $appfolder . "/" . $tarballname;
468			my $destfile = $contentsfolder . "/" . $tarballname;
469
470			installer::systemactions::remove_complete_directory($contentsfolder);
471			installer::systemactions::create_directory($contentsfolder);
472
473			installer::systemactions::copy_one_file($sourcefile, $destfile);
474			unlink($sourcefile);
475
476			# Copy two files into installation set next to the tar ball
477			# 1. "osx_install.applescript"
478			# 2 "OpenOffice.org Languagepack"
479
480			my $scriptrealfilename = "osx_install.applescript";
481			my $scriptfilename = "";
482			if ( $installer::globals::languagepack ) { $scriptfilename = "osx_install_languagepack.applescript"; }
483			if ( $installer::globals::patch ) { $scriptfilename = "osx_install_patch.applescript"; }
484			my $scripthelpersolverfilename = "mac_install.script";
485			# my $scripthelperrealfilename = $volume_name;
486			my $scripthelperrealfilename = $volume_name_classic_app;
487			my $translationfilename = $installer::globals::macinstallfilename;
488
489			# Finding both files in solver
490
491			my $scriptref = installer::scriptitems::get_sourcepath_from_filename_and_includepath( \$scriptfilename, $includepatharrayref, 0);
492			if ($$scriptref eq "") { installer::exiter::exit_program("ERROR: Could not find Apple script $scriptfilename!", "create_package"); }
493			my $scripthelperref = installer::scriptitems::get_sourcepath_from_filename_and_includepath( \$scripthelpersolverfilename, $includepatharrayref, 0);
494			if ($$scripthelperref eq "") { installer::exiter::exit_program("ERROR: Could not find Apple script $scripthelpersolverfilename!", "create_package"); }
495			my $translationfileref = installer::scriptitems::get_sourcepath_from_filename_and_includepath( \$translationfilename, $includepatharrayref, 0);
496			if ($$translationfileref eq "") { installer::exiter::exit_program("ERROR: Could not find Apple script translation file $translationfilename!", "create_package"); }
497
498			$scriptfilename = $contentsfolder . "/" . $scriptrealfilename;
499			$scripthelperrealfilename = $contentsfolder . "/" . $scripthelperrealfilename;
500
501			installer::systemactions::copy_one_file($$scriptref, $scriptfilename);
502			installer::systemactions::copy_one_file($$scripthelperref, $scripthelperrealfilename);
503
504			# Replacing variables in script $scriptfilename
505			# Localizing script $scriptfilename
506			my $scriptfilecontent = installer::files::read_file($scriptfilename);
507			my $translationfilecontent = installer::files::read_file($$translationfileref);
508			localize_scriptfile($scriptfilecontent, $translationfilecontent, $languagestringref);
509			# replace_variables_in_scriptfile($scriptfilecontent, $volume_name, $allvariables);
510			replace_variables_in_scriptfile($scriptfilecontent, $volume_name_classic, $volume_name_classic_app, $allvariables);
511			installer::files::save_file($scriptfilename, $scriptfilecontent);
512
513			$systemcall = "chmod 775 " . "\"" . $scriptfilename . "\"";
514			system($systemcall);
515			$systemcall = "chmod 775 " . "\"" . $scripthelperrealfilename . "\"";
516			system($systemcall);
517
518			# Copy also Info.plist and icon file
519			# Finding both files in solver
520			my $iconfile = "ooo3_installer.icns";
521			my $iconfileref = installer::scriptitems::get_sourcepath_from_filename_and_includepath( \$iconfile, $includepatharrayref, 0);
522			if ($$iconfileref eq "") { installer::exiter::exit_program("ERROR: Could not find Apple script icon file $iconfile!", "create_package"); }
523			my $subdir = $contentsfolder . "/" . "Resources";
524			if ( ! -d $subdir ) { installer::systemactions::create_directory($subdir); }
525			$destfile = $subdir . "/" . $iconfile;
526			installer::systemactions::copy_one_file($$iconfileref, $destfile);
527
528			my $infoplistfile = "Info.plist.langpack";
529			my $installname = "Info.plist";
530			my $infoplistfileref = installer::scriptitems::get_sourcepath_from_filename_and_includepath( \$infoplistfile, $includepatharrayref, 0);
531			if ($$infoplistfileref eq "") { installer::exiter::exit_program("ERROR: Could not find Apple script Info.plist: $infoplistfile!", "create_package"); }
532			$destfile = $contentsfolder . "/" . $installname;
533			installer::systemactions::copy_one_file($$infoplistfileref, $destfile);
534
535			# Replacing variables in Info.plist
536			$scriptfilecontent = installer::files::read_file($destfile);
537			# replace_one_variable_in_shellscript($scriptfilecontent, $volume_name, "FULLPRODUCTNAME" );
538			replace_one_variable_in_shellscript($scriptfilecontent, $volume_name_classic_app, "FULLAPPPRODUCTNAME" ); # OpenOffice.org Language Pack
539			installer::files::save_file($destfile, $scriptfilecontent);
540
541			chdir $localfrom;
542		}
543
544		$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 && ";
545        if (( $ref ne "" ) && ( $$ref ne "" )) {
546			$systemcall .= "hdiutil unflatten $archive && Rez -a $$ref -o $archive && hdiutil flatten $archive &&";
547		}
548		$systemcall .= "rm -f $installdir/tmp.dmg";
549	}
550	else
551	{
552		# getting the path of the getuid.so (Solaris) or fakeroot (Linux)
553		my $getuidlibrary = "";
554		my $ldpreloadstring = "";
555		if ( $installer::globals::issolarisbuild )
556		{
557			$getuidlibrary = installer::download::get_path_for_library($includepatharrayref);
558			if ( $getuidlibrary ne "" ) { $ldpreloadstring = "LD_PRELOAD=" . $getuidlibrary; }
559		}
560		elsif ( $installer::globals::islinuxbuild )
561		{
562			$ldpreloadstring = $ENV{'FAKEROOT'};
563		}
564
565		$systemcall = "cd $tempdir; $ldpreloadstring tar -cf - . | gzip > $archive";
566	}
567
568	if ( $makesystemcall )
569	{
570		$installer::logger::Info->printf("... %s ...\n", $systemcall);
571		my $returnvalue = system($systemcall);
572		my $infoline = "Systemcall: $systemcall\n";
573		$installer::logger::Lang->print($infoline);
574
575		if ($returnvalue)
576		{
577			$infoline = "ERROR: Could not execute \"$systemcall\"!\n";
578			$installer::logger::Lang->print($infoline);
579		}
580		else
581		{
582			$infoline = "Success: Executed \"$systemcall\" successfully!\n";
583			$installer::logger::Lang->print($infoline);
584		}
585	}
586
587	if ( $return_to_start ) { chdir($from); }
588
589	$installer::logger::Info->printf("... removing %s ...\n", $tempdir);
590	installer::systemactions::remove_complete_directory($tempdir);
591}
592
593####################################################
594# Main method for creating the simple package
595# installation sets
596####################################################
597
598sub create_simple_package
599{
600	my ( $filesref, $dirsref, $scpactionsref, $linksref, $unixlinksref, $loggingdir, $languagestringref, $shipinstalldir, $allsettingsarrayref, $allvariables, $includepatharrayref ) = @_;
601
602	# Creating directories
603
604	my $current_install_number = "";
605	my $infoline = "";
606
607	$installer::logger::Info->print( "... creating installation directory ...\n" );
608	installer::logger::include_header_into_logfile("Creating installation directory");
609
610	$installer::globals::csp_installdir = installer::worker::create_installation_directory($shipinstalldir, $languagestringref, \$current_install_number);
611	$installer::globals::csp_installlogdir = installer::systemactions::create_directory_next_to_directory($installer::globals::csp_installdir, "log");
612
613	my $installdir = $installer::globals::csp_installdir;
614	my $installlogdir = $installer::globals::csp_installlogdir;
615
616	# Setting package name (similar to the download name)
617	my $packagename = "";
618
619	if ( $installer::globals::packageformat eq "archive"  ||
620		$installer::globals::packageformat eq "dmg" )
621	{
622		$installer::globals::csp_languagestring = $$languagestringref;
623
624		my $locallanguage = $installer::globals::csp_languagestring;
625
626		if ( $allvariables->{'AOODOWNLOADNAME'} )
627		{
628			$packagename = installer::download::set_download_filename(\$locallanguage, $allvariables);
629		}
630		else
631		{
632			$downloadname = installer::ziplist::getinfofromziplist($allsettingsarrayref, "downloadname");
633			if ( $installer::globals::languagepack ) { $downloadname = installer::ziplist::getinfofromziplist($allsettingsarrayref, "langpackdownloadname"); }
634			if ( $installer::globals::patch ) { $downloadname = installer::ziplist::getinfofromziplist($allsettingsarrayref, "patchdownloadname"); }
635			$packagename = installer::download::resolve_variables_in_downloadname($allvariables, $$downloadname, \$locallanguage);
636		}
637	}
638
639    # Work around Windows problems with long pathnames (see issue 50885) by
640    # putting the to-be-archived installation tree into the temp directory
641    # instead of the module output tree (unless LOCALINSTALLDIR dictates
642    # otherwise, anyway); can be removed once issue 50885 is fixed:
643    my $tempinstalldir = $installdir;
644    if ( $installer::globals::iswindowsbuild &&
645         $installer::globals::packageformat eq "archive" &&
646         !$installer::globals::localinstalldirset )
647    {
648        $tempinstalldir = File::Temp::tempdir;
649    }
650
651	# Creating subfolder in installdir, which shall become the root of package or zip file
652	my $subfolderdir = "";
653	if ( $packagename ne "" ) { $subfolderdir = $tempinstalldir . $installer::globals::separator . $packagename; }
654	else { $subfolderdir = $tempinstalldir; }
655
656	if ( ! -d $subfolderdir ) { installer::systemactions::create_directory($subfolderdir); }
657
658	# Create directories, copy files and ScpActions
659
660	$installer::logger::Info->print("... creating directories ...\n");
661	installer::logger::include_header_into_logfile("Creating directories:");
662
663	for ( my $i = 0; $i <= $#{$dirsref}; $i++ )
664	{
665		my $onedir = ${$dirsref}[$i];
666
667		if ( $onedir->{'HostName'} )
668		{
669			my $destdir = $subfolderdir . $installer::globals::separator . $onedir->{'HostName'};
670
671			if ( ! -d $destdir )
672			{
673				if ( $^O =~ /cygwin/i || $^O =~ /os2/i ) # Cygwin performance check
674				{
675                    $installer::logger::Lang->printf("Try to create directory %s\n", $destdir);
676					# Directories in $dirsref are sorted and all parents were added -> "mkdir" works without parent creation!
677					if ( ! ( -d $destdir )) { mkdir($destdir, 0775); }
678				}
679				else
680				{
681					installer::systemactions::create_directory_structure($destdir);
682				}
683			}
684		}
685	}
686
687	# stripping files ?!
688	if (( $installer::globals::strip ) && ( ! $installer::globals::iswindowsbuild ) && ( ! $installer::globals::isos2 )) { installer::strip::strip_libraries($filesref, $languagestringref); }
689
690	# copy Files
691	$installer::logger::Info->print("... copying files ...\n");
692	installer::logger::include_header_into_logfile("Copying files:");
693
694	for ( my $i = 0; $i <= $#{$filesref}; $i++ )
695	{
696		my $onefile = ${$filesref}[$i];
697
698		if (( $onefile->{'Styles'} ) && ( $onefile->{'Styles'} =~ /\bBINARYTABLE_ONLY\b/ )) { next; }
699		if (( $installer::globals::patch ) && ( $onefile->{'Styles'} ) && ( ! ( $onefile->{'Styles'} =~ /\bPATCH\b/ ))) { next; }
700		if (( $installer::globals::patch ) && ( $installer::globals::packageformat eq "dmg" )) { push(@installer::globals::patchfilecollector, "$onefile->{'destination'}\n"); }
701
702		my $source = $onefile->{'sourcepath'};
703		my $destination = $onefile->{'destination'};
704		$destination = $subfolderdir . $installer::globals::separator . $destination;
705
706		# Replacing $$ by $ is necessary to install files with $ in its name (back-masquerading)
707		# Otherwise, the following shell command does not work and the file list is not correct
708		$source =~ s/\$\$/\$/;
709		$destination =~ s/\$\$/\$/;
710
711		if ( $^O =~ /cygwin/i || $^O =~ /os2/i )	# Cygwin performance, do not use copy_one_file. "chmod -R" at the end
712		{
713			my $copyreturn = copy($source, $destination);
714
715			if ($copyreturn)
716			{
717                $installer::logger::Lang->printf("Copy: $source to %s\n", $destination);
718				$returnvalue = 1;
719			}
720			else
721			{
722                $installer::logger::Lang->printf("ERROR: Could not copy %s to %s\n", $source, $destination);
723				$returnvalue = 0;
724			}
725		}
726		else
727		{
728			installer::systemactions::copy_one_file($source, $destination);
729
730			if ( ! $installer::globals::iswindowsbuild )
731			{
732				# see issue 102274
733				my $unixrights = "";
734				if ( $onefile->{'UnixRights'} )
735				{
736					$unixrights = $onefile->{'UnixRights'};
737
738					my $localcall = "$installer::globals::wrapcmd chmod $unixrights \'$destination\' \>\/dev\/null 2\>\&1";
739					system($localcall);
740				}
741			}
742		}
743	}
744
745	# creating Links
746
747	$installer::logger::Info->print("... creating links ...\n");
748	installer::logger::include_header_into_logfile("Creating links:");
749
750	for ( my $i = 0; $i <= $#{$linksref}; $i++ )
751	{
752		my $onelink = ${$linksref}[$i];
753
754		if (( $installer::globals::patch ) && ( $onelink->{'Styles'} ) && ( ! ( $onelink->{'Styles'} =~ /\bPATCH\b/ ))) { next; }
755
756		my $destination = $onelink->{'destination'};
757		$destination = $subfolderdir . $installer::globals::separator . $destination;
758		my $destinationfile = $onelink->{'destinationfile'};
759
760		my $localcall = "ln -sf \'$destinationfile\' \'$destination\' \>\/dev\/null 2\>\&1";
761		system($localcall);
762
763        $installer::logger::Lang->printf("Creating link: \"ln -sf %s %s\"\n",
764            $destinationfile,
765            $destination);
766	}
767
768	for ( my $i = 0; $i <= $#{$unixlinksref}; $i++ )
769	{
770		my $onelink = ${$unixlinksref}[$i];
771
772		if (( $installer::globals::patch ) && ( $onelink->{'Styles'} ) && ( ! ( $onelink->{'Styles'} =~ /\bPATCH\b/ ))) { next; }
773
774		my $target = $onelink->{'Target'};
775		my $destination = $subfolderdir . $installer::globals::separator . $onelink->{'destination'};
776
777		my $localcall = "ln -sf \'$target\' \'$destination\' \>\/dev\/null 2\>\&1";
778		system($localcall);
779
780        $installer::logger::Lang->printf("Creating Unix link: \"ln -sf %s %s\"\n",
781            $target,
782            $destination);
783	}
784
785	# Setting privileges for cygwin globally
786
787	if ( $^O =~ /cygwin/i )
788	{
789		$installer::logger::Lang->print( "... changing privileges in $subfolderdir ...\n" );
790		installer::logger::include_header_into_logfile("Changing privileges in $subfolderdir:");
791
792		my $localcall = "chmod -R 755 " . "\"" . $subfolderdir . "\"";
793		system($localcall);
794	}
795
796	$installer::logger::Lang->print( "... removing superfluous directories ...\n" );
797	installer::logger::include_header_into_logfile("Removing superfluous directories:");
798
799	my ( $extensionfolder, $preregdir ) = get_extensions_dir($subfolderdir);
800	installer::systemactions::remove_empty_dirs_in_folder($extensionfolder);
801
802	# Registering the extensions
803
804	$installer::logger::Lang->print( "... registering extensions ...\n" );
805	installer::logger::include_header_into_logfile("Registering extensions:");
806	register_extensions($subfolderdir, $languagestringref, $preregdir);
807
808	if ( $installer::globals::compiler =~ /^unxmac/ )
809	{
810		installer::worker::put_scpactions_into_installset("$installdir/$packagename");
811	}
812
813	# Creating archive file
814    if ( $installer::globals::packageformat eq "archive" )
815    {
816        create_package($tempinstalldir, $installdir, $packagename, $allvariables, $includepatharrayref, $languagestringref, $installer::globals::archiveformat);
817    }
818    elsif ( $installer::globals::packageformat eq "dmg" )
819    {
820        create_package($installdir, $installdir, $packagename, $allvariables, $includepatharrayref, $languagestringref, ".dmg");
821    }
822
823	# Analyzing the log file
824
825	installer::worker::clean_output_tree();	# removing directories created in the output tree
826	installer::worker::analyze_and_save_logfile($loggingdir, $installdir, $installlogdir, $allsettingsarrayref, $languagestringref, $current_install_number);
827}
828
8291;
830