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