1*b1cdbd2cSJim Jagielski#**************************************************************
2*b1cdbd2cSJim Jagielski#
3*b1cdbd2cSJim Jagielski#  Licensed to the Apache Software Foundation (ASF) under one
4*b1cdbd2cSJim Jagielski#  or more contributor license agreements.  See the NOTICE file
5*b1cdbd2cSJim Jagielski#  distributed with this work for additional information
6*b1cdbd2cSJim Jagielski#  regarding copyright ownership.  The ASF licenses this file
7*b1cdbd2cSJim Jagielski#  to you under the Apache License, Version 2.0 (the
8*b1cdbd2cSJim Jagielski#  "License"); you may not use this file except in compliance
9*b1cdbd2cSJim Jagielski#  with the License.  You may obtain a copy of the License at
10*b1cdbd2cSJim Jagielski#
11*b1cdbd2cSJim Jagielski#    http://www.apache.org/licenses/LICENSE-2.0
12*b1cdbd2cSJim Jagielski#
13*b1cdbd2cSJim Jagielski#  Unless required by applicable law or agreed to in writing,
14*b1cdbd2cSJim Jagielski#  software distributed under the License is distributed on an
15*b1cdbd2cSJim Jagielski#  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*b1cdbd2cSJim Jagielski#  KIND, either express or implied.  See the License for the
17*b1cdbd2cSJim Jagielski#  specific language governing permissions and limitations
18*b1cdbd2cSJim Jagielski#  under the License.
19*b1cdbd2cSJim Jagielski#
20*b1cdbd2cSJim Jagielski#**************************************************************
21*b1cdbd2cSJim Jagielski
22*b1cdbd2cSJim Jagielski
23*b1cdbd2cSJim Jagielski
24*b1cdbd2cSJim Jagielskipackage installer::languagepack;
25*b1cdbd2cSJim Jagielski
26*b1cdbd2cSJim Jagielskiuse installer::converter;
27*b1cdbd2cSJim Jagielskiuse installer::existence;
28*b1cdbd2cSJim Jagielskiuse installer::files;
29*b1cdbd2cSJim Jagielskiuse installer::globals;
30*b1cdbd2cSJim Jagielskiuse installer::logger;
31*b1cdbd2cSJim Jagielskiuse installer::pathanalyzer;
32*b1cdbd2cSJim Jagielskiuse installer::scpzipfiles;
33*b1cdbd2cSJim Jagielskiuse installer::scriptitems;
34*b1cdbd2cSJim Jagielskiuse installer::systemactions;
35*b1cdbd2cSJim Jagielskiuse installer::worker;
36*b1cdbd2cSJim Jagielski
37*b1cdbd2cSJim Jagielski####################################################
38*b1cdbd2cSJim Jagielski# Selecting all files with the correct language
39*b1cdbd2cSJim Jagielski####################################################
40*b1cdbd2cSJim Jagielski
41*b1cdbd2cSJim Jagielskisub select_language_items
42*b1cdbd2cSJim Jagielski{
43*b1cdbd2cSJim Jagielski	my ( $itemsref, $languagesarrayref, $itemname ) = @_;
44*b1cdbd2cSJim Jagielski
45*b1cdbd2cSJim Jagielski	installer::logger::include_header_into_logfile("Selecting languages for language pack. Item: $itemname");
46*b1cdbd2cSJim Jagielski
47*b1cdbd2cSJim Jagielski	my @itemsarray = ();
48*b1cdbd2cSJim Jagielski
49*b1cdbd2cSJim Jagielski	for ( my $i = 0; $i <= $#{$itemsref}; $i++ )
50*b1cdbd2cSJim Jagielski	{
51*b1cdbd2cSJim Jagielski		my $oneitem = ${$itemsref}[$i];
52*b1cdbd2cSJim Jagielski
53*b1cdbd2cSJim Jagielski		my $ismultilingual = $oneitem->{'ismultilingual'};
54*b1cdbd2cSJim Jagielski
55*b1cdbd2cSJim Jagielski		if (!($ismultilingual))
56*b1cdbd2cSJim Jagielski		{
57*b1cdbd2cSJim Jagielski			# Files with style "LANGUAGEPACK" and "FORCELANGUAGEPACK" also have to be included into the language pack.
58*b1cdbd2cSJim Jagielski			# Files with style "LANGUAGEPACK" are only included into language packs.
59*b1cdbd2cSJim Jagielski			# Files with style "FORCELANGUAGEPACK" are included into language packs and non language packs. They are
60*b1cdbd2cSJim Jagielski			# forced, because otherwise they not not be included into languagepacks.
61*b1cdbd2cSJim Jagielski
62*b1cdbd2cSJim Jagielski			my $styles = "";
63*b1cdbd2cSJim Jagielski			if ( $oneitem->{'Styles'} ) { $styles = $oneitem->{'Styles'}; }
64*b1cdbd2cSJim Jagielski
65*b1cdbd2cSJim Jagielski			if (( $styles =~ /\bLANGUAGEPACK\b/ ) || ( $styles =~ /\bFORCELANGUAGEPACK\b/ )) { push(@itemsarray, $oneitem); }
66*b1cdbd2cSJim Jagielski
67*b1cdbd2cSJim Jagielski			next; 	# single language files are not included into language pack
68*b1cdbd2cSJim Jagielski		}
69*b1cdbd2cSJim Jagielski
70*b1cdbd2cSJim Jagielski		my $specificlanguage = "";
71*b1cdbd2cSJim Jagielski		if ( $oneitem->{'specificlanguage'} ) { $specificlanguage = $oneitem->{'specificlanguage'}; }
72*b1cdbd2cSJim Jagielski
73*b1cdbd2cSJim Jagielski		for ( my $j = 0; $j <= $#{$languagesarrayref}; $j++ )	# iterating over all languages
74*b1cdbd2cSJim Jagielski		{
75*b1cdbd2cSJim Jagielski			my $onelanguage = ${$languagesarrayref}[$j];
76*b1cdbd2cSJim Jagielski			my $locallang = $onelanguage;
77*b1cdbd2cSJim Jagielski			$locallang =~ s/-/_/;
78*b1cdbd2cSJim Jagielski
79*b1cdbd2cSJim Jagielski			if ( $specificlanguage eq $onelanguage )
80*b1cdbd2cSJim Jagielski			{
81*b1cdbd2cSJim Jagielski				# $oneitem->{'modules'} = $installer::globals::rootmodulegid; 	 # all files in a language pack are root files
82*b1cdbd2cSJim Jagielski				# Using $installer::globals::languagemodulesbase (?)
83*b1cdbd2cSJim Jagielski
84*b1cdbd2cSJim Jagielski#				# no more automatic change of module assignments
85*b1cdbd2cSJim Jagielski#				$oneitem->{'modules'} = $installer::globals::rootmodulegid . "_$locallang"; 	 # all files in a language pack are root files
86*b1cdbd2cSJim Jagielski#
87*b1cdbd2cSJim Jagielski#				if (( $installer::globals::islinuxbuild ) || ( $installer::globals::issolarispkgbuild ))
88*b1cdbd2cSJim Jagielski#				{
89*b1cdbd2cSJim Jagielski#					if ( $oneitem->{'Dir'} )
90*b1cdbd2cSJim Jagielski#					{
91*b1cdbd2cSJim Jagielski#						if ( $oneitem->{'Dir'} eq "gid_Dir_Fonts_Truetype" ) { $oneitem->{'modules'} = "gid_Module_Langpack_Fonts_$locallang"; }
92*b1cdbd2cSJim Jagielski#						if ( $oneitem->{'Dir'} eq "gid_Dir_Resource" ) { $oneitem->{'modules'} = "gid_Module_Langpack_Resource_$locallang"; }
93*b1cdbd2cSJim Jagielski#						if ( $oneitem->{'Dir'} eq "gid_Dir_Help_Isolanguage" ) { $oneitem->{'modules'} = "gid_Module_Langpack_Help_$locallang"; }
94*b1cdbd2cSJim Jagielski#					}
95*b1cdbd2cSJim Jagielski#				}
96*b1cdbd2cSJim Jagielski
97*b1cdbd2cSJim Jagielski				# preparing different modules for Windows Installer language packs
98*b1cdbd2cSJim Jagielski				# my $underlinelanguage = $specificlanguage;
99*b1cdbd2cSJim Jagielski				# $underlinelanguage =~ s/-/_/;
100*b1cdbd2cSJim Jagielski				# if ( $installer::globals::iswindowsbuild ) { $oneitem->{'modules'} = $installer::globals::languagemodulesbase . $underlinelanguage; }
101*b1cdbd2cSJim Jagielski
102*b1cdbd2cSJim Jagielski#               # no more collecting of language pack feature
103*b1cdbd2cSJim Jagielski#				if (! installer::existence::exists_in_array($oneitem->{'modules'}, \@installer::globals::languagepackfeature))
104*b1cdbd2cSJim Jagielski#				{
105*b1cdbd2cSJim Jagielski#					push(@installer::globals::languagepackfeature, $oneitem->{'modules'});	# Collecting all language pack feature
106*b1cdbd2cSJim Jagielski#				}
107*b1cdbd2cSJim Jagielski
108*b1cdbd2cSJim Jagielski				push(@itemsarray, $oneitem);
109*b1cdbd2cSJim Jagielski			}
110*b1cdbd2cSJim Jagielski		}
111*b1cdbd2cSJim Jagielski	}
112*b1cdbd2cSJim Jagielski
113*b1cdbd2cSJim Jagielski	return \@itemsarray;
114*b1cdbd2cSJim Jagielski}
115*b1cdbd2cSJim Jagielski
116*b1cdbd2cSJim Jagielskisub replace_languagestring_variable
117*b1cdbd2cSJim Jagielski{
118*b1cdbd2cSJim Jagielski	my ($onepackageref, $languagestringref) = @_;
119*b1cdbd2cSJim Jagielski
120*b1cdbd2cSJim Jagielski	my $key;
121*b1cdbd2cSJim Jagielski
122*b1cdbd2cSJim Jagielski	foreach $key (keys %{$onepackageref})
123*b1cdbd2cSJim Jagielski	{
124*b1cdbd2cSJim Jagielski		my $value = $onepackageref->{$key};
125*b1cdbd2cSJim Jagielski		$value =~ s/\%LANGUAGESTRING/$$languagestringref/g;
126*b1cdbd2cSJim Jagielski		$onepackageref->{$key} = $value;
127*b1cdbd2cSJim Jagielski	}
128*b1cdbd2cSJim Jagielski}
129*b1cdbd2cSJim Jagielski
130*b1cdbd2cSJim Jagielski#########################################################
131*b1cdbd2cSJim Jagielski# Including the license text into the script template
132*b1cdbd2cSJim Jagielski#########################################################
133*b1cdbd2cSJim Jagielski
134*b1cdbd2cSJim Jagielskisub put_license_file_into_script
135*b1cdbd2cSJim Jagielski{
136*b1cdbd2cSJim Jagielski	my ($scriptfile, $licensefile) = @_;
137*b1cdbd2cSJim Jagielski
138*b1cdbd2cSJim Jagielski	my $infoline = "Adding licensefile into language pack script\n";
139*b1cdbd2cSJim Jagielski	$installer::logger::Lang->print($infoline);
140*b1cdbd2cSJim Jagielski
141*b1cdbd2cSJim Jagielski	my $includestring = "";
142*b1cdbd2cSJim Jagielski
143*b1cdbd2cSJim Jagielski	for ( my $i = 0; $i <= $#{$licensefile}; $i++ )
144*b1cdbd2cSJim Jagielski	{
145*b1cdbd2cSJim Jagielski		$includestring = $includestring . ${$licensefile}[$i];
146*b1cdbd2cSJim Jagielski	}
147*b1cdbd2cSJim Jagielski
148*b1cdbd2cSJim Jagielski	for ( my $i = 0; $i <= $#{$scriptfile}; $i++ )
149*b1cdbd2cSJim Jagielski	{
150*b1cdbd2cSJim Jagielski		${$scriptfile}[$i] =~ s/LICENSEFILEPLACEHOLDER/$includestring/;
151*b1cdbd2cSJim Jagielski	}
152*b1cdbd2cSJim Jagielski}
153*b1cdbd2cSJim Jagielski
154*b1cdbd2cSJim Jagielski#########################################################
155*b1cdbd2cSJim Jagielski# Creating a tar.gz file from a Solaris package
156*b1cdbd2cSJim Jagielski#########################################################
157*b1cdbd2cSJim Jagielski
158*b1cdbd2cSJim Jagielskisub create_tar_gz_file
159*b1cdbd2cSJim Jagielski{
160*b1cdbd2cSJim Jagielski	my ($installdir, $packagename, $packagestring) = @_;
161*b1cdbd2cSJim Jagielski
162*b1cdbd2cSJim Jagielski	$packagename =~ s/\.rpm\s*$//;
163*b1cdbd2cSJim Jagielski	my $targzname = $packagename . ".tar.gz";
164*b1cdbd2cSJim Jagielski	$systemcall = "cd $installdir; tar -cf - $packagestring | gzip > $targzname";
165*b1cdbd2cSJim Jagielski	$installer::logger::Info->printf("... %s ...\n", $systemcall);
166*b1cdbd2cSJim Jagielski
167*b1cdbd2cSJim Jagielski	my $returnvalue = system($systemcall);
168*b1cdbd2cSJim Jagielski
169*b1cdbd2cSJim Jagielski	my $infoline = "Systemcall: $systemcall\n";
170*b1cdbd2cSJim Jagielski	$installer::logger::Lang->print($infoline);
171*b1cdbd2cSJim Jagielski
172*b1cdbd2cSJim Jagielski	if ($returnvalue)
173*b1cdbd2cSJim Jagielski	{
174*b1cdbd2cSJim Jagielski		$infoline = "ERROR: Could not execute \"$systemcall\"!\n";
175*b1cdbd2cSJim Jagielski		$installer::logger::Lang->print($infoline);
176*b1cdbd2cSJim Jagielski	}
177*b1cdbd2cSJim Jagielski	else
178*b1cdbd2cSJim Jagielski	{
179*b1cdbd2cSJim Jagielski		$infoline = "Success: Executed \"$systemcall\" successfully!\n";
180*b1cdbd2cSJim Jagielski		$installer::logger::Lang->print($infoline);
181*b1cdbd2cSJim Jagielski	}
182*b1cdbd2cSJim Jagielski
183*b1cdbd2cSJim Jagielski	return $targzname;
184*b1cdbd2cSJim Jagielski}
185*b1cdbd2cSJim Jagielski
186*b1cdbd2cSJim Jagielski#########################################################
187*b1cdbd2cSJim Jagielski# Determining the name of the package file
188*b1cdbd2cSJim Jagielski#########################################################
189*b1cdbd2cSJim Jagielski
190*b1cdbd2cSJim Jagielskisub get_packagename_from_packagelist
191*b1cdbd2cSJim Jagielski{
192*b1cdbd2cSJim Jagielski	my ( $alldirs, $allvariables, $languagestringref ) = @_;
193*b1cdbd2cSJim Jagielski
194*b1cdbd2cSJim Jagielski	# my $packagename = "";
195*b1cdbd2cSJim Jagielski
196*b1cdbd2cSJim Jagielski	# for ( my $i = 0; $i <= $#{$alldirs}; $i++ )
197*b1cdbd2cSJim Jagielski	# {
198*b1cdbd2cSJim Jagielski	#	if ( ${$alldirs}[$i] =~ /-fonts/ ) { next; }
199*b1cdbd2cSJim Jagielski	#	if ( ${$alldirs}[$i] =~ /-help/ ) { next; }
200*b1cdbd2cSJim Jagielski	#	if ( ${$alldirs}[$i] =~ /-res/ ) { next; }
201*b1cdbd2cSJim Jagielski	#
202*b1cdbd2cSJim Jagielski	#	$packagename = ${$alldirs}[$i];
203*b1cdbd2cSJim Jagielski	#	last;
204*b1cdbd2cSJim Jagielski	# }
205*b1cdbd2cSJim Jagielski
206*b1cdbd2cSJim Jagielski	# if ( $packagename eq "" ) { installer::exiter::exit_program("ERROR: Could not find base package in directory $installdir!", "get_packagename_from_packagelist"); }
207*b1cdbd2cSJim Jagielski
208*b1cdbd2cSJim Jagielski	my $localproductname = $allvariables->{'PRODUCTNAME'};
209*b1cdbd2cSJim Jagielski	$localproductname = lc($localproductname);
210*b1cdbd2cSJim Jagielski	$localproductname =~ s/ //g;
211*b1cdbd2cSJim Jagielski	$localproductname =~ s/-/_/g;
212*b1cdbd2cSJim Jagielski
213*b1cdbd2cSJim Jagielski	my $packagename = $localproductname . "_" . $$languagestringref;
214*b1cdbd2cSJim Jagielski
215*b1cdbd2cSJim Jagielski	return $packagename;
216*b1cdbd2cSJim Jagielski}
217*b1cdbd2cSJim Jagielski
218*b1cdbd2cSJim Jagielski#########################################################
219*b1cdbd2cSJim Jagielski# Determining the name of the package file or the rpm
220*b1cdbd2cSJim Jagielski# in the installation directory. For language packs
221*b1cdbd2cSJim Jagielski# there is only one file in this directory
222*b1cdbd2cSJim Jagielski#########################################################
223*b1cdbd2cSJim Jagielski
224*b1cdbd2cSJim Jagielskisub determine_packagename
225*b1cdbd2cSJim Jagielski{
226*b1cdbd2cSJim Jagielski	my ( $installdir, $allvariables, $languagestringref ) = @_;
227*b1cdbd2cSJim Jagielski
228*b1cdbd2cSJim Jagielski	my $packagename = "";
229*b1cdbd2cSJim Jagielski	my $allnames = "";
230*b1cdbd2cSJim Jagielski
231*b1cdbd2cSJim Jagielski	if ( $installer::globals::islinuxrpmbuild )
232*b1cdbd2cSJim Jagielski	{
233*b1cdbd2cSJim Jagielski		# determining the rpm file in directory $installdir
234*b1cdbd2cSJim Jagielski
235*b1cdbd2cSJim Jagielski		my $fileextension = "rpm";
236*b1cdbd2cSJim Jagielski		my $rpmfiles = installer::systemactions::find_file_with_file_extension($fileextension, $installdir);
237*b1cdbd2cSJim Jagielski		if ( ! ( $#{$rpmfiles} > -1 )) { installer::exiter::exit_program("ERROR: Could not find package in directory $installdir!", "determine_packagename"); }
238*b1cdbd2cSJim Jagielski		my $rpmsav = installer::converter::copy_array_from_references($rpmfiles);
239*b1cdbd2cSJim Jagielski		for ( my $i = 0; $i <= $#{$rpmfiles}; $i++ ) { installer::pathanalyzer::make_absolute_filename_to_relative_filename(\${$rpmfiles}[$i]); }
240*b1cdbd2cSJim Jagielski
241*b1cdbd2cSJim Jagielski		$packagename = get_packagename_from_packagelist($rpmfiles, $allvariables, $languagestringref);
242*b1cdbd2cSJim Jagielski
243*b1cdbd2cSJim Jagielski		my $packagestring = installer::converter::convert_array_to_space_separated_string($rpmfiles);
244*b1cdbd2cSJim Jagielski		$packagename = create_tar_gz_file($installdir, $packagename, $packagestring);	# only one file
245*b1cdbd2cSJim Jagielski		for ( my $i = 0; $i <= $#{$rpmsav}; $i++ )
246*b1cdbd2cSJim Jagielski		{
247*b1cdbd2cSJim Jagielski			my $onefile = $installdir . $installer::globals::separator . ${$rpmsav}[$i];
248*b1cdbd2cSJim Jagielski			unlink($onefile);
249*b1cdbd2cSJim Jagielski		}
250*b1cdbd2cSJim Jagielski
251*b1cdbd2cSJim Jagielski		$allnames = $rpmfiles;
252*b1cdbd2cSJim Jagielski	}
253*b1cdbd2cSJim Jagielski
254*b1cdbd2cSJim Jagielski	if ( $installer::globals::issolarisbuild )
255*b1cdbd2cSJim Jagielski	{
256*b1cdbd2cSJim Jagielski		# determining the Solaris package file in directory $installdir
257*b1cdbd2cSJim Jagielski		my $alldirs = installer::systemactions::get_all_directories($installdir);
258*b1cdbd2cSJim Jagielski
259*b1cdbd2cSJim Jagielski		if ( ! ( $#{$alldirs} > -1 )) { installer::exiter::exit_program("ERROR: Could not find package in directory $installdir!", "determine_packagename"); }
260*b1cdbd2cSJim Jagielski		my $alldirssav = installer::converter::copy_array_from_references($alldirs);
261*b1cdbd2cSJim Jagielski		for ( my $i = 0; $i <= $#{$alldirs}; $i++ ) { installer::pathanalyzer::make_absolute_filename_to_relative_filename(\${$alldirs}[$i]); }
262*b1cdbd2cSJim Jagielski
263*b1cdbd2cSJim Jagielski		$packagename = get_packagename_from_packagelist($alldirs, $allvariables, $languagestringref);
264*b1cdbd2cSJim Jagielski		my $packagestring = installer::converter::convert_array_to_space_separated_string($alldirs);
265*b1cdbd2cSJim Jagielski		$packagename = create_tar_gz_file($installdir, $packagename, $packagestring);	# only a file (not a directory) can be included into the shell script
266*b1cdbd2cSJim Jagielski		for ( my $i = 0; $i <= $#{$alldirssav}; $i++ ) { installer::systemactions::remove_complete_directory(${$alldirssav}[$i], 1); }
267*b1cdbd2cSJim Jagielski		$allnames = $alldirs;
268*b1cdbd2cSJim Jagielski	}
269*b1cdbd2cSJim Jagielski
270*b1cdbd2cSJim Jagielski	my $infoline = "Found package in installation directory $installdir : $packagename\n";
271*b1cdbd2cSJim Jagielski	$installer::logger::Lang->print($infoline);
272*b1cdbd2cSJim Jagielski
273*b1cdbd2cSJim Jagielski	return ( $packagename, $allnames);
274*b1cdbd2cSJim Jagielski}
275*b1cdbd2cSJim Jagielski
276*b1cdbd2cSJim Jagielski#########################################################
277*b1cdbd2cSJim Jagielski# Including the name of the package file or the rpm
278*b1cdbd2cSJim Jagielski# into the script template
279*b1cdbd2cSJim Jagielski#########################################################
280*b1cdbd2cSJim Jagielski
281*b1cdbd2cSJim Jagielskisub put_packagename_into_script
282*b1cdbd2cSJim Jagielski{
283*b1cdbd2cSJim Jagielski	my ($scriptfile, $packagename, $allnames) = @_;
284*b1cdbd2cSJim Jagielski
285*b1cdbd2cSJim Jagielski	my $localpackagename = $packagename;
286*b1cdbd2cSJim Jagielski	$localpackagename =~ s/\.tar\.gz//;	# making "OOOopenoffice-it-ea.tar.gz" to "OOOopenoffice-it-ea"
287*b1cdbd2cSJim Jagielski	my $infoline = "Adding packagename $localpackagename into language pack script\n";
288*b1cdbd2cSJim Jagielski	$installer::logger::Lang->print($infoline);
289*b1cdbd2cSJim Jagielski
290*b1cdbd2cSJim Jagielski	my $installline = "";
291*b1cdbd2cSJim Jagielski
292*b1cdbd2cSJim Jagielski	if ( $installer::globals::issolarisbuild ) { $installline = "  /usr/sbin/pkgadd -d \$outdir -a \$adminfile"; }
293*b1cdbd2cSJim Jagielski
294*b1cdbd2cSJim Jagielski	if ( $installer::globals::islinuxrpmbuild ) { $installline = "  rpm --prefix \$PRODUCTINSTALLLOCATION --replacepkgs -i"; }
295*b1cdbd2cSJim Jagielski
296*b1cdbd2cSJim Jagielski	for ( my $i = 0; $i <= $#{$allnames}; $i++ )
297*b1cdbd2cSJim Jagielski	{
298*b1cdbd2cSJim Jagielski		if ( $installer::globals::issolarisbuild ) { $installline = $installline . " ${$allnames}[$i]"; }
299*b1cdbd2cSJim Jagielski
300*b1cdbd2cSJim Jagielski		if ( $installer::globals::islinuxrpmbuild ) { $installline = $installline . " \$outdir/${$allnames}[$i]"; }
301*b1cdbd2cSJim Jagielski	}
302*b1cdbd2cSJim Jagielski
303*b1cdbd2cSJim Jagielski	for ( my $j = 0; $j <= $#{$scriptfile}; $j++ )
304*b1cdbd2cSJim Jagielski	{
305*b1cdbd2cSJim Jagielski		${$scriptfile}[$j] =~ s/INSTALLLINES/$installline/;
306*b1cdbd2cSJim Jagielski	}
307*b1cdbd2cSJim Jagielski}
308*b1cdbd2cSJim Jagielski
309*b1cdbd2cSJim Jagielski##################################################################
310*b1cdbd2cSJim Jagielski# Including the lowercase product name into the script template
311*b1cdbd2cSJim Jagielski##################################################################
312*b1cdbd2cSJim Jagielski
313*b1cdbd2cSJim Jagielskisub put_productname_into_script
314*b1cdbd2cSJim Jagielski{
315*b1cdbd2cSJim Jagielski	my ($scriptfile, $variableshashref) = @_;
316*b1cdbd2cSJim Jagielski
317*b1cdbd2cSJim Jagielski	my $productname = $variableshashref->{'PRODUCTNAME'};
318*b1cdbd2cSJim Jagielski	$productname = lc($productname);
319*b1cdbd2cSJim Jagielski	$productname =~ s/\.//g;	# openoffice.org -> openofficeorg
320*b1cdbd2cSJim Jagielski
321*b1cdbd2cSJim Jagielski	my $infoline = "Adding productname $productname into language pack script\n";
322*b1cdbd2cSJim Jagielski	$installer::logger::Lang->print($infoline);
323*b1cdbd2cSJim Jagielski
324*b1cdbd2cSJim Jagielski	for ( my $i = 0; $i <= $#{$scriptfile}; $i++ )
325*b1cdbd2cSJim Jagielski	{
326*b1cdbd2cSJim Jagielski		${$scriptfile}[$i] =~ s/PRODUCTNAMEPLACEHOLDER/$productname/;
327*b1cdbd2cSJim Jagielski	}
328*b1cdbd2cSJim Jagielski}
329*b1cdbd2cSJim Jagielski
330*b1cdbd2cSJim Jagielski##################################################################
331*b1cdbd2cSJim Jagielski# Including the full product name into the script template
332*b1cdbd2cSJim Jagielski# (name and version)
333*b1cdbd2cSJim Jagielski##################################################################
334*b1cdbd2cSJim Jagielski
335*b1cdbd2cSJim Jagielskisub put_fullproductname_into_script
336*b1cdbd2cSJim Jagielski{
337*b1cdbd2cSJim Jagielski	my ($scriptfile, $variableshashref) = @_;
338*b1cdbd2cSJim Jagielski
339*b1cdbd2cSJim Jagielski	my $productname = $variableshashref->{'PRODUCTNAME'};
340*b1cdbd2cSJim Jagielski	my $productversion = "";
341*b1cdbd2cSJim Jagielski	if ( $variableshashref->{'PRODUCTVERSION'} ) { $productversion = $variableshashref->{'PRODUCTVERSION'}; };
342*b1cdbd2cSJim Jagielski	my $fullproductname = $productname . " " . $productversion;
343*b1cdbd2cSJim Jagielski
344*b1cdbd2cSJim Jagielski	my $infoline = "Adding full productname \"$fullproductname\" into language pack script\n";
345*b1cdbd2cSJim Jagielski	$installer::logger::Lang->print($infoline);
346*b1cdbd2cSJim Jagielski
347*b1cdbd2cSJim Jagielski	for ( my $i = 0; $i <= $#{$scriptfile}; $i++ )
348*b1cdbd2cSJim Jagielski	{
349*b1cdbd2cSJim Jagielski		${$scriptfile}[$i] =~ s/FULLPRODUCTNAMELONGPLACEHOLDER/$fullproductname/;
350*b1cdbd2cSJim Jagielski	}
351*b1cdbd2cSJim Jagielski}
352*b1cdbd2cSJim Jagielski
353*b1cdbd2cSJim Jagielski##################################################################
354*b1cdbd2cSJim Jagielski# Including the name of the search package (-core01)
355*b1cdbd2cSJim Jagielski# into the script template
356*b1cdbd2cSJim Jagielski##################################################################
357*b1cdbd2cSJim Jagielski
358*b1cdbd2cSJim Jagielskisub put_searchpackage_into_script
359*b1cdbd2cSJim Jagielski{
360*b1cdbd2cSJim Jagielski	my ($scriptfile, $variableshashref) = @_;
361*b1cdbd2cSJim Jagielski
362*b1cdbd2cSJim Jagielski	my $basispackageprefix = $variableshashref->{'BASISPACKAGEPREFIX'};
363*b1cdbd2cSJim Jagielski	my $basispackageversion = $variableshashref->{'OOOBASEVERSION'};
364*b1cdbd2cSJim Jagielski
365*b1cdbd2cSJim Jagielski	if ( $installer::globals::issolarisbuild ) { $basispackageversion =~ s/\.//g; }	# "3.0" -> "30"
366*b1cdbd2cSJim Jagielski
367*b1cdbd2cSJim Jagielski	my $infoline = "Adding basis package prefix $basispackageprefix into language pack script\n";
368*b1cdbd2cSJim Jagielski	$installer::logger::Lang->print($infoline);
369*b1cdbd2cSJim Jagielski
370*b1cdbd2cSJim Jagielski	$infoline = "Adding basis package version $basispackageversion into language pack script\n";
371*b1cdbd2cSJim Jagielski	$installer::logger::Lang->print($infoline);
372*b1cdbd2cSJim Jagielski
373*b1cdbd2cSJim Jagielski	for ( my $i = 0; $i <= $#{$scriptfile}; $i++ )
374*b1cdbd2cSJim Jagielski	{
375*b1cdbd2cSJim Jagielski		${$scriptfile}[$i] =~ s/BASISPACKAGEPREFIXPLACEHOLDER/$basispackageprefix/;
376*b1cdbd2cSJim Jagielski		${$scriptfile}[$i] =~ s/OOOBASEVERSIONPLACEHOLDER/$basispackageversion/;
377*b1cdbd2cSJim Jagielski	}
378*b1cdbd2cSJim Jagielski
379*b1cdbd2cSJim Jagielski}
380*b1cdbd2cSJim Jagielski
381*b1cdbd2cSJim Jagielski#########################################################
382*b1cdbd2cSJim Jagielski# Including the linenumber into the script template
383*b1cdbd2cSJim Jagielski#########################################################
384*b1cdbd2cSJim Jagielski
385*b1cdbd2cSJim Jagielskisub put_linenumber_into_script
386*b1cdbd2cSJim Jagielski{
387*b1cdbd2cSJim Jagielski	my ( $scriptfile, $licensefile, $allnames ) = @_;
388*b1cdbd2cSJim Jagielski
389*b1cdbd2cSJim Jagielski	my $linenumber =  $#{$scriptfile} + $#{$licensefile} + 3;	# also adding the content of the license file!
390*b1cdbd2cSJim Jagielski
391*b1cdbd2cSJim Jagielski	my $infoline = "Adding linenumber $linenumber into language pack script\n";
392*b1cdbd2cSJim Jagielski	$installer::logger::Lang->print($infoline);
393*b1cdbd2cSJim Jagielski
394*b1cdbd2cSJim Jagielski	for ( my $i = 0; $i <= $#{$scriptfile}; $i++ )
395*b1cdbd2cSJim Jagielski	{
396*b1cdbd2cSJim Jagielski		${$scriptfile}[$i] =~ s/LINENUMBERPLACEHOLDER/$linenumber/;
397*b1cdbd2cSJim Jagielski	}
398*b1cdbd2cSJim Jagielski}
399*b1cdbd2cSJim Jagielski
400*b1cdbd2cSJim Jagielski#########################################################
401*b1cdbd2cSJim Jagielski# Determining the name of the new scriptfile
402*b1cdbd2cSJim Jagielski#########################################################
403*b1cdbd2cSJim Jagielski
404*b1cdbd2cSJim Jagielskisub determine_scriptfile_name
405*b1cdbd2cSJim Jagielski{
406*b1cdbd2cSJim Jagielski	my ( $packagename ) = @_;
407*b1cdbd2cSJim Jagielski
408*b1cdbd2cSJim Jagielski	my $scriptfilename = $packagename;
409*b1cdbd2cSJim Jagielski
410*b1cdbd2cSJim Jagielski#	if ( $installer::globals::islinuxrpmbuild ) { $scriptfilename =~ s/\.rpm\s*$/\.sh/; }
411*b1cdbd2cSJim Jagielski#	if ( $installer::globals::issolarisbuild ) { $scriptfilename =~ s/\.tar\.gz\s*$/\.sh/; }
412*b1cdbd2cSJim Jagielski
413*b1cdbd2cSJim Jagielski	$scriptfilename =~ s/\.tar\.gz\s*$/\.sh/;
414*b1cdbd2cSJim Jagielski
415*b1cdbd2cSJim Jagielski	my $infoline = "Setting language pack script file name to $scriptfilename\n";
416*b1cdbd2cSJim Jagielski	$installer::logger::Lang->print($infoline);
417*b1cdbd2cSJim Jagielski
418*b1cdbd2cSJim Jagielski	return $scriptfilename;
419*b1cdbd2cSJim Jagielski}
420*b1cdbd2cSJim Jagielski
421*b1cdbd2cSJim Jagielski#########################################################
422*b1cdbd2cSJim Jagielski# Saving the script file in the installation directory
423*b1cdbd2cSJim Jagielski#########################################################
424*b1cdbd2cSJim Jagielski
425*b1cdbd2cSJim Jagielskisub save_script_file
426*b1cdbd2cSJim Jagielski{
427*b1cdbd2cSJim Jagielski	my ($installdir, $newscriptfilename, $scriptfile) = @_;
428*b1cdbd2cSJim Jagielski
429*b1cdbd2cSJim Jagielski	$newscriptfilename = $installdir . $installer::globals::separator . $newscriptfilename;
430*b1cdbd2cSJim Jagielski	installer::files::save_file($newscriptfilename, $scriptfile);
431*b1cdbd2cSJim Jagielski
432*b1cdbd2cSJim Jagielski	my $infoline = "Saving script file $newscriptfilename\n";
433*b1cdbd2cSJim Jagielski	$installer::logger::Lang->print($infoline);
434*b1cdbd2cSJim Jagielski
435*b1cdbd2cSJim Jagielski	return $newscriptfilename;
436*b1cdbd2cSJim Jagielski}
437*b1cdbd2cSJim Jagielski
438*b1cdbd2cSJim Jagielski#########################################################
439*b1cdbd2cSJim Jagielski# Including the binary package into the script
440*b1cdbd2cSJim Jagielski#########################################################
441*b1cdbd2cSJim Jagielski
442*b1cdbd2cSJim Jagielskisub include_package_into_script
443*b1cdbd2cSJim Jagielski{
444*b1cdbd2cSJim Jagielski	my ( $scriptfilename, $installdir, $packagename ) = @_;
445*b1cdbd2cSJim Jagielski
446*b1cdbd2cSJim Jagielski	my $longpackagename = $installdir . $installer::globals::separator . $packagename;
447*b1cdbd2cSJim Jagielski	my $systemcall = "cat $longpackagename >>$scriptfilename";
448*b1cdbd2cSJim Jagielski
449*b1cdbd2cSJim Jagielski	my $returnvalue = system($systemcall);
450*b1cdbd2cSJim Jagielski
451*b1cdbd2cSJim Jagielski	my $infoline = "Systemcall: $systemcall\n";
452*b1cdbd2cSJim Jagielski	$installer::logger::Lang->print($infoline);
453*b1cdbd2cSJim Jagielski
454*b1cdbd2cSJim Jagielski	if ($returnvalue)
455*b1cdbd2cSJim Jagielski	{
456*b1cdbd2cSJim Jagielski		$infoline = "ERROR: Could not execute \"$systemcall\"!\n";
457*b1cdbd2cSJim Jagielski		$installer::logger::Lang->print($infoline);
458*b1cdbd2cSJim Jagielski	}
459*b1cdbd2cSJim Jagielski	else
460*b1cdbd2cSJim Jagielski	{
461*b1cdbd2cSJim Jagielski		$infoline = "Success: Executed \"$systemcall\" successfully!\n";
462*b1cdbd2cSJim Jagielski		$installer::logger::Lang->print($infoline);
463*b1cdbd2cSJim Jagielski	}
464*b1cdbd2cSJim Jagielski
465*b1cdbd2cSJim Jagielski	my $localcall = "chmod 775 $scriptfilename \>\/dev\/null 2\>\&1";
466*b1cdbd2cSJim Jagielski	system($localcall);
467*b1cdbd2cSJim Jagielski
468*b1cdbd2cSJim Jagielski}
469*b1cdbd2cSJim Jagielski
470*b1cdbd2cSJim Jagielski#########################################################
471*b1cdbd2cSJim Jagielski# Removing the binary package
472*b1cdbd2cSJim Jagielski#########################################################
473*b1cdbd2cSJim Jagielski
474*b1cdbd2cSJim Jagielskisub remove_package
475*b1cdbd2cSJim Jagielski{
476*b1cdbd2cSJim Jagielski	my ( $installdir, $packagename ) = @_;
477*b1cdbd2cSJim Jagielski
478*b1cdbd2cSJim Jagielski	my $remove_package = 1;
479*b1cdbd2cSJim Jagielski
480*b1cdbd2cSJim Jagielski	if ( $ENV{'DONT_REMOVE_PACKAGE'} ) { $remove_package = 0; }
481*b1cdbd2cSJim Jagielski
482*b1cdbd2cSJim Jagielski	if ( $remove_package )
483*b1cdbd2cSJim Jagielski	{
484*b1cdbd2cSJim Jagielski		my $longpackagename = $installdir . $installer::globals::separator . $packagename;
485*b1cdbd2cSJim Jagielski		unlink $longpackagename;
486*b1cdbd2cSJim Jagielski
487*b1cdbd2cSJim Jagielski		my $infoline = "Removing package: $longpackagename \n";
488*b1cdbd2cSJim Jagielski		$installer::logger::Lang->print($infoline);
489*b1cdbd2cSJim Jagielski	}
490*b1cdbd2cSJim Jagielski}
491*b1cdbd2cSJim Jagielski
492*b1cdbd2cSJim Jagielski####################################################
493*b1cdbd2cSJim Jagielski# Unix language packs, that are not part of
494*b1cdbd2cSJim Jagielski# multilingual installation sets, need a
495*b1cdbd2cSJim Jagielski# shell script installer
496*b1cdbd2cSJim Jagielski####################################################
497*b1cdbd2cSJim Jagielski
498*b1cdbd2cSJim Jagielskisub build_installer_for_languagepack
499*b1cdbd2cSJim Jagielski{
500*b1cdbd2cSJim Jagielski	my ($installdir, $allvariableshashref, $includepatharrayref, $languagesarrayref, $languagestringref) = @_;
501*b1cdbd2cSJim Jagielski
502*b1cdbd2cSJim Jagielski	$installer::logger::Info->print("... creating shell script installer ...\n");
503*b1cdbd2cSJim Jagielski
504*b1cdbd2cSJim Jagielski	installer::logger::include_header_into_logfile("Creating shell script installer:");
505*b1cdbd2cSJim Jagielski
506*b1cdbd2cSJim Jagielski	# find and read setup script template
507*b1cdbd2cSJim Jagielski
508*b1cdbd2cSJim Jagielski	my $scriptfilename = "langpackscript.sh";
509*b1cdbd2cSJim Jagielski	my $scriptref = installer::scriptitems::get_sourcepath_from_filename_and_includepath(\$scriptfilename, $includepatharrayref, 0);
510*b1cdbd2cSJim Jagielski	if ($$scriptref eq "") { installer::exiter::exit_program("ERROR: Could not find script file $scriptfilename!", "build_installer_for_languagepack"); }
511*b1cdbd2cSJim Jagielski	my $scriptfile = installer::files::read_file($$scriptref);
512*b1cdbd2cSJim Jagielski
513*b1cdbd2cSJim Jagielski	my $infoline = "Found  script file $scriptfilename: $$scriptref \n";
514*b1cdbd2cSJim Jagielski	$installer::logger::Lang->print($infoline);
515*b1cdbd2cSJim Jagielski
516*b1cdbd2cSJim Jagielski	# find and read english license file
517*b1cdbd2cSJim Jagielski	my $licenselanguage = "en-US";					# always english !
518*b1cdbd2cSJim Jagielski	my $licensefilename = "LICENSE";
519*b1cdbd2cSJim Jagielski	my $licenseincludepatharrayref = installer::worker::get_language_specific_include_pathes($includepatharrayref, $licenselanguage);
520*b1cdbd2cSJim Jagielski
521*b1cdbd2cSJim Jagielski	my $licenseref = installer::scriptitems::get_sourcepath_from_filename_and_includepath(\$licensefilename, $licenseincludepatharrayref, 0);
522*b1cdbd2cSJim Jagielski	if ($$licenseref eq "") { installer::exiter::exit_program("ERROR: Could not find License file $licensefilename!", "build_installer_for_languagepack"); }
523*b1cdbd2cSJim Jagielski	my $licensefile = installer::files::read_file($$licenseref);
524*b1cdbd2cSJim Jagielski
525*b1cdbd2cSJim Jagielski	$infoline = "Found licensefile $licensefilename: $$licenseref \n";
526*b1cdbd2cSJim Jagielski	$installer::logger::Lang->print($infoline);
527*b1cdbd2cSJim Jagielski
528*b1cdbd2cSJim Jagielski	# including variables into license file
529*b1cdbd2cSJim Jagielski	installer::scpzipfiles::replace_all_ziplistvariables_in_file($licensefile, $allvariableshashref);
530*b1cdbd2cSJim Jagielski
531*b1cdbd2cSJim Jagielski	# add license text into script template
532*b1cdbd2cSJim Jagielski	put_license_file_into_script($scriptfile, $licensefile);
533*b1cdbd2cSJim Jagielski
534*b1cdbd2cSJim Jagielski	# add rpm or package file name into script template
535*b1cdbd2cSJim Jagielski	my ( $packagename, $allnames) = determine_packagename($installdir, $allvariableshashref, $languagestringref);
536*b1cdbd2cSJim Jagielski	put_packagename_into_script($scriptfile, $packagename, $allnames);
537*b1cdbd2cSJim Jagielski
538*b1cdbd2cSJim Jagielski	# add product name into script template
539*b1cdbd2cSJim Jagielski	put_productname_into_script($scriptfile, $allvariableshashref);
540*b1cdbd2cSJim Jagielski
541*b1cdbd2cSJim Jagielski	# add product name into script template
542*b1cdbd2cSJim Jagielski	put_fullproductname_into_script($scriptfile, $allvariableshashref);
543*b1cdbd2cSJim Jagielski
544*b1cdbd2cSJim Jagielski	# add product name into script template
545*b1cdbd2cSJim Jagielski	put_searchpackage_into_script($scriptfile, $allvariableshashref);
546*b1cdbd2cSJim Jagielski
547*b1cdbd2cSJim Jagielski	# replace linenumber in script template
548*b1cdbd2cSJim Jagielski	put_linenumber_into_script($scriptfile, $licensefile, $allnames);
549*b1cdbd2cSJim Jagielski
550*b1cdbd2cSJim Jagielski	# saving the script file
551*b1cdbd2cSJim Jagielski	my $newscriptfilename = determine_scriptfile_name($packagename);
552*b1cdbd2cSJim Jagielski	$newscriptfilename = save_script_file($installdir, $newscriptfilename, $scriptfile);
553*b1cdbd2cSJim Jagielski
554*b1cdbd2cSJim Jagielski	# include rpm or package into script
555*b1cdbd2cSJim Jagielski	include_package_into_script($newscriptfilename, $installdir, $packagename);
556*b1cdbd2cSJim Jagielski
557*b1cdbd2cSJim Jagielski	# remove rpm or package
558*b1cdbd2cSJim Jagielski	remove_package($installdir, $packagename);
559*b1cdbd2cSJim Jagielski}
560*b1cdbd2cSJim Jagielski
561*b1cdbd2cSJim Jagielski1;
562