1#*************************************************************************
2#
3# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4#
5# Copyright 2000, 2010 Oracle and/or its affiliates.
6#
7# OpenOffice.org - a multi-platform office productivity suite
8#
9# This file is part of OpenOffice.org.
10#
11# OpenOffice.org is free software: you can redistribute it and/or modify
12# it under the terms of the GNU Lesser General Public License version 3
13# only, as published by the Free Software Foundation.
14#
15# OpenOffice.org is distributed in the hope that it will be useful,
16# but WITHOUT ANY WARRANTY; without even the implied warranty of
17# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18# GNU Lesser General Public License version 3 for more details
19# (a copy is included in the LICENSE file that accompanied this code).
20#
21# You should have received a copy of the GNU Lesser General Public License
22# version 3 along with OpenOffice.org.  If not, see
23# <http://www.openoffice.org/license.html>
24# for a copy of the LGPLv3 License.
25#
26#*************************************************************************
27package installer::xpdinstaller;
28
29use Cwd;
30use installer::converter;
31use installer::exiter;
32use installer::globals;
33use installer::languages;
34use installer::logger;
35use installer::pathanalyzer;
36use installer::remover;
37use installer::systemactions;
38
39
40#######################################################
41# Searching for the module name and description in the
42# modules collector
43#######################################################
44
45sub get_module_name_description
46{
47	my ($modulesarrayref, $onelanguage, $gid, $type) = @_;
48
49	my $found = 0;
50
51	my $newstring = "";
52
53	for ( my $i = 0; $i <= $#{$modulesarrayref}; $i++ )
54	{
55		my $onemodule = ${$modulesarrayref}[$i];
56
57		if ( $onemodule->{'gid'} eq $gid )
58		{
59			my $typestring = $type . " " . "(" . $onelanguage . ")";
60			if ( $onemodule->{$typestring} ) { $newstring = $onemodule->{$typestring}; }
61			$found = 1;
62		}
63
64		if ( $found ) { last; }
65	}
66
67	# defaulting to english
68
69	if ( ! $found )
70	{
71		my $defaultlanguage = "en-US";
72
73		for ( my $i = 0; $i <= $#{$modulesarrayref}; $i++ )
74		{
75			my $onemodule = ${$modulesarrayref}[$i];
76
77			if ( $onemodule->{'gid'} eq $gid )
78			{
79				my $typestring = $type . " " . "(" . $defaultlanguage . ")";
80				if ( $onemodule->{$typestring} ) { $newstring = $onemodule->{$typestring}; }
81				$found = 1;
82			}
83
84			if ( $found ) { last; }
85		}
86	}
87
88	return $newstring;
89}
90
91###################################################
92# Finding module, specified by the gid
93###################################################
94
95sub get_module
96{
97	my ($modulegid, $modulesarrayref) = @_;
98
99	my $found = 0;
100	my $searchmodule = "";
101
102	for ( my $i = 0; $i <= $#{$modulesarrayref}; $i++ )
103	{
104		my $onemodule = ${$modulesarrayref}[$i];
105
106		if ( $onemodule->{'gid'} eq $modulegid )
107		{
108			$searchmodule = $onemodule;
109			$found = 1;
110			last;
111		}
112
113		# if ( ! $found ) { installer::exiter::exit_program("ERROR: Could not find module belonging to gid $modulegid!", "get_module (xpdinstaller)"); }
114	}
115
116	return $searchmodule;
117}
118
119###################################################
120# Creating package start tag
121###################################################
122
123sub get_package_tag
124{
125	my ( $module, $indent, $linkpackage ) = @_;
126
127	my $modulegid = $module->{'gid'};
128	if ( $linkpackage ) { $modulegid = $modulegid . "u"; }
129	my $parentgid = "";
130	if ( $module->{'ParentID'} ) { $parentgid = $module->{'ParentID'}; }
131	if ( $parentgid eq "" ) { $parentgid = "root"; }
132	if ( $module->{'XPDParentID'} ) { $parentgid = $module->{'XPDParentID'}; } # changing parent of "Prg" and "Opt" to "root"
133
134	my $tag = $indent . "<package " . "name=" . "\"" . $modulegid . "\" " . "parent=" . "\"" . $parentgid . "\">" . "\n";
135
136	return ( $tag, $parentgid );
137}
138
139###################################################
140# Creating display start tag
141###################################################
142
143sub get_display_tag
144{
145	my ( $module, $indent ) = @_;
146
147	# Styles=(HIDDEN_ROOT)
148	my $styles = "";
149	my $type = "";
150	if ( $module->{'Styles'} ) { $styles = $module->{'Styles'}; }
151	if ( $styles =~ /\bHIDDEN_ROOT\b/ ) { $type = "hidden"; }
152	else { $type = "show"; }
153
154	# special handling for language modules. Only visible in multilingual installation set.
155	if (( $styles =~ /\bSHOW_MULTILINGUAL_ONLY\b/ ) && ( ! $installer::globals::ismultilingual )) { $type = "hidden"; }
156
157	# special handling for the root module, which has no parent
158	my $parentgid = "";
159	if ( $module->{'ParentID'} ) { $parentgid = $module->{'ParentID'}; }
160	if ( $parentgid eq "" ) { $type = "hidden"; }
161
162	my $tag = $indent . "<display " . "type=" . "\"" . $type . "\"" . ">" . "\n";
163
164	return $tag;
165}
166
167###################################################
168# Creating installunit start tag
169###################################################
170
171sub get_installunit_tag
172{
173	my ( $indent ) = @_;
174
175	my $type = $installer::globals::packageformat;
176
177	my $tag = $indent . "<installunit " . "type=" . "\"" . $type . "\"" . ">" . "\n";
178
179	return $tag;
180}
181
182###################################################
183# Creating simple start tags
184###################################################
185
186sub get_start_tag
187{
188	my ( $tag, $indent ) = @_;
189
190	my $starttag = $indent . "<" . $tag . ">" . "\n";
191	return $starttag;
192}
193
194###################################################
195# Creating end tags
196###################################################
197
198sub get_end_tag
199{
200	my ( $tag, $indent ) = @_;
201
202	my $endtag = $indent . "</" . $tag . ">" . "\n";
203	return $endtag;
204}
205
206###################################################
207# Creating simple complete tag
208###################################################
209
210sub get_tag_line
211{
212	my ( $indent, $name, $value ) = @_;
213	$value = '' unless defined $value;
214
215	my $line = $indent . "<" . $name . ">" . $value . "</" . $name . ">" . "\n";
216
217}
218
219###################################################
220# Asking module for sortkey entry
221###################################################
222
223sub get_sortkey_value
224{
225	my ( $module ) = @_;
226
227	my $value = "9999";
228
229	if ( $module->{'Sortkey'} ) { $value = $module->{'Sortkey'}; }
230
231	return $value;
232}
233
234###################################################
235# Asking module for default entry
236###################################################
237
238sub get_default_value
239{
240	my ( $module ) = @_;
241
242	my $value = "";
243
244	if ( $module->{'Default'} ) { $value = $module->{'Default'}; } # is YES or NO
245
246	if ( $value =~ /\bNO\b/i ) { $value = "false"; }
247	else { $value = "true"; }
248
249	return $value;
250}
251
252###################################################
253# Asking module for showinuserinstall entry
254# scp style: DONTSHOWINUSERINSTALL
255###################################################
256
257sub get_showinuserinstall_value
258{
259	my ( $module ) = @_;
260
261	my $value = "true";
262
263	my $styles = "";
264	if ( $module->{'Styles'} ) { $styles = $module->{'Styles'}; }
265	if ( $styles =~ /\bDONTSHOWINUSERINSTALL\b/ ) { $value = "false"; }
266
267	return $value;
268}
269
270###################################################
271# Asking module for showinuserinstall entry
272# scp style: USERINSTALLONLY
273###################################################
274
275sub get_userinstallonly_value
276{
277	my ( $module ) = @_;
278
279	my $value = "false";
280
281	my $styles = "";
282	if ( $module->{'Styles'} ) { $styles = $module->{'Styles'}; }
283	if ( $styles =~ /\bUSERINSTALLONLY\b/ ) { $value = "true"; }
284
285	return $value;
286}
287
288###################################################
289# Asking module for dontuninstall entry
290# scp style: DONTUNINSTALL
291###################################################
292
293sub get_dontuninstall_value
294{
295	my ( $module ) = @_;
296
297	my $value = "false";
298
299	my $styles = "";
300	if ( $module->{'Styles'} ) { $styles = $module->{'Styles'}; }
301	if ( $styles =~ /\bDONTUNINSTALL\b/ ) { $value = "true"; }
302
303	return $value;
304}
305
306###################################################
307# Asking module for XpdCheckSolaris entry
308# (belongs to scp module)
309###################################################
310
311sub get_checksolaris_value
312{
313	my ( $module ) = @_;
314
315	my $value = "";
316	if ( $module->{'XpdCheckSolaris'} ) { $value = $module->{'XpdCheckSolaris'}; }
317
318	return $value;
319}
320
321###################################################
322# Asking module for isupdatepackage entry
323# scp style: ISUPDATEPACKAGE
324###################################################
325
326sub get_isupdatepackage_value
327{
328	my ( $module ) = @_;
329
330	my $value = "false";
331
332	my $styles = "";
333	if ( $module->{'Styles'} ) { $styles = $module->{'Styles'}; }
334	if ( $styles =~ /\bISUPDATEPACKAGE\b/ ) { $value = "true"; }
335
336	return $value;
337}
338
339###################################################
340# Asking module for showmultilingualonly entry
341# scp style: SHOW_MULTILINGUAL_ONLY
342###################################################
343
344sub get_showmultilingualonly_value
345{
346	my ( $module ) = @_;
347
348	my $value = "false";
349
350	my $styles = "";
351	if ( $module->{'Styles'} ) { $styles = $module->{'Styles'}; }
352	if ( $styles =~ /\bSHOW_MULTILINGUAL_ONLY\b/ ) { $value = "true"; }
353
354	return $value;
355}
356
357###################################################
358# Asking module for showmultilingualonly entry
359# scp style: SHOW_MULTILINGUAL_ONLY
360###################################################
361
362sub get_applicationmodule_value
363{
364	my ( $module ) = @_;
365
366	my $value = "false";
367
368	my $styles = "";
369	if ( $module->{'Styles'} ) { $styles = $module->{'Styles'}; }
370	if ( $styles =~ /\bAPPLICATIONMODULE\b/ ) { $value = "true"; }
371
372	return $value;
373}
374
375###################################################
376# Asking module for java module entry
377# scp style: JAVAMODULE
378###################################################
379
380sub get_isjavamodule_value
381{
382	my ( $module ) = @_;
383
384	my $value = "false";
385
386	my $styles = "";
387	if ( $module->{'Styles'} ) { $styles = $module->{'Styles'}; }
388	if ( $styles =~ /\bJAVAMODULE\b/ ) { $value = "true"; }
389
390	return $value;
391}
392
393#####################################################################
394# Asking module, if installation shall use --force
395# scp style: USEFORCE  (Linux only)
396#####################################################################
397
398sub get_useforce_value
399{
400	my ( $module ) = @_;
401
402	my $value = "false";
403
404	my $styles = "";
405	if ( $module->{'Styles'} ) { $styles = $module->{'Styles'}; }
406	if ( $styles =~ /\bUSEFORCE\b/ ) { $value = "true"; }
407
408	return $value;
409}
410
411###################################################
412# Asking module, if installation can fail
413# scp style: INSTALLCANFAIL
414###################################################
415
416sub get_installcanfail_value
417{
418	my ( $module ) = @_;
419
420	my $value = "false";
421
422	my $styles = "";
423	if ( $module->{'Styles'} ) { $styles = $module->{'Styles'}; }
424	if ( $styles =~ /\bINSTALLCANFAIL\b/ ) { $value = "true"; }
425
426	return $value;
427}
428
429###################################################
430# Asking module, if installation can fail
431# scp style: INSTALLCANFAIL
432###################################################
433
434sub get_forceintoupdate_value
435{
436	my ( $module ) = @_;
437
438	my $value = "false";
439
440	my $styles = "";
441	if ( $module->{'Styles'} ) { $styles = $module->{'Styles'}; }
442	if ( $styles =~ /\bFORCEINTOUPDATE\b/ ) { $value = "true"; }
443
444	return $value;
445}
446
447###################################################
448# Substituting all occurences of "<" by "&lt;"
449# and all occurences of ">" by "&gt;"
450###################################################
451
452sub replace_brackets_in_string
453{
454	my ( $string ) = @_;
455
456	if ( $string =~ /\</ ) { $string =~ s/\</\&lt\;/g; }
457	if ( $string =~ /\>/ ) { $string =~ s/\>/\&gt\;/g; }
458
459	return $string;
460}
461
462###################################################
463# Substituting all occurences of "\uUXYZ" by
464# "&#xUXYZ;", because the use xml saxparser does
465# not know anything about this encoding. Therfore
466# the xml file can keep standard encoding "UTF-8"
467# and all strings with "\uUXYZ" do not need to
468# be converted from the Java installer.
469###################################################
470
471sub replace_javaencoding_in_string
472{
473	my ( $string ) = @_;
474
475	while ( $string =~ /(\\u\w\w\w\w)/ )
476	{
477		my $oldvalue = $1;
478		my $newvalue = "";
479		if ( $oldvalue =~ /\\u(\w\w\w\w)/ )
480		{
481			my $number = $1;
482			$newvalue = "&#x" . $number . ";";
483		}
484
485		$string =~ s/\Q$oldvalue\E/$newvalue/;
486	}
487
488	return $string;
489}
490
491###################################################
492# Collecting language dependent entries from scp
493# (Name and Description)
494###################################################
495
496sub collect_lang_values
497{
498	my ($indent, $module, $xpdfile, $searchentry, $saveentry) = @_;
499
500	foreach $key (keys %{$module})
501	{
502		my $write_line = 0;
503		my $javalanguage = "";
504
505		if ( $key =~ /^\s*\Q$searchentry\E\s+\((\S+)\)\s*$/ )	# this are the language dependent keys
506		{
507			$language = $1;
508			$javalanguage = installer::languages::get_java_language($language);
509			$write_line = 1;
510		}
511		elsif ( $key =~ /^\s*\Q$searchentry\E\s*$/ )	# this are the language independent keys
512		{
513			$javalanguage = "en_US";
514			$write_line = 1;
515		}
516
517		if ( $write_line )
518		{
519			my $value = $module->{$key};
520			$value = replace_brackets_in_string($value);
521			$value = replace_javaencoding_in_string($value);
522			my $line = $indent . "<" . $saveentry . " lang=" . "\"" . $javalanguage . "\"" . ">" . $value . "<\/" . $saveentry . ">" . "\n";
523			push(@{$xpdfile}, $line);
524		}
525	}
526}
527
528###################################################
529# Removing language dependent entries from
530# module hash (Name and Description)
531###################################################
532
533sub remove_lang_values
534{
535	my ($module, $searchentry) = @_;
536
537	my $key = "";
538
539	foreach $key (keys %{$module})
540	{
541		if ( $key =~ /^\s*\Q$searchentry\E\s+\((\S+)\)\s*$/ )	# this are the language dependent keys
542		{
543			delete($module->{$key});
544		}
545	}
546}
547
548###################################################
549# Setting package install order
550###################################################
551
552sub get_order_value
553{
554	my ( $module ) = @_;
555
556	my $value = "1000"; # Setting the default value
557
558	if ( $module->{'InstallOrder'} ) { $value = $module->{'InstallOrder'}; }
559
560	return $value;
561}
562
563###################################################
564# Checking size of package
565###################################################
566
567sub get_size_value
568{
569	my ( $packagename, $xpdinfo ) = @_;
570
571	my $value = "";
572
573	if ( $xpdinfo->{'FileSize'} )
574	{
575		$value =  $xpdinfo->{'FileSize'};
576		return $value;
577	}
578
579	my $isrpmfile = 0;
580	if ( $packagename =~ /\.rpm\s*$/ ) { $isrpmfile = 1; }
581
582	if (( $installer::globals::islinuxrpmbuild ) && ( $isrpmfile ))
583	{
584		# if ( ! $installer::globals::rpmquerycommand ) { installer::exiter::exit_program("ERROR: rpm not found for querying packages!", "get_size_value"); }
585		if ( ! $installer::globals::rpmquerycommand ) { $installer::globals::rpmquerycommand = "rpm"; }
586
587		my $systemcall = "$installer::globals::rpmquerycommand -qp --queryformat \"\[\%\{FILESIZES\}\\n\]\" $packagename 2\>\&1 |";
588		my $ld_library_backup = $ENV{LD_LIBRARY_PATH};
589		if ( defined $ENV{SYSBASE}) {
590			my $sysbase = $ENV{SYSBASE};
591            if ( !defined ($ld_library_backup) or ("$ld_library_backup" eq "") ) {
592				$ld_library_backup = "" if ! defined $ld_library_backup;
593				$ENV{LD_LIBRARY_PATH} = "$sysbase/usr/lib";
594			} else {
595				$ENV{LD_LIBRARY_PATH} = "$ld_library_backup:$sysbase/lib";
596			}
597		}
598		my ($rpmout, $error) = make_systemcall_allowing_error($systemcall, 0, 1);
599		$ENV{LD_LIBRARY_PATH} = $ld_library_backup;
600		# Evaluating an error, because of rpm problems with removed LD_LIBRARY_PATH
601		if ( $error )
602		{
603			installer::logger::print_message( "... trying /usr/bin/rpm ...\n" );
604			my $systemcall = "/usr/bin/rpm -qp --queryformat \"\[\%\{FILESIZES\}\\n\]\" $packagename 2\>\&1 |";
605			($rpmout, $error) = make_systemcall_allowing_error($systemcall, 0, 0);
606			if ( $error ) { installer::exiter::exit_program("ERROR: rpm failed to query package!", "get_size_value"); }
607		}
608		$value = do_sum($rpmout);		# adding all filesizes in bytes
609		$value = $value/1000;
610
611		my $ganzzahl = int $value;
612		if ($ganzzahl < $value) { $value = $ganzzahl + 1; }
613		else { $value = $ganzzahl; }
614
615		my $rpmname = $packagename;
616		installer::pathanalyzer::make_absolute_filename_to_relative_filename(\$rpmname);
617		$infoline = "Filesize $rpmname : $value\n";
618		push( @installer::globals::logfileinfo, $infoline);
619	}
620
621	if ( $installer::globals::issolarispkgbuild )
622	{
623		my $filename = "pkgmap";
624		$filename = $packagename . $installer::globals::separator . $filename;
625		$file = installer::files::read_file($filename);
626
627		for ( my $i = 0; $i <= $#{$file}; $i++ )
628		{
629			my $line = ${$file}[$i];
630			if ( $line =~ /^\s*\:\s+\d+\s+(\d+?)\s+/ )
631			{
632				$value = $1;
633				if ( ! ( $value%2 == 0 )) { $value = $value + 1; }
634				$value = $value/2;		# not blocks, but kB
635				last;
636			}
637		}
638	}
639
640	if ( $value eq "" ) { $value = "0"; }
641
642	return $value;
643}
644
645###################################################
646# Checking md5 of package
647###################################################
648
649sub get_md5_value
650{
651	my ( $packagename, $xpdinfo ) = @_;
652
653	my $value = "";
654
655	if ( $xpdinfo->{'md5sum'} )
656	{
657		$value =  $xpdinfo->{'md5sum'};
658		return $value;
659	}
660
661	if ( $installer::globals::islinuxrpmbuild )
662	{
663		my $md5file = "/usr/bin/md5sum";
664
665		if ( -x $md5file )
666		{
667			my $systemcall = "$md5file $packagename 2\>\&1 |";
668			my $md5out = make_systemcall($systemcall, 1);
669			$value = ${$md5out}[0];
670			if ( $value =~ /^\s*(\S+?)\s+.*$/ )
671			{
672				$value = $1;
673			}
674
675			my $rpmname = $packagename;
676			installer::pathanalyzer::make_absolute_filename_to_relative_filename(\$rpmname);
677			$infoline = "md5sum of $rpmname : $value\n";
678			push( @installer::globals::logfileinfo, $infoline);
679		}
680	}
681
682	return $value;
683}
684
685###################################################
686# Checking name of package
687###################################################
688
689sub get_name_value
690{
691	my ( $packagename ) = @_;
692
693	my $value = $packagename;
694
695	# $packagename contains the complete path to the package
696	# Only the name of file or directory is required
697
698	installer::pathanalyzer::make_absolute_filename_to_relative_filename(\$value);
699
700	return $value;
701}
702
703###################################################
704# Checking full package name (Linux only)
705###################################################
706
707sub get_fullpkgname_value
708{
709	my ( $packagename, $xpdinfo ) = @_;
710
711	my $value = "";
712	my $isrpmfile = 0;
713	if ( $packagename =~ /\.rpm\s*$/ ) { $isrpmfile = 1; }
714
715	if (( $installer::globals::islinuxrpmbuild ) && ( $isrpmfile ))
716	{
717		if ( $xpdinfo->{'FullPackageName'} )
718		{
719			$value =  $xpdinfo->{'FullPackageName'};
720			return $value;
721		}
722
723		# if ( ! $installer::globals::rpmquerycommand ) { installer::exiter::exit_program("ERROR: rpm not found for querying packages!", "get_fullpkgname_value"); }
724		if ( ! $installer::globals::rpmquerycommand ) { $installer::globals::rpmquerycommand = "rpm"; }
725		my $systemcall = "$installer::globals::rpmquerycommand -qp $packagename |";
726		my $ld_library_backup = $ENV{LD_LIBRARY_PATH};
727		if ( defined $ENV{SYSBASE}) {
728			my $sysbase = $ENV{SYSBASE};
729    		if ( !defined ($ld_library_backup) or ("$ld_library_backup" eq "") ) {
730				$ld_library_backup = "" if ! defined $ld_library_backup;
731				$ENV{LD_LIBRARY_PATH} = "$sysbase/usr/lib";
732			} else {
733				$ENV{LD_LIBRARY_PATH} = "$ld_library_backup:$sysbase/lib";
734			}
735		}
736		my ($returnarray, $error) = make_systemcall_allowing_error($systemcall, 0, 1);
737		$ENV{LD_LIBRARY_PATH} = $ld_library_backup;
738		# Evaluating an error, because of rpm problems with removed LD_LIBRARY_PATH
739		if ( $error )
740		{
741			installer::logger::print_message( "... trying /usr/bin/rpm ...\n" );
742			my $systemcall = "/usr/bin/rpm -qp $packagename |";
743			($returnarray, $error) = make_systemcall_allowing_error($systemcall, 0, 0);
744			if ( $error ) { installer::exiter::exit_program("ERROR: rpm failed to query package!", "get_fullpkgname_value"); }
745		}
746		$value = ${$returnarray}[0];
747		installer::remover::remove_leading_and_ending_whitespaces(\$value);
748
749		my $rpmname = $packagename;
750		installer::pathanalyzer::make_absolute_filename_to_relative_filename(\$rpmname);
751
752		$infoline = "Full package name from $rpmname: $value\n";
753		push( @installer::globals::logfileinfo, $infoline);
754	}
755
756	return $value;
757}
758
759###################################################
760# Checking package version (Solaris only)
761###################################################
762
763sub get_pkgversion_value
764{
765	my ( $completepackagename, $xpdinfo ) = @_;
766
767	my $value = "";
768
769	if ( $xpdinfo->{'PkgVersion'} )
770	{
771		$value =  $xpdinfo->{'PkgVersion'};
772		return $value;
773	}
774
775	if ( $installer::globals::issolarispkgbuild )
776	{
777		my $pkgfile = "pkgparam";
778		my $packagepath = $completepackagename;
779		installer::pathanalyzer::get_path_from_fullqualifiedname(\$packagepath);
780
781		my $packagename = $completepackagename;
782		installer::pathanalyzer::make_absolute_filename_to_relative_filename(\$packagename);
783
784		my $systemcall = "$pkgfile -d $packagepath $packagename param VERSION 2\>\&1 |";
785		my $returnarray = make_systemcall($systemcall, 0);
786
787		$value = ${$returnarray}[0];
788		installer::remover::remove_leading_and_ending_whitespaces(\$value);
789	}
790
791	return $value;
792}
793
794###################################################
795# Writing subdirectory into xpd file
796###################################################
797
798sub get_subdir_value
799{
800	my ( $packagename, $subdir, $module ) = @_;
801
802	my $value = "";
803
804	if ( $subdir ) { $value = $subdir; }
805
806	if ( $module->{'Subdir'} ) { $value = $module->{'Subdir'}; }
807
808	return $value;
809}
810
811###################################################
812# Checking if package is relocatable
813###################################################
814
815sub get_relocatable_value
816{
817	my ( $module ) = @_;
818
819	my $value = "true";
820
821	my $styles = "";
822	if ( $module->{'Styles'} ) { $styles = $module->{'Styles'}; }
823	if ( $styles =~ /\bNOTRELOCATABLE\b/ ) { $value = "false"; }
824
825	return $value;
826}
827
828###################################################
829# Checking if package is relocatable
830###################################################
831
832sub get_languagespecific_value
833{
834	my ( $islanguagemodule ) = @_;
835
836	my $value = "false";
837
838	if ( defined $islanguagemodule && $islanguagemodule == 1 ) { $value = "true"; }
839
840	return $value;
841}
842
843#######################################################
844# Adding the values of the array
845#######################################################
846
847sub do_sum
848{
849	my ( $allnumbers ) = @_;
850
851	my $sum = 0;
852
853	for ( my $i = 0; $i <= $#{$allnumbers}; $i++ )
854	{
855		$sum = $sum + ${$allnumbers}[$i];
856	}
857
858	return $sum;
859}
860
861#######################################################
862# Executing one system call
863#######################################################
864
865sub make_systemcall
866{
867	my ( $systemcall, $logreturn ) = @_;
868
869	my @returns = ();
870
871	installer::logger::print_message( "... $systemcall ...\n" );
872
873	open (REG, "$systemcall");
874	while (<REG>) {push(@returns, $_); }
875	close (REG);
876
877	my $returnvalue = $?;	# $? contains the return value of the systemcall
878
879	my $infoline = "Systemcall: $systemcall\n";
880	push( @installer::globals::logfileinfo, $infoline);
881
882	if ( $logreturn )
883	{
884		for ( my $j = 0; $j <= $#returns; $j++ ) { push( @installer::globals::logfileinfo, "$returns[$j]"); }
885	}
886
887	if ($returnvalue)
888	{
889		$infoline = "ERROR: $systemcall\n";
890		push( @installer::globals::logfileinfo, $infoline);
891		$error_occured = 1;
892	}
893	else
894	{
895		$infoline = "SUCCESS: $systemcall\n";
896		push( @installer::globals::logfileinfo, $infoline);
897	}
898
899	return \@returns;
900}
901
902#######################################################
903# Executing one system call
904#######################################################
905
906sub make_systemcall_allowing_error
907{
908	my ( $systemcall, $logreturn, $can_fail ) = @_;
909
910	my @returns = ();
911
912	installer::logger::print_message( "... $systemcall ...\n" );
913
914	open (REG, "$systemcall");
915	while (<REG>) {push(@returns, $_); }
916	close (REG);
917
918	my $returnvalue = $?;	# $? contains the return value of the systemcall
919
920	my $infoline = "Systemcall: $systemcall\n";
921	push( @installer::globals::logfileinfo, $infoline);
922
923	if ( $logreturn )
924	{
925		for ( my $j = 0; $j <= $#returns; $j++ ) { push( @installer::globals::logfileinfo, "$returns[$j]"); }
926	}
927
928	if ($returnvalue)
929	{
930		if ( $can_fail )
931		{
932			$infoline = "WARNING: Failed system call:  $systemcall\n";
933			push( @installer::globals::logfileinfo, $infoline);
934			$error_occured = 1;
935		}
936		else
937		{
938			$infoline = "ERROR: $systemcall\n";
939			push( @installer::globals::logfileinfo, $infoline);
940			$error_occured = 1;
941		}
942	}
943	else
944	{
945		$infoline = "SUCCESS: $systemcall\n";
946		push( @installer::globals::logfileinfo, $infoline);
947	}
948
949	return (\@returns, $returnvalue);
950}
951
952###################################################
953# Setting product name tag
954###################################################
955
956sub get_product_tag
957{
958	my ($allvariables, $indent) = @_;
959
960	my $productname = $allvariables->{'LCONEWORDPRODUCTNAME'};
961	my $tag = $indent . "<product " . "name=" . "\"" . $productname . "\">" . "\n";
962
963	return $tag;
964}
965
966###################################################
967# Macro tags
968###################################################
969
970sub set_macro_tag
971{
972	my ($allvariables, $indent, $key) = @_;
973
974	my $property = "";
975	my $value = "";
976
977	if ( $key eq "product_name" ) { $property = "PRODUCTNAME"; }
978	elsif ( $key eq "product_version" ) { $property = "PRODUCTVERSION"; }
979	elsif ( $key eq "product_suffix" ) { $property = "PRODUCTEXTENSION"; }
980	elsif ( $key eq "product_fullname" ) { $property = "FULLPRODUCTNAME"; }
981
982	if (( $property eq "PRODUCTNAME" ) || ( $property eq "PRODUCTVERSION" ) || ( $property eq "PRODUCTEXTENSION" ))
983	{
984		$value = $allvariables->{$property};
985	}
986
987	if ( $property eq "FULLPRODUCTNAME" )
988	{
989		$value = $allvariables->{"PRODUCTNAME"} . " " . $allvariables->{"PRODUCTVERSION"};
990		if ( $allvariables->{"PRODUCTEXTENSION"} ) { $value = $value . " " . $allvariables->{"PRODUCTEXTENSION"}; }
991	}
992
993	my $tag = $indent . "<macro " . "key=" . "\"" . $key . "\">" . $value . "\<\/macro\>" . "\n";
994
995	return $tag;
996
997}
998
999###################################################
1000# Setting the minor of the product version
1001# Required to check for Major Upgrades.
1002###################################################
1003
1004sub set_minor_tag
1005{
1006	my ($allvariables, $indent) = @_;
1007
1008	my $productminor = 0;
1009	if ( $allvariables->{"PACKAGEVERSION"} )
1010	{
1011		if ( $allvariables->{"PACKAGEVERSION"} =~ /^\s*\d+\.(\d+)/ ) { $productminor = $1; }
1012	}
1013	my $tag = $indent . "<productminor>" . $productminor . "</productminor>" . "\n";
1014
1015	return $tag;
1016}
1017
1018###################################################
1019# Setting the update behaviour
1020###################################################
1021
1022sub set_update_tag
1023{
1024	my ($allvariables, $indent) = @_;
1025
1026	my $updateflag = "false";
1027	if ( $allvariables->{"DONTUPDATE"} ) { $updateflag = "true"; }
1028	my $tag = $indent . "<dontupdate>" . $updateflag . "</dontupdate>" . "\n";
1029
1030	return $tag;
1031}
1032
1033###################################################
1034# Setting the license dialog behaviour
1035###################################################
1036
1037sub set_hideeula_tag
1038{
1039	my ($allvariables, $indent) = @_;
1040
1041	my $hidelicenseflag = "false";
1042	if ( $allvariables->{"HIDELICENSEDIALOG"} ) { $hidelicenseflag = "true"; }
1043	my $tag = $indent . "<hideeula>" . $hidelicenseflag . "</hideeula>" . "\n";
1044
1045	return $tag;
1046}
1047
1048###################################################
1049# Setting default directory
1050###################################################
1051
1052sub set_defaultdir_tag
1053{
1054	my ($allvariables, $indent) = @_;
1055
1056	my $defaultdir = "";
1057	if ( $allvariables->{"DEFAULTDESTPATH"} ) { $defaultdir = $allvariables->{"DEFAULTDESTPATH"}; }
1058	my $tag = $indent . "<defaultdir>" . $defaultdir . "</defaultdir>" . "\n";
1059
1060	return $tag;
1061}
1062
1063###################################################
1064# Setting product directory
1065###################################################
1066
1067sub set_productdir_tag
1068{
1069	my ($allvariables, $indent) = @_;
1070
1071	my $productdir = "";
1072	if ( $allvariables->{"UNIXPRODUCTNAME"} )
1073	{
1074		$productdir = $allvariables->{"UNIXPRODUCTNAME"};
1075
1076		if ( $allvariables->{"BRANDPACKAGEVERSION"} )
1077		{
1078			$productdir = $productdir . $allvariables->{"BRANDPACKAGEVERSION"};
1079#			if ( $allvariables->{"LCPRODUCTEXTENSION"} ) { $productdir = $productdir . $allvariables->{"LCPRODUCTEXTENSION"}; }
1080		}
1081		else
1082		{
1083			if ( $allvariables->{"PRODUCTVERSION"} )
1084			{
1085				$productdir = $productdir . $allvariables->{"PRODUCTVERSION"};
1086			}
1087		}
1088	}
1089	my $tag = $indent . "<productdir>" . $productdir . "</productdir>" . "\n";
1090
1091	return $tag;
1092}
1093
1094#####################################################
1095# Setting the package directory in installation set
1096#####################################################
1097
1098sub set_packagedir_tag
1099{
1100	my ($indent) = @_;
1101
1102	my $tag = $indent . "<packagedirectory>" . $installer::globals::epmoutpath . "</packagedirectory>" . "\n";
1103
1104	return $tag;
1105}
1106
1107###################################################
1108# Setting the packagetype of installation set
1109###################################################
1110
1111sub set_packagetype_tag
1112{
1113	my ($indent) = @_;
1114
1115	my $tag = $indent . "<packageformat>" . $installer::globals::packageformat . "</packageformat>" . "\n";
1116
1117	return $tag;
1118}
1119
1120###################################################
1121# Setting the architecture of installation set
1122###################################################
1123
1124sub set_architecture_tag
1125{
1126	my ($indent) = @_;
1127
1128	my $architecture = "";
1129	if ( $installer::globals::issolarissparcbuild ) { $architecture = "sparc"; }
1130	if ( $installer::globals::issolarisx86build ) { $architecture = "i386"; }
1131
1132	my $tag = $indent . "<architecture>" . $architecture . "</architecture>" . "\n";
1133
1134	return $tag;
1135}
1136
1137###################################################
1138# Setting the multi language tag
1139###################################################
1140
1141sub set_multilanguage_tag
1142{
1143	my ($indent) = @_;
1144
1145	my $value = "false";
1146	if ( $installer::globals::ismultilingual == 1 ) { $value = "true"; }
1147
1148	my $tag = $indent . "<multilingual>" . $value . "</multilingual>" . "\n";
1149
1150	return $tag;
1151}
1152
1153###################################################
1154# Setting the language tag
1155###################################################
1156
1157sub set_language_tag
1158{
1159	my ($languagestringref, $indent) = @_;
1160
1161	my $tag = $indent . "<languages>" . $$languagestringref . "</languages>" . "\n";
1162
1163	return $tag;
1164}
1165
1166###################################################
1167# Collecting content for product xpd file
1168###################################################
1169
1170# <?xml version='1.0' encoding='utf-8'?>
1171#
1172# <!-- General application description -->
1173#
1174# <product name="openoffice">
1175#     <macro key="product_name">Sun OpenOffice.org</macro>
1176#     <macro key="product_version">1.0</macro>
1177#     <macro key="product_suffix">Mephisto</macro>
1178#     <macro key="product_fullname">Sun OpenOffice.org 1.0 Mephisto</macro>
1179#     <defaultdir>/opt/Sun/OpenOffice.org-Mephisto</defaultdir>
1180# </product>
1181
1182sub get_setup_file_content
1183{
1184	my ($allvariables, $languagestringref) = @_;
1185
1186	my @xpdfile = ();
1187	my $noindent = "";
1188	my $singleindent = "    ";
1189
1190	my $line = "<?xml version='1.0' encoding='utf-8'?>\n\n";
1191	push(@xpdfile, $line);
1192	$line = "<!-- General application description -->\n\n";
1193	push(@xpdfile, $line);
1194
1195	my $tag = get_product_tag($allvariables, $noindent);
1196	push(@xpdfile, $tag);
1197
1198	$tag = set_macro_tag($allvariables, $singleindent, "product_name");
1199	push(@xpdfile, $tag);
1200	$tag = set_macro_tag($allvariables, $singleindent, "product_version");
1201	push(@xpdfile, $tag);
1202	$tag = set_macro_tag($allvariables, $singleindent, "product_suffix");
1203	push(@xpdfile, $tag);
1204	$tag = set_macro_tag($allvariables, $singleindent, "product_fullname");
1205	push(@xpdfile, $tag);
1206
1207	$tag = set_defaultdir_tag($allvariables, $singleindent);
1208	push(@xpdfile, $tag);
1209
1210	$tag = set_productdir_tag($allvariables, $singleindent);
1211	push(@xpdfile, $tag);
1212
1213	$tag = set_minor_tag($allvariables, $singleindent);
1214	push(@xpdfile, $tag);
1215
1216	$tag = set_update_tag($allvariables, $singleindent);
1217	push(@xpdfile, $tag);
1218
1219	$tag = set_packagedir_tag($singleindent);
1220	push(@xpdfile, $tag);
1221
1222	$tag = set_packagetype_tag($singleindent);
1223	push(@xpdfile, $tag);
1224
1225	$tag = set_architecture_tag($singleindent);
1226	push(@xpdfile, $tag);
1227
1228	$tag = set_multilanguage_tag($singleindent);
1229	push(@xpdfile, $tag);
1230
1231	$tag = set_language_tag($languagestringref, $singleindent);
1232	push(@xpdfile, $tag);
1233
1234	$tag = set_hideeula_tag($allvariables, $singleindent);
1235	push(@xpdfile, $tag);
1236
1237	$tag = get_end_tag("product", $noindent);
1238	push(@xpdfile, $tag);
1239
1240	return \@xpdfile;
1241}
1242
1243###################################################
1244# Collecting content for xpd file
1245###################################################
1246
1247sub get_file_content
1248{
1249	my ( $module, $packagename, $solslanguage, $linkpackage, $isemptyparent, $subdir, $islanguagemodule, $onelanguage, $xpdinfo ) = @_;
1250
1251	my @xpdfile = ();
1252	my $value = "";
1253	my $line = "";
1254	my $noindent = "";
1255	my $singleindent = "    ";
1256	my $doubleindent = $singleindent . $singleindent;
1257
1258	my ( $tag, $parentgid ) = get_package_tag($module, $noindent, $linkpackage);
1259	push(@xpdfile, $tag);
1260
1261	# start of installunit tag -> using info from scp module
1262
1263	$tag = get_display_tag($module, $singleindent);
1264	push(@xpdfile, $tag);
1265
1266	$value = get_sortkey_value($module);
1267	$line = get_tag_line($doubleindent, "sortkey", $value);
1268	push(@xpdfile, $line);
1269
1270	$value = get_default_value($module);
1271	$line = get_tag_line($doubleindent, "default", $value);
1272	push(@xpdfile, $line);
1273
1274	$value = get_showinuserinstall_value($module);
1275	$line = get_tag_line($doubleindent, "showinuserinstall", $value);
1276	push(@xpdfile, $line);
1277
1278	$value = get_userinstallonly_value($module);
1279	$line = get_tag_line($doubleindent, "showinuserinstallonly", $value);
1280	push(@xpdfile, $line);
1281
1282	$value = get_dontuninstall_value($module);
1283	$line = get_tag_line($doubleindent, "dontuninstall", $value);
1284	push(@xpdfile, $line);
1285
1286	$value = get_checksolaris_value($module);
1287	$line = get_tag_line($doubleindent, "checksolaris", $value);
1288	push(@xpdfile, $line);
1289
1290	$value = get_isupdatepackage_value($module);
1291	$line = get_tag_line($doubleindent, "isupdatepackage", $value);
1292	push(@xpdfile, $line);
1293
1294	$value = get_showmultilingualonly_value($module);
1295	$line = get_tag_line($doubleindent, "showmultilingualonly", $value);
1296	push(@xpdfile, $line);
1297
1298	$value = get_applicationmodule_value($module);
1299	$line = get_tag_line($doubleindent, "applicationmodule", $value);
1300	push(@xpdfile, $line);
1301
1302	$value = get_isjavamodule_value($module);
1303	$line = get_tag_line($doubleindent, "isjavapackage", $value);
1304	push(@xpdfile, $line);
1305
1306	$value = get_installcanfail_value($module);
1307	$line = get_tag_line($doubleindent, "installcanfail", $value);
1308	push(@xpdfile, $line);
1309
1310	$value = get_forceintoupdate_value($module);
1311	$line = get_tag_line($doubleindent, "forceintoupdate", $value);
1312	push(@xpdfile, $line);
1313
1314	$value = get_useforce_value($module);
1315	$line = get_tag_line($doubleindent, "useforce", $value);
1316	push(@xpdfile, $line);
1317
1318	# iterating over all languages to get names and descriptions
1319	collect_lang_values($doubleindent, $module, \@xpdfile, "Name", "name");
1320	collect_lang_values($doubleindent, $module, \@xpdfile, "Description", "description");
1321
1322	$tag = get_end_tag("display", $singleindent);
1323	push(@xpdfile, $tag);
1324
1325	# end of display tag
1326
1327	if ( ! $isemptyparent )
1328	{
1329		# start of installunit tag -> using info from package defined in packagelist
1330
1331		$tag = get_installunit_tag($singleindent);
1332		push(@xpdfile, $tag);
1333
1334		$value = get_size_value($packagename, $xpdinfo);
1335		$line = get_tag_line($doubleindent, "size", $value);
1336		push(@xpdfile, $line);
1337
1338		$value = get_order_value($module);
1339		$line = get_tag_line($doubleindent, "installorder", $value);
1340		push(@xpdfile, $line);
1341
1342		$value = get_md5_value($packagename, $xpdinfo);
1343		$line = get_tag_line($doubleindent, "md5", $value);
1344		push(@xpdfile, $line);
1345
1346		$value = get_name_value($packagename);
1347		$line = get_tag_line($doubleindent, "name", $value);
1348		push(@xpdfile, $line);
1349
1350		$value = get_fullpkgname_value($packagename, $xpdinfo);
1351		$line = get_tag_line($doubleindent, "fullpkgname", $value);
1352		push(@xpdfile, $line);
1353
1354		$value = get_pkgversion_value($packagename, $xpdinfo);
1355		$line = get_tag_line($doubleindent, "pkgversion", $value);
1356		push(@xpdfile, $line);
1357
1358		$value = get_subdir_value($packagename, $subdir, $module);
1359		$line = get_tag_line($doubleindent, "subdir", $value);
1360		push(@xpdfile, $line);
1361
1362		$value = get_relocatable_value($module);
1363		$line = get_tag_line($doubleindent, "relocatable", $value);
1364		push(@xpdfile, $line);
1365
1366		$value = get_languagespecific_value($islanguagemodule);
1367		$line = get_tag_line($doubleindent, "languagespecific", $value);
1368		push(@xpdfile, $line);
1369
1370		$value = $onelanguage;
1371		$line = get_tag_line($doubleindent, "language", $value);
1372		push(@xpdfile, $line);
1373
1374		$line = get_tag_line($doubleindent, "solarislanguage", $solslanguage);
1375		push(@xpdfile, $line);
1376
1377		$tag = get_end_tag("installunit", $singleindent);
1378		push(@xpdfile, $tag);
1379
1380		# end of installunit tag
1381	}
1382
1383	$tag = get_end_tag("package", $noindent);
1384	push(@xpdfile, $tag);
1385
1386	return ( \@xpdfile, $parentgid );
1387}
1388
1389###################################################
1390# Setting xpd file name
1391###################################################
1392
1393sub get_xpd_filename
1394{
1395	my ($modulegid, $linkpackage) = @_;
1396
1397	if ( $linkpackage ) { $modulegid = $modulegid . "u"; }
1398
1399	my $filename = $modulegid . ".xpd";
1400
1401	return $filename;
1402}
1403
1404###################################################
1405# Determine, which package was created newly
1406###################################################
1407
1408sub determine_new_packagename
1409{
1410	my ( $installdir, $subdir, $xpdinfo ) = @_;
1411
1412	my $newpackage = "";
1413	$installdir =~ s/\Q$installer::globals::separator\E\s*$//;
1414	my $directory = $installdir . $installer::globals::separator . $subdir;
1415	$directory =~ s/\Q$installer::globals::separator\E\s*$//;
1416
1417	if ( $xpdinfo->{'RealPackageName'} )
1418	{
1419		$newpackage = $directory . $installer::globals::separator . $xpdinfo->{'RealPackageName'};
1420		push(@installer::globals::currentcontent, $newpackage);
1421		return $newpackage;
1422	}
1423
1424	my ($newcontent, $allcontent) = installer::systemactions::find_new_content_in_directory($directory, \@installer::globals::currentcontent);
1425	@installer::globals::currentcontent = ();
1426	foreach my $element ( @{$allcontent} ) { push(@installer::globals::currentcontent, $element); }
1427
1428	my $newentriesnumber = $#{$newcontent} + 1;
1429	if ( $newentriesnumber > 1 ) { installer::exiter::exit_program("ERROR: More than one new package in directory $directory", "determine_new_packagename (xpdinstaller)"); }
1430	elsif ( $newentriesnumber < 1 )  { installer::exiter::exit_program("ERROR: No new package in directory $directory", "determine_new_packagename (xpdinstaller)"); }
1431	$newpackage = ${$newcontent}[0];
1432
1433	return $newpackage;
1434}
1435
1436###################################################
1437# Checking, if the parentgid is defined in
1438# another package
1439###################################################
1440
1441sub is_empty_parent
1442{
1443	my ($gid, $packages) = @_;
1444
1445	my $is_empty_parent = 1;
1446
1447	for ( my $k = 0; $k <= $#{$packages}; $k++ )
1448	{
1449		my $onepackage = ${$packages}[$k];
1450		my $packagegid = $onepackage->{'module'};
1451
1452		if ( $packagegid eq $gid )
1453		{
1454			$is_empty_parent = 0;
1455			last;
1456		}
1457	}
1458
1459	return $is_empty_parent;
1460}
1461
1462###################################################
1463# Creating additional xpd files for empty parents
1464###################################################
1465
1466sub create_emptyparents_xpd_file
1467{
1468	my ($parentgid, $modulesarrayref, $xpddir) = @_;
1469
1470	my $module = get_module($parentgid, $modulesarrayref);
1471	my $grandpagid = "";
1472
1473	if ( $module ne "" )
1474	{
1475		my $packagename = "";
1476		# all content saved in scp is now available and can be used to create the xpd file
1477		my ( $xpdfile, $newparentgid ) = get_file_content($module, $packagename, "", 0, 1, "", 0, "", "");
1478
1479		$grandpagid = $newparentgid;
1480
1481		my $xpdfilename = get_xpd_filename($parentgid, 0);
1482		$xpdfilename = $xpddir . $installer::globals::separator . $xpdfilename;
1483
1484		installer::files::save_file($xpdfilename, $xpdfile);
1485		push(@installer::globals::allxpdfiles, $xpdfilename);
1486		my $infoline = "Saving xpd file: $xpdfilename\n";
1487		push(@installer::globals::logfileinfo, $infoline);
1488	}
1489
1490	# push(@installer::globals::emptyxpdparents, $parentgid);
1491	push( @installer::globals::createdxpdfiles, $parentgid);
1492
1493	return $grandpagid;
1494}
1495
1496###################################################
1497# Creating additional xpd files for empty parents
1498###################################################
1499
1500sub filter_content_from_xpdfile
1501{
1502	my ($xpdfile) = @_;
1503
1504	my @newxpdfile = ();
1505
1506	my $include = 1;
1507
1508	for ( my $i = 0; $i <= $#{$xpdfile}; $i++ )
1509	{
1510		my $line = ${$xpdfile}[$i];
1511
1512		if (( $line =~ /^\s*\<installunit/ ) && ( $include )) { $include = 0; }
1513		if ( $include ) { push(@newxpdfile, $line); }
1514		if (( $line =~ /^\s*\<\/installunit/ ) && ( ! $include )) { $include = 1; }
1515	}
1516
1517	return \@newxpdfile;
1518}
1519
1520##########################################################################
1521# Changing the parent inside the xpd file
1522# Old: <package name="gid_Module_Root" parent="root">
1523# New: <package name="gid_Module_Root_Files_1" parent="gid_Module_Root">
1524##########################################################################
1525
1526sub change_parent_in_xpdfile
1527{
1528	my ($xpdfile, $modulename) = @_;
1529
1530	for ( my $i = 0; $i <= $#{$xpdfile}; $i++ )
1531	{
1532		if ( ${$xpdfile}[$i] =~ /^\s*\<package name\s*=\s*\"(\S+?)\"\s+parent\s*=\s*\"(\S+?)\"\s*\>\s*$/ )
1533		{
1534			my $oldname = $1;
1535			my $oldparent = $2;
1536
1537			my $newname = $modulename;
1538			my $newparent = $oldname;
1539
1540			${$xpdfile}[$i] =~ s/\"\Q$oldname\E\"/\"$newname\"/;
1541			${$xpdfile}[$i] =~ s/\"\Q$oldparent\E\"/\"$newparent\"/;
1542
1543			last;
1544		}
1545	}
1546}
1547
1548###################################################
1549# Creating one xpd file for each package
1550###################################################
1551
1552sub create_xpd_file
1553{
1554	my ($onepackage, $allpackages, $languagestringref, $allvariables, $modulesarrayref, $installdir, $subdir, $linkpackage, $xpdinfo) = @_;
1555
1556	my $infoline = "";
1557	# creating the directory
1558	my $xpddir = installer::systemactions::create_directories("xpdinstaller", $languagestringref);
1559	$xpddir =~ s/\/\s*$//;
1560	$installer::globals::xpddir = $xpddir;
1561	# push(@installer::globals::removedirs, $xpddir);
1562
1563	my $modulegid = $onepackage->{'module'};
1564
1565	my $onelanguage = "";	#
1566    my $solslanguage = "";	#
1567	my $islanguagemodule = 0;	#
1568	if ( $onepackage->{'islanguagemodule'} ) { $islanguagemodule = $onepackage->{'islanguagemodule'}; }	#
1569	if ( $islanguagemodule )	#
1570	{
1571		$onelanguage = $onepackage->{'language'};	#
1572		if ( $installer::globals::issolarispkgbuild ) { $solslanguage = installer::epmfile::get_solaris_language_for_langpack($onelanguage); }	#
1573	}
1574
1575	installer::logger::include_header_into_logfile("Creating xpd file ($modulegid):");
1576
1577	my $module = get_module($modulegid, $modulesarrayref);
1578
1579	if ( $module ne "" )
1580	{
1581		my $packagename = determine_new_packagename($installdir, $subdir, $xpdinfo);
1582
1583		# all content saved in scp is now available and can be used to create the xpd file
1584		my ( $xpdfile, $parentgid ) = get_file_content($module, $packagename, $solslanguage, $linkpackage, 0, "", $islanguagemodule, $onelanguage, $xpdinfo);
1585
1586		my $xpdfilename = get_xpd_filename($modulegid, $linkpackage);
1587		$xpdfilename = $xpddir . $installer::globals::separator . $xpdfilename;
1588
1589		# Very special handling for Root module:
1590		# Because packages should only be assigned to leaves and not to knods,
1591		# the root module is divided into a knod without package and a new
1592		# leave with package. The name of the leave is defined at $module->{'XpdPackageName'}.
1593		if ( $module->{'XpdPackageName'} )
1594		{
1595			my $newxpdfilename = get_xpd_filename($module->{'XpdPackageName'}, 0);
1596			$newxpdfilename = $xpddir . $installer::globals::separator . $newxpdfilename;
1597			my $emptyfilecontent = filter_content_from_xpdfile($xpdfile);
1598
1599			installer::files::save_file($xpdfilename, $emptyfilecontent);
1600			push(@installer::globals::allxpdfiles, $xpdfilename);
1601			$infoline = "Saving xpd file: $xpdfilename\n";
1602			push( @installer::globals::logfileinfo, $infoline);
1603
1604			$xpdfilename = $newxpdfilename;
1605			change_parent_in_xpdfile($xpdfile, $module->{'XpdPackageName'});
1606		}
1607
1608		installer::files::save_file($xpdfilename, $xpdfile);
1609		push( @installer::globals::createdxpdfiles, $modulegid);
1610		push(@installer::globals::allxpdfiles, $xpdfilename);
1611		$infoline = "Saving xpd file: $xpdfilename\n";
1612		push( @installer::globals::logfileinfo, $infoline);
1613
1614		my $grandpagid = "root";
1615		if ( $parentgid ne "root" )
1616		{
1617			my $create_missing_parent = is_empty_parent($parentgid, $allpackages);
1618
1619			# if (( $create_missing_parent ) && ( ! installer::existence::exists_in_array($parentgid, \@installer::globals::emptyxpdparents) ))
1620			if (( $create_missing_parent ) && ( ! installer::existence::exists_in_array($parentgid, \@installer::globals::createdxpdfiles) ))
1621			{
1622				$grandpagid = create_emptyparents_xpd_file($parentgid, $modulesarrayref, $xpddir);
1623			}
1624		}
1625
1626		if ( $grandpagid ne "root" )
1627		{
1628			my $create_missing_parent = is_empty_parent($grandpagid, $allpackages);
1629
1630			# if (( $create_missing_parent ) && ( ! installer::existence::exists_in_array($parentgid, \@installer::globals::emptyxpdparents) ))
1631			if (( $create_missing_parent ) && ( ! installer::existence::exists_in_array($grandpagid, \@installer::globals::createdxpdfiles) ))
1632			{
1633				create_emptyparents_xpd_file($grandpagid, $modulesarrayref, $xpddir);
1634 			}
1635 		}
1636	}
1637	else
1638	{
1639		installer::exiter::exit_program("ERROR: No module definition found for gid: $modulegid", "create_xpd_file (xpdinstaller)");
1640	}
1641
1642}
1643
1644###################################################
1645# Creating a xpd file for a copied package
1646###################################################
1647
1648sub create_xpd_file_for_childproject
1649{
1650	my ($module, $destdir, $packagename, $allvariableshashref, $modulesarrayref) = @_;
1651
1652	my $modulegid = $module->{'gid'};
1653
1654	my $currentdir = cwd();
1655	$destdir =~ s/\/\s*$//;
1656	$currentdir =~ s/\/\s*$//;
1657
1658	my $completepackage = $currentdir . $installer::globals::separator . $destdir . $installer::globals::separator . $packagename;
1659
1660	# all content saved in scp is now available and can be used to create the xpd file
1661	my ( $xpdfile, $parentgid ) = get_file_content($module, $completepackage, "", 0, 0, "", 0, "", "");
1662
1663	my $xpdfilename = get_xpd_filename($modulegid, 0);
1664	$xpdfilename = $installer::globals::xpddir . $installer::globals::separator . $xpdfilename;
1665
1666	installer::files::save_file($xpdfilename, $xpdfile);
1667	push( @installer::globals::createdxpdfiles, $modulegid);
1668	push(@installer::globals::allxpdfiles, $xpdfilename);
1669	my $infoline = "Saving xpd file: $xpdfilename\n";
1670	push( @installer::globals::logfileinfo, $infoline);
1671
1672	if ( $parentgid ne "root" )
1673	{
1674		# my $create_missing_parent = is_empty_parent($parentgid, $allpackages);
1675		my $create_missing_parent = 1; # -> Always missing parent by child projects!
1676		# Parent is now created, if it was not created before. Attention: Parent module must not come later.
1677		if (( $create_missing_parent ) && ( ! installer::existence::exists_in_array($parentgid, \@installer::globals::createdxpdfiles) ))
1678		{
1679			create_emptyparents_xpd_file($parentgid, $modulesarrayref, $installer::globals::xpddir);
1680		}
1681	}
1682}
1683
1684##############################################################
1685# Creating a xpd file for copied system integration package
1686##############################################################
1687
1688sub create_xpd_file_for_systemintegration
1689{
1690	my ($module, $newcontent, $modulesarrayref, $subdir) = @_;
1691
1692	my $parentgid = $module->{'gid'};
1693
1694	# Create new visible module from scp info and create
1695	# new hidden module for each package inside in tar file
1696
1697	for ( my $i = 0; $i <= $#{$newcontent}; $i++ )
1698	{
1699		my $newpackagename = ${$newcontent}[$i];
1700
1701		# installer::pathanalyzer::make_absolute_filename_to_relative_filename(\$newpackagename);
1702
1703		my $infoline = "Creating xpd file for package: $newpackagename\n";
1704		push( @installer::globals::logfileinfo, $infoline);
1705
1706		my $childmodule = installer::worker::copy_hash_from_references($module);
1707		$childmodule->{'ParentID'} = $module->{'gid'};  # the module gid is the new parent
1708		$childmodule->{'InstallOrder'} = $installer::globals::defaultsystemintinstallorder;
1709		my $number = $i + 1;
1710		my $modulegid = $module->{'gid'} . "_child_" . $number; # setting a dynamic new gid
1711		$childmodule->{'gid'} = $modulegid;
1712		$childmodule->{'Styles'} =~ s/\)/\,HIDDEN_ROOT\)/;
1713		# iterating over all languages to get names and descriptions
1714		remove_lang_values($childmodule, "Name");
1715		remove_lang_values($childmodule, "Description");
1716
1717		my $shortpackagename = $newpackagename;
1718		installer::pathanalyzer::make_absolute_filename_to_relative_filename(\$shortpackagename);
1719		$childmodule->{'PackageName'} = $shortpackagename;
1720		$childmodule->{'Name'} = $modulegid;
1721		$childmodule->{'Description'} = $modulegid;
1722
1723		# Checking, if installorder can be set:
1724		# scp syntax: InstallOrder = "desktop:1050, suse:1060";
1725		# The string before the number can be compared with $shortpackagename
1726		if ( $module->{'InstallOrder'} )
1727		{
1728			my $installorder = $module->{'InstallOrder'};
1729			$installorder =~ s/^\s*\"//g;
1730			$installorder =~ s/\"\s*$//g;
1731			# $installorder is comma separated list
1732			my $allorders = installer::converter::convert_stringlist_into_array(\$installorder, ",");
1733			for ( my $j = 0; $j <= $#{$allorders}; $j++ )
1734			{
1735				my $oneitem = ${$allorders}[$j];
1736				if ( $oneitem =~ /^\s*(\S+?)\s*:\s*(\S+?)\s*$/ )
1737				{
1738					my $name = $1;
1739					my $order = $2;
1740
1741					if ( $shortpackagename =~ /\Q$name\E/ ) { $childmodule->{'InstallOrder'} = $order; }
1742				}
1743			}
1744		}
1745
1746		# all content saved in scp is now available and can be used to create the xpd file
1747		my ( $xpdfile, $parentgid_ ) = get_file_content($childmodule, $newpackagename, "", 0, 0, $subdir, 0, "", "");
1748
1749		my $xpdfilename = get_xpd_filename($modulegid, 0);
1750		$xpdfilename = $installer::globals::xpddir . $installer::globals::separator . $xpdfilename;
1751
1752		installer::files::save_file($xpdfilename, $xpdfile);
1753		push(@installer::globals::allxpdfiles, $xpdfilename);
1754		$infoline = "Saving xpd file: $xpdfilename\n";
1755		push( @installer::globals::logfileinfo, $infoline);
1756	}
1757
1758	# Creating the top level visible xpd file
1759	create_emptyparents_xpd_file($parentgid, $modulesarrayref, $installer::globals::xpddir);
1760}
1761
1762##############################################################
1763# Copying xpd files into installation set
1764##############################################################
1765
1766sub copy_xpd_files
1767{
1768	my ( $destdir ) = @_;
1769
1770	for ( my $i = 0; $i <= $#installer::globals::allxpdfiles; $i++ )
1771	{
1772		if ( ! -f $installer::globals::allxpdfiles[$i] ) { installer::exiter::exit_program("ERROR: Could not find xpd file: $installer::globals::allxpdfiles[$i]!", "copy_xpd_files"); }
1773		installer::systemactions::copy_one_file($installer::globals::allxpdfiles[$i], $destdir);
1774	}
1775}
1776
1777##############################################################
1778# Copying all xpd files into the installation set
1779##############################################################
1780
1781sub copy_xpd_files_into_installset
1782{
1783	my ($installdir) = @_;
1784
1785	$installdir =~ s/\Q$installer::globals::separator\E\s*$//;
1786
1787	my $instdir = $installdir . $installer::globals::separator . "installdata";
1788	installer::systemactions::create_directory($instdir);
1789
1790	my $xpddir = $instdir . $installer::globals::separator . "xpd";
1791	installer::systemactions::create_directory($xpddir);
1792	copy_xpd_files($xpddir);
1793}
1794
1795##############################################################
1796# Creating base xpd file with product information
1797##############################################################
1798
1799sub create_setup_xpd
1800{
1801	my ($allvariables, $languagestringref) = @_;
1802
1803	my ( $xpdfile ) = get_setup_file_content($allvariables, $languagestringref);
1804
1805	my $xpdfilename = $installer::globals::productxpdfile;
1806	$xpdfilename = $installer::globals::xpddir . $installer::globals::separator . $xpdfilename;
1807
1808	installer::files::save_file($xpdfilename, $xpdfile);
1809	push(@installer::globals::allxpdfiles, $xpdfilename);
1810	my $infoline = "Saving xpd file: $xpdfilename\n";
1811	push( @installer::globals::logfileinfo, $infoline);
1812}
1813
1814###################################################
1815# Copying the files needed by the xpd installer
1816# into the installation directory
1817###################################################
1818
1819sub create_xpd_installer
1820{
1821	my ( $installdir, $allvariables, $languagestringref) = @_;
1822
1823	installer::logger::include_header_into_logfile("Creating xpd installer:");
1824
1825	# create setup.xpd file
1826	create_setup_xpd($allvariables, $languagestringref);
1827
1828	# copy xpd files into installation set
1829	copy_xpd_files_into_installset($installdir);
1830}
1831
18321;
1833