xref: /AOO41X/main/solenv/bin/modules/installer/epmfile.pm (revision 43c75f1d068f8e69f57d055e6d8a8fc2b9ad3743)
1#**************************************************************
2#
3#  Licensed to the Apache Software Foundation (ASF) under one
4#  or more contributor license agreements.  See the NOTICE file
5#  distributed with this work for additional information
6#  regarding copyright ownership.  The ASF licenses this file
7#  to you under the Apache License, Version 2.0 (the
8#  "License"); you may not use this file except in compliance
9#  with the License.  You may obtain a copy of the License at
10#
11#    http://www.apache.org/licenses/LICENSE-2.0
12#
13#  Unless required by applicable law or agreed to in writing,
14#  software distributed under the License is distributed on an
15#  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16#  KIND, either express or implied.  See the License for the
17#  specific language governing permissions and limitations
18#  under the License.
19#
20#**************************************************************
21
22
23
24package installer::epmfile;
25
26use Cwd;
27use installer::converter;
28use installer::existence;
29use installer::exiter;
30use installer::files;
31use installer::globals;
32use installer::logger;
33use installer::packagelist;
34use installer::pathanalyzer;
35use installer::remover;
36use installer::scriptitems;
37use installer::systemactions;
38use installer::worker;
39use POSIX qw(uname);
40
41############################################################################
42# Reading the package map to find Solaris package names for
43# the corresponding abbreviations
44############################################################################
45
46sub read_packagemap
47{
48    my ($allvariables, $includepatharrayref, $languagesarrayref) = @_;
49
50    my $packagemapname = "";
51    if ( $allvariables->{'PACKAGEMAP'} ) { $packagemapname = $allvariables->{'PACKAGEMAP'}; }
52    if ( $packagemapname eq "" ) { installer::exiter::exit_program("ERROR: Property PACKAGEMAP must be defined!", "read_packagemap"); }
53
54    $installer::logger::Lang->printf("\n");
55    $installer::logger::Lang->printf("\n");
56    $installer::logger::Lang->printf("nCollected abbreviations and package names:\n");
57
58    # Can be a comma separated list. All files have to be found in include pathes
59    my $allpackagemapnames = installer::converter::convert_stringlist_into_hash(\$packagemapname, ",");
60    foreach my $onepackagemapname ( keys %{$allpackagemapnames} )
61    {
62        my $packagemapref = installer::scriptitems::get_sourcepath_from_filename_and_includepath(\$onepackagemapname, $includepatharrayref, 0);
63
64        if ( $$packagemapref eq "" ) { installer::exiter::exit_program("ERROR: Could not find package map file \"$onepackagemapname\" (propery PACKAGEMAP)!", "read_packagemap"); }
65
66        my $packagemapcontent = installer::files::read_file($$packagemapref);
67
68        for ( my $i = 0; $i <= $#{$packagemapcontent}; $i++ )
69        {
70            my $line = ${$packagemapcontent}[$i];
71
72            if ( $line =~ /^\s*\#/ ) { next; }  # comment line
73            if ( $line =~ /^\s*$/ ) { next; }  # empty line
74
75            if ( $line =~ /^\s*(.*?)\t(.*?)\s*$/ )
76            {
77                my $abbreviation = $1;
78                my $packagename = $2;
79                installer::packagelist::resolve_packagevariables(\$abbreviation, $allvariables, 0);
80                installer::packagelist::resolve_packagevariables(\$packagename, $allvariables, 0);
81
82                # Special handling for language strings %LANGUAGESTRING
83
84                if (( $abbreviation =~ /\%LANGUAGESTRING/ ) || ( $packagename =~ /\%LANGUAGESTRING/ ))
85                {
86                    foreach my $onelang ( @{$languagesarrayref} )
87                    {
88                        my $local_abbreviation = $abbreviation;
89                        my $local_packagename = $packagename;
90                        $local_abbreviation =~ s/\%LANGUAGESTRING/$onelang/g;
91                        $local_packagename =~ s/\%LANGUAGESTRING/$onelang/g;
92
93                        # Logging all abbreviations and packagenames
94                        $installer::logger::Lang->printf("%s : %s : %s\n",
95                            $onelang,
96                            $local_abbreviation,
97                            $local_packagename);
98
99                        if ( exists($installer::globals::dependfilenames{$local_abbreviation}) )
100                        {
101                            installer::exiter::exit_program("ERROR: Packagename for  Solaris package $local_abbreviation already defined ($installer::globals::dependfilenames{$local_abbreviation})!", "read_packagemap");
102                        }
103                        else
104                        {
105                            $installer::globals::dependfilenames{$local_abbreviation} = $local_packagename;
106                        }
107                    }
108                }
109                else
110                {
111                    # Logging all abbreviations and packagenames
112                    $installer::logger::Lang->printf("%s : %s\n", $abbreviation, $packagename);
113
114                    if ( exists($installer::globals::dependfilenames{$abbreviation}) )
115                    {
116                        installer::exiter::exit_program("ERROR: Packagename for  Solaris package $abbreviation already defined ($installer::globals::dependfilenames{$abbreviation})!", "read_packagemap");
117                    }
118                    else
119                    {
120                        $installer::globals::dependfilenames{$abbreviation} = $packagename;
121                    }
122                }
123            }
124            else
125            {
126                my $errorline = $i + 1;
127                installer::exiter::exit_program("ERROR: Wrong syntax in file \"$onepackagemapname\" (line $errorline)!", "read_packagemap");
128            }
129        }
130    }
131
132    $installer::logger::Lang->print("\n");
133    $installer::logger::Lang->print("\n");
134}
135
136############################################################################
137# The header file contains the strings for the epm header in all languages
138############################################################################
139
140sub get_string_from_headerfile
141{
142    my ($searchstring, $language, $fileref) = @_;
143
144    my $returnstring  = "";
145    my $onestring  = "";
146    my $englishstring  = "";
147    my $foundblock = 0;
148    my $foundstring = 0;
149    my $foundenglishstring = 0;
150    my $englishidentifier = "01";
151
152    $searchstring = "[" . $searchstring . "]";
153
154    for ( my $i = 0; $i <= $#{$fileref}; $i++ )
155    {
156        my $line = ${$fileref}[$i];
157
158        if ( $line =~ /^\s*\Q$searchstring\E\s*$/ )
159        {
160            $foundblock = 1;
161            my $counter = $i + 1;
162
163            $line = ${$fileref}[$counter];
164
165            # Beginning of the next block oder Dateiende
166
167            while ((!($line =~ /^\s*\[\s*\w+\s*\]\s*$/ )) && ( $counter <= $#{$fileref} ))
168            {
169                if ( $line =~ /^\s*\Q$language\E\s+\=\s*\"(.*)\"\s*$/ )
170                {
171                    $onestring = $1;
172                    $foundstring = 1;
173                    last;
174                }
175
176                if ( $line =~ /^\s*\Q$englishidentifier\E\s+\=\s*\"(.*)\"\s*$/ )
177                {
178                    $englishstring = $1;
179                    $foundenglishstring = 1;
180                }
181
182                $counter++;
183                $line = ${$fileref}[$counter];
184            }
185        }
186    }
187
188    if ( $foundstring )
189    {
190        $returnstring = $onestring;
191    }
192    else
193    {
194        if ( $foundenglishstring )
195        {
196            $returnstring = $englishstring;
197        }
198        else
199        {
200            installer::exiter::exit_program("ERROR: No string found for $searchstring in epm header file (-h)", "get_string_from_headerfile");
201        }
202    }
203
204    return \$returnstring;
205}
206
207##########################################################
208# Filling the epm file with directories, files and links
209##########################################################
210
211sub put_directories_into_epmfile
212{
213    my ($directoriesarrayref, $epmfileref, $allvariables, $packagerootpath) = @_;
214    my $group = "bin";
215
216    if ( $installer::globals::islinuxbuild )
217    {
218        $group = "root";
219    }
220
221    for ( my $i = 0; $i <= $#{$directoriesarrayref}; $i++ )
222    {
223        my $onedir = ${$directoriesarrayref}[$i];
224        my $dir = "";
225
226        if ( $onedir->{'Dir'} ) { $dir = $onedir->{'Dir'}; }
227
228        # if (!($dir =~ /\bPREDEFINED_/ ))
229        if ((!($dir =~ /\bPREDEFINED_/ )) || ( $dir =~ /\bPREDEFINED_PROGDIR\b/ ))
230        {
231            my $hostname = $onedir->{'HostName'};
232
233            # not including simple directory "/opt"
234            # if (( $allvariables->{'SETSTATICPATH'} ) && ( $hostname eq $packagerootpath )) { next; }
235
236            my $line = "d 755 root $group $hostname -\n";
237
238            push(@{$epmfileref}, $line)
239        }
240    }
241}
242
243sub put_files_into_epmfile
244{
245    my ($filesinproductarrayref, $epmfileref) = @_;
246
247    for ( my $i = 0; $i <= $#{$filesinproductarrayref}; $i++ )
248    {
249        my $onefile = ${$filesinproductarrayref}[$i];
250
251        my $unixrights = $onefile->{'UnixRights'};
252        my $destination = $onefile->{'destination'};
253        my $sourcepath = $onefile->{'sourcepath'};
254
255        my $filetype = "f";
256        my $styles = "";
257        if ( $onefile->{'Styles'} ) { $styles = $onefile->{'Styles'}; }
258        if ( $styles =~ /\bCONFIGFILE\b/ ) { $filetype = "c"; }
259
260        my $group = "bin";
261        if ( $installer::globals::islinuxbuild ) { $group = "root"; }
262        if (( $installer::globals::issolarisbuild ) && ( $onefile->{'SolarisGroup'} )) { $group = $onefile->{'SolarisGroup'}; }
263
264        my $line = "$filetype $unixrights root $group $destination $sourcepath\n";
265
266        push(@{$epmfileref}, $line);
267    }
268}
269
270sub put_links_into_epmfile
271{
272    my ($linksinproductarrayref, $epmfileref) = @_;
273    my $group = "bin";
274
275    if ( $installer::globals::islinuxbuild )
276    {
277        $group = "root";
278    }
279
280
281    for ( my $i = 0; $i <= $#{$linksinproductarrayref}; $i++ )
282    {
283        my $onelink = ${$linksinproductarrayref}[$i];
284        my $destination = $onelink->{'destination'};
285        my $destinationfile = $onelink->{'destinationfile'};
286
287        my $line = "l 000 root $group $destination $destinationfile\n";
288
289        push(@{$epmfileref}, $line)
290    }
291}
292
293sub put_unixlinks_into_epmfile
294{
295    my ($unixlinksinproductarrayref, $epmfileref) = @_;
296    my $group = "bin";
297
298    if ( $installer::globals::islinuxbuild ) { $group = "root"; }
299
300    for ( my $i = 0; $i <= $#{$unixlinksinproductarrayref}; $i++ )
301    {
302        my $onelink = ${$unixlinksinproductarrayref}[$i];
303        my $destination = $onelink->{'destination'};
304        my $target = $onelink->{'Target'};
305
306        my $line = "l 000 root $group $destination $target\n";
307
308        push(@{$epmfileref}, $line)
309    }
310}
311
312###############################################
313# Creating epm header file
314###############################################
315
316sub create_epm_header
317{
318    my ($variableshashref, $filesinproduct, $languagesref, $onepackage) = @_;
319
320    my @epmheader = ();
321
322    my ($licensefilename, $readmefilename);
323
324    my $foundlicensefile = 0;
325    my $foundreadmefile = 0;
326
327    my $line = "";
328    my $infoline = "";
329
330    # %product Apache OpenOffice Software
331    # %version 2.0
332    # %description A really great software
333    # %copyright 1999-2003 by OOo
334    # %vendor Apache OpenOffice project
335    # %license /test/replace/01/LICENSE01
336    # %readme /test/replace/01/README01
337    # %requires foo
338    # %provides bar
339
340    # The first language in the languages array determines the language of license and readme file
341
342    my $searchlanguage = ${$languagesref}[0];
343
344    # using the description for the %product line in the epm list file
345
346    my $productnamestring = $onepackage->{'description'};
347    installer::packagelist::resolve_packagevariables(\$productnamestring, $variableshashref, 0);
348    if ( $variableshashref->{'PRODUCTEXTENSION'} ) { $productnamestring = $productnamestring . " " . $variableshashref->{'PRODUCTEXTENSION'}; }
349
350    $line = "%product" . " " . $productnamestring . "\n";
351    push(@epmheader, $line);
352
353    # Determining the release version
354    # This release version has to be listed in the line %version : %version versionnumber releasenumber
355
356    # if ( $variableshashref->{'PACKAGEVERSION'} ) { $installer::globals::packageversion = $variableshashref->{'PACKAGEVERSION'}; }
357    if ( ! $onepackage->{'packageversion'} ) { installer::exiter::exit_program("ERROR: No packageversion defined for package: $onepackage->{'module'}!", "create_epm_header"); }
358    $installer::globals::packageversion = $onepackage->{'packageversion'};
359    installer::packagelist::resolve_packagevariables(\$installer::globals::packageversion, $variableshashref, 0);
360    if ( $variableshashref->{'PACKAGEREVISION'} ) { $installer::globals::packagerevision = $variableshashref->{'PACKAGEREVISION'}; }
361
362    $line = "%version" . " " . $installer::globals::packageversion . "\n";
363    push(@epmheader, $line);
364
365    $line = "%release" . " " . $installer::globals::packagerevision . "\n";
366    if ( $installer::globals::islinuxrpmbuild ) { $line = "%release" . " " . $installer::globals::buildid . "\n"; }
367    push(@epmheader, $line);
368
369    # Description, Copyright and Vendor are multilingual and are defined in
370    # the string file for the header file ($headerfileref)
371
372    my $descriptionstring = $onepackage->{'description'};
373    installer::packagelist::resolve_packagevariables(\$descriptionstring, $variableshashref, 0);
374    $line = "%description" . " " . $descriptionstring . "\n";
375    push(@epmheader, $line);
376
377    my $copyrightstring = $onepackage->{'copyright'};
378    installer::packagelist::resolve_packagevariables(\$copyrightstring, $variableshashref, 0);
379    $line = "%copyright" . " " . $copyrightstring . "\n";
380    push(@epmheader, $line);
381
382    my $vendorstring = $onepackage->{'vendor'};
383    installer::packagelist::resolve_packagevariables(\$vendorstring, $variableshashref, 0);
384    $line = "%vendor" . " " . $vendorstring . "\n";
385    push(@epmheader, $line);
386
387    # License and Readme file can be included automatically from the file list
388
389    if ( $installer::globals::iswindowsbuild || $installer::globals::isos2 )
390    {
391        $licensefilename = "LICENSE.txt";
392        $readmefilename = "readme.txt";
393    }
394    else
395    {
396        $licensefilename = "LICENSE";
397        $readmefilename = "README";
398    }
399
400    if (( $installer::globals::languagepack )   # in language packs the files LICENSE and README are removed, because they are not language specific
401        || ( $variableshashref->{'NO_README_IN_ROOTDIR'} ))
402    {
403        if ( $installer::globals::iswindowsbuild || $installer::globals::isos2 )
404        {
405            $licensefilename = "LICENSE.txt";
406            $readmefilename = "readme_$searchlanguage.txt";
407        }
408        else
409        {
410            $licensefilename = "LICENSE";
411            $readmefilename = "README_$searchlanguage";
412        }
413    }
414
415    my $license_in_package_defined = 0;
416
417    if ( $installer::globals::issolarisbuild )
418    {
419        if ( $onepackage->{'solariscopyright'} )
420        {
421            $licensefilename = $onepackage->{'solariscopyright'};
422            $license_in_package_defined = 1;
423        }
424    }
425
426    # Process for Linux packages, in which only a very basic license file is
427    # included into the package.
428
429    if ( $installer::globals::islinuxbuild )
430    {
431        if ( $variableshashref->{'COPYRIGHT_INTO_LINUXPACKAGE'} )
432        {
433            $licensefilename = "linuxcopyrightfile";
434            $license_in_package_defined = 1;
435        }
436    }
437    # searching for and readme file
438
439    for ( my $i = 0; $i <= $#{$filesinproduct}; $i++ )
440    {
441        my $onefile = ${$filesinproduct}[$i];
442        my $filename = $onefile->{'Name'};
443        if ( $filename eq $readmefilename )
444        {
445            $foundreadmefile = 1;
446            $line = "%readme" . " " . $onefile->{'sourcepath'} . "\n";
447            push(@epmheader, $line);
448            last;
449        }
450    }
451
452    # searching for and license file
453
454    if ( $license_in_package_defined )
455    {
456        my $fileref = installer::scriptitems::get_sourcepath_from_filename_and_includepath(\$licensefilename, "" , 0);
457
458        if ( $$fileref eq "" ) { installer::exiter::exit_program("ERROR: Could not find license file $licensefilename (A)!", "create_epm_header"); }
459
460        # Special handling to add the content of the file "license_en-US" to the solaris copyrightfile. But not for all products
461
462        if (( $installer::globals::issolarispkgbuild ) && ( ! $variableshashref->{'NO_LICENSE_INTO_COPYRIGHT'} ))
463        {
464            if ( ! $installer::globals::englishlicenseset ) { installer::worker::set_english_license() }
465
466            # The location for the new file
467            my $languagestring = "";
468            for ( my $i = 0; $i <= $#{$languagesref}; $i++ ) { $languagestring = $languagestring . "_" . ${$languagesref}[$i]; }
469            $languagestring =~ s/^\s*_//;
470
471            my $copyrightdir = installer::systemactions::create_directories("copyright", \$languagestring);
472
473            my $copyrightfile = installer::files::read_file($$fileref);
474
475            # Adding license content to copyright file
476            push(@{$copyrightfile}, "\n");
477            for ( my $i = 0; $i <= $#{$installer::globals::englishlicense}; $i++ ) { push(@{$copyrightfile}, ${$installer::globals::englishlicense}[$i]); }
478
479            # New destination for $$fileref
480            $$fileref = $copyrightdir . $installer::globals::separator . "solariscopyrightfile_" . $onepackage->{'module'};
481            if ( -f $$fileref ) { unlink $$fileref; }
482            installer::files::save_file($$fileref, $copyrightfile);
483        }
484
485        $installer::logger::Lang->printf("Using license file: \"%s\"!\n", $$fileref);
486
487        $foundlicensefile = 1;
488        $line = "%license" . " " . $$fileref . "\n";
489        push(@epmheader, $line);
490    }
491    else
492    {
493        # refer to the license in the matching AOO installation
494        # TODO: sync AOO dest license full path with lpacks/sdks/exts
495        my $licpath = "openoffice4/program/" . $licensefilename;
496        $foundlicensefile = 1;
497        $line = "%license " . $licpath . "\n";
498        push(@epmheader, $line);
499    }
500
501    if (!($foundlicensefile))
502    {
503        installer::exiter::exit_program("ERROR: Could not find license file $licensefilename (B)", "create_epm_header");
504    }
505
506    if (!($foundreadmefile))
507    {
508        installer::exiter::exit_program("ERROR: Could not find readme file $readmefilename (C)", "create_epm_header");
509    }
510
511    # including %replaces
512
513    my $replaces = "";
514
515    if (( $installer::globals::issolarispkgbuild ) && ( ! $installer::globals::patch ))
516    {
517        $replaces = "solarisreplaces";   # the name in the packagelist
518    }
519    elsif (( $installer::globals::islinuxbuild ) && ( ! $installer::globals::patch ))
520    {
521        $replaces = "linuxreplaces";    # the name in the packagelist
522    }
523
524    if (( $replaces ) && ( ! $installer::globals::patch ))
525    {
526        if ( $onepackage->{$replaces} )
527        {
528            my $replacesstring = $onepackage->{$replaces};
529
530            my $allreplaces = installer::converter::convert_stringlist_into_array(\$replacesstring, ",");
531
532            for ( my $i = 0; $i <= $#{$allreplaces}; $i++ )
533            {
534                my $onereplaces = ${$allreplaces}[$i];
535                $onereplaces =~ s/\s*$//;
536                installer::packagelist::resolve_packagevariables(\$onereplaces, $variableshashref, 1);
537                if ( $installer::globals::linuxlinkrpmprocess ) { $onereplaces = $onereplaces . "u"; }
538                if ( $installer::globals::debian ) { $onereplaces =~ s/_/-/g; } # Debian allows no underline in package name
539                $line = "%replaces" . " " . $onereplaces . "\n";
540                push(@epmheader, $line);
541            }
542
543            if ( $installer::globals::debian && $variableshashref->{'UNIXPRODUCTNAME'} eq 'openoffice' )
544            {
545                $line = "%provides" . " openoffice.org-unbundled\n";
546                push(@epmheader, $line);
547                $line = "%replaces" . " openoffice.org-bundled\n";
548                push(@epmheader, $line);
549            }
550        }
551    }
552
553    # including the directives for %requires and %provides
554
555    my $provides = "";
556    my $requires = "";
557
558    if ( $installer::globals::issolarispkgbuild )
559    {
560        $provides = "solarisprovides";   # the name in the packagelist
561        $requires = "solarisrequires";   # the name in the packagelist
562    }
563    elsif ( $installer::globals::isfreebsdpkgbuild )
564    {
565        $provides = "freebsdprovides";   # the name in the packagelist
566        $requires = "freebsdrequires";   # the name in the packagelist
567    }
568    elsif (( $installer::globals::islinuxrpmbuild ) &&
569            ( $installer::globals::patch ) &&
570            ( exists($onepackage->{'linuxpatchrequires'}) ))
571    {
572        $provides = "provides";  # the name in the packagelist
573        $requires = "linuxpatchrequires";    # the name in the packagelist
574    }
575    else
576    {
577        $provides = "provides";         # the name in the packagelist
578        $requires = "requires";         # the name in the packagelist
579    }
580
581    # if ( $installer::globals::patch )
582    # {
583    #   $onepackage->{$provides} = "";
584        my $isdict = 0;
585        if ( $onepackage->{'packagename'} =~ /-dict-/ ) { $isdict = 1;  }
586
587    #   $onepackage->{$requires} = "";
588    # }
589
590    if ( $onepackage->{$provides} )
591    {
592        my $providesstring = $onepackage->{$provides};
593
594        my $allprovides = installer::converter::convert_stringlist_into_array(\$providesstring, ",");
595
596        for ( my $i = 0; $i <= $#{$allprovides}; $i++ )
597        {
598            my $oneprovides = ${$allprovides}[$i];
599            $oneprovides =~ s/\s*$//;
600            installer::packagelist::resolve_packagevariables(\$oneprovides, $variableshashref, 1);
601            if ( $installer::globals::linuxlinkrpmprocess ) { $oneprovides = $oneprovides . "u"; }
602            if ( $installer::globals::debian ) { $oneprovides =~ s/_/-/g; } # Debian allows no underline in package name
603            $line = "%provides" . " " . $oneprovides . "\n";
604            push(@epmheader, $line);
605        }
606    }
607
608    if ( $onepackage->{$requires} )
609    {
610        my $requiresstring = $onepackage->{$requires};
611
612        if ( $installer::globals::add_required_package ) { $requiresstring = $requiresstring . "," . $installer::globals::add_required_package; }
613
614        # The requires string can contain the separator "," in the names (descriptions) of the packages
615        # (that are required for Solaris depend files). Therefore "," inside such a description has to
616        # masked with a backslash.
617        # This masked separator need to be found and replaced, before the stringlist is converted into an array.
618        # This replacement has to be turned back after the array is created.
619
620        my $replacementstring = "COMMAREPLACEMENT";
621        $requiresstring = installer::converter::replace_masked_separator($requiresstring, ",", "$replacementstring");
622
623        my $allrequires = installer::converter::convert_stringlist_into_array(\$requiresstring, ",");
624
625        installer::converter::resolve_masked_separator($allrequires, ",", $replacementstring);
626
627        for ( my $i = 0; $i <= $#{$allrequires}; $i++ )
628        {
629            my $onerequires = ${$allrequires}[$i];
630            $onerequires =~ s/\s*$//;
631            installer::packagelist::resolve_packagevariables2(\$onerequires, $variableshashref, 0, $isdict);
632            if ( $installer::globals::debian ) { $onerequires =~ s/_/-/g; } # Debian allows no underline in package name
633
634            # Special handling for Solaris. In depend files, the names of the packages are required, not
635            # only the abbreviation. Therefore there is a special syntax for names in packagelist:
636            # solarisrequires = "SUNWcar (Name="Package name of SUNWcar"),SUNWkvm (Name="Package name of SUNWcar"), ...
637            # if ( $installer::globals::issolarispkgbuild )
638            # {
639            #   if ( $onerequires =~ /^\s*(.*?)\s+\(\s*Name\s*=\s*\"(.*?)\"\s*\)\s*$/ )
640            #   {
641            #       $onerequires = $1;
642            #       $packagename = $2;
643            #       $installer::globals::dependfilenames{$onerequires} = $packagename;
644            #   }
645            # }
646
647            $line = "%requires" . " " . $onerequires . "\n";
648            push(@epmheader, $line);
649        }
650    }
651    else
652    {
653        if ( $installer::globals::add_required_package )
654        {
655            my $requiresstring = $installer::globals::add_required_package;
656
657            my $replacementstring = "COMMAREPLACEMENT";
658            $requiresstring = installer::converter::replace_masked_separator($requiresstring, ",", "$replacementstring");
659            my $allrequires = installer::converter::convert_stringlist_into_array(\$requiresstring, ",");
660            installer::converter::resolve_masked_separator($allrequires, ",", $replacementstring);
661
662            for ( my $i = 0; $i <= $#{$allrequires}; $i++ )
663            {
664                my $onerequires = ${$allrequires}[$i];
665                $onerequires =~ s/\s*$//;
666                installer::packagelist::resolve_packagevariables(\$onerequires, $variableshashref, 0);
667                if ( $installer::globals::debian ) { $onerequires =~ s/_/-/g; } # Debian allows no underline in package name
668
669                # Special handling for Solaris. In depend files, the names of the packages are required, not
670                # only the abbreviation. Therefore there is a special syntax for names in packagelist:
671                # solarisrequires = "SUNWcar (Name="Package name of SUNWcar"),SUNWkvm (Name="Package name of SUNWcar"), ...
672                # if ( $installer::globals::issolarispkgbuild )
673                # {
674                #   if ( $onerequires =~ /^\s*(.*?)\s+\(\s*Name\s*=\s*\"(.*?)\"\s*\)\s*$/ )
675                #   {
676                #       $onerequires = $1;
677                #       $packagename = $2;
678                #       $installer::globals::dependfilenames{$onerequires} = $packagename;
679                #   }
680                # }
681
682                $line = "%requires" . " " . $onerequires . "\n";
683                push(@epmheader, $line);
684            }
685        }
686    }
687
688    return \@epmheader;
689}
690
691#######################################
692# Adding header to epm file
693#######################################
694
695sub adding_header_to_epm_file
696{
697    my ($epmfileref, $epmheaderref) = @_;
698
699    for ( my $i = 0; $i <= $#{$epmheaderref}; $i++ )
700    {
701        push( @{$epmfileref}, ${$epmheaderref}[$i] );
702    }
703
704    push( @{$epmfileref}, "\n\n" );
705}
706
707#####################################################
708# Replace one in shell scripts ( ${VARIABLENAME} )
709#####################################################
710
711sub replace_variable_in_shellscripts
712{
713    my ($scriptref, $variable, $searchstring) = @_;
714
715    for ( my $i = 0; $i <= $#{$scriptref}; $i++ )
716    {
717        ${$scriptref}[$i] =~ s/\$\{$searchstring\}/$variable/g;
718    }
719}
720
721###################################################
722# Replace one in shell scripts ( %VARIABLENAME )
723###################################################
724
725sub replace_percent_variable_in_shellscripts
726{
727    my ($scriptref, $variable, $searchstring) = @_;
728
729    for ( my $i = 0; $i <= $#{$scriptref}; $i++ )
730    {
731        ${$scriptref}[$i] =~ s/\%$searchstring/$variable/g;
732    }
733}
734
735################################################
736# Replacing many variables in shell scripts
737################################################
738
739sub replace_many_variables_in_shellscripts
740{
741    my ($scriptref, $variableshashref) = @_;
742
743    my $key;
744
745    foreach $key (keys %{$variableshashref})
746    {
747        my $value = $variableshashref->{$key};
748        # $value = lc($value);  # lowercase !
749        # if ( $installer::globals::issolarisbuild) { $value =~ s/\.org/org/g; }    # openofficeorg instead of openoffice.org
750        replace_variable_in_shellscripts($scriptref, $value, $key);
751    }
752}
753
754#######################################
755# Adding shell scripts to epm file
756#######################################
757
758sub adding_shellscripts_to_epm_file
759{
760    my ($epmfileref, $shellscriptsfilename, $localrootpath, $allvariableshashref, $filesinpackage) = @_;
761
762    # $installer::globals::shellscriptsfilename
763
764    push( @{$epmfileref}, "\n\n" );
765
766    my $shellscriptsfileref = installer::files::read_file($shellscriptsfilename);
767
768    replace_variable_in_shellscripts($shellscriptsfileref, $localrootpath, "rootpath");
769
770    replace_many_variables_in_shellscripts($shellscriptsfileref, $allvariableshashref);
771
772    for ( my $i = 0; $i <= $#{$shellscriptsfileref}; $i++ )
773    {
774        push( @{$epmfileref}, ${$shellscriptsfileref}[$i] );
775    }
776
777    push( @{$epmfileref}, "\n" );
778}
779
780#################################################
781# Determining the epm on the system
782#################################################
783
784sub find_epm_on_system
785{
786    my ($includepatharrayref) = @_;
787
788    installer::logger::include_header_into_logfile("Check epm on system");
789
790    my $epmname = "epm";
791
792    # epm should be defined through the configure script but we need to
793    # check for it to be defined because of the Sun environment.
794    # Check the environment variable first and if it is not defined,
795    # or if it is but the location is not executable, search further.
796    # It has to be found in the solver or it has to be in the path
797    # (saved in $installer::globals::epm_in_path) or we get the specified
798    # one through the environment (i.e. when --with-epm=... is specified)
799
800    if ($ENV{'EPM'})
801    {
802        if (($ENV{'EPM'} ne "") && (-x "$ENV{'EPM'}"))
803        {
804            $epmname = $ENV{'EPM'};
805        }
806        elsif ( ($ENV{'EPM'} eq "no") || ($ENV{'EPM'} eq "internal") )
807        {
808            $epmname = "epm";
809            my $epmref = installer::scriptitems::get_sourcepath_from_filename_and_includepath( \$epmname, $includepatharrayref, 0);
810            if ($$epmref eq "") { installer::exiter::exit_program("ERROR: Could not find program $epmname (EPM set to \"internal\" or \"no\")!", "find_epm_on_system"); }
811            $epmname = $$epmref;
812        }
813        else
814        {
815            installer::exiter::exit_program("Environment variable EPM set (\"$ENV{'EPM'}\"), but file does not exist or is not executable!", "find_epm_on_system");
816        }
817    }
818    else
819    {
820        my $epmfileref = installer::scriptitems::get_sourcepath_from_filename_and_includepath(\$epmname, $includepatharrayref, 0);
821
822        if (($$epmfileref eq "") && (!($installer::globals::epm_in_path))) { installer::exiter::exit_program("ERROR: Could not find program $epmname!", "find_epm_on_system"); }
823        if (($$epmfileref eq "") && ($installer::globals::epm_in_path)) { $epmname = $installer::globals::epm_path; }
824        if (!($$epmfileref eq "")) { $epmname = $$epmfileref; }
825    }
826
827    $installer::logger::Lang->printf("Using epmfile: %s\n", $epmname);
828
829    return $epmname;
830}
831
832#################################################
833# Determining the epm patch state
834# saved in $installer::globals::is_special_epm
835#################################################
836
837sub set_patch_state
838{
839    my ($epmexecutable) = @_;
840
841    my $infoline = "";
842
843    my $systemcall = "$epmexecutable |";
844    open (EPMPATCH, "$systemcall");
845
846    while (<EPMPATCH>)
847    {
848        chop;
849        if ( $_ =~ /Patched for OpenOffice.org/ ) { $installer::globals::is_special_epm = 1; }
850    }
851
852    close (EPMPATCH);
853
854    if ( $installer::globals::is_special_epm )
855    {
856        $installer::logger::Lang->print("\n");
857        $installer::logger::Lang->print("Patch state: This is a patched version of epm!\n");
858        $installer::logger::Lang->print("\n");
859    }
860    else
861    {
862        $installer::logger::Lang->print("\n");
863        $installer::logger::Lang->print("Patch state: This is an unpatched version of epm!\n");
864        $installer::logger::Lang->print("\n");
865    }
866
867    if ( ( $installer::globals::is_special_epm ) && (($installer::globals::islinuxrpmbuild) || ($installer::globals::issolarispkgbuild)) )
868    {
869        # Special postprocess handling only for Linux RPM and Solaris packages
870        $installer::globals::postprocess_specialepm = 1;
871        $installer::globals::postprocess_standardepm = 0;
872    }
873    else
874    {
875        $installer::globals::postprocess_specialepm = 0;
876        $installer::globals::postprocess_standardepm = 1;
877    }
878}
879
880#################################################
881# LD_PRELOAD string for Debian packages
882#################################################
883
884sub get_ld_preload_string
885{
886    my ($includepatharrayref) = @_;
887
888    my $getuidlibraryname = "getuid.so";
889
890    my $ldpreloadstring;
891
892    my $getuidlibraryref = installer::scriptitems::get_sourcepath_from_filename_and_includepath(\$getuidlibraryname, $includepatharrayref, 0);
893
894    if (($ENV{'FAKEROOT'} ne "no") && ($ENV{'FAKEROOT'} ne "")) {
895
896        $ldpreloadstring = $ENV{'FAKEROOT'};
897
898    } else {
899
900        if ($$getuidlibraryref eq "") { installer::exiter::exit_program("ERROR: Could not find $getuidlibraryname!", "get_ld_preload_string"); }
901
902        my $ldpreloadstring = "LD_PRELOAD=" . $$getuidlibraryref;
903    }
904
905    return $ldpreloadstring;
906}
907
908#################################################
909# Calling epm to create the installation sets
910#################################################
911
912sub call_epm
913{
914    my ($epmname, $epmlistfilename, $packagename, $includepatharrayref) = @_;
915
916    installer::logger::include_header_into_logfile("epm call for $packagename");
917
918    my $packageformat = $installer::globals::packageformat;
919
920    my $localpackagename = $packagename;
921    # Debian allows only lowercase letters in package name
922    if ( $installer::globals::debian ) { $localpackagename = lc($localpackagename); }
923
924    my $outdirstring = "";
925    if ( $installer::globals::epmoutpath ne "" ) { $outdirstring = " --output-dir $installer::globals::epmoutpath"; }
926
927    # Debian package build needs fakeroot or our LD_PRELOAD hack for correct rights
928
929    my $ldpreloadstring = "";
930
931    if ( $installer::globals::debian ) { $ldpreloadstring = get_ld_preload_string($includepatharrayref) . " "; }
932
933    my $extraflags = "";
934        if ($ENV{'EPM_FLAGS'}) { $extraflags = $ENV{'EPM_FLAGS'}; }
935
936    my $verboseflag = "-v";
937    if ( ! $installer::globals::quiet ) { $verboseflag = "-v2"; };
938
939    my $systemcall = $ldpreloadstring . $epmname . " -f " . $packageformat . " " . $extraflags . " " . $localpackagename . " " . $epmlistfilename . $outdirstring . " " . $verboseflag . " " . " 2\>\&1 |";
940
941    $installer::logger::Info->printf("... %s ...\n", $systemcall);
942
943    my $maxepmcalls = 3;
944
945    for ( my $i = 1; $i <= $maxepmcalls; $i++ )
946    {
947        my @epmoutput = ();
948
949        open (EPM, "$systemcall");
950        while (<EPM>) {push(@epmoutput, $_); }
951        close (EPM);
952
953        my $returnvalue = $?;   # $? contains the return value of the systemcall
954
955        $installer::logger::Lang->printf("Systemcall  (Try %d): \n", $i, $systemcall);
956
957        for ( my $j = 0; $j <= $#epmoutput; $j++ )
958        {
959            if ( $i < $maxepmcalls ) { $epmoutput[$j] =~ s/\bERROR\b/PROBLEM/ig; }
960            $installer::logger::Lang->print($epmoutput[$j]);
961        }
962
963        if ($returnvalue)
964        {
965            $installer::logger::Lang->printf("Try %d : Could not execute \"%s\"!\n", $i, $systemcall);
966            if ( $i == $maxepmcalls ) { installer::exiter::exit_program("ERROR: \"$systemcall\"!", "call_epm"); }
967        }
968        else
969        {
970            $installer::logger::Info->printf("Success: Executed (Try %d): \"%s\" successfully\n", $i, $systemcall);
971            $installer::logger::Lang->printf("Success: Executed (Try %d): \"%s\" successfully\n", $i, $systemcall);
972            last;
973        }
974    }
975}
976
977#####################################################################
978# Adding the new line for relocatables into pkginfo file (Solaris)
979# or spec file (Linux) created by epm
980#####################################################################
981
982sub add_one_line_into_file
983{
984    my ($file, $insertline, $filename) = @_;
985
986    if ( $installer::globals::issolarispkgbuild )
987    {
988        push(@{$file}, $insertline);        # simply adding at the end of pkginfo file
989    }
990
991    if ( $installer::globals::islinuxrpmbuild )
992    {
993        # Adding behind the line beginning with: Group:
994
995        my $inserted_line = 0;
996
997        for ( my $i = 0; $i <= $#{$file}; $i++ )
998        {
999            if ( ${$file}[$i] =~ /^\s*Group\:\s*/ )
1000            {
1001                splice(@{$file},$i+1,0,$insertline);
1002                $inserted_line = 1;
1003                last;
1004            }
1005        }
1006
1007        if (! $inserted_line) { installer::exiter::exit_program("ERROR: Did not find string \"Group:\" in file: $filename", "add_one_line_into_file"); }
1008    }
1009
1010    $insertline =~ s/\s*$//;    # removing line end for correct logging
1011    $installer::logger::Lang->printf("Success: Added line %s into file !\n", $insertline, $filename);
1012}
1013
1014#####################################################################
1015# Setting the revision VERSION=1.9,REV=66  .
1016# Also adding the new line: "AutoReqProv: no"
1017#####################################################################
1018
1019sub set_revision_in_pkginfo
1020{
1021    my ($file, $filename, $variables, $packagename) = @_;
1022
1023    my $revisionstring = "\,REV\=" . $installer::globals::packagerevision;
1024
1025    # Adding also a time string to the revision. Syntax: VERSION=8.0.0,REV=66.2005.01.24
1026
1027    my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime(time);
1028
1029    $mday = $mday;
1030    $mon = $mon + 1;
1031    $year = $year + 1900;
1032
1033    if ( $mday < 10 ) { $mday = "0" . $mday; }
1034    if ( $mon < 10 ) { $mon = "0" . $mon; }
1035    $datestring = $year . "." . $mon . "." . $mday;
1036    $revisionstring = $revisionstring . "." . $datestring;
1037
1038    for ( my $i = 0; $i <= $#{$file}; $i++ )
1039    {
1040        if ( ${$file}[$i] =~ /^\s*(VERSION\=.*?)\s*$/ )
1041        {
1042            my $oldstring = $1;
1043            my $newstring = $oldstring . $revisionstring;   # also adding the date string
1044            ${$file}[$i] =~ s/$oldstring/$newstring/;
1045            $installer::logger::Lang->printf("Info: Changed in %s file: \"%s\" to \"\"!\n",
1046                $filename,
1047                $oldstring,
1048                $newstring);
1049            last;
1050        }
1051    }
1052
1053    # For Update and Patch reasons, this string can also be kept constant
1054
1055    my $pkgversion = "SOLSPARCPKGVERSION";
1056    if ( $installer::globals::issolarisx86build ) { $pkgversion = "SOLIAPKGVERSION"; }
1057
1058    if (( $variables->{$pkgversion} ) && ( $variables->{$pkgversion} ne "" ))
1059    {
1060        if ( $variables->{$pkgversion} ne "FINALVERSION" )
1061        {
1062            # In OOo 3.x timeframe, this string is no longer unique for all packages, because of the three layer.
1063            # In the string: "3.0.0,REV=9.2008.09.30" only the part "REV=9.2008.09.30" can be unique for all packages
1064            # and therefore be set as $pkgversion.
1065            # The first part "3.0.0" has to be derived from the
1066
1067            my $version = $installer::globals::packageversion;
1068            if ( $version =~ /^\s*(\d+)\.(\d+)\.(\d+)\s*$/ )
1069            {
1070                my $major = $1;
1071                my $minor = $2;
1072                my $micro = $3;
1073
1074                my $finalmajor = $major;
1075                my $finalminor = $minor;
1076                my $finalmicro = 0;
1077
1078                # if (( $packagename =~ /-ure\s*$/ ) && ( $finalmajor == 1 )) { $finalminor = 4; }
1079
1080                $version = "$finalmajor.$finalminor.$finalmicro";
1081            }
1082
1083            my $datestring = $variables->{$pkgversion};
1084
1085            # Allowing some packages to have another date of creation.
1086            # They can be defined in product definition using a key like "SOLSPARCPKGVERSION_$packagename"
1087
1088            my $additionalkey = $pkgversion . "_" . $packagename;
1089            if (( $variables->{$additionalkey} ) && ( $variables->{$additionalkey} ne "" )) { $datestring = $variables->{$additionalkey}; }
1090
1091            my $versionstring = "$version,$datestring";
1092
1093            for ( my $i = 0; $i <= $#{$file}; $i++ )
1094            {
1095                if ( ${$file}[$i] =~ /^\s*(VERSION\=).*?\s*$/ )
1096                {
1097                    my $start = $1;
1098                    my $newstring = $start . $versionstring . "\n"; # setting the complete new string
1099                    my $oldstring = ${$file}[$i];
1100                    ${$file}[$i] = $newstring;
1101                    $oldstring =~ s/\s*$//;
1102                    $newstring =~ s/\s*$//;
1103                    $installer::logger::Lang->printf("Info: Changed in %s file: \"%s\" to \"\"!\n", $filename, $oldstring, $newstring);
1104                    last;
1105                }
1106            }
1107        }
1108    }
1109}
1110
1111########################################################
1112# Setting Patch information for Respin versions
1113# into pkginfo file. This prevents Respin versions
1114# from patching.
1115########################################################
1116
1117sub set_patchlist_in_pkginfo_for_respin
1118{
1119    my ($changefile, $filename, $allvariables, $packagename) = @_;
1120
1121    my $patchlistname = "SOLSPARCPATCHLISTFORRESPIN";
1122    if ( $installer::globals::issolarisx86build ) { $patchlistname = "SOLIAPATCHLISTFORRESPIN"; }
1123
1124    if ( $allvariables->{$patchlistname} )
1125    {
1126        # patchlist separator is a blank
1127        my $allpatchesstring = $allvariables->{$patchlistname};
1128        my @usedpatches = ();
1129
1130        # Analyzing the patchlist
1131        # Syntax: 120186-10 126411-01(+core-01) -> use 126411-01 only for core-01
1132        # Syntax: 120186-10 126411-01(-core-01) -> use 126411-01 for all packages except for core-01
1133        my $allpatches = installer::converter::convert_whitespace_stringlist_into_array(\$allpatchesstring);
1134
1135        for ( my $i = 0; $i <= $#{$allpatches}; $i++ )
1136        {
1137            my $patchdefinition = ${$allpatches}[$i];
1138
1139            my $patchid = "";
1140            my $symbol = "";
1141            my $constraint = "";
1142            my $isusedpatch = 0;
1143
1144            if ( $patchdefinition =~ /^\s*(.+)\(([+-])(.+)\)\s*$/ )
1145            {
1146                $patchid = $1;
1147                $symbol = $2;
1148                $constraint = $3;
1149            }
1150            elsif (( $patchdefinition =~ /\(/ ) || ( $patchdefinition =~ /\)/ ))    # small syntax check
1151            {
1152                # if there is a bracket in the $patchdefinition, but it does not
1153                # match the if-condition, this is an erroneous definition.
1154                installer::exiter::exit_program("ERROR: Unknown patch string: $patchdefinition", "set_patchlist_in_pkginfo_for_respin");
1155            }
1156            else
1157            {
1158                $patchid = $patchdefinition;
1159                $isusedpatch = 1; # patches without constraint are always included
1160            }
1161
1162            if ( $symbol ne "" )
1163            {
1164                if ( $symbol eq "+" )
1165                {
1166                    if ( $packagename =~ /^.*\Q$constraint\E\s*$/ ) { $isusedpatch = 1; }
1167                }
1168
1169                if ( $symbol eq "-" )
1170                {
1171                    if ( ! ( $packagename =~ /^.*\Q$constraint\E\s*$/ )) { $isusedpatch = 1; }
1172                }
1173            }
1174
1175            if ( $isusedpatch ) { push(@usedpatches, $patchid); }
1176        }
1177
1178        if ( $#usedpatches > -1 )
1179        {
1180            my $patchstring = installer::converter::convert_array_to_space_separated_string(\@usedpatches);
1181
1182            my $newline = "PATCHLIST=" . $patchstring . "\n";
1183            add_one_line_into_file($changefile, $newline, $filename);
1184
1185            # Adding patch info for each used patch in the patchlist
1186
1187            for ( my $i = 0; $i <= $#usedpatches; $i++ )
1188            {
1189                my $patchid = $usedpatches[$i];
1190                my $key = "PATCH_INFO_" . $patchid;
1191                $key =~ s/\s*$//;
1192
1193                if ( ! $allvariables->{$key} ) { installer::exiter::exit_program("ERROR: No Patch info available in zip list file for $key", "set_patchlist_in_pkginfo"); }
1194                my $value = set_timestamp_in_patchinfo($allvariables->{$key});
1195                $newline = $key . "=" . $value . "\n";
1196
1197                add_one_line_into_file($changefile, $newline, $filename);
1198            }
1199        }
1200    }
1201}
1202
1203########################################################
1204# Solaris requires, that the time of patch installation
1205# must not be empty.
1206# Format: Mon Mar 24 11:20:56 PDT 2008
1207# Log file: Tue Apr 29 23:26:19 2008 (04:31 min.)
1208# Replace string: ${TIMESTAMP}
1209########################################################
1210
1211sub set_timestamp_in_patchinfo
1212{
1213    my ($value) = @_;
1214
1215    my $currenttime = localtime();
1216
1217    if ( $currenttime =~ /^\s*(.+?)(\d\d\d\d)\s*$/ )
1218    {
1219        my $start = $1;
1220        my $year = $2;
1221        $currenttime = $start . "CET " . $year;
1222    }
1223
1224    $value =~ s/\$\{TIMESTAMP\}/$currenttime/;
1225
1226    return $value;
1227}
1228
1229########################################################
1230# Setting MAXINST=1000 into the pkginfo file.
1231########################################################
1232
1233sub set_maxinst_in_pkginfo
1234{
1235    my ($changefile, $filename) = @_;
1236
1237    my $newline = "MAXINST\=1000\n";
1238
1239    add_one_line_into_file($changefile, $newline, $filename);
1240}
1241
1242#############################################################
1243# Setting several Solaris variables into the pkginfo file.
1244#############################################################
1245
1246sub set_solaris_parameter_in_pkginfo
1247{
1248    my ($changefile, $filename, $allvariables) = @_;
1249
1250    my $newline = "";
1251
1252    # SUNW_PRODNAME
1253    # SUNW_PRODVERS
1254    # SUNW_PKGVERS
1255    # Not: SUNW_PKGTYPE
1256    # HOTLINE
1257    # EMAIL
1258
1259    my $productname = $allvariables->{'PRODUCTNAME'};
1260    $newline = "SUNW_PRODNAME=$productname\n";
1261    add_one_line_into_file($changefile, $newline, $filename);
1262
1263    my $productversion = "";
1264    if ( $allvariables->{'PRODUCTVERSION'} )
1265    {
1266        $productversion = $allvariables->{'PRODUCTVERSION'};
1267        if ( $allvariables->{'PRODUCTEXTENSION'} ) { $productversion = $productversion . "/" . $allvariables->{'PRODUCTEXTENSION'}; }
1268    }
1269    $newline = "SUNW_PRODVERS=$productversion\n";
1270    add_one_line_into_file($changefile, $newline, $filename);
1271
1272    $newline = "SUNW_PKGVERS=1\.0\n";
1273    add_one_line_into_file($changefile, $newline, $filename);
1274
1275    if ( $allvariables->{'SUNW_PKGTYPE'} )
1276    {
1277        $newline = "SUNW_PKGTYPE=$allvariables->{'SUNW_PKGTYPE'}\n";
1278        add_one_line_into_file($changefile, $newline, $filename);
1279    }
1280    else
1281    {
1282        $newline = "SUNW_PKGTYPE=\n";
1283        add_one_line_into_file($changefile, $newline, $filename);
1284    }
1285
1286    $newline = "HOTLINE=Please contact your local service provider\n";
1287    add_one_line_into_file($changefile, $newline, $filename);
1288
1289    $newline = "EMAIL=\n";
1290    add_one_line_into_file($changefile, $newline, $filename);
1291
1292}
1293
1294#####################################################################
1295# epm uses as archtecture for Solaris x86 "i86pc". This has to be
1296# changed to "i386".
1297#####################################################################
1298
1299sub fix_architecture_setting
1300{
1301    my ($changefile) = @_;
1302
1303    for ( my $i = 0; $i <= $#{$changefile}; $i++ )
1304    {
1305        if ( ${$changefile}[$i] =~ /^\s*ARCH=i86pc\s*$/ )
1306        {
1307            ${$changefile}[$i] =~ s/i86pc/i386/;
1308            last;
1309        }
1310
1311    }
1312}
1313
1314#####################################################################
1315# Adding a new line for topdir into specfile, removing old
1316# topdir if set.
1317#####################################################################
1318
1319sub set_topdir_in_specfile
1320{
1321    my ($changefile, $filename, $newepmdir) = @_;
1322
1323    # $newepmdir =~ s/^\s*\.//; # removing leading "."
1324    $newepmdir = cwd() . $installer::globals::separator . $newepmdir; # only absolute path allowed
1325
1326    # removing "%define _topdir", if existing
1327
1328    for ( my $i = 0; $i <= $#{$changefile}; $i++ )
1329    {
1330        if ( ${$changefile}[$i] =~ /^\s*\%define _topdir\s+/ )
1331        {
1332            my $removeline = ${$changefile}[$i];
1333            $removeline =~ s/\s*$//;
1334            splice(@{$changefile},$i,1);
1335            $installer::logger::Lang->printf("Info: Removed line \"%s\" from file %s!\n", $removeline, $filename);
1336            last;
1337        }
1338    }
1339
1340    # Adding "topdir" behind the line beginning with: Group:
1341
1342    my $inserted_line = 0;
1343
1344    my $topdirline = "\%define _topdir $newepmdir\n";
1345
1346    for ( my $i = 0; $i <= $#{$changefile}; $i++ )
1347    {
1348        if ( ${$changefile}[$i] =~ /^\s*Group\:\s*/ )
1349        {
1350            splice(@{$changefile},$i+1,0,$topdirline);
1351            $inserted_line = 1;
1352            $topdirline =~ s/\s*$//;
1353            $installer::logger::Lang->printf("Success: Added line %s into file %s!\n", $topdirline, $filename);
1354        }
1355    }
1356
1357    if (! $inserted_line) { installer::exiter::exit_program("ERROR: Did not find string \"Group:\" in file: $filename", "set_topdir_in_specfile"); }
1358
1359}
1360
1361#####################################################################
1362# Setting the packager in the spec file
1363# Syntax: Packager: abc@def
1364#####################################################################
1365
1366sub set_packager_in_specfile
1367{
1368    my ($changefile) = @_;
1369
1370    my $packager = $installer::globals::longmanufacturer;
1371
1372    for ( my $i = 0; $i <= $#{$changefile}; $i++ )
1373    {
1374        if ( ${$changefile}[$i] =~ /^\s*Packager\s*:\s*(.+?)\s*$/ )
1375        {
1376            my $oldstring = $1;
1377            ${$changefile}[$i] =~ s/\Q$oldstring\E/$packager/;
1378            $installer::logger::Lang->printf("Info: Changed Packager in spec file from %s to %s!\n",
1379                $oldstring,
1380                $packager);
1381            last;
1382        }
1383    }
1384}
1385
1386#####################################################################
1387# Setting the requirements in the spec file (i81494)
1388# Syntax: PreReq: "requirements" (only for shared extensions)
1389#####################################################################
1390
1391sub set_prereq_in_specfile
1392{
1393    my ($changefile) = @_;
1394
1395    my $prereq = "PreReq:";
1396
1397    for ( my $i = 0; $i <= $#{$changefile}; $i++ )
1398    {
1399        if ( ${$changefile}[$i] =~ /^\s*Requires:\s*(.+?)\s*$/ )
1400        {
1401            my $oldstring = ${$changefile}[$i];
1402            ${$changefile}[$i] =~ s/Requires:/$prereq/;
1403            $installer::logger::Lang->printf("Info: Changed requirements in spec file from %s to %s!\n",
1404                $oldstring,
1405                ${$changefile}[$i]);
1406        }
1407    }
1408}
1409
1410#####################################################################
1411# Setting the Auto[Req]Prov line and __find_requires
1412#####################################################################
1413
1414sub set_autoprovreq_in_specfile
1415{
1416    my ($changefile, $findrequires, $bindir) = @_;
1417
1418    my $autoreqprovline;
1419
1420    if ( $findrequires )
1421    {
1422        $autoreqprovline = "AutoProv\: no\n%define __find_requires $bindir/$findrequires\n";
1423    }
1424    else
1425    {
1426        $autoreqprovline = "AutoReqProv\: no\n";
1427    }
1428
1429    $autoreqprovline .= "%define _binary_filedigest_algorithm 1\n%define _binary_payload w9.gzdio\n";
1430
1431    for ( my $i = 0; $i <= $#{$changefile}; $i++ )
1432    {
1433        # Adding "autoreqprov" behind the line beginning with: Group:
1434        if ( ${$changefile}[$i] =~ /^\s*Group\:\s*/ )
1435        {
1436            splice(@{$changefile},$i+1,0,$autoreqprovline);
1437            $autoreqprovline =~ s/\s*$//;
1438            $installer::logger::Lang->printf("Success: Added line %s into spec file!\n", $autoreqprovline);
1439            last;
1440        }
1441    }
1442}
1443
1444#####################################################################
1445# Replacing Copyright with License in the spec file
1446# Syntax: License: ALv2 (older usages were LGPL, SISSL)
1447#####################################################################
1448
1449sub set_license_in_specfile
1450{
1451    my ($changefile, $variableshashref) = @_;
1452
1453    my $license = $variableshashref->{'LICENSENAME'};
1454
1455    for ( my $i = 0; $i <= $#{$changefile}; $i++ )
1456    {
1457        if ( ${$changefile}[$i] =~ /^\s*Copyright\s*:\s*(.+?)\s*$/ )
1458        {
1459            ${$changefile}[$i] = "License: $license\n";
1460            $installer::logger::Lang->printf("Info: Replaced Copyright with License: %s !\n", $license);
1461            last;
1462        }
1463    }
1464}
1465
1466#########################################################
1467# Building relocatable Solaris packages means:
1468# 1. Add "BASEDIR=/opt" into pkginfo
1469# 2. Remove "/opt/" from all objects in prototype file
1470# For step2 this function exists
1471# Sample: d none /opt/openofficeorg20/help 0755 root other
1472# -> d none openofficeorg20/help 0755 root other
1473#########################################################
1474
1475sub make_prototypefile_relocatable
1476{
1477    my ($prototypefile, $relocatablepath) = @_;
1478
1479    for ( my $i = 0; $i <= $#{$prototypefile}; $i++ )
1480    {
1481        if ( ${$prototypefile}[$i] =~ /^\s*\w\s+\w+\s+\/\w+/ )  # this is an object line
1482        {
1483            ${$prototypefile}[$i] =~ s/$relocatablepath//;  # Important: $relocatablepath has a "/" at the end. Example "/opt/"
1484        }
1485    }
1486
1487    # If the $relocatablepath is "/opt/openoffice20/" the line "d none /opt/openoffice20" was not changed.
1488    # This line has to be removed now
1489
1490    if ( $relocatablepath ne "/" ) { $relocatablepath =~ s/\/\s*$//; }      # removing the ending slash
1491
1492    for ( my $i = 0; $i <= $#{$prototypefile}; $i++ )
1493    {
1494        if ( ${$prototypefile}[$i] =~ /^\s*d\s+\w+\s+\Q$relocatablepath\E/ )
1495        {
1496            my $line = ${$prototypefile}[$i];
1497            splice(@{$prototypefile},$i,1); # removing the line
1498            $line =~ s/\s*$//;
1499            $installer::logger::Lang->printf("Info: Removed line \"%s\" from prototype file!\n", $line);
1500            last;
1501        }
1502    }
1503
1504    # Making "\$" to "$" in prototype file. "\$" was created by epm.
1505
1506    for ( my $i = 0; $i <= $#{$prototypefile}; $i++ )
1507    {
1508        if ( ${$prototypefile}[$i] =~ /\\\$/ )
1509        {
1510            ${$prototypefile}[$i] =~ s/\\\$/\$/g;
1511            $installer::logger::Lang->printf("Info: Changed line in prototype file: %s !\n", ${$prototypefile}[$i]);
1512        }
1513    }
1514}
1515
1516
1517#########################################################################
1518# In scp the flag VOLATEFILE can be used. This shall lead to style "v"
1519# in Solaris prototype file. This is not supported by epm and has
1520# therefore to be included in prototypefile, not in epm list file.
1521#########################################################################
1522
1523sub set_volatilefile_into_prototypefile
1524{
1525    my ($prototypefile, $filesref) = @_;
1526
1527    for ( my $i = 0; $i <= $#{$filesref}; $i++ )
1528    {
1529        my $onefile = ${$filesref}[$i];
1530
1531        my $styles = "";
1532        if ( $onefile->{'Styles'} ) { $styles = $onefile->{'Styles'}; }
1533
1534        if ( $styles =~ /\bVOLATILEFILE\b/ )
1535        {
1536            my $sourcepath = $onefile->{'sourcepath'};
1537
1538            for ( my $j = 0; $j <= $#{$prototypefile}; $j++ )
1539            {
1540                if (( ${$prototypefile}[$j] =~ /^\s*f\s+none\s+/ ) && ( ${$prototypefile}[$j] =~ /\=\Q$sourcepath\E\s+/ ))
1541                {
1542                    my $oldline = ${$prototypefile}[$j];
1543                    ${$prototypefile}[$j] =~ s/^\s*f/v/;
1544                    my $newline = ${$prototypefile}[$j];
1545                    $oldline =~ s/\s*$//;
1546                    $newline =~ s/\s*$//;
1547                    $installer::logger::Lang->printf(
1548                        "Volatile file: Changing content from \"%s\" to \"%s\" .\n",
1549                        $oldline,
1550                        $newline);
1551                    last;
1552                }
1553            }
1554        }
1555    }
1556}
1557
1558#########################################################################
1559# Replacing the variables in the Solaris patch shell scripts.
1560# Taking care, that multiple slashes are not always removed.
1561#########################################################################
1562
1563sub replace_variables_in_shellscripts_for_patch
1564{
1565    my ($scriptfile, $scriptfilename, $oldstring, $newstring) = @_;
1566
1567    for ( my $i = 0; $i <= $#{$scriptfile}; $i++ )
1568    {
1569        if ( ${$scriptfile}[$i] =~ /\Q$oldstring\E/ )
1570        {
1571            my $oldline = ${$scriptfile}[$i];
1572            if (( $oldstring eq "PRODUCTDIRECTORYNAME" ) && ( $newstring eq "" )) { $oldstring = $oldstring . "/"; }
1573            ${$scriptfile}[$i] =~ s/\Q$oldstring\E/$newstring/g;
1574            $installer::logger::Lang->printf("Info: Substituting in %s %s by %s\n",
1575                $scriptfilename, $oldstring, $newstring);
1576        }
1577    }
1578}
1579
1580#########################################################################
1581# Replacing the variables in the shell scripts or in the epm list file
1582# Linux: spec file
1583# Solaris: preinstall, postinstall, preremove, postremove
1584# If epm is used in the original version (not relocatable)
1585# the variables have to be exchanged in the list file,
1586# created for epm.
1587#########################################################################
1588
1589sub replace_variables_in_shellscripts
1590{
1591    my ($scriptfile, $scriptfilename, $oldstring, $newstring) = @_;
1592
1593    my $debug = 0;
1594    if ( $oldstring eq "PRODUCTDIRECTORYNAME" ) { $debug = 1; }
1595
1596    for ( my $i = 0; $i <= $#{$scriptfile}; $i++ )
1597    {
1598        if ( ${$scriptfile}[$i] =~ /\Q$oldstring\E/ )
1599        {
1600            my $oldline = ${$scriptfile}[$i];
1601            ${$scriptfile}[$i] =~ s/\Q$oldstring\E/$newstring/g;
1602            ${$scriptfile}[$i] =~ s/\/\//\//g;  # replacing "//" by "/" , if path $newstring is empty!
1603            $installer::logger::Lang->printf("Info: Substituting in %s %s by %s\n",
1604                $scriptfilename,
1605                $oldstring,
1606                $newstring);
1607            if ( $debug )
1608            {
1609                $installer::logger::Lang->printf("Old Line: %s", $oldline);
1610                $installer::logger::Lang->printf("New Line: %s", ${$scriptfile}[$i]);
1611            }
1612        }
1613    }
1614}
1615
1616############################################################
1617# Determinig the directory created by epm, in which the
1618# RPMS or Solaris packages are created.
1619############################################################
1620
1621sub determine_installdir_ooo
1622{
1623    # A simple "ls" command returns the directory name
1624
1625    my $dirname = "";
1626
1627    my $systemcall = "ls |";
1628    open (LS, "$systemcall");
1629    $dirname = <LS>;
1630    close (LS);
1631
1632    $dirname =~ s/\s*$//;
1633
1634    $installer::logger::Lang->printf("Info: Directory created by epm: %s\n", $dirname);
1635
1636    return $dirname;
1637}
1638
1639############################################################
1640# Setting the tab content into the file container
1641############################################################
1642
1643sub set_tab_into_datafile
1644{
1645    my ($changefile, $filesref) = @_;
1646
1647    my @newclasses = ();
1648    my $newclassesstring = "";
1649
1650    if ( $installer::globals::issolarispkgbuild )
1651    {
1652        for ( my $i = 0; $i <= $#{$filesref}; $i++ )
1653        {
1654            my $onefile = ${$filesref}[$i];
1655
1656            if ( $onefile->{'SolarisClass'} )
1657            {
1658                my $sourcepath = $onefile->{'sourcepath'};
1659
1660                for ( my $j = 0; $j <= $#{$changefile}; $j++ )
1661                {
1662                    if (( ${$changefile}[$j] =~ /^\s*f\s+none\s+/ ) && ( ${$changefile}[$j] =~ /\=\Q$sourcepath\E\s+/ ))
1663                    {
1664                        my $oldline = ${$changefile}[$j];
1665                        ${$changefile}[$j] =~ s/f\s+none/e $onefile->{'SolarisClass'}/;
1666                        my $newline = ${$changefile}[$j];
1667                        $oldline =~ s/\s*$//;
1668                        $newline =~ s/\s*$//;
1669
1670                        $installer::logger::Lang->printf("TAB: Changing content from \"%s\" to \"%s\" .\n",
1671                            $oldline, $newline);
1672
1673                        # collecting all new classes
1674                        if (! installer::existence::exists_in_array($onefile->{'SolarisClass'}, \@newclasses))
1675                        {
1676                            push(@newclasses, $onefile->{'SolarisClass'});
1677                        }
1678
1679                        last;
1680                    }
1681                }
1682            }
1683        }
1684
1685        $newclassesstring = installer::converter::convert_array_to_space_separated_string(\@newclasses);
1686    }
1687
1688    if ( $installer::globals::islinuxrpmbuild )
1689    {
1690        for ( my $i = 0; $i <= $#{$filesref}; $i++ )
1691        {
1692            my $onefile = ${$filesref}[$i];
1693
1694            if ( $onefile->{'SpecFileContent'} )
1695            {
1696                my $destination = $onefile->{'destination'};
1697
1698                for ( my $j = 0; $j <= $#{$changefile}; $j++ )
1699                {
1700                    if ( ${$changefile}[$j] =~ /^\s*(\%attr\(.*\))\s+(\".*?\Q$destination\E\"\s*)$/ )
1701                    {
1702                        my $begin = $1;
1703                        my $end = $2;
1704
1705                        my $oldline = ${$changefile}[$j];
1706                        ${$changefile}[$j] = $begin . " " . $onefile->{'SpecFileContent'} . " " . $end;
1707                        my $newline = ${$changefile}[$j];
1708
1709                        $oldline =~ s/\s*$//;
1710                        $newline =~ s/\s*$//;
1711
1712                        $installer::logger::Lang->printf(
1713                            "TAB: Changing content from \"%s\" to \"%s\" .\n", $oldline, $newline);
1714
1715                        last;
1716                    }
1717                }
1718            }
1719        }
1720    }
1721
1722    return $newclassesstring;
1723}
1724
1725############################################################
1726# Including additional classes into the pkginfo file
1727############################################################
1728
1729sub include_classes_into_pkginfo
1730{
1731    my ($changefile, $classesstring) = @_;
1732
1733    for ( my $i = 0; $i <= $#{$changefile}; $i++ )
1734    {
1735        if ( ${$changefile}[$i] =~ /^\s*CLASSES\=none/ )
1736        {
1737            ${$changefile}[$i] =~ s/\s*$//;
1738            my $oldline = ${$changefile}[$i];
1739            ${$changefile}[$i] = ${$changefile}[$i] . " " . $classesstring . "\n";
1740            my $newline = ${$changefile}[$i];
1741            $newline =~ s/\s*$//;
1742
1743            $installer::logger::Lang->printf("pkginfo file: Changing content from \"%s\" to \"%s\" .\n",
1744                $oldline, $newline);
1745        }
1746    }
1747}
1748
1749##########################################################################################
1750# Checking, if an extension is included into the package (Linux).
1751# All extension files have to be installed into directory
1752# share/extension/install
1753# %attr(0444,root,root) "/opt/staroffice8/share/extension/install/SunSearchToolbar.oxt"
1754##########################################################################################
1755
1756sub is_extension_package
1757{
1758    my ($specfile) = @_;
1759
1760    my $is_extension_package = 0;
1761
1762    for ( my $i = 0; $i <= $#{$specfile}; $i++ )
1763    {
1764        my $line = ${$specfile}[$i];
1765        if ( $line =~ /share\/extension\/install\/.*?\.oxt\"\s*$/ )
1766        {
1767            $is_extension_package = 1;
1768            last;
1769        }
1770    }
1771
1772    return $is_extension_package;
1773}
1774
1775######################################################################
1776# Checking, if an extension is included into the package (Solaris).
1777# All extension files have to be installed into directory
1778# share/extension/install
1779######################################################################
1780
1781sub contains_extension_dir
1782{
1783    my ($prototypefile) = @_;
1784
1785    my $contains_extension_dir = 0;
1786
1787    # d none opt/openoffice.org3/share/extensions/
1788
1789    for ( my $i = 0; $i <= $#{$prototypefile}; $i++ )
1790    {
1791        my $line = ${$prototypefile}[$i];
1792        if ( $line =~ /^\s*d\s+none\s.*\/share\/extensions\// )
1793        {
1794            $contains_extension_dir = 1;
1795            last;
1796        }
1797    }
1798
1799    return $contains_extension_dir;
1800}
1801
1802############################################################
1803# A Solaris patch contains 7 specific scripts
1804############################################################
1805
1806sub add_scripts_into_prototypefile
1807{
1808    my ($prototypefile, $prototypefilename, $languagestringref, $staticpath) = @_;
1809
1810    # The files are stored in the directory $installer::globals::patchincludepath
1811    # The file names are available via @installer::globals::solarispatchscripts
1812
1813    my $path = $installer::globals::patchincludepath;
1814    $path =~ s/\/\s*$//;
1815    $path = $path . $installer::globals::separator;
1816
1817    my @newlines = ();
1818    my $is_extension_package = contains_extension_dir($prototypefile);
1819
1820    if ( $is_extension_package )
1821    {
1822        for ( my $i = 0; $i <= $#installer::globals::solarispatchscriptsforextensions; $i++ )
1823        {
1824            my $sourcefilename = $path . $installer::globals::solarispatchscriptsforextensions[$i];
1825            my $destfile = $installer::globals::solarispatchscriptsforextensions[$i];
1826
1827            # If the sourcepath has "_extension" in its name, this has to be removed
1828            $destfile =~ s/_extensions\s*$//;  # hard coded renaming of script name
1829
1830            # Creating unique directory name with $prototypefilename
1831            my $extensiondir = installer::systemactions::create_directories("extensionscripts", $languagestringref);
1832
1833            if ( $prototypefilename =~ /\/(\S*?)\s*$/ ) { $prototypefilename = $1; }
1834            $prototypefilename =~ s/\./_/g;
1835            my $destdir = $extensiondir . $installer::globals::separator . $prototypefilename;
1836            if ( ! -d $destdir ) { installer::systemactions::create_directory($destdir); }
1837            my $destpath = $destdir . $installer::globals::separator . $destfile;
1838            if ( -f $destpath ) { unlink($destpath); }
1839
1840            # Reading file
1841            my $scriptfile = installer::files::read_file($sourcefilename);
1842
1843            # Replacing variables
1844            my $oldstring = "PRODUCTDIRECTORYNAME";
1845            replace_variables_in_shellscripts_for_patch($scriptfile, $destpath, $oldstring, $staticpath);
1846
1847            # Saving file
1848            installer::files::save_file($destpath, $scriptfile);
1849
1850            # Writing file destination into prototype file
1851            my $line = "i $destfile=" . $destpath . "\n";
1852            push(@newlines, $line);
1853        }
1854    }
1855    else
1856    {
1857        for ( my $i = 0; $i <= $#installer::globals::solarispatchscripts; $i++ )
1858        {
1859            my $line = "i $installer::globals::solarispatchscripts[$i]=" . $path . $installer::globals::solarispatchscripts[$i] . "\n";
1860            push(@newlines, $line);
1861        }
1862    }
1863
1864    # Including the new lines after the last line starting with "i"
1865
1866    for ( my $i = 0; $i <= $#{$prototypefile}; $i++ )
1867    {
1868        if ( ${$prototypefile}[$i] =~ /^\s*i\s+copyright/ )
1869        {
1870            splice(@{$prototypefile}, $i, 1);   # ignoring old copyright text, using patch standard
1871            next;
1872        }
1873        if ( ${$prototypefile}[$i] =~ /^\s*i\s+/ ) { next; }
1874        splice(@{$prototypefile}, $i, 0, @newlines);
1875        last;
1876    }
1877}
1878
1879############################################################
1880# Adding patch infos in pkginfo file
1881############################################################
1882
1883sub include_patchinfos_into_pkginfo
1884{
1885    my ( $changefile, $filename, $variableshashref ) = @_;
1886
1887    # SUNW_PATCHID=101998-10
1888    # SUNW_OBSOLETES=114999-01 113999-01
1889    # SUNW_PKGTYPE=usr
1890    # SUNW_PKGVERS=1.0
1891    # SUNW_REQUIRES=126411-01
1892
1893    my $patchidname = "SOLSPARCPATCHID";
1894    if ( $installer::globals::issolarisx86build ) { $patchidname = "SOLIAPATCHID"; }
1895
1896    if ( ! $variableshashref->{$patchidname} ) { installer::exiter::exit_program("ERROR: Variable $patchidname not defined in zip list file!", "include_patchinfos_into_pkginfo"); }
1897
1898    my $newline = "SUNW_PATCHID=" . $variableshashref->{$patchidname} . "\n";
1899    add_one_line_into_file($changefile, $newline, $filename);
1900
1901    my $patchobsoletesname = "SOLSPARCPATCHOBSOLETES";
1902    if ( $installer::globals::issolarisx86build ) { $patchobsoletesname = "SOLIAPATCHOBSOLETES"; }
1903
1904    my $obsoletes = "";
1905    if ( $variableshashref->{$patchobsoletesname} ) { $obsoletes = $variableshashref->{$patchobsoletesname}; }
1906    $newline = "SUNW_OBSOLETES=" . $obsoletes . "\n";
1907    add_one_line_into_file($changefile, $newline, $filename);
1908
1909    my $patchrequiresname = "SOLSPARCPATCHREQUIRES";
1910    if ( $installer::globals::issolarisx86build ) { $patchrequiresname = "SOLIAPATCHREQUIRES"; }
1911
1912    if ( $variableshashref->{$patchrequiresname} )
1913    {
1914        my $requires = $variableshashref->{$patchrequiresname};
1915        $newline = "SUNW_REQUIRES=" . $requires . "\n";
1916        add_one_line_into_file($changefile, $newline, $filename);
1917    }
1918    $newline = "SUNW_PATCH_PROPERTIES=\n";
1919    add_one_line_into_file($changefile, $newline, $filename);
1920    # $newline = "SUNW_PKGTYPE=usr\n";
1921    # add_one_line_into_file($changefile, $newline, $filename);
1922
1923    # $newline = "SUNW_PKGVERS=1.0\n";
1924    # add_one_line_into_file($changefile, $newline, $filename);
1925}
1926
1927############################################################
1928# Setting the correct Solaris locales
1929############################################################
1930
1931sub get_solaris_language_for_langpack
1932{
1933    my ( $onelanguage ) = @_;
1934
1935    my $sollanguage = $onelanguage;
1936    $sollanguage =~ s/\-/\_/;
1937
1938    if ( $sollanguage eq "de" ) { $sollanguage = "de"; }
1939    elsif ( $sollanguage eq "en_US" ) { $sollanguage = "en_AU,en_CA,en_GB,en_IE,en_MT,en_NZ,en_US,en_US.UTF-8"; }
1940    elsif ( $sollanguage eq "es" ) { $sollanguage = "es"; }
1941    elsif ( $sollanguage eq "fr" ) { $sollanguage = "fr"; }
1942    elsif ( $sollanguage eq "hu" ) { $sollanguage = "hu_HU"; }
1943    elsif ( $sollanguage eq "it" ) { $sollanguage = "it"; }
1944    elsif ( $sollanguage eq "nl" ) { $sollanguage = "nl_BE,nl_NL"; }
1945    elsif ( $sollanguage eq "pl" ) { $sollanguage = "pl_PL"; }
1946    elsif ( $sollanguage eq "sv" ) { $sollanguage = "sv"; }
1947    elsif ( $sollanguage eq "pt" ) { $sollanguage = "pt_PT"; }
1948    elsif ( $sollanguage eq "pt_BR" ) { $sollanguage = "pt_BR"; }
1949    elsif ( $sollanguage eq "ru" ) { $sollanguage = "ru_RU"; }
1950    elsif ( $sollanguage eq "ja" ) { $sollanguage = "ja,ja_JP,ja_JP.PCK,ja_JP.UTF-8"; }
1951    elsif ( $sollanguage eq "ko" ) { $sollanguage = "ko,ko.UTF-8"; }
1952    elsif ( $sollanguage eq "zh_CN" ) { $sollanguage = "zh,zh.GBK,zh_CN.GB18030,zh.UTF-8"; }
1953    elsif ( $sollanguage eq "zh_TW" ) { $sollanguage = "zh_TW,zh_TW.BIG5,zh_TW.UTF-8,zh_HK.BIG5HK,zh_HK.UTF-8"; }
1954
1955    return $sollanguage;
1956}
1957
1958############################################################
1959# Adding language infos in pkginfo file
1960############################################################
1961
1962sub include_languageinfos_into_pkginfo
1963{
1964    my ( $changefile, $filename, $languagestringref, $onepackage, $variableshashref ) = @_;
1965
1966    # SUNWPKG_LIST=core01
1967    # SUNW_LOC=de
1968
1969    my $locallang = $onepackage->{'language'};
1970    my $solarislanguage = get_solaris_language_for_langpack($locallang);
1971
1972    my $newline = "SUNW_LOC=" . $solarislanguage . "\n";
1973    add_one_line_into_file($changefile, $newline, $filename);
1974
1975    # SUNW_PKGLIST is required, if SUNW_LOC is defined.
1976    if ( $onepackage->{'pkg_list_entry'} )
1977    {
1978        my $packagelistentry = $onepackage->{'pkg_list_entry'};
1979        installer::packagelist::resolve_packagevariables(\$packagelistentry, $variableshashref, 1);
1980        $newline = "SUNW_PKGLIST=" . $packagelistentry . "\n";
1981        add_one_line_into_file($changefile, $newline, $filename);
1982    }
1983    else
1984    {
1985        # Using default package ooobasis30-core01.
1986        my $packagelistentry = "%BASISPACKAGEPREFIX%WITHOUTDOTOOOBASEVERSION-core01";
1987        installer::packagelist::resolve_packagevariables(\$packagelistentry, $variableshashref, 1);
1988        $newline = "SUNW_PKGLIST=" . $packagelistentry . "\n";
1989        add_one_line_into_file($changefile, $newline, $filename);
1990    }
1991}
1992
1993############################################################
1994# Collecting all files included in patch in
1995# @installer::globals::patchfilecollector
1996############################################################
1997
1998sub collect_patch_files
1999{
2000    my ($file, $packagename, $prefix) = @_;
2001
2002    # $file is the spec file or the prototypefile
2003
2004    $prefix = $prefix . "/";
2005    my $packagenamestring = "Package " . $packagename . " \:\n";
2006    push(@installer::globals::patchfilecollector, $packagenamestring);
2007
2008    for ( my $i = 0; $i <= $#{$file}; $i++ )
2009    {
2010        my $line = ${$file}[$i];
2011
2012        if ( $installer::globals::islinuxrpmbuild )
2013        {
2014            # %attr(0444,root,root) "/opt/openofficeorg20/program/about.bmp"
2015
2016            if ( $line =~ /^\s*\%attr\(.*\)\s*\"(.*?)\"\s*$/ )
2017            {
2018                my $filename = $1 . "\n";
2019                $filename =~ s/^\s*\Q$prefix\E//;
2020                push(@installer::globals::patchfilecollector, $filename);
2021            }
2022        }
2023
2024        if ( $installer::globals::issolarispkgbuild )
2025        {
2026            # f none program/msomrl.rdb=/ab/SRC680/unxsols4.pro/bin/msomrl.rdb 0444 root bin
2027
2028            if ( $line =~ /^\s*f\s+\w+\s+(.*?)\=/ )
2029            {
2030                my $filename = $1 . "\n";
2031                push(@installer::globals::patchfilecollector, $filename);
2032            }
2033        }
2034    }
2035
2036    push(@installer::globals::patchfilecollector, "\n");
2037
2038}
2039
2040############################################################
2041# Including package names into the depend files.
2042# The package names have to be included into
2043# packagelist. They are already saved in
2044# %installer::globals::dependfilenames.
2045############################################################
2046
2047sub put_packagenames_into_dependfile
2048{
2049    my ( $file ) = @_;
2050
2051    for ( my $i = 0; $i <= $#{$file}; $i++ )
2052    {
2053        my $line = ${$file}[$i];
2054        if ( $line =~ /^\s*\w\s+(.*?)\s*$/ )
2055        {
2056            my $abbreviation = $1;
2057
2058            if ( $abbreviation =~ /\%/ ) { installer::exiter::exit_program("ERROR: Could not resolve all properties in Solaris package abbreviation \"$abbreviation\"!", "read_packagemap"); }
2059
2060            if ( exists($installer::globals::dependfilenames{$abbreviation}) )
2061            {
2062                my $packagename = $installer::globals::dependfilenames{$abbreviation};
2063                if ( $packagename =~ /\%/ ) { installer::exiter::exit_program("ERROR: Could not resolve all properties in Solaris package name \"$packagename\"!", "read_packagemap"); }
2064
2065                $line =~ s/\s*$//;
2066                ${$file}[$i] = $line . "\t" . $packagename . "\n";
2067            }
2068            else
2069            {
2070                installer::exiter::exit_program("ERROR: Missing packagename for Solaris package \"$abbreviation\"!", "put_packagenames_into_dependfile");
2071            }
2072        }
2073    }
2074}
2075
2076############################################################
2077# Including the relocatable directory into
2078# spec file and pkginfo file
2079# Linux: set topdir in specfile
2080# Solaris: remove $relocatablepath (/opt/)
2081# for all objects in prototype file
2082# and changing "topdir" for Linux
2083############################################################
2084
2085sub prepare_packages
2086{
2087    my ($loggingdir, $packagename, $staticpath, $relocatablepath, $onepackage, $variableshashref, $filesref, $languagestringref) = @_;
2088
2089    my $filename = "";
2090    my $newline = "";
2091    my $newepmdir = $installer::globals::epmoutpath . $installer::globals::separator;
2092
2093    my $localrelocatablepath = $relocatablepath;
2094    if ( $localrelocatablepath ne "/" ) { $localrelocatablepath =~ s/\/\s*$//; }
2095
2096    if ( $installer::globals::issolarispkgbuild )
2097    {
2098        $filename = $packagename . ".pkginfo";
2099        $newline = "BASEDIR\=" . $localrelocatablepath . "\n";
2100    }
2101
2102    if ( $installer::globals::islinuxrpmbuild )
2103    {
2104        # if ( $localrelocatablepath =~ /^\s*$/ ) { $localrelocatablepath = "/"; }; # at least the "/"
2105        $filename =  $packagename . ".spec";
2106        $newline = "Prefix\:\ " . $localrelocatablepath . "\n";
2107    }
2108
2109    my $completefilename = $newepmdir . $filename;
2110
2111    if ( ! -f $completefilename) { installer::exiter::exit_program("ERROR: Did not find file: $completefilename", "prepare_packages"); }
2112    my $changefile = installer::files::read_file($completefilename);
2113    if ( $newline ne "" )
2114    {
2115        add_one_line_into_file($changefile, $newline, $filename);
2116        installer::files::save_file($completefilename, $changefile);
2117    }
2118
2119    # my $newepmdir = $completefilename;
2120    # installer::pathanalyzer::get_path_from_fullqualifiedname(\$newepmdir);
2121
2122    # adding new "topdir" and removing old "topdir" in specfile
2123
2124    if ( $installer::globals::islinuxrpmbuild )
2125    {
2126        set_topdir_in_specfile($changefile, $filename, $newepmdir);
2127        set_autoprovreq_in_specfile($changefile, $onepackage->{'findrequires'}, "$installer::globals::unpackpath" . "/bin");
2128        set_packager_in_specfile($changefile);
2129        if ( is_extension_package($changefile) ) { set_prereq_in_specfile($changefile); }
2130        set_license_in_specfile($changefile, $variableshashref);
2131        set_tab_into_datafile($changefile, $filesref);
2132        # check_requirements_in_specfile($changefile);
2133        installer::files::save_file($completefilename, $changefile);
2134        if ( $installer::globals::patch ) { collect_patch_files($changefile, $packagename, $localrelocatablepath); }
2135    }
2136
2137    # removing the relocatable path in prototype file
2138
2139    if ( $installer::globals::issolarispkgbuild )
2140    {
2141        set_revision_in_pkginfo($changefile, $filename, $variableshashref, $packagename);
2142        set_maxinst_in_pkginfo($changefile, $filename);
2143        set_solaris_parameter_in_pkginfo($changefile, $filename, $variableshashref);
2144        if ( $installer::globals::issolarisx86build ) { fix_architecture_setting($changefile); }
2145        if ( ! $installer::globals::patch ) { set_patchlist_in_pkginfo_for_respin($changefile, $filename, $variableshashref, $packagename); }
2146        if ( $installer::globals::patch ) { include_patchinfos_into_pkginfo($changefile, $filename, $variableshashref); }
2147        if (( $onepackage->{'language'} ) && ( $onepackage->{'language'} ne "" ) && ( $onepackage->{'language'} ne "en-US" )) { include_languageinfos_into_pkginfo($changefile, $filename, $languagestringref, $onepackage, $variableshashref); }
2148        installer::files::save_file($completefilename, $changefile);
2149
2150        my $prototypefilename = $packagename . ".prototype";
2151        $prototypefilename = $newepmdir . $prototypefilename;
2152        if (! -f $prototypefilename) { installer::exiter::exit_program("ERROR: Did not find prototype file: $prototypefilename", "prepare_packages"); }
2153
2154        my $prototypefile = installer::files::read_file($prototypefilename);
2155        make_prototypefile_relocatable($prototypefile, $relocatablepath);
2156        set_volatilefile_into_prototypefile($prototypefile, $filesref);
2157        my $classesstring = set_tab_into_datafile($prototypefile, $filesref);
2158        if ($classesstring)
2159        {
2160            include_classes_into_pkginfo($changefile, $classesstring);
2161            installer::files::save_file($completefilename, $changefile);
2162        }
2163
2164        if ( $installer::globals::patch ) { add_scripts_into_prototypefile($prototypefile, $prototypefilename, $languagestringref, $staticpath); }
2165
2166        installer::files::save_file($prototypefilename, $prototypefile);
2167        if ( $installer::globals::patch ) { collect_patch_files($prototypefile, $packagename, ""); }
2168
2169        # Adding package names into depend files for Solaris (not supported by epm)
2170        my $dependfilename = $packagename . ".depend";
2171        $dependfilename = $newepmdir . $dependfilename;
2172        if ( -f $dependfilename)
2173        {
2174            my $dependfile = installer::files::read_file($dependfilename);
2175            put_packagenames_into_dependfile($dependfile);
2176            installer::files::save_file($dependfilename, $dependfile);
2177        }
2178    }
2179
2180    return $newepmdir;
2181}
2182
2183############################################################
2184# Linux requirement for perl is changed by epm from
2185# /usr/bin/perl to perl .
2186# Requires: perl
2187############################################################
2188
2189sub check_requirements_in_specfile
2190{
2191    my ( $specfile ) = @_;
2192
2193    for ( my $i = 0; $i <= $#{$specfile}; $i++ )
2194    {
2195        if (( ${$specfile}[$i] =~ /^\s*Requires/ ) && ( ${$specfile}[$i] =~ /\bperl\b/ ) && ( ! (  ${$specfile}[$i] =~ /\/usr\/bin\/perl\b/ )))
2196        {
2197            my $oldline = ${$specfile}[$i];
2198            ${$specfile}[$i] =~ s/perl/\/usr\/bin\/perl/;
2199            my $newline = ${$specfile}[$i];
2200
2201            $oldline =~ s/\s*$//;
2202            $newline =~ s/\s*$//;
2203            $installer::logger::Lang->printf("Spec File: Changing content from \"%s\" to \"%s\".\n",
2204                $oldline, $newline);
2205        }
2206    }
2207}
2208
2209###############################################################################
2210# Replacement of PRODUCTINSTALLLOCATION and PRODUCTDIRECTORYNAME in the
2211# epm list file.
2212# The complete rootpath is stored in $installer::globals::rootpath
2213# or for each package in $onepackage->{'destpath'}
2214# The static rootpath is stored in $staticpath
2215# The relocatable path is stored in $relocatablepath
2216# PRODUCTINSTALLLOCATION is the relocatable part ("/opt") and
2217# PRODUCTDIRECTORYNAME the static path ("openofficeorg20").
2218# In standard epm process:
2219# No usage of package specific variables like $BASEDIR, because
2220# 1. These variables would be replaced in epm process
2221# 2. epm version 3.7 does not support relocatable packages
2222###############################################################################
2223
2224sub resolve_path_in_epm_list_before_packaging
2225{
2226    my ($listfile, $listfilename, $variable, $path) = @_;
2227
2228    installer::logger::include_header_into_logfile("Replacing variables in epm list file:");
2229
2230    $path =~ s/\/\s*$//;
2231    replace_variables_in_shellscripts($listfile, $listfilename, $variable, $path);
2232
2233}
2234
2235#################################################################
2236# Determining the rpm version. Beginning with rpm version 4.0
2237# the tool to create RPMs is "rpmbuild" and no longer "rpm"
2238#################################################################
2239
2240sub determine_rpm_version
2241{
2242    my $rpmversion = 0;
2243    my $rpmout = "";
2244    my $systemcall = "";
2245
2246    # my $systemcall = "rpm --version |";
2247    # "rpm --version" has problems since LD_LIBRARY_PATH was removed. Therefore the content of $RPM has to be called.
2248    # "rpm --version" and "rpmbuild --version" have the same output. Therefore $RPM can be used. Its value
2249    # is saved in $installer::globals::rpm
2250
2251    if ( $installer::globals::rpm ne "" )
2252    {
2253        $systemcall = "$installer::globals::rpm --version |";
2254    }
2255    else
2256    {
2257        $systemcall = "rpm --version |";
2258    }
2259
2260    open (RPM, "$systemcall");
2261    $rpmout = <RPM>;
2262    close (RPM);
2263
2264    if ( $rpmout ne "" )
2265    {
2266        $rpmout =~ s/\s*$//g;
2267
2268        $installer::logger::Lang->printf("Systemcall: %s\n", $systemcall);
2269
2270        if ( $rpmout eq "" )
2271        {
2272            $installer::logger::Lang->printf("ERROR: Could not find file \"rpm\" !\n");
2273        }
2274        else
2275        {
2276            $installer::logger::Lang->printf("Success: rpm version: %s\n", $rpmout);
2277        }
2278
2279        if ( $rpmout =~ /(\d+)\.(\d+)\.(\d+)/ ) { $rpmversion = $1; }
2280        elsif ( $rpmout =~ /(\d+)\.(\d+)/ ) { $rpmversion = $1; }
2281        elsif ( $rpmout =~ /(\d+)/ ) { $rpmversion = $1; }
2282        else { installer::exiter::exit_program("ERROR: Unknown format: $rpmout ! Expected: \"a.b.c\", or \"a.b\", or \"a\"", "determine_rpm_version"); }
2283    }
2284
2285    return $rpmversion;
2286}
2287
2288####################################################
2289# Writing some info about rpm into the log file
2290####################################################
2291
2292sub log_rpm_info
2293{
2294    my $systemcall = "";
2295    my $infoline = "";
2296
2297    $installer::logger::Lang->printf("\n");
2298    $installer::logger::Lang->printf("Logging rpmrc content using --showrc\n");
2299    $installer::logger::Lang->printf("\n");
2300
2301    if ( $installer::globals::rpm ne "" )
2302    {
2303        $systemcall = "$installer::globals::rpm --showrc |";
2304    }
2305    else
2306    {
2307        $systemcall = "rpm --showrc |";
2308    }
2309
2310    my @fullrpmout = ();
2311
2312    open (RPM, "$systemcall");
2313    while (<RPM>) {push(@fullrpmout, $_); }
2314    close (RPM);
2315
2316    if ( $#fullrpmout > -1 )
2317    {
2318        for ( my $i = 0; $i <= $#fullrpmout; $i++ )
2319        {
2320            my $rpmout = $fullrpmout[$i];
2321            $rpmout =~ s/\s*$//g;
2322
2323            $infoline = "$rpmout\n";
2324            $infoline =~ s/error/e_r_r_o_r/gi;  # avoiding log problems
2325            $installer::logger::Lang->print($infoline);
2326        }
2327    }
2328    else
2329    {
2330        $installer::logger::Lang->printf("Problem in systemcall: %s : No return value\n", $systemcall);
2331    }
2332
2333    $installer::logger::Lang->printf("End of logging rpmrc\n");
2334    $installer::logger::Lang->print("\n");
2335}
2336
2337#################################################
2338# Systemcall to start the packaging process
2339#################################################
2340
2341sub create_packages_without_epm
2342{
2343    my ($epmdir, $packagename, $includepatharrayref, $allvariables, $languagestringref) = @_;
2344
2345    # Solaris: pkgmk -o -f solaris-2.8-sparc/SUNWso8m34.prototype -d solaris-2.8-sparc
2346    # Solaris: pkgtrans solaris-2.8-sparc SUNWso8m34.pkg SUNWso8m34
2347    # Solaris: tar -cf - SUNWso8m34 | gzip > SUNWso8m34.tar.gz
2348
2349    if ( $installer::globals::issolarispkgbuild )
2350    {
2351        my $prototypefile = $epmdir . $packagename . ".prototype";
2352        if (! -f $prototypefile) { installer::exiter::exit_program("ERROR: Did not find file: $prototypefile", "create_packages_without_epm"); }
2353
2354        my $destinationdir = $prototypefile;
2355        installer::pathanalyzer::get_path_from_fullqualifiedname(\$destinationdir);
2356        $destinationdir =~ s/\/\s*$//;  # removing ending slashes
2357
2358        # my $systemcall = "pkgmk -o -f $prototypefile -d $destinationdir \> /dev/null 2\>\&1";
2359        my $systemcall = "pkgmk -l 1073741824 -o -f $prototypefile -d $destinationdir 2\>\&1 |";
2360        $installer::logger::Info->printf("... %s ...\n", $systemcall);
2361
2362        my $maxpkgmkcalls = 3;
2363
2364        for ( my $i = 1; $i <= $maxpkgmkcalls; $i++ )
2365        {
2366            my @pkgmkoutput = ();
2367
2368            open (PKGMK, "$systemcall");
2369            while (<PKGMK>) {push(@pkgmkoutput, $_); }
2370            close (PKGMK);
2371
2372            my $returnvalue = $?;   # $? contains the return value of the systemcall
2373
2374            $installer::logger::Lang->printf("Systemcall (Try %d): %s\n", $i, $systemcall);
2375
2376            for ( my $j = 0; $j <= $#pkgmkoutput; $j++ )
2377            {
2378                if ( $i < $maxpkgmkcalls ) { $pkgmkoutput[$j] =~ s/\bERROR\b/PROBLEM/ig; }
2379                $installer::logger::Lang->print($pkgmkoutput[$j]);
2380            }
2381
2382            if ($returnvalue)
2383            {
2384                $installer::logger::Lang->printf("Try %s : Could not execute \"%s\"!\n",
2385                    $i, $systemcall);
2386                if ( $i == $maxpkgmkcalls ) { installer::exiter::exit_program("ERROR: \"$systemcall\"!", "create_packages_without_epm"); }
2387            }
2388            else
2389            {
2390                $installer::logger::Info->printf("Success: (Try %d): Executed \"%s\" successfully\n",
2391                    $i, $systemcall);
2392                $installer::logger::Lang->printf("Success: (Try %d): Executed \"%s\" successfully\n",
2393                    $i, $systemcall);
2394                last;
2395            }
2396        }
2397
2398        # It might be necessary to save uncompressed Solaris packages
2399
2400        if ( $allvariables->{'JDSBUILD'} )
2401        {
2402            if ( ! $installer::globals::jds_language_controlled )
2403            {
2404                my $correct_language = installer::worker::check_jds_language($allvariables, $languagestringref);
2405                $installer::globals::correct_jds_language = $correct_language;
2406                $installer::globals::jds_language_controlled = 1;
2407            }
2408
2409            if ( $installer::globals::correct_jds_language )
2410            {
2411                if ( $installer::globals::saved_packages_path eq "" )
2412                {
2413                    $packagestempdir = installer::systemactions::create_directories("jds", $languagestringref);
2414                    $installer::globals::saved_packages_path = $packagestempdir;
2415                    push(@installer::globals::jdsremovedirs, $packagestempdir);
2416                }
2417
2418                $systemcall = "cd $destinationdir; cp -p -R $packagename $installer::globals::saved_packages_path;";
2419                make_systemcall($systemcall);
2420                $installer::logger::Info->printf("... %s ...\n", $systemcall);
2421
2422                # Setting unix rights to "775" for all created directories inside the package,
2423                # that is saved in temp directory
2424
2425                $systemcall = "cd $packagestempdir; find $packagename -type d -exec chmod 775 \{\} \\\;";
2426                $installer::logger::Info->printf("... %s ...\n", $systemcall);
2427
2428                $returnvalue = system($systemcall);
2429
2430                $installer::logger::Lang->printf("Systemcall: %s\n", $systemcall);
2431
2432                if ($returnvalue)
2433                {
2434                    $installer::logger::Lang->printf("ERROR: Could not execute \"%s\"!\n", $systemcall);
2435                }
2436                else
2437                {
2438                    $installer::logger::Lang->printf("Success: Executed \"%s\" successfully!\n", $systemcall);
2439                }
2440            }
2441        }
2442
2443        # compressing packages
2444
2445        if ( ! $installer::globals::solarisdontcompress )
2446        {
2447            my $faspac = "faspac-so.sh";
2448
2449            my $compressorref = installer::scriptitems::get_sourcepath_from_filename_and_includepath(\$faspac, $includepatharrayref, 0);
2450            if ($$compressorref ne "")
2451            {
2452                # Saving original pkginfo, to set time stamp later
2453                my $pkginfoorig = "$destinationdir/$packagename/pkginfo";
2454                my $pkginfotmp = "$destinationdir/$packagename" . ".pkginfo.tmp";
2455                $systemcall = "cp -p $pkginfoorig $pkginfotmp";
2456                make_systemcall($systemcall);
2457
2458                $faspac = $$compressorref;
2459                $installer::logger::Lang->printf("Found compressor: %s\n", $faspac);
2460
2461                $installer::logger::Info->printf("... %s ...\n", $faspac);
2462                $installer::logger::Lang->add_timestamp("Starting $faspac");
2463
2464                $systemcall = "/bin/sh $faspac -a -q -d $destinationdir $packagename";   # $faspac has to be the absolute path!
2465                make_systemcall($systemcall);
2466
2467                # Setting time stamp for pkginfo, because faspac-so.sh changed the pkginfo file,
2468                # updated the size and checksum, but not the time stamp.
2469                $systemcall = "touch -r $pkginfotmp $pkginfoorig";
2470                make_systemcall($systemcall);
2471                if ( -f $pkginfotmp ) { unlink($pkginfotmp); }
2472
2473                $installer::logger::Lang->add_timestamp("End of $faspac");
2474            }
2475            else
2476            {
2477                $installer::logger::Lang->printf("Not found: %s\n", $faspac);
2478            }
2479        }
2480
2481        # Setting unix rights to "775" for all created directories inside the package
2482
2483        $systemcall = "cd $destinationdir; find $packagename -type d -exec chmod 775 \{\} \\\;";
2484        $installer::logger::Info->printf("... %s ...\n", $systemcall);
2485
2486        $returnvalue = system($systemcall);
2487
2488        $installer::logger::Lang->printf("Systemcall: %s\n", $systemcall);
2489
2490        if ($returnvalue)
2491        {
2492            $installer::logger::Lang->printf("ERROR: Could not execute \"%s\"!\n", $systemcall);
2493        }
2494        else
2495        {
2496            $installer::logger::Lang->printf("Success: Executed \"%s\" successfully!\n", $systemcall);
2497        }
2498    }
2499
2500    # Linux: rpm -bb so8m35.spec    ( -> dependency check abklemmen? )
2501
2502    if ( $installer::globals::islinuxrpmbuild )
2503    {
2504        my $specfilename = $epmdir . $packagename . ".spec";
2505        if (! -f $specfilename) { installer::exiter::exit_program("ERROR: Did not find file: $specfilename", "create_packages_without_epm"); }
2506
2507        # my $rpmcommand = "rpm";
2508        my $rpmcommand = $installer::globals::rpm;
2509        my $rpmversion = determine_rpm_version();
2510
2511        # if ( $rpmversion >= 4 ) { $rpmcommand = "rpmbuild"; }
2512
2513        # saving globally for later usage
2514        $installer::globals::rpmcommand = $rpmcommand;
2515        $installer::globals::rpmquerycommand = "rpm";
2516
2517        my $target = "";
2518        if ( $installer::globals::compiler =~ /unxlngi/) { $target = "i586"; }
2519        elsif ( $installer::globals::compiler =~ /unxlng/) {$target = (POSIX::uname())[4]; }
2520
2521        # rpm 4.6 ignores buildroot tag in spec file
2522
2523        my $buildrootstring = "";
2524
2525        if ( $rpmversion >= 4 )
2526        {
2527            my $dir = getcwd;
2528            my $buildroot = $dir . "/" . $epmdir . "buildroot/";
2529            $buildrootstring = "--buildroot=$buildroot";
2530            mkdir($buildroot = $dir . "/" . $epmdir . "BUILD/");
2531        }
2532
2533        if ( ! $installer::globals::rpminfologged )
2534        {
2535            log_rpm_info();
2536            $installer::globals::rpminfologged = 1;
2537        }
2538
2539        my $systemcall = "$rpmcommand -bb --define \"_unpackaged_files_terminate_build  0\" $specfilename --target $target $buildrootstring 2\>\&1 |";
2540
2541        $installer::logger::Info->printf("... %s ...\n", $systemcall);
2542
2543        my $maxrpmcalls = 3;
2544        my $rpm_failed = 0;
2545
2546        for ( my $i = 1; $i <= $maxrpmcalls; $i++ )
2547        {
2548            my @rpmoutput = ();
2549
2550            open (RPM, "$systemcall");
2551            while (<RPM>) {push(@rpmoutput, $_); }
2552            close (RPM);
2553
2554            my $returnvalue = $?;   # $? contains the return value of the systemcall
2555
2556            $installer::logger::Lang->printf("Systemcall (Try %d): %s\n", $i, $systemcall);
2557
2558            for ( my $j = 0; $j <= $#rpmoutput; $j++ )
2559            {
2560                # if ( $i < $maxrpmcalls ) { $rpmoutput[$j] =~ s/\bERROR\b/PROBLEM/ig; }
2561                $rpmoutput[$j] =~ s/\bERROR\b/PROBLEM/ig;
2562                $installer::logger::Lang->print($rpmoutput[$j]);
2563            }
2564
2565            if ($returnvalue)
2566            {
2567                $installer::logger::Lang->printf("Try %d : Could not execute \"%s\"!\n", $i, $systemcall);
2568                $rpm_failed = 1;
2569            }
2570            else
2571            {
2572                $installer::logger::Info->printf("Success (Try %d): Executed \"%s\" successfully!\n", $i, $systemcall);
2573                $installer::logger::Lang->printf("Success (Try %d): Executed \"%s\" successfully!\n", $i, $systemcall);
2574                $rpm_failed = 0;
2575                last;
2576            }
2577        }
2578
2579        if ( $rpm_failed )
2580        {
2581            # Because of the problems with LD_LIBARY_PATH, a direct call of local "rpm" or "rpmbuild" might be successful
2582            my $rpmprog = "";
2583            if ( -f "/usr/bin/rpmbuild" ) { $rpmprog = "/usr/bin/rpmbuild"; }
2584            elsif ( -f "/usr/bin/rpm" ) { $rpmprog = "/usr/bin/rpm"; }
2585
2586            if ( $rpmprog ne "" )
2587            {
2588                $installer::logger::Info->printf("... %s ...\n", $rpmprog);
2589
2590                my $helpersystemcall = "$rpmprog -bb $specfilename --target $target $buildrootstring 2\>\&1 |";
2591
2592                my @helperrpmoutput = ();
2593
2594                open (RPM, "$helpersystemcall");
2595                while (<RPM>) {push(@helperrpmoutput, $_); }
2596                close (RPM);
2597
2598                my $helperreturnvalue = $?; # $? contains the return value of the systemcall
2599
2600                $installer::logger::Lang->printf("\n");
2601                $installer::logger::Lang->printf("Last try: Using %s directly (problem with LD_LIBARY_PATH)\n",
2602                    $rpmprog);
2603
2604                $installer::logger::Lang->printf("\n");
2605                $installer::logger::Lang->printf("Systemcall: %s\n", $helpersystemcall);
2606
2607                foreach my $line (@helperrpmoutput)
2608                {
2609                    $installer::logger::Lang->print($helperrpmoutput[$j]);
2610                }
2611
2612                if ($helperreturnvalue)
2613                {
2614                    $installer::logger::Lang->printf("Could not execute \"%s\"!\n", $helpersystemcall);
2615                }
2616                else
2617                {
2618                    $installer::logger::Lang->printf("Success: Executed \"%s\" successfully!\n", $helpersystemcall);
2619                    $installer::logger::Info->printf("Success: Executed \"%s\" successfully!\n", $helpersystemcall);
2620                    $rpm_failed = 0;
2621                }
2622            }
2623
2624            # Now it is really time to exit this packaging process, if the error still occurs
2625            if ( $rpm_failed ) { installer::exiter::exit_program("ERROR: \"$systemcall\"!", "create_packages_without_epm"); }
2626        }
2627    }
2628}
2629
2630#################################################
2631# Removing all temporary files created by epm
2632#################################################
2633
2634sub remove_temporary_epm_files
2635{
2636    my ($epmdir, $loggingdir, $packagename) = @_;
2637
2638    # saving the files into the loggingdir
2639
2640    if ( $installer::globals::issolarispkgbuild )
2641    {
2642        my @extensions = ();
2643        push(@extensions, ".pkginfo");
2644        push(@extensions, ".prototype");
2645        push(@extensions, ".postinstall");
2646        push(@extensions, ".postremove");
2647        push(@extensions, ".preinstall");
2648        push(@extensions, ".preremove");
2649        push(@extensions, ".depend");
2650
2651        for ( my $i = 0; $i <= $#extensions; $i++ )
2652        {
2653            my $removefile = $epmdir . $packagename . $extensions[$i];
2654            my $destfile = $loggingdir . $packagename . $extensions[$i] . ".log";
2655
2656            if (! -f $removefile) { next; }
2657
2658            my $systemcall = "mv -f $removefile $destfile";
2659            system($systemcall);     # ignoring the return value
2660            $installer::logger::Lang->printf("Systemcall: %s\n", $systemcall);
2661        }
2662    }
2663
2664    if ( $installer::globals::islinuxrpmbuild )
2665    {
2666        my $removefile = $epmdir . $packagename . ".spec";
2667        my $destfile = $loggingdir . $packagename . ".spec.log";
2668
2669         # if (! -f $removefile) { next; }
2670
2671        my $systemcall = "mv -f $removefile $destfile";
2672        system($systemcall);     # ignoring the return value
2673        $installer::logger::Lang->printf("Systemcall: %s\n", $systemcall);
2674
2675        # removing the directory "buildroot"
2676
2677        my $removedir = $epmdir . "buildroot";
2678
2679        $systemcall = "rm -rf $removedir";
2680
2681        $installer::logger::Info->printf("... %s ...\n", $systemcall);
2682
2683        my $returnvalue = system($systemcall);
2684
2685        $removedir = $epmdir . "BUILD";
2686
2687        $systemcall = "rm -rf $removedir";
2688
2689        $installer::logger::Info->printf("... %s ...\n", $systemcall);
2690
2691        $returnvalue = system($systemcall);
2692
2693        $installer::logger::Lang->printf("Systemcall: %s\n", $systemcall);
2694
2695        if ($returnvalue)
2696        {
2697            $installer::logger::Lang->printf("ERROR: Could not execute \"%s\"!\n", $systemcall);
2698        }
2699        else
2700        {
2701            $installer::logger::Lang->printf("Success: Executed \"%s\" successfully!\n", $systemcall);
2702        }
2703    }
2704}
2705
2706######################################################
2707# Making the systemcall
2708######################################################
2709
2710sub make_systemcall
2711{
2712    my ($systemcall) = @_;
2713
2714    my $returnvalue = system($systemcall);
2715
2716    $installer::logger::Lang->printf("Systemcall: %s\n", $systemcall);
2717
2718    if ($returnvalue)
2719    {
2720        $installer::logger::Lang->printf("ERROR: Could not execute \"%s\"!\n", $systemcall);
2721    }
2722    else
2723    {
2724        $installer::logger::Lang->printf("Success: Executed \"%s\" successfully!\n", $systemcall);
2725    }
2726}
2727
2728###########################################################
2729# Creating a better directory structure in the solver.
2730###########################################################
2731
2732sub create_new_directory_structure
2733{
2734    my ($newepmdir) = @_;
2735
2736    my $newdir = $installer::globals::epmoutpath;
2737
2738    if ( $installer::globals::islinuxrpmbuild )
2739    {
2740        my $rpmdir;
2741                my $machine = "";
2742        if ( $installer::globals::compiler =~ /unxlngi/) {
2743                    $rpmdir = "$installer::globals::epmoutpath/RPMS/i586";
2744                }
2745        elsif ( $installer::globals::compiler =~ /unxlng/) {
2746                    $machine = (POSIX::uname())[4];
2747                    $rpmdir = "$installer::globals::epmoutpath/RPMS/$machine";
2748                }
2749                else { installer::exiter::exit_program("ERROR: rpmdir undefined !", "create_new_directory_structure"); }
2750
2751        my $systemcall = "mv $rpmdir/* $newdir";    # moving the rpms into the directory "RPMS"
2752
2753        my $returnvalue = system($systemcall);
2754
2755        $installer::logger::Lang->printf("Systemcall: %s\n", $systemcall);
2756
2757        if ($returnvalue)
2758        {
2759            $installer::logger::Lang->printf("ERROR: Could not move content of \"%s\" to \"%s\"!\n",
2760                $rpmdir,$newdir);
2761        }
2762        else
2763        {
2764            $installer::logger::Lang->printf("Success: Moved content of \"%s\" to \"%s\"!\n",
2765                $rpmdir, $newdir);
2766        }
2767
2768        # and removing the empty directory
2769
2770        if ( $machine ne "" )
2771        {
2772            installer::systemactions::remove_empty_directory("$installer::globals::epmoutpath/RPMS/$machine");
2773        }
2774        installer::systemactions::remove_empty_directory("$installer::globals::epmoutpath/RPMS/x86_64");
2775        installer::systemactions::remove_empty_directory("$installer::globals::epmoutpath/RPMS/i586");
2776        installer::systemactions::remove_empty_directory("$installer::globals::epmoutpath/RPMS/i386");
2777        installer::systemactions::remove_empty_directory("$installer::globals::epmoutpath/RPMS");
2778
2779    }
2780
2781    # Setting unix rights to "775" for $newdir ("RPMS" or "packages")
2782
2783    my $localcall = "chmod 775 $newdir \>\/dev\/null 2\>\&1";
2784    my $callreturnvalue = system($localcall);
2785
2786    $installer::logger::Lang->printf("Systemcall: %s\n", $localcall);
2787
2788    if ($callreturnvalue)
2789    {
2790        $installer::logger::Lang->printf("ERROR: Could not execute \"%s\"!\n", $localcall);
2791    }
2792    else
2793    {
2794        $installer::logger::Lang->printf("Success: Executed \"%s\" successfully!\n", $localcall);
2795    }
2796}
2797
2798######################################################
2799# Collect modules with product specific styles.
2800######################################################
2801
2802sub collect_modules_with_style
2803{
2804    my ($style, $modulesarrayref) = @_;
2805
2806    my @allmodules = ();
2807
2808    for ( my $i = 0; $i <= $#{$modulesarrayref}; $i++ )
2809    {
2810        my $onemodule = ${$modulesarrayref}[$i];
2811        my $styles = "";
2812        if ( $onemodule->{'Styles'} ) { $styles = $onemodule->{'Styles'}; }
2813        if ( $styles =~ /\b\Q$style\E\b/ )
2814        {
2815            push(@allmodules, $onemodule);
2816        }
2817    }
2818
2819    return \@allmodules;
2820}
2821
2822######################################################
2823# Remove modules without packagecontent.
2824######################################################
2825
2826sub remove_modules_without_package
2827{
2828    my ($allmodules) = @_;
2829
2830    my @allmodules = ();
2831
2832    for ( my $i = 0; $i <= $#{$allmodules}; $i++ )
2833    {
2834        my $onemodule = ${$allmodules}[$i];
2835        my $packagename = "";
2836        if ( $onemodule->{'PackageName'} ) { $packagename = $onemodule->{'PackageName'}; }
2837        if ( $packagename ne "" )
2838        {
2839            push(@allmodules, $onemodule);
2840        }
2841    }
2842
2843    return \@allmodules;
2844}
2845
2846######################################################
2847# Unpacking tar.gz file and setting new packagename.
2848######################################################
2849
2850sub unpack_tar_gz_file
2851{
2852    my ($packagename, $destdir) = @_;
2853
2854    my $newpackagename = "";
2855
2856    if ( $packagename =~ /\.tar\.gz\s*$/ )
2857    {
2858        # Collecting all packages in directory "packages"
2859        my $oldcontent = installer::systemactions::read_directory($destdir);
2860
2861        # unpacking gunzip
2862        my $systemcall = "cd $destdir; cat $packagename | gunzip | tar -xf -";
2863        make_systemcall($systemcall);
2864
2865        # deleting the tar.gz files
2866        $systemcall = "cd $destdir; rm -f $packagename";
2867        make_systemcall($systemcall);
2868
2869        # Finding new content -> that is the package name
2870        my ($newcontent, $allcontent ) = installer::systemactions::find_new_content_in_directory($destdir, $oldcontent);
2871        $newpackagename = ${$newcontent}[0];
2872        installer::pathanalyzer::make_absolute_filename_to_relative_filename(\$newpackagename);
2873    }
2874
2875    if ( $newpackagename ne "" ) { $packagename = $newpackagename; }
2876
2877    return $packagename;
2878}
2879
2880######################################################
2881# Copying files of child projects.
2882######################################################
2883
2884sub copy_childproject_files
2885{
2886    my ($allmodules, $sopackpath, $destdir, $modulesarrayref, $allvariables, $subdir, $includepatharrayref, $use_sopackpath) = @_;
2887
2888    for ( my $i = 0; $i <= $#{$allmodules}; $i++ )
2889    {
2890        my $localdestdir = $destdir;
2891        my $onemodule = ${$allmodules}[$i];
2892        my $packagename = $onemodule->{'PackageName'};
2893        my $sourcefile = "";
2894        if ( $use_sopackpath )
2895        {
2896            $sourcefile = $sopackpath . $installer::globals::separator . $installer::globals::compiler . $installer::globals::separator . $subdir . $installer::globals::separator . $packagename;
2897        }
2898        else
2899        {
2900            my $sourcepathref = installer::scriptitems::get_sourcepath_from_filename_and_includepath(\$packagename, $includepatharrayref, 1);
2901            $sourcefile = $$sourcepathref;
2902        }
2903
2904        if ( ! -f $sourcefile ) { installer::exiter::exit_program("ERROR: File not found: $sourcefile ($packagename) !", "copy_childproject_files"); }
2905        if ( $onemodule->{'Subdir'} )
2906        {
2907            $localdestdir = $localdestdir . $installer::globals::separator . $onemodule->{'Subdir'};
2908            if ( ! -d $localdestdir ) { installer::systemactions::create_directory($localdestdir); }
2909        }
2910        installer::systemactions::copy_one_file($sourcefile, $localdestdir);
2911        # Solaris: unpacking tar.gz files and setting new packagename
2912        if ( $installer::globals::issolarispkgbuild ) { $packagename = unpack_tar_gz_file($packagename, $localdestdir); }
2913
2914        if (( $installer::globals::isxpdplatform ) && ( $allvariables->{'XPDINSTALLER'} ))
2915        {
2916            installer::xpdinstaller::create_xpd_file_for_childproject($onemodule, $localdestdir, $packagename, $allvariableshashref, $modulesarrayref);
2917        }
2918    }
2919
2920}
2921
2922######################################################
2923# Copying files for system integration.
2924######################################################
2925
2926sub copy_and_unpack_tar_gz_files
2927{
2928    my ($sourcefile, $destdir) = @_;
2929
2930    my $systemcall = "cd $destdir; cat $sourcefile | gunzip | tar -xf -";
2931    make_systemcall($systemcall);
2932}
2933
2934######################################################
2935# Including child packages into the
2936# installation set.
2937######################################################
2938
2939sub put_childprojects_into_installset
2940{
2941    my ($newdir, $allvariables, $modulesarrayref, $includepatharrayref) = @_;
2942
2943    my $infoline = "";
2944
2945    my $sopackpath = "";
2946    if ( $ENV{'SO_PACK'} ) { $sopackpath  = $ENV{'SO_PACK'}; }
2947    else { installer::exiter::exit_program("ERROR: Environment variable SO_PACK not set!", "put_childprojects_into_installset"); }
2948
2949    my $destdir = "$newdir";
2950
2951    # adding Java
2952
2953    my $sourcefile = "";
2954
2955    # Finding the modules defined in scp (with flag JAVAMODULE, ADAMODULE, ...)
2956    # Getting name of package from scp-Module
2957    # Copy file into installation set
2958    # Create xpd file and put it into xpd directory
2959    # xpd file has to be created completely from module and package itself (-> no packagelist!)
2960
2961    if ( $allvariables->{'JAVAPRODUCT'} )
2962    {
2963        # Collect all modules with flag "JAVAMODULE"
2964        my $allmodules = collect_modules_with_style("JAVAMODULE", $modulesarrayref);
2965        $allmodules = remove_modules_without_package($allmodules);
2966        copy_childproject_files($allmodules, $sopackpath, $destdir, $modulesarrayref, $allvariables, "jre", $includepatharrayref, 1);
2967    }
2968
2969    # Adding additional required packages (freetype).
2970    # This package names are stored in global array @installer::globals::requiredpackages
2971
2972    if ( $allvariables->{'ADDREQUIREDPACKAGES'} )
2973    {
2974        # Collect all modules with flag "REQUIREDPACKAGEMODULE"
2975        my $allmodules = collect_modules_with_style("REQUIREDPACKAGEMODULE", $modulesarrayref);
2976        $allmodules = remove_modules_without_package($allmodules);
2977        copy_childproject_files($allmodules, $sopackpath, $destdir, $modulesarrayref, $allvariables, "requiredpackages", $includepatharrayref, 1);
2978    }
2979
2980    # Collect all modules with flag "USERLANDMODULE"
2981    my $alluserlandmodules = collect_modules_with_style("USERLANDMODULE", $modulesarrayref);
2982    $alluserlandmodules = remove_modules_without_package($alluserlandmodules);
2983    copy_childproject_files($alluserlandmodules, $sopackpath, $destdir, $modulesarrayref, $allvariables, "", $includepatharrayref, 0);
2984
2985}
2986
2987######################################################
2988# Checking whether the new content is a directory and
2989# not a package. If it is a directory, the complete
2990# content of the directory has to be added to the
2991# array newcontent.
2992######################################################
2993
2994sub control_subdirectories
2995{
2996    my ($content, $subdir) = @_;
2997
2998    my @newcontent = ();
2999
3000    for ( my $i = 0; $i <= $#{$content}; $i++ )
3001    {
3002        if ( -d ${$content}[$i] )
3003        {
3004            $subdir = ${$content}[$i];
3005            installer::pathanalyzer::make_absolute_filename_to_relative_filename(\$subdir);
3006            my $allpackages = installer::systemactions::read_directory(${$content}[$i]);
3007            for ( my $j = 0; $j <= $#{$allpackages}; $j++ )
3008            {
3009                # Currently only Linux rpm is supported, debian packages cannot be installed via xpd installer
3010                if (( $installer::globals::islinuxbuild ) && ( ! ( ${$allpackages}[$j] =~ /\.rpm\s*$/ ))) { next; }
3011                push(@newcontent, ${$allpackages}[$j]);
3012            }
3013        }
3014        else
3015        {
3016            push(@newcontent, ${$content}[$i]);
3017        }
3018    }
3019
3020    return (\@newcontent, $subdir);
3021}
3022
3023######################################################
3024# Including the system integration files into the
3025# installation sets.
3026######################################################
3027
3028sub put_systemintegration_into_installset
3029{
3030    my ($newdir, $includepatharrayref, $allvariables, $modulesarrayref) = @_;
3031
3032    my $destdir = $newdir;
3033
3034    # adding System integration files
3035
3036    my $sourcefile = "";
3037
3038    # Finding the modules defined in scp (with flag SYSTEMMODULE)
3039    # Getting name of package from scp-Module
3040    # Search package in list off all include files
3041    # Copy file into installation set and unpack it (always tar.gz)
3042    # Create xpd file and put it into xpd directory
3043    # tar.gz can contain a different number of packages -> automatically create hidden sub modules
3044    # xpd file has to be created completely from module and package itself (-> no packagelist!)
3045
3046    # Collect all modules with flag "SYSTEMMODULE"
3047    my $allmodules = collect_modules_with_style("SYSTEMMODULE", $modulesarrayref);
3048    $allmodules = remove_modules_without_package($allmodules);
3049
3050    for ( my $i = 0; $i <= $#{$allmodules}; $i++ )
3051    {
3052        my $onemodule = ${$allmodules}[$i];
3053        my $packagetarfilename = $onemodule->{'PackageName'};
3054
3055        $installer::logger::Lang->printf("Including into installation set: %s\n", $packagetarfilename);
3056
3057        my $sourcepathref = installer::scriptitems::get_sourcepath_from_filename_and_includepath(\$packagetarfilename, $includepatharrayref, 1);
3058        if ( $$sourcepathref eq "" ) { installer::exiter::exit_program("ERROR: Source path not found for $packagetarfilename!", "copy_systemintegration_files"); }
3059
3060        # Collecting all packages in directory "packages" or "RPMS"
3061        my $oldcontent = installer::systemactions::read_directory($destdir);
3062
3063        copy_and_unpack_tar_gz_files($$sourcepathref, $destdir);
3064
3065        # Finding new content -> that is the package name
3066        my ($newcontent, $allcontent ) = installer::systemactions::find_new_content_in_directory($destdir, $oldcontent);
3067
3068        # special handling, if new content is a directory
3069        my $subdir = "";
3070        if ( ! $installer::globals::issolarispkgbuild ) { ($newcontent, $subdir) = control_subdirectories($newcontent); }
3071
3072        # Adding license content into Solaris packages
3073        if (( $installer::globals::issolarispkgbuild ) && ( $installer::globals::englishlicenseset ) && ( ! $variableshashref->{'NO_LICENSE_INTO_COPYRIGHT'} )) { installer::worker::add_license_into_systemintegrationpackages($destdir, $newcontent); }
3074
3075        if (( $installer::globals::isxpdplatform ) && ( $allvariables->{'XPDINSTALLER'} ))
3076        {
3077            installer::xpdinstaller::create_xpd_file_for_systemintegration($onemodule, $newcontent, $modulesarrayref, $subdir);
3078        }
3079    }
3080}
3081
3082######################################################
3083# Analyzing the Unix installation path.
3084# From the installation path /opt/openofficeorg20
3085# is the part /opt relocatable and the part
3086# openofficeorg20 static.
3087######################################################
3088
3089sub analyze_rootpath
3090{
3091    my ($rootpath, $staticpathref, $relocatablepathref, $allvariables) = @_;
3092
3093    $rootpath =~ s/\/\s*$//;    # removing ending slash
3094
3095    ##############################################################
3096    # Version 1: "/opt" is variable and "openofficeorg20" fixed
3097    ##############################################################
3098
3099    # my $staticpath = $rootpath;
3100    # installer::pathanalyzer::make_absolute_filename_to_relative_filename(\$staticpath);
3101    # $$staticpathref = $staticpath;                # will be "openofficeorg20"
3102
3103    # my $relocatablepath = $rootpath;
3104    # installer::pathanalyzer::get_path_from_fullqualifiedname(\$relocatablepath);
3105    # $$relocatablepathref = $relocatablepath;      # will be "/opt/"
3106
3107    ##############################################################
3108    # Version 2: "/opt/openofficeorg20" is variable and "" fixed
3109    ##############################################################
3110
3111    # if ( $$relocatablepathref eq "" ) # relocatablepath is not defined in package list
3112    # {
3113    #   $$staticpathref = "";   # will be ""
3114    #   $$relocatablepathref = $rootpath . "\/"; # relocatable path must end with "/", will be "/opt/openofficeorg20/"
3115    #   # setting the static path to the hostname of the directory with style OFFICEDIRECTORY
3116    #   if ( $allvariables->{'SETSTATICPATH'} ) { $$staticpathref = $installer::globals::officedirhostname; }
3117    #
3118    # }
3119    # else  # relocatablepath is defined in package list
3120    # {
3121    #   $$relocatablepathref =~ s/\/\s*$//;         # removing ending slash
3122    #   $$relocatablepathref = $$relocatablepathref . "\/"; # relocatable path must end with "/"
3123    #   my $staticpath = $rootpath;
3124    #   $staticpath =~ s/\Q$$relocatablepathref\E//;
3125    #   $staticpath =~ s/\/\s*$//;
3126    #   $$staticpathref = $staticpath;
3127    # }
3128
3129    ##############################################################
3130    # Version 3: "/" is variable and "/opt/openofficeorg20" fixed
3131    ##############################################################
3132
3133    $$relocatablepathref = "/";
3134    # Static path has to contain the office directory name. This is replaced in shellscripts.
3135    $$staticpathref = $rootpath . $installer::globals::separator . $installer::globals::officedirhostname;
3136    # For RPM version 3.x it is required, that Prefix is not "/" in spec file. In this case --relocate will not work,
3137    # because RPM 3.x says, that the package is not relocatable. Therefore we have to use Prefix=/opt and for
3138    # all usages of --relocate this path has to be on both sides of the "=": --relocate /opt=<myselectdir>/opt .
3139    if ( $installer::globals::islinuxrpmbuild )
3140    {
3141        $$relocatablepathref = $rootpath . "\/"; # relocatable path must end with "/", will be "/opt/"
3142        $$staticpathref = $installer::globals::officedirhostname; # to be used as replacement in shell scripts
3143    }
3144
3145    if ( $installer::globals::islinuxdebbuild )
3146    {
3147        $$relocatablepathref = "";
3148        # $$staticpathref is already "/opt/openoffice.org3", no additional $rootpath required.
3149        # $$staticpathref = $rootpath . $installer::globals::separator . $$staticpathref;  # no relocatibility for Debian
3150    }
3151
3152}
3153
3154######################################################
3155# Including license and readme into
3156# Unix installation sets.
3157######################################################
3158
3159sub put_installsetfiles_into_installset
3160{
3161    my ($destdir) = @_;
3162
3163    # All files for the installation set are saved in the global
3164    # array @installer::globals::installsetfiles
3165
3166    for ( my $i = 0; $i <= $#installer::globals::installsetfiles; $i++ )
3167    {
3168        my $onefile = $installer::globals::installsetfiles[$i];
3169        my $sourcefile = $onefile->{'sourcepath'};
3170        my $destfile = "";
3171        if ( $installer::globals::addjavainstaller ) { $destfile = $onefile->{'Name'}; }
3172        else { $destfile = $destdir . $installer::globals::separator . $onefile->{'Name'}; }
3173        installer::systemactions::copy_one_file($sourcefile, $destfile);
3174
3175        $installer::logger::Lang->printf("Adding to installation set \"%s\" from source \"%s\".\n",
3176            $destfile, $sourcefile);
3177    }
3178}
3179
3180######################################################
3181# Replacing one variable in patchinfo file
3182######################################################
3183
3184sub replace_one_variable_in_file
3185{
3186    my ( $file, $placeholder, $value ) = @_;
3187
3188    for ( my $i = 0; $i <= $#{$file}; $i++ )
3189    {
3190        ${$file}[$i] =~ s/$placeholder/$value/g;
3191    }
3192}
3193
3194######################################################
3195# Setting variables in the patchinfo file
3196######################################################
3197
3198sub set_patchinfo
3199{
3200    my ( $patchinfofile, $patchid, $allvariables ) = @_;
3201
3202    # Setting: PATCHIDPLACEHOLDER and ARCHITECTUREPLACEHOLDER and PATCHCORRECTSPLACEHOLDER
3203
3204    replace_one_variable_in_file($patchinfofile, "PATCHIDPLACEHOLDER", $patchid);
3205
3206    my $architecture = "";
3207    if ( $installer::globals::issolarissparcbuild ) { $architecture = "sparc"; }
3208    if ( $installer::globals::issolarisx86build ) { $architecture = "i386"; }
3209
3210    replace_one_variable_in_file($patchinfofile, "ARCHITECTUREPLACEHOLDER", $architecture);
3211
3212    if ( ! $allvariables->{'SOLARISPATCHCORRECTS'} ) { installer::exiter::exit_program("ERROR: No setting for PATCH_CORRECTS in zip list file!", "set_patchinfo"); }
3213    my $patchcorrects = $allvariables->{'SOLARISPATCHCORRECTS'};
3214
3215    replace_one_variable_in_file($patchinfofile, "PATCHCORRECTSPLACEHOLDER", $patchcorrects);
3216
3217    # Setting also PATCH_REQUIRES in patch info file, if entry in zip list file exists
3218    my $requiresstring = "";
3219    if ( $installer::globals::issolarissparcbuild ) { $requiresstring = "SOLSPARCPATCHREQUIRES"; }
3220    if ( $installer::globals::issolarisx86build ) { $requiresstring = "SOLIAPATCHREQUIRES"; }
3221
3222    if ( $allvariables->{$requiresstring} )
3223    {
3224        my $newline = "PATCH_REQUIRES=\"" . $allvariables->{$requiresstring} . "\"" . "\n";
3225        push(@{$patchinfofile}, $newline);
3226    }
3227}
3228
3229######################################################
3230# Finalizing patch: Renaming directory and
3231# including additional patch files.
3232######################################################
3233
3234sub finalize_patch
3235{
3236    my ( $newepmdir, $allvariables ) = @_;
3237
3238    my $patchidname = "SOLSPARCPATCHID";
3239    if ( $installer::globals::issolarisx86build ) { $patchidname = "SOLIAPATCHID"; }
3240
3241    if ( ! $allvariables->{$patchidname} ) { installer::exiter::exit_program("ERROR: Variable $patchidname not defined in zip list file!", "finalize_patch"); }
3242    my $patchid = $allvariables->{$patchidname};
3243    installer::systemactions::rename_directory($newepmdir, $patchid);
3244
3245    # Copying all typical patch files into the patch directory
3246    # All patch file names are stored in @installer::globals::solarispatchfiles
3247    # Location of the file is $installer::globals::patchincludepath
3248
3249    my $sourcepath = $installer::globals::patchincludepath;
3250    $sourcepath =~ s/\/\s*$//;
3251
3252    for ( my $i = 0; $i <= $#installer::globals::solarispatchfiles; $i++ )
3253    {
3254        my $sourcefile = $sourcepath . $installer::globals::separator . $installer::globals::solarispatchfiles[$i];
3255        my $destfile = $patchid . $installer::globals::separator . $installer::globals::solarispatchfiles[$i];
3256        installer::systemactions::copy_one_file($sourcefile, $destfile);
3257    }
3258
3259    # And editing the patchinfo file
3260
3261    my $patchinfofilename = $patchid . $installer::globals::separator . "patchinfo";
3262    my $patchinfofile = installer::files::read_file($patchinfofilename);
3263    set_patchinfo($patchinfofile, $patchid, $allvariables);
3264    installer::files::save_file($patchinfofilename, $patchinfofile);
3265}
3266
3267######################################################
3268# Finalizing Linux patch: Renaming directory and
3269# including additional patch files.
3270######################################################
3271
3272sub finalize_linux_patch
3273{
3274    my ( $newepmdir, $allvariables, $includepatharrayref ) = @_;
3275
3276    # Copying the setup into the patch directory
3277    # and including the list of RPMs into it
3278
3279    print "... creating patch setup ...\n";
3280
3281    installer::logger::include_header_into_logfile("Creating Linux patch setup:");
3282
3283    # find and read setup script template
3284
3285    my $scriptfilename = "linuxpatchscript.sh";
3286    my $scriptref = installer::scriptitems::get_sourcepath_from_filename_and_includepath(\$scriptfilename, $includepatharrayref, 0);
3287    if ($$scriptref eq "") { installer::exiter::exit_program("ERROR: Could not find patch script template $scriptfilename!", "finalize_linux_patch"); }
3288    my $scriptfile = installer::files::read_file($$scriptref);
3289
3290    $installer::logger::Lang->printf("Found  script file %s: %s \n", $scriptfilename, $$scriptref);
3291
3292    # Collecting all RPMs in the patch directory
3293
3294    my $fileextension = "rpm";
3295    my $rpmfiles = installer::systemactions::find_file_with_file_extension($fileextension, $newepmdir);
3296    if ( ! ( $#{$rpmfiles} > -1 )) { installer::exiter::exit_program("ERROR: Could not find rpm in directory $newepmdir!", "finalize_linux_patch"); }
3297    for ( my $i = 0; $i <= $#{$rpmfiles}; $i++ ) { installer::pathanalyzer::make_absolute_filename_to_relative_filename(\${$rpmfiles}[$i]); }
3298
3299#   my $installline = "";
3300#
3301#   for ( my $i = 0; $i <= $#{$rpmfiles}; $i++ )
3302#   {
3303#       $installline = $installline . "  rpm --prefix \$PRODUCTINSTALLLOCATION -U $newepmdir/${$rpmfiles}[$i]\n";
3304#   }
3305#
3306#   $installline =~ s/\s*$//;
3307#
3308#   for ( my $j = 0; $j <= $#{$scriptfile}; $j++ )
3309#   {
3310#       ${$scriptfile}[$j] =~ s/INSTALLLINES/$installline/;
3311#   }
3312
3313    # Searching packagename containing -core01
3314    my $found_package = 0;
3315    my $searchpackagename = "";
3316    for ( my $i = 0; $i <= $#{$rpmfiles}; $i++ )
3317    {
3318        if ( ${$rpmfiles}[$i] =~ /-core01-/ )
3319        {
3320            $searchpackagename = ${$rpmfiles}[$i];
3321            $found_package = 1;
3322            if ( $searchpackagename =~ /^\s*(.*?-core01)-.*/ ) { $searchpackagename = $1; }
3323            last;
3324        }
3325    }
3326
3327    if ( ! $found_package ) { installer::exiter::exit_program("ERROR: No package containing \"-core01\" found in directory \"$newepmdir\"", "finalize_linux_patch"); }
3328
3329    # Replacing the searchpackagename
3330    for ( my $j = 0; $j <= $#{$scriptfile}; $j++ ) { ${$scriptfile}[$j] =~ s/SEARCHPACKAGENAMEPLACEHOLDER/$searchpackagename/; }
3331
3332    # Setting the PRODUCTDIRECTORYNAME to $installer::globals::officedirhostname
3333    for ( my $j = 0; $j <= $#{$scriptfile}; $j++ ) { ${$scriptfile}[$j] =~ s/PRODUCTDIRECTORYNAME/$installer::globals::officedirhostname/; }
3334
3335    # Replacing the productname
3336    my $productname = $allvariables->{'PRODUCTNAME'};
3337    $productname = lc($productname);
3338    $productname =~ s/ /_/g;    # abc office -> abc_office
3339
3340    $installer::logger::Lang->printf("Adding productname %s into Linux patch script\n", $productname);
3341
3342    for ( my $j = 0; $j <= $#{$scriptfile}; $j++ ) { ${$scriptfile}[$j] =~ s/PRODUCTNAMEPLACEHOLDER/$productname/; }
3343
3344    # Saving the file
3345
3346    my $newscriptfilename = "setup"; # $newepmdir . $installer::globals::separator . "setup";
3347    installer::files::save_file($newscriptfilename, $scriptfile);
3348
3349    $installer::logger::Lang->printf("Saved Linux patch setup %s\n", $newscriptfilename);
3350
3351    # Setting unix rights 755
3352    my $localcall = "chmod 775 $newscriptfilename \>\/dev\/null 2\>\&1";
3353    system($localcall);
3354}
3355
33561;
3357