19780544fSAndrew Rist#**************************************************************
29780544fSAndrew Rist#
39780544fSAndrew Rist#  Licensed to the Apache Software Foundation (ASF) under one
49780544fSAndrew Rist#  or more contributor license agreements.  See the NOTICE file
59780544fSAndrew Rist#  distributed with this work for additional information
69780544fSAndrew Rist#  regarding copyright ownership.  The ASF licenses this file
79780544fSAndrew Rist#  to you under the Apache License, Version 2.0 (the
89780544fSAndrew Rist#  "License"); you may not use this file except in compliance
99780544fSAndrew Rist#  with the License.  You may obtain a copy of the License at
109780544fSAndrew Rist#
119780544fSAndrew Rist#    http://www.apache.org/licenses/LICENSE-2.0
129780544fSAndrew Rist#
139780544fSAndrew Rist#  Unless required by applicable law or agreed to in writing,
149780544fSAndrew Rist#  software distributed under the License is distributed on an
159780544fSAndrew Rist#  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
169780544fSAndrew Rist#  KIND, either express or implied.  See the License for the
179780544fSAndrew Rist#  specific language governing permissions and limitations
189780544fSAndrew Rist#  under the License.
199780544fSAndrew Rist#
209780544fSAndrew Rist#**************************************************************
219780544fSAndrew Rist
229780544fSAndrew Rist
23cdf0e10cSrcweir
24cdf0e10cSrcweirpackage installer::worker;
25cdf0e10cSrcweir
26cdf0e10cSrcweiruse Cwd;
27cdf0e10cSrcweiruse File::Copy;
28cdf0e10cSrcweiruse File::stat;
29cdf0e10cSrcweiruse File::Temp qw(tmpnam);
30cdf0e10cSrcweiruse installer::control;
31cdf0e10cSrcweiruse installer::converter;
32cdf0e10cSrcweiruse installer::existence;
33cdf0e10cSrcweiruse installer::exiter;
34cdf0e10cSrcweiruse installer::files;
35cdf0e10cSrcweiruse installer::globals;
36cdf0e10cSrcweiruse installer::logger;
37cdf0e10cSrcweiruse installer::mail;
38cdf0e10cSrcweiruse installer::pathanalyzer;
39cdf0e10cSrcweiruse installer::scpzipfiles;
40cdf0e10cSrcweiruse installer::scriptitems;
41cdf0e10cSrcweiruse installer::sorter;
42cdf0e10cSrcweiruse installer::systemactions;
43cdf0e10cSrcweiruse installer::windows::language;
44cdf0e10cSrcweir
45cdf0e10cSrcweir#####################################################################
46cdf0e10cSrcweir# Unpacking all files ending with tar.gz in a specified directory
47cdf0e10cSrcweir#####################################################################
48cdf0e10cSrcweir
49cdf0e10cSrcweirsub unpack_all_targzfiles_in_directory
50cdf0e10cSrcweir{
51cdf0e10cSrcweir	my ( $directory ) = @_;
52cdf0e10cSrcweir
53cdf0e10cSrcweir	installer::logger::include_header_into_logfile("Unpacking tar.gz files:");
54cdf0e10cSrcweir
55b274bc22SAndre Fischer	$installer::logger::Info->print( "... unpacking tar.gz files ... \n" );
56cdf0e10cSrcweir
57cdf0e10cSrcweir	my $localdirectory = $directory . $installer::globals::separator . "packages";
58cdf0e10cSrcweir	my $alltargzfiles = installer::systemactions::find_file_with_file_extension("tar.gz", $localdirectory);
59cdf0e10cSrcweir
60cdf0e10cSrcweir	for ( my $i = 0; $i <= $#{$alltargzfiles}; $i++ )
61cdf0e10cSrcweir	{
62cdf0e10cSrcweir		my $onefile = $localdirectory . $installer::globals::separator . ${$alltargzfiles}[$i];
63cdf0e10cSrcweir
64cdf0e10cSrcweir		my $systemcall = "cd $localdirectory; cat ${$alltargzfiles}[$i] \| gunzip \| tar -xf -";
65cdf0e10cSrcweir		$returnvalue = system($systemcall);
66cdf0e10cSrcweir
67cdf0e10cSrcweir		my $infoline = "Systemcall: $systemcall\n";
68b274bc22SAndre Fischer		$installer::logger::Lang->print($infoline);
69cdf0e10cSrcweir
70cdf0e10cSrcweir		if ($returnvalue)
71cdf0e10cSrcweir		{
72cdf0e10cSrcweir			$infoline = "ERROR: Could not execute \"$systemcall\"!\n";
73b274bc22SAndre Fischer			$installer::logger::Lang->print($infoline);
74cdf0e10cSrcweir		}
75cdf0e10cSrcweir		else
76cdf0e10cSrcweir		{
77cdf0e10cSrcweir			$infoline = "Success: Executed \"$systemcall\" successfully!\n";
78b274bc22SAndre Fischer			$installer::logger::Lang->print($infoline);
79cdf0e10cSrcweir		}
80cdf0e10cSrcweir	}
81cdf0e10cSrcweir}
82cdf0e10cSrcweir
83cdf0e10cSrcweir#########################################
84cdf0e10cSrcweir# Copying installation sets to ship
85cdf0e10cSrcweir#########################################
86cdf0e10cSrcweir
87cdf0e10cSrcweirsub copy_install_sets_to_ship
88cdf0e10cSrcweir{
89cdf0e10cSrcweir	my ( $destdir, $shipinstalldir  ) = @_;
90cdf0e10cSrcweir
91cdf0e10cSrcweir	installer::logger::include_header_into_logfile("Copying installation set to ship:");
92cdf0e10cSrcweir
93cdf0e10cSrcweir	my $dirname = $destdir;
94cdf0e10cSrcweir	installer::pathanalyzer::make_absolute_filename_to_relative_filename(\$dirname);
95cdf0e10cSrcweir	$dirname = $dirname . "_inprogress";
96cdf0e10cSrcweir	my $localshipinstalldir = $shipinstalldir . $installer::globals::separator . $dirname;
97cdf0e10cSrcweir	if ( ! -d $localshipinstalldir ) { installer::systemactions::create_directory_structure($localshipinstalldir); }
98cdf0e10cSrcweir
99cdf0e10cSrcweir	# copy installation set to /ship ($localshipinstalldir)
100b274bc22SAndre Fischer	$installer::logger::Info->print( "... copy installation set from " . $destdir . " to " . $localshipinstalldir . "\n" );
101cdf0e10cSrcweir	installer::systemactions::copy_complete_directory($destdir, $localshipinstalldir);
102cdf0e10cSrcweir
103cdf0e10cSrcweir	if (( ! $installer::globals::iswindowsbuild ) && ( $installer::globals::addjavainstaller ))
104cdf0e10cSrcweir	{
105cdf0e10cSrcweir		# Setting Unix rights for Java starter ("setup")
106cdf0e10cSrcweir		my $localcall = "chmod 775 $localshipinstalldir/setup \>\/dev\/null 2\>\&1";
107cdf0e10cSrcweir		system($localcall);
108cdf0e10cSrcweir	}
109cdf0e10cSrcweir
110cdf0e10cSrcweir	# unpacking the tar.gz file for Solaris
111cdf0e10cSrcweir	if ( $installer::globals::issolarisbuild ) { unpack_all_targzfiles_in_directory($localshipinstalldir); }
112cdf0e10cSrcweir
113cdf0e10cSrcweir	$localshipinstalldir = installer::systemactions::rename_string_in_directory($localshipinstalldir, "_inprogress", "");
114cdf0e10cSrcweir
115cdf0e10cSrcweir	return $localshipinstalldir;
116cdf0e10cSrcweir}
117cdf0e10cSrcweir
118cdf0e10cSrcweir#########################################
119cdf0e10cSrcweir# Copying installation sets to ship
120cdf0e10cSrcweir#########################################
121cdf0e10cSrcweir
122cdf0e10cSrcweirsub link_install_sets_to_ship
123cdf0e10cSrcweir{
124cdf0e10cSrcweir	my ( $destdir, $shipinstalldir  ) = @_;
125cdf0e10cSrcweir
126cdf0e10cSrcweir	installer::logger::include_header_into_logfile("Linking installation set to ship:");
127cdf0e10cSrcweir
128cdf0e10cSrcweir	my $infoline = "... destination directory: $shipinstalldir ...\n";
129b274bc22SAndre Fischer	$installer::logger::Info->print( $infoline );
130b274bc22SAndre Fischer	$installer::logger::Lang->print($infoline);
131cdf0e10cSrcweir
132cdf0e10cSrcweir	if ( ! -d $shipinstalldir)
133cdf0e10cSrcweir	{
134cdf0e10cSrcweir		$infoline = "Creating directory: $shipinstalldir\n";
135b274bc22SAndre Fischer		$installer::logger::Lang->print($infoline);
136cdf0e10cSrcweir		installer::systemactions::create_directory_structure($shipinstalldir);
137cdf0e10cSrcweir		$infoline = "Created directory: $shipinstalldir\n";
138b274bc22SAndre Fischer		$installer::logger::Lang->print($infoline);
139cdf0e10cSrcweir	}
140cdf0e10cSrcweir
141cdf0e10cSrcweir	my $dirname = $destdir;
142cdf0e10cSrcweir	installer::pathanalyzer::make_absolute_filename_to_relative_filename(\$dirname);
143cdf0e10cSrcweir
144cdf0e10cSrcweir	my $localshipinstalldir = $shipinstalldir . $installer::globals::separator . $dirname;
145cdf0e10cSrcweir
146cdf0e10cSrcweir	# link installation set to /ship ($localshipinstalldir)
147b274bc22SAndre Fischer	$installer::logger::Lang->print( "... linking installation set from " . $destdir . " to " . $localshipinstalldir . "\n" );
148cdf0e10cSrcweir
149cdf0e10cSrcweir	my $systemcall = "ln -s $destdir $localshipinstalldir";
150cdf0e10cSrcweir
151cdf0e10cSrcweir	$returnvalue = system($systemcall);
152cdf0e10cSrcweir
153cdf0e10cSrcweir	$infoline = "Systemcall: $systemcall\n";
154b274bc22SAndre Fischer	$installer::logger::Lang->print($infoline);
155cdf0e10cSrcweir
156cdf0e10cSrcweir	if ($returnvalue)
157cdf0e10cSrcweir	{
158cdf0e10cSrcweir		$infoline = "ERROR: Could not create link \"$localshipinstalldir\"!\n";
159b274bc22SAndre Fischer		$installer::logger::Lang->print($infoline);
160cdf0e10cSrcweir	}
161cdf0e10cSrcweir	else
162cdf0e10cSrcweir	{
163cdf0e10cSrcweir		$infoline = "Success: Created link \"$localshipinstalldir\"!\n";
164b274bc22SAndre Fischer		$installer::logger::Lang->print($infoline);
165cdf0e10cSrcweir	}
166cdf0e10cSrcweir
167cdf0e10cSrcweir	return $localshipinstalldir;
168cdf0e10cSrcweir}
169cdf0e10cSrcweir
170cdf0e10cSrcweir#########################################
171cdf0e10cSrcweir# Create checksum file
172cdf0e10cSrcweir#########################################
173cdf0e10cSrcweir
174cdf0e10cSrcweirsub make_checksum_file
175cdf0e10cSrcweir{
176cdf0e10cSrcweir	my ( $filesref, $includepatharrayref ) = @_;
177cdf0e10cSrcweir
178cdf0e10cSrcweir	my @checksum = ();
179cdf0e10cSrcweir
180cdf0e10cSrcweir	my $checksumfileref = installer::scriptitems::get_sourcepath_from_filename_and_includepath(\$installer::globals::checksumfile, $includepatharrayref, 1);
181cdf0e10cSrcweir	if ( $$checksumfileref eq "" ) { installer::exiter::exit_program("ERROR: Could not find file $installer::globals::checksumfile !", "make_checksum_file"); }
182cdf0e10cSrcweir
183cdf0e10cSrcweir#	# very slow on Windows
184cdf0e10cSrcweir#	for ( my $i = 0; $i <= $#{$filesref}; $i++ )
185cdf0e10cSrcweir#	{
186cdf0e10cSrcweir#		my $onefile = ${$filesref}[$i];
187cdf0e10cSrcweir#		my $systemcall = "$$checksumfileref $onefile->{'sourcepath'} |";
188cdf0e10cSrcweir#		open (CHECK, "$systemcall");
189cdf0e10cSrcweir#		my $localchecksum = <CHECK>;
190cdf0e10cSrcweir#		close (CHECK);
191cdf0e10cSrcweir#		push(@checksum, $localchecksum);
192cdf0e10cSrcweir#	}
193cdf0e10cSrcweir
194cdf0e10cSrcweir	my $systemcall = "$$checksumfileref";
195cdf0e10cSrcweir
196cdf0e10cSrcweir	for ( my $i = 0; $i <= $#{$filesref}; $i++ )
197cdf0e10cSrcweir	{
198cdf0e10cSrcweir		my $onefile = ${$filesref}[$i];
199cdf0e10cSrcweir		$systemcall = $systemcall . " " . $onefile->{'sourcepath'};		# very very long systemcall
200cdf0e10cSrcweir
201cdf0e10cSrcweir		if ((( $i > 0 ) &&  ( $i%100 == 0 )) || ( $i == $#{$filesref} ))	# limiting to 100 files
202cdf0e10cSrcweir		{
203cdf0e10cSrcweir			$systemcall = $systemcall . " \|";
204cdf0e10cSrcweir
205cdf0e10cSrcweir			my @localchecksum = ();
206cdf0e10cSrcweir			open (CHECK, "$systemcall");
207cdf0e10cSrcweir			@localchecksum = <CHECK>;
208cdf0e10cSrcweir			close (CHECK);
209cdf0e10cSrcweir
210cdf0e10cSrcweir			for ( my $j = 0; $j <= $#localchecksum; $j++ ) { push(@checksum, $localchecksum[$j]); }
211cdf0e10cSrcweir
212cdf0e10cSrcweir			$systemcall = "$$checksumfileref";	# reset the system call
213cdf0e10cSrcweir		}
214cdf0e10cSrcweir	}
215cdf0e10cSrcweir
216cdf0e10cSrcweir	return \@checksum;
217cdf0e10cSrcweir}
218cdf0e10cSrcweir
219cdf0e10cSrcweir#########################################
220cdf0e10cSrcweir# Saving the checksum file
221cdf0e10cSrcweir#########################################
222cdf0e10cSrcweir
223cdf0e10cSrcweirsub save_checksum_file
224cdf0e10cSrcweir{
225cdf0e10cSrcweir	my ($current_install_number, $installchecksumdir, $checksumfile) = @_;
226cdf0e10cSrcweir
227cdf0e10cSrcweir	my $numberedchecksumfilename = $installer::globals::checksumfilename;
228cdf0e10cSrcweir	$numberedchecksumfilename =~ s/\./_$current_install_number\./;	# checksum.txt -> checksum_01.txt
229cdf0e10cSrcweir	installer::files::save_file($installchecksumdir . $installer::globals::separator . $numberedchecksumfilename, $checksumfile);
230cdf0e10cSrcweir}
231cdf0e10cSrcweir
232cdf0e10cSrcweir#################################################
233cdf0e10cSrcweir# Writing some global information into
234cdf0e10cSrcweir# the list of files without flag PATCH
235cdf0e10cSrcweir#################################################
236cdf0e10cSrcweir
237cdf0e10cSrcweirsub write_nopatchlist_header
238cdf0e10cSrcweir{
239cdf0e10cSrcweir	my ( $content ) = @_;
240cdf0e10cSrcweir
241cdf0e10cSrcweir	my @header = ();
242cdf0e10cSrcweir	my $infoline = "This is a list of files, that are defined in scp-projects without\n";
243cdf0e10cSrcweir	push(@header, $infoline);
244cdf0e10cSrcweir	$infoline = "flag \"PATCH\". Important: This does not mean in any case, that \n";
245cdf0e10cSrcweir	push(@header, $infoline);
246cdf0e10cSrcweir	$infoline = "this files are included into or excluded from a patch. \n\n";
247cdf0e10cSrcweir	push(@header, $infoline);
248cdf0e10cSrcweir	$infoline = "Exception Linux: A patch rpm is a complete rpm. This means that all \n";
249cdf0e10cSrcweir	push(@header, $infoline);
250cdf0e10cSrcweir	$infoline = "files are included into a patch rpm, if only one file of the rpm has the \n";
251cdf0e10cSrcweir	push(@header, $infoline);
252cdf0e10cSrcweir	$infoline = "style \"PATCH\". \n\n";
253cdf0e10cSrcweir	push(@header, $infoline);
254cdf0e10cSrcweir
255cdf0e10cSrcweir	for ( my $i = 0; $i <= $#header; $i++ ) { push(@{$content},$header[$i]); }
256cdf0e10cSrcweir}
257cdf0e10cSrcweir
258cdf0e10cSrcweir#################################################
259cdf0e10cSrcweir# Creating the content of the list of files
260cdf0e10cSrcweir# without flag PATCH.
261cdf0e10cSrcweir# All files are saved in
262cdf0e10cSrcweir# @{$installer::globals::nopatchfilecollector}
263cdf0e10cSrcweir#################################################
264cdf0e10cSrcweir
265cdf0e10cSrcweirsub create_nopatchlist
266cdf0e10cSrcweir{
267cdf0e10cSrcweir	my @content =();
268cdf0e10cSrcweir
269cdf0e10cSrcweir	write_nopatchlist_header(\@content);
270cdf0e10cSrcweir
271cdf0e10cSrcweir	for ( my $i = 0; $i <= $#{$installer::globals::nopatchfilecollector}; $i++ )
272cdf0e10cSrcweir	{
273cdf0e10cSrcweir		my $onefile = ${$installer::globals::nopatchfilecollector}[$i];
274cdf0e10cSrcweir		my $oneline = $onefile->{'destination'};
275cdf0e10cSrcweir		if ( $onefile->{'zipfilename'} ) { $oneline = $oneline . " (" . $onefile->{'zipfilename'} . ")"; }
276cdf0e10cSrcweir		$oneline = $oneline . "\n";
277cdf0e10cSrcweir		push(@content, $oneline);
278cdf0e10cSrcweir	}
279cdf0e10cSrcweir
280cdf0e10cSrcweir	return \@content;
281cdf0e10cSrcweir}
282cdf0e10cSrcweir
283cdf0e10cSrcweir#########################################
284cdf0e10cSrcweir# Saving the patchlist file
285cdf0e10cSrcweir#########################################
286cdf0e10cSrcweir
287cdf0e10cSrcweirsub save_patchlist_file
288cdf0e10cSrcweir{
289cdf0e10cSrcweir	my ($installlogdir, $patchlistfilename) = @_;
290cdf0e10cSrcweir
291cdf0e10cSrcweir	my $installpatchlistdir = installer::systemactions::create_directory_next_to_directory($installlogdir, "patchlist");
292cdf0e10cSrcweir	$patchlistfilename =~ s/log\_/patchfiles\_/;
293cdf0e10cSrcweir	$patchlistfilename =~ s/\.log/\.txt/;
294cdf0e10cSrcweir	installer::files::save_file($installpatchlistdir . $installer::globals::separator . $patchlistfilename, \@installer::globals::patchfilecollector);
295b274bc22SAndre Fischer	$installer::logger::Info->print( "... creating patchlist file $patchlistfilename \n" );
296cdf0e10cSrcweir
297cdf0e10cSrcweir	if (( $installer::globals::patch ) && ( ! $installer::globals::creating_windows_installer_patch ))	# only for non-Windows patches
298cdf0e10cSrcweir	{
299cdf0e10cSrcweir		$patchlistfilename =~ s/patchfiles\_/nopatchfiles\_/;
300cdf0e10cSrcweir		my $nopatchlist = create_nopatchlist();
301cdf0e10cSrcweir		installer::files::save_file($installpatchlistdir . $installer::globals::separator . $patchlistfilename, $nopatchlist);
302b274bc22SAndre Fischer		$installer::logger::Info->print( "... creating patch exclusion file $patchlistfilename \n" );
303cdf0e10cSrcweir	}
304cdf0e10cSrcweir
305cdf0e10cSrcweir}
306cdf0e10cSrcweir
307cdf0e10cSrcweir###############################################################
308cdf0e10cSrcweir# Removing all directories of a special language
309cdf0e10cSrcweir# in the directory $basedir
310cdf0e10cSrcweir###############################################################
311cdf0e10cSrcweir
312cdf0e10cSrcweirsub remove_old_installation_sets
313cdf0e10cSrcweir{
314cdf0e10cSrcweir	my ($basedir) = @_;
315cdf0e10cSrcweir
316b274bc22SAndre Fischer	$installer::logger::Info->print( "... removing old installation directories ...\n" );
317cdf0e10cSrcweir
318cdf0e10cSrcweir	my $removedir = $basedir;
319cdf0e10cSrcweir
320cdf0e10cSrcweir	if ( -d $removedir ) { installer::systemactions::remove_complete_directory($removedir, 1); }
321cdf0e10cSrcweir
322cdf0e10cSrcweir	# looking for non successful old installation sets
323cdf0e10cSrcweir
324cdf0e10cSrcweir	$removedir = $basedir . "_witherror";
325cdf0e10cSrcweir	if ( -d $removedir ) { installer::systemactions::remove_complete_directory($removedir, 1); }
326cdf0e10cSrcweir
327cdf0e10cSrcweir	$removedir = $basedir . "_inprogress";
328cdf0e10cSrcweir	if ( -d $removedir ) { installer::systemactions::remove_complete_directory($removedir, 1); }
329cdf0e10cSrcweir
330cdf0e10cSrcweir	# finally the $basedir can be created empty
331cdf0e10cSrcweir
332cdf0e10cSrcweir	if ( $installer::globals::localinstalldirset ) { installer::systemactions::create_directory_structure($basedir); }
333cdf0e10cSrcweir
334cdf0e10cSrcweir	installer::systemactions::create_directory($basedir);
335cdf0e10cSrcweir}
336cdf0e10cSrcweir
337cdf0e10cSrcweir###############################################################
338cdf0e10cSrcweir# Removing all non successful installation sets on ship
339cdf0e10cSrcweir###############################################################
340cdf0e10cSrcweir
341cdf0e10cSrcweirsub remove_old_ship_installation_sets
342cdf0e10cSrcweir{
343cdf0e10cSrcweir	my ($fulldir, $counter) = @_;
344cdf0e10cSrcweir
345b274bc22SAndre Fischer	$installer::logger::Info->print( "... removing old installation directories ...\n" );
346cdf0e10cSrcweir
347cdf0e10cSrcweir	my $basedir = $fulldir;
348cdf0e10cSrcweir	installer::pathanalyzer::get_path_from_fullqualifiedname(\$basedir);
349cdf0e10cSrcweir
350cdf0e10cSrcweir	# collecting all directories next to the new installation directory
351cdf0e10cSrcweir	my $alldirs = installer::systemactions::get_all_directories($basedir);
352cdf0e10cSrcweir
353cdf0e10cSrcweir	if ( $fulldir =~ /^\s*(.*?inprogress\-)(\d+)(.*?)\s*$/ )
354cdf0e10cSrcweir	{
355cdf0e10cSrcweir		my $pre_inprogress = $1;		# $pre still contains "inprogress"
356cdf0e10cSrcweir		my $number = $2;
357cdf0e10cSrcweir		my $post = $3;
358cdf0e10cSrcweir		my $pre_witherror = $pre_inprogress;
359cdf0e10cSrcweir		$pre_witherror =~ s/inprogress/witherror/;
360cdf0e10cSrcweir
361cdf0e10cSrcweir		for ( my $i = 0; $i <= $#{$alldirs}; $i++ )
362cdf0e10cSrcweir		{
363cdf0e10cSrcweir			if ( ${$alldirs}[$i] eq $fulldir ) { next; }	# do not delete the newly created directory
364cdf0e10cSrcweir
365cdf0e10cSrcweir			if ( ${$alldirs}[$i] =~ /^\s*\Q$pre_inprogress\E\d+\Q$post\E\s*$/ )	# removing old "inprogress" directories
366cdf0e10cSrcweir			{
367cdf0e10cSrcweir				installer::systemactions::remove_complete_directory(${$alldirs}[$i], 1);
368cdf0e10cSrcweir			}
369cdf0e10cSrcweir
370cdf0e10cSrcweir			if ( ${$alldirs}[$i] =~ /^\s*\Q$pre_witherror\E\d+\Q$post\E\s*$/ )	# removing old "witherror" directories
371cdf0e10cSrcweir			{
372cdf0e10cSrcweir				installer::systemactions::remove_complete_directory(${$alldirs}[$i], 1);
373cdf0e10cSrcweir			}
374cdf0e10cSrcweir		}
375cdf0e10cSrcweir	}
376cdf0e10cSrcweir}
377cdf0e10cSrcweir
378cdf0e10cSrcweir###############################################################
379cdf0e10cSrcweir# Creating the installation directory structure
380cdf0e10cSrcweir###############################################################
381cdf0e10cSrcweir
382cdf0e10cSrcweirsub create_installation_directory
383cdf0e10cSrcweir{
384cdf0e10cSrcweir	my ($shipinstalldir, $languagestringref, $current_install_number_ref) = @_;
385cdf0e10cSrcweir
386cdf0e10cSrcweir	my $installdir = "";
387cdf0e10cSrcweir
388cdf0e10cSrcweir	my $languageref = $languagestringref;
389cdf0e10cSrcweir
390cdf0e10cSrcweir	if ( $installer::globals::updatepack )
391cdf0e10cSrcweir	{
392cdf0e10cSrcweir		$installdir = $shipinstalldir;
393cdf0e10cSrcweir		installer::systemactions::create_directory_structure($installdir);
394cdf0e10cSrcweir		$$current_install_number_ref = installer::systemactions::determine_maximum_number($installdir, $languageref);
395cdf0e10cSrcweir		$installdir = installer::systemactions::rename_string_in_directory($installdir, "number", $$current_install_number_ref);
396cdf0e10cSrcweir		remove_old_ship_installation_sets($installdir);
397cdf0e10cSrcweir	}
398cdf0e10cSrcweir	else
399cdf0e10cSrcweir	{
400cdf0e10cSrcweir		$installdir = installer::systemactions::create_directories("install", $languageref);
401b274bc22SAndre Fischer		$installer::logger::Info->print( "... creating installation set in $installdir ...\n" );
402cdf0e10cSrcweir		remove_old_installation_sets($installdir);
403cdf0e10cSrcweir		my $inprogressinstalldir = $installdir . "_inprogress";
404cdf0e10cSrcweir		installer::systemactions::rename_directory($installdir, $inprogressinstalldir);
405cdf0e10cSrcweir		$installdir = $inprogressinstalldir;
406cdf0e10cSrcweir	}
407cdf0e10cSrcweir
408cdf0e10cSrcweir	$installer::globals::saveinstalldir = $installdir; 	# saving directory globally, in case of exiting
409cdf0e10cSrcweir
410cdf0e10cSrcweir	return $installdir;
411cdf0e10cSrcweir}
412cdf0e10cSrcweir
413cdf0e10cSrcweir###############################################################
414cdf0e10cSrcweir# Analyzing and creating the log file
415cdf0e10cSrcweir###############################################################
416cdf0e10cSrcweir
417cdf0e10cSrcweirsub analyze_and_save_logfile
418cdf0e10cSrcweir{
419cdf0e10cSrcweir	my ($loggingdir, $installdir, $installlogdir, $allsettingsarrayref, $languagestringref, $current_install_number) = @_;
420cdf0e10cSrcweir
421cdf0e10cSrcweir	my $is_success = 1;
422cdf0e10cSrcweir	my $finalinstalldir = "";
423cdf0e10cSrcweir
424b274bc22SAndre Fischer	$installer::logger::Info->print( "... checking log file " . $loggingdir . $installer::globals::logfilename . "\n" );
425cdf0e10cSrcweir
426b274bc22SAndre Fischer    my $contains_error = installer::control::check_logfile();
427b274bc22SAndre Fischer
428cdf0e10cSrcweir	# Dependent from the success, the installation directory can be renamed and mails can be send.
429cdf0e10cSrcweir
430b274bc22SAndre Fischer	if ($contains_error)
431cdf0e10cSrcweir	{
432cdf0e10cSrcweir		my $errordir = installer::systemactions::rename_string_in_directory($installdir, "_inprogress", "_witherror");
433b274bc22SAndre Fischer		if ($installer::globals::updatepack)
434b274bc22SAndre Fischer        {
435b274bc22SAndre Fischer            installer::mail::send_fail_mail($allsettingsarrayref, $languagestringref, $errordir);
436b274bc22SAndre Fischer        }
437cdf0e10cSrcweir		# Error output to STDERR
438cdf0e10cSrcweir		for ( my $j = 0; $j <= $#installer::globals::errorlogfileinfo; $j++ )
439cdf0e10cSrcweir		{
440cdf0e10cSrcweir			my $line = $installer::globals::errorlogfileinfo[$j];
441cdf0e10cSrcweir			$line =~ s/\s*$//g;
442cdf0e10cSrcweir			installer::logger::print_error( $line );
443cdf0e10cSrcweir		}
444cdf0e10cSrcweir		$is_success = 0;
445cdf0e10cSrcweir
446cdf0e10cSrcweir		$finalinstalldir = $errordir;
447cdf0e10cSrcweir	}
448cdf0e10cSrcweir	else
449cdf0e10cSrcweir	{
450cdf0e10cSrcweir		my $destdir = "";
451cdf0e10cSrcweir
452cdf0e10cSrcweir		if ( $installer::globals::updatepack )
453cdf0e10cSrcweir		{
454cdf0e10cSrcweir			if ( $installdir =~ /_download_inprogress/ ) { $destdir = installer::systemactions::rename_string_in_directory($installdir, "_download_inprogress", "_download"); }
455cdf0e10cSrcweir			elsif ( $installdir =~ /_jds_inprogress/ ) { $destdir = installer::systemactions::rename_string_in_directory($installdir, "_jds_inprogress", "_jds"); }
456cdf0e10cSrcweir			elsif ( $installdir =~ /_msp_inprogress/ ) { $destdir = installer::systemactions::rename_string_in_directory($installdir, "_msp_inprogress", "_msp"); }
457cdf0e10cSrcweir			else
458cdf0e10cSrcweir			{
459cdf0e10cSrcweir				if ( $installdir =~ /_packed/ ) { $destdir = installer::systemactions::rename_string_in_directory($installdir, "_inprogress", ""); }
460cdf0e10cSrcweir				else { $destdir = installer::systemactions::rename_string_in_directory($installdir, "_inprogress", "_packed"); }
461cdf0e10cSrcweir			}
462cdf0e10cSrcweir			installer::mail::send_success_mail($allsettingsarrayref, $languagestringref, $destdir);
463cdf0e10cSrcweir		}
464cdf0e10cSrcweir		else
465cdf0e10cSrcweir		{
466cdf0e10cSrcweir			$destdir = installer::systemactions::rename_string_in_directory($installdir, "_inprogress", "");
467cdf0e10cSrcweir		}
468cdf0e10cSrcweir
469cdf0e10cSrcweir		$finalinstalldir = $destdir;
470cdf0e10cSrcweir	}
471cdf0e10cSrcweir
472cdf0e10cSrcweir	# Saving the logfile in the log file directory and additionally in a log directory in the install directory
473cdf0e10cSrcweir
474cdf0e10cSrcweir	my $numberedlogfilename = $installer::globals::logfilename;
475b274bc22SAndre Fischer	if ( $installer::globals::updatepack )
476b274bc22SAndre Fischer    {
477b274bc22SAndre Fischer        $numberedlogfilename =~ s /log_/log_$current_install_number\_/;
478b274bc22SAndre Fischer    }
479b274bc22SAndre Fischer    foreach my $log_file_name (
480b274bc22SAndre Fischer        $loggingdir . $numberedlogfilename,
481b274bc22SAndre Fischer        $installlogdir . $installer::globals::separator . $numberedlogfilename)
482b274bc22SAndre Fischer    {
483b274bc22SAndre Fischer        if ($log_file_name ne $installer::logger::Lang->{'filename'})
484b274bc22SAndre Fischer        {
485b274bc22SAndre Fischer            $installer::logger::Info->printf("    copying log file to %s\n", $log_file_name);
486b274bc22SAndre Fischer            installer::systemactions::copy_one_file($installer::logger::Lang->{'filename'}, $log_file_name);
487b274bc22SAndre Fischer        }
488b274bc22SAndre Fischer    }
489b274bc22SAndre Fischer
490cdf0e10cSrcweir	# Saving the list of patchfiles in a patchlist directory in the install directory
491cdf0e10cSrcweir	if (( $installer::globals::patch ) || ( $installer::globals::creating_windows_installer_patch )) { installer::worker::save_patchlist_file($installlogdir, $numberedlogfilename); }
492cdf0e10cSrcweir
493cdf0e10cSrcweir	if ( $installer::globals::creating_windows_installer_patch ) { $installer::globals::creating_windows_installer_patch = 0; }
494cdf0e10cSrcweir
49586e1cf34SPedro Giffuni	# Exiting the packaging process, if an error occurred.
496cdf0e10cSrcweir	# This is important, to get an error code "-1", if an error was found in the log file,
497cdf0e10cSrcweir	# that did not break the packaging process
498cdf0e10cSrcweir
499cdf0e10cSrcweir	if ( ! $is_success) { installer::exiter::exit_program("ERROR: Found an error in the logfile. Packaging failed.", "analyze_and_save_logfile"); }
500cdf0e10cSrcweir
501cdf0e10cSrcweir	return ($is_success, $finalinstalldir);
502cdf0e10cSrcweir}
503cdf0e10cSrcweir
504cdf0e10cSrcweir###############################################################
505cdf0e10cSrcweir# Analyzing and creating the log file
506cdf0e10cSrcweir###############################################################
507cdf0e10cSrcweir
508cdf0e10cSrcweirsub save_logfile_after_linking
509cdf0e10cSrcweir{
510cdf0e10cSrcweir	my ($loggingdir, $installlogdir, $current_install_number) = @_;
511cdf0e10cSrcweir
512cdf0e10cSrcweir	# Saving the logfile in the log file directory and additionally in a log directory in the install directory
513cdf0e10cSrcweir	my $numberedlogfilename = $installer::globals::logfilename;
514cdf0e10cSrcweir	if ( $installer::globals::updatepack ) { $numberedlogfilename =~ s /log_/log_$current_install_number\_/; }
515b274bc22SAndre Fischer	$installer::logger::Info->print( "... creating log file $numberedlogfilename \n" );
516cdf0e10cSrcweir	installer::files::save_file($loggingdir . $numberedlogfilename, \@installer::globals::logfileinfo);
517cdf0e10cSrcweir	installer::files::save_file($installlogdir . $installer::globals::separator . $numberedlogfilename, \@installer::globals::logfileinfo);
518cdf0e10cSrcweir}
519cdf0e10cSrcweir
520cdf0e10cSrcweir###############################################################
521cdf0e10cSrcweir# Removing all directories that are saved in the
522cdf0e10cSrcweir# global directory @installer::globals::removedirs
523cdf0e10cSrcweir###############################################################
524cdf0e10cSrcweir
525cdf0e10cSrcweirsub clean_output_tree
526cdf0e10cSrcweir{
527b274bc22SAndre Fischer	$installer::logger::Info->print( "... cleaning the output tree ...\n" );
528cdf0e10cSrcweir
529cdf0e10cSrcweir	for ( my $i = 0; $i <= $#installer::globals::removedirs; $i++ )
530cdf0e10cSrcweir	{
531cdf0e10cSrcweir		if ( -d $installer::globals::removedirs[$i] )
532cdf0e10cSrcweir		{
533b274bc22SAndre Fischer			$installer::logger::Info->print( "... removing directory $installer::globals::removedirs[$i] ...\n" );
534cdf0e10cSrcweir			installer::systemactions::remove_complete_directory($installer::globals::removedirs[$i], 1);
535cdf0e10cSrcweir		}
536cdf0e10cSrcweir	}
537cdf0e10cSrcweir
538cdf0e10cSrcweir	# Last try to remove the ship test directory
539cdf0e10cSrcweir
540cdf0e10cSrcweir	if ( $installer::globals::shiptestdirectory )
541cdf0e10cSrcweir	{
542cdf0e10cSrcweir		if ( -d $installer::globals::shiptestdirectory )
543cdf0e10cSrcweir		{
544cdf0e10cSrcweir			my $infoline = "Last try to remove $installer::globals::shiptestdirectory . \n";
545b274bc22SAndre Fischer			$installer::logger::Lang->print($infoline);
546cdf0e10cSrcweir			my $systemcall = "rmdir $installer::globals::shiptestdirectory";
547cdf0e10cSrcweir			my $returnvalue = system($systemcall);
548cdf0e10cSrcweir		}
549cdf0e10cSrcweir	}
550cdf0e10cSrcweir}
551cdf0e10cSrcweir
552cdf0e10cSrcweir###############################################################
553cdf0e10cSrcweir# Removing all directories that are saved in the
554cdf0e10cSrcweir# global directory @installer::globals::jdsremovedirs
555cdf0e10cSrcweir###############################################################
556cdf0e10cSrcweir
557cdf0e10cSrcweirsub clean_jds_temp_dirs
558cdf0e10cSrcweir{
559b274bc22SAndre Fischer	$installer::logger::Info->print( "... cleaning jds directories ...\n" );
560cdf0e10cSrcweir
561cdf0e10cSrcweir	for ( my $i = 0; $i <= $#installer::globals::jdsremovedirs; $i++ )
562cdf0e10cSrcweir	{
563cdf0e10cSrcweir		if ( -d $installer::globals::jdsremovedirs[$i] )
564cdf0e10cSrcweir		{
565b274bc22SAndre Fischer			$installer::logger::Info->print( "... removing directory $installer::globals::jdsremovedirs[$i] ...\n" );
566cdf0e10cSrcweir			installer::systemactions::remove_complete_directory($installer::globals::jdsremovedirs[$i], 1);
567cdf0e10cSrcweir		}
568cdf0e10cSrcweir	}
569cdf0e10cSrcweir}
570cdf0e10cSrcweir
571cdf0e10cSrcweir###########################################################
572cdf0e10cSrcweir# Copying a reference array
573cdf0e10cSrcweir###########################################################
574cdf0e10cSrcweir
575cdf0e10cSrcweirsub copy_array_from_references
576cdf0e10cSrcweir{
577cdf0e10cSrcweir	my ( $arrayref ) = @_;
578cdf0e10cSrcweir
579cdf0e10cSrcweir	my @newarray = ();
580cdf0e10cSrcweir
581cdf0e10cSrcweir	for ( my $i = 0; $i <= $#{$arrayref}; $i++ )
582cdf0e10cSrcweir	{
583cdf0e10cSrcweir		push(@newarray, ${$arrayref}[$i]);
584cdf0e10cSrcweir	}
585cdf0e10cSrcweir
586cdf0e10cSrcweir	return \@newarray;
587cdf0e10cSrcweir}
588cdf0e10cSrcweir
589cdf0e10cSrcweir###########################################################
590cdf0e10cSrcweir# Copying a reference hash
591cdf0e10cSrcweir###########################################################
592cdf0e10cSrcweir
593cdf0e10cSrcweirsub copy_hash_from_references
594cdf0e10cSrcweir{
595cdf0e10cSrcweir	my ($hashref) = @_;
596cdf0e10cSrcweir
597cdf0e10cSrcweir	my %newhash = ();
598cdf0e10cSrcweir	my $key;
599cdf0e10cSrcweir
600cdf0e10cSrcweir	foreach $key (keys %{$hashref})
601cdf0e10cSrcweir	{
602cdf0e10cSrcweir		$newhash{$key} = $hashref->{$key};
603cdf0e10cSrcweir	}
604cdf0e10cSrcweir
605cdf0e10cSrcweir	return \%newhash;
606cdf0e10cSrcweir}
607cdf0e10cSrcweir
608cdf0e10cSrcweir###########################################################
609cdf0e10cSrcweir# Setting one language in the language independent
61086e1cf34SPedro Giffuni# array of include paths with $(LANG)
611cdf0e10cSrcweir###########################################################
612cdf0e10cSrcweir
613cdf0e10cSrcweirsub get_language_specific_include_pathes
614cdf0e10cSrcweir{
615cdf0e10cSrcweir	my ( $patharrayref, $onelanguage ) = @_;
616cdf0e10cSrcweir
617cdf0e10cSrcweir	my @patharray = ();
618cdf0e10cSrcweir
619cdf0e10cSrcweir	for ( my $i = 0; $i <= $#{$patharrayref}; $i++ )
620cdf0e10cSrcweir	{
621cdf0e10cSrcweir		my $line = ${$patharrayref}[$i];
622cdf0e10cSrcweir		$line =~ s/\$\(LANG\)/$onelanguage/g;
623cdf0e10cSrcweir		push(@patharray ,$line);
624cdf0e10cSrcweir	}
625cdf0e10cSrcweir
626cdf0e10cSrcweir	return \@patharray;
627cdf0e10cSrcweir}
628cdf0e10cSrcweir
629cdf0e10cSrcweir##############################################################
630cdf0e10cSrcweir# Returning the first item with a defined flag
631cdf0e10cSrcweir##############################################################
632cdf0e10cSrcweir
633cdf0e10cSrcweirsub return_first_item_with_special_flag
634cdf0e10cSrcweir{
635cdf0e10cSrcweir	my ($itemsref, $flag) = @_;
636cdf0e10cSrcweir
637cdf0e10cSrcweir	my $firstitem = "";
638cdf0e10cSrcweir
639cdf0e10cSrcweir	for ( my $i = 0; $i <= $#{$itemsref}; $i++ )
640cdf0e10cSrcweir	{
641cdf0e10cSrcweir		my $oneitem = ${$itemsref}[$i];
642cdf0e10cSrcweir		my $styles = "";
643cdf0e10cSrcweir		if ( $oneitem->{'Styles'} ) { $styles = $oneitem->{'Styles'} };
644cdf0e10cSrcweir
645cdf0e10cSrcweir		if ( $styles =~ /\b$flag\b/ )
646cdf0e10cSrcweir		{
647cdf0e10cSrcweir			$firstitem = $oneitem;
648cdf0e10cSrcweir			last;
649cdf0e10cSrcweir		}
650cdf0e10cSrcweir	}
651cdf0e10cSrcweir
652cdf0e10cSrcweir	return $firstitem;
653cdf0e10cSrcweir}
654cdf0e10cSrcweir
655cdf0e10cSrcweir##############################################################
656cdf0e10cSrcweir# Collecting all items with a defined flag
657cdf0e10cSrcweir##############################################################
658cdf0e10cSrcweir
659cdf0e10cSrcweirsub collect_all_items_with_special_flag
660cdf0e10cSrcweir{
661cdf0e10cSrcweir	my ($itemsref, $flag) = @_;
662cdf0e10cSrcweir
663cdf0e10cSrcweir	my @allitems = ();
664cdf0e10cSrcweir
665cdf0e10cSrcweir	for ( my $i = 0; $i <= $#{$itemsref}; $i++ )
666cdf0e10cSrcweir	{
667cdf0e10cSrcweir		my $oneitem = ${$itemsref}[$i];
668cdf0e10cSrcweir		my $styles = "";
669cdf0e10cSrcweir		if ( $oneitem->{'Styles'} ) { $styles = $oneitem->{'Styles'} };
670cdf0e10cSrcweir
671cdf0e10cSrcweir		if ( $styles =~ /\b$flag\b/ )
672cdf0e10cSrcweir		{
673cdf0e10cSrcweir			push( @allitems, $oneitem );
674cdf0e10cSrcweir		}
675cdf0e10cSrcweir	}
676cdf0e10cSrcweir
677cdf0e10cSrcweir	return \@allitems;
678cdf0e10cSrcweir}
679cdf0e10cSrcweir
680cdf0e10cSrcweir##############################################################
681cdf0e10cSrcweir# Collecting all files without patch flag in
682cdf0e10cSrcweir# $installer::globals::nopatchfilecollector
683cdf0e10cSrcweir##############################################################
684cdf0e10cSrcweir
685cdf0e10cSrcweirsub collect_all_files_without_patch_flag
686cdf0e10cSrcweir{
687cdf0e10cSrcweir	my ($filesref) = @_;
688cdf0e10cSrcweir
689cdf0e10cSrcweir	my $newfiles = collect_all_items_without_special_flag($filesref, "PATCH");
690cdf0e10cSrcweir
691cdf0e10cSrcweir	for ( my $i = 0; $i <= $#{$newfiles}; $i++ ) { push(@{$installer::globals::nopatchfilecollector}, ${$newfiles}[$i]); }
692cdf0e10cSrcweir}
693cdf0e10cSrcweir
694cdf0e10cSrcweir##############################################################
695cdf0e10cSrcweir# Collecting all items without a defined flag
696cdf0e10cSrcweir##############################################################
697cdf0e10cSrcweir
698cdf0e10cSrcweirsub collect_all_items_without_special_flag
699cdf0e10cSrcweir{
700cdf0e10cSrcweir	my ($itemsref, $flag) = @_;
701cdf0e10cSrcweir
702cdf0e10cSrcweir	my @allitems = ();
703cdf0e10cSrcweir
704cdf0e10cSrcweir	for ( my $i = 0; $i <= $#{$itemsref}; $i++ )
705cdf0e10cSrcweir	{
706cdf0e10cSrcweir		my $oneitem = ${$itemsref}[$i];
707cdf0e10cSrcweir		my $styles = "";
708cdf0e10cSrcweir		if ( $oneitem->{'Styles'} ) { $styles = $oneitem->{'Styles'} };
709cdf0e10cSrcweir
710cdf0e10cSrcweir		if ( !( $styles =~ /\b$flag\b/ ))
711cdf0e10cSrcweir		{
712cdf0e10cSrcweir			push( @allitems, $oneitem );
713cdf0e10cSrcweir		}
714cdf0e10cSrcweir	}
715cdf0e10cSrcweir
716cdf0e10cSrcweir	return \@allitems;
717cdf0e10cSrcweir}
718cdf0e10cSrcweir
719cdf0e10cSrcweir##############################################################
720cdf0e10cSrcweir# Removing all items with a defined flag from collector
721cdf0e10cSrcweir##############################################################
722cdf0e10cSrcweir
723cdf0e10cSrcweirsub remove_all_items_with_special_flag
724cdf0e10cSrcweir{
725cdf0e10cSrcweir	my ($itemsref, $flag) = @_;
726cdf0e10cSrcweir
727cdf0e10cSrcweir	my @allitems = ();
728cdf0e10cSrcweir
729cdf0e10cSrcweir	for ( my $i = 0; $i <= $#{$itemsref}; $i++ )
730cdf0e10cSrcweir	{
731cdf0e10cSrcweir		my $oneitem = ${$itemsref}[$i];
732cdf0e10cSrcweir		my $styles = "";
733cdf0e10cSrcweir		if ( $oneitem->{'Styles'} ) { $styles = $oneitem->{'Styles'} };
734cdf0e10cSrcweir		if ( $styles =~ /\b$flag\b/ )
735cdf0e10cSrcweir		{
736213d2b27SAndre Fischer            $installer::logger::Lang->printf(
737213d2b27SAndre Fischer                "Attention: Removing from collector '%s' because it has flag %s\n",
738213d2b27SAndre Fischer                $oneitem->{'Name'},
739213d2b27SAndre Fischer                $flag);
7401ba1fd99SAndre Fischer			if ( $flag eq "BINARYTABLE_ONLY" ) { push(@installer::globals::binarytableonlyfiles, $oneitem); }
741cdf0e10cSrcweir			next;
742cdf0e10cSrcweir		}
743cdf0e10cSrcweir		push( @allitems, $oneitem );
744cdf0e10cSrcweir	}
745cdf0e10cSrcweir
746cdf0e10cSrcweir	return \@allitems;
747cdf0e10cSrcweir}
748cdf0e10cSrcweir
749cdf0e10cSrcweir###########################################################
750cdf0e10cSrcweir# Mechanism for simple installation without packing
751cdf0e10cSrcweir###########################################################
752cdf0e10cSrcweir
753cdf0e10cSrcweirsub install_simple ($$$$$$)
754cdf0e10cSrcweir{
755cdf0e10cSrcweir	my ($packagename, $languagestring, $directoriesarray, $filesarray, $linksarray, $unixlinksarray) = @_;
756cdf0e10cSrcweir
757cdf0e10cSrcweir        # locate GNU cp on the system
758cdf0e10cSrcweir        my $gnucp = 'cp';
759cdf0e10cSrcweir        if ( $ENV{'GNUCOPY'} ) { $gnucp = $ENV{'GNUCOPY'}; }
760cdf0e10cSrcweir	my $copyopts = '-af';
761cdf0e10cSrcweir	$copyopts = '-PpRf' unless ( $ENV{'GNUCOPY'} ); # if not gnucopy, assume POSIX copy
762cdf0e10cSrcweir
763b274bc22SAndre Fischer	$installer::logger::Info->print( "... installing module $packagename ...\n" );
764cdf0e10cSrcweir
765cdf0e10cSrcweir	my $destdir = $installer::globals::destdir;
766cdf0e10cSrcweir	my @lines = ();
767cdf0e10cSrcweir
768b274bc22SAndre Fischer	$installer::logger::Info->print( "DestDir: $destdir \n" );
769b274bc22SAndre Fischer	$installer::logger::Info->print( "Rootpath: $installer::globals::rootpath \n" );
770cdf0e10cSrcweir
771cdf0e10cSrcweir	`mkdir -p $destdir` if $destdir ne "";
772cdf0e10cSrcweir	`mkdir -p $destdir$installer::globals::rootpath`;
773cdf0e10cSrcweir
774cdf0e10cSrcweir	# Create Directories
775cdf0e10cSrcweir	for ( my $i = 0; $i <= $#{$directoriesarray}; $i++ )
776cdf0e10cSrcweir	{
777cdf0e10cSrcweir		my $onedir = ${$directoriesarray}[$i];
778cdf0e10cSrcweir		my $dir = "";
779cdf0e10cSrcweir
780cdf0e10cSrcweir		if ( $onedir->{'Dir'} ) { $dir = $onedir->{'Dir'}; }
781cdf0e10cSrcweir
782cdf0e10cSrcweir		if ((!($dir =~ /\bPREDEFINED_/ )) || ( $dir =~ /\bPREDEFINED_PROGDIR\b/ ))
783cdf0e10cSrcweir		{
784cdf0e10cSrcweir			# printf "mkdir $destdir$onedir->{'HostName'}\n";
785cdf0e10cSrcweir			mkdir $destdir . $onedir->{'HostName'};
786cdf0e10cSrcweir			push @lines, "%dir " . $onedir->{'HostName'} . "\n";
787cdf0e10cSrcweir		}
788cdf0e10cSrcweir	}
789cdf0e10cSrcweir
790cdf0e10cSrcweir	for ( my $i = 0; $i <= $#{$filesarray}; $i++ )
791cdf0e10cSrcweir	{
792cdf0e10cSrcweir		my $onefile = ${$filesarray}[$i];
793cdf0e10cSrcweir		my $unixrights = $onefile->{'UnixRights'};
794cdf0e10cSrcweir		my $destination = $onefile->{'destination'};
795cdf0e10cSrcweir		my $sourcepath = $onefile->{'sourcepath'};
796cdf0e10cSrcweir
797cdf0e10cSrcweir		# This is necessary to install SDK that includes files with $ in its name
798cdf0e10cSrcweir		# Otherwise, the following shell commands does not work and the file list
799cdf0e10cSrcweir		# is not correct
800cdf0e10cSrcweir		$destination =~ s/\$\$/\$/;
801cdf0e10cSrcweir		$sourcepath =~ s/\$\$/\$/;
802cdf0e10cSrcweir
803cdf0e10cSrcweir		push @lines, "$destination\n";
804cdf0e10cSrcweir		# printf "cp $sourcepath $destdir$destination\n";
805cdf0e10cSrcweir		copy ("$sourcepath", "$destdir$destination") || die "Can't copy file: $sourcepath -> $destdir$destination $!";
806cdf0e10cSrcweir		my $sourcestat = stat($sourcepath);
807cdf0e10cSrcweir		utime ($sourcestat->atime, $sourcestat->mtime, "$destdir$destination");
808cdf0e10cSrcweir		chmod (oct($unixrights), "$destdir$destination") || die "Can't change permissions: $!";
809cdf0e10cSrcweir 		push @lines, "$destination\n";
810cdf0e10cSrcweir	}
811cdf0e10cSrcweir
812cdf0e10cSrcweir	for ( my $i = 0; $i <= $#{$linksarray}; $i++ )
813cdf0e10cSrcweir	{
814cdf0e10cSrcweir		my $onelink = ${$linksarray}[$i];
815cdf0e10cSrcweir		my $destination = $onelink->{'destination'};
816cdf0e10cSrcweir		my $destinationfile = $onelink->{'destinationfile'};
817cdf0e10cSrcweir
818cdf0e10cSrcweir		# print "link $destinationfile -> $destdir$destination\n";
819cdf0e10cSrcweir		symlink ("$destinationfile", "$destdir$destination") || die "Can't create symlink: $!";
820cdf0e10cSrcweir		push @lines, "$destination\n";
821cdf0e10cSrcweir	}
822cdf0e10cSrcweir
823cdf0e10cSrcweir	for ( my $i = 0; $i <= $#{$unixlinksarray}; $i++ )
824cdf0e10cSrcweir	{
825cdf0e10cSrcweir		my $onelink = ${$unixlinksarray}[$i];
826cdf0e10cSrcweir        my $target = $onelink->{'Target'};
827cdf0e10cSrcweir		my $destination = $onelink->{'destination'};
828cdf0e10cSrcweir
829cdf0e10cSrcweir		# print "Unix link $target -> $destdir$destination\n";
830cdf0e10cSrcweir		`ln -sf '$target' '$destdir$destination'`;
831cdf0e10cSrcweir		push @lines, "$destination\n";
832cdf0e10cSrcweir	}
833cdf0e10cSrcweir
834cdf0e10cSrcweir	if ( $destdir ne "" )
835cdf0e10cSrcweir	{
836cdf0e10cSrcweir		my $filelist;
837cdf0e10cSrcweir		my $fname = $installer::globals::destdir . "/$packagename";
838cdf0e10cSrcweir		if ($installer::globals::languagepack) { $fname .= ".$languagestring"; }
839cdf0e10cSrcweir		open ($filelist, ">$fname") || die "Can't open $fname: $!";
840cdf0e10cSrcweir		print $filelist @lines;
841cdf0e10cSrcweir		close ($filelist);
842cdf0e10cSrcweir	}
843cdf0e10cSrcweir
844cdf0e10cSrcweir}
845cdf0e10cSrcweir
846cdf0e10cSrcweir###########################################################
847cdf0e10cSrcweir# Adding shellnew files into files collector for
848cdf0e10cSrcweir# user installation
849cdf0e10cSrcweir###########################################################
850cdf0e10cSrcweir
851cdf0e10cSrcweirsub add_shellnewfile_into_filesarray
852cdf0e10cSrcweir{
853cdf0e10cSrcweir	my ($filesref, $onefile, $inffile) = @_;
854cdf0e10cSrcweir
855cdf0e10cSrcweir	my %shellnewfile = ();
856cdf0e10cSrcweir	my $shellnewfileref = \%shellnewfile;
857cdf0e10cSrcweir
858cdf0e10cSrcweir	installer::converter::copy_item_object($inffile, $shellnewfileref);
859cdf0e10cSrcweir
860cdf0e10cSrcweir	$shellnewfileref->{'Name'} = $onefile->{'Name'};
861cdf0e10cSrcweir	$shellnewfileref->{'sourcepath'} = $onefile->{'sourcepath'};
862cdf0e10cSrcweir	$shellnewfileref->{'gid'} = $onefile->{'gid'} . "_Userinstall";
863cdf0e10cSrcweir
864cdf0e10cSrcweir	# the destination has to be adapted
865cdf0e10cSrcweir	my $destination = $inffile->{'destination'};
866cdf0e10cSrcweir	installer::pathanalyzer::get_path_from_fullqualifiedname(\$destination);
867cdf0e10cSrcweir	$destination = $destination . $onefile->{'Name'};
868cdf0e10cSrcweir	$shellnewfileref->{'destination'} = $destination;
869cdf0e10cSrcweir
870cdf0e10cSrcweir	# add language specific inffile into filesarray
871cdf0e10cSrcweir	push(@{$filesref}, $shellnewfileref);
872cdf0e10cSrcweir}
873cdf0e10cSrcweir
874cdf0e10cSrcweir###########################################################
875cdf0e10cSrcweir# Replacing one placehoder in template file
876cdf0e10cSrcweir###########################################################
877cdf0e10cSrcweir
878cdf0e10cSrcweirsub replace_in_template_file
879cdf0e10cSrcweir{
880cdf0e10cSrcweir	my ($templatefile, $placeholder, $newstring) = @_;
881cdf0e10cSrcweir
882cdf0e10cSrcweir	for ( my $i = 0; $i <= $#{$templatefile}; $i++ )
883cdf0e10cSrcweir	{
884cdf0e10cSrcweir		${$templatefile}[$i] =~ s/\Q$placeholder\E/$newstring/g;
885cdf0e10cSrcweir	}
886cdf0e10cSrcweir}
887cdf0e10cSrcweir
888cdf0e10cSrcweir###########################################################
889cdf0e10cSrcweir# Replacing one placehoder with an array in template file
890cdf0e10cSrcweir###########################################################
891cdf0e10cSrcweir
892cdf0e10cSrcweirsub replace_array_in_template_file
893cdf0e10cSrcweir{
894cdf0e10cSrcweir	my ($templatefile, $placeholder, $arrayref) = @_;
895cdf0e10cSrcweir
896cdf0e10cSrcweir	for ( my $i = 0; $i <= $#{$templatefile}; $i++ )
897cdf0e10cSrcweir	{
898cdf0e10cSrcweir		if ( ${$templatefile}[$i] =~ /\Q$placeholder\E/ )
899cdf0e10cSrcweir		{
900cdf0e10cSrcweir			my @return = splice(@{$templatefile}, $i, 1, @{$arrayref});
901cdf0e10cSrcweir		}
902cdf0e10cSrcweir	}
903cdf0e10cSrcweir}
904cdf0e10cSrcweir
905cdf0e10cSrcweir###########################################################
906cdf0e10cSrcweir# Collecting all modules from registry items
907cdf0e10cSrcweir###########################################################
908cdf0e10cSrcweir
909cdf0e10cSrcweirsub collect_all_modules
910cdf0e10cSrcweir{
911cdf0e10cSrcweir	my ($registryitemsref) = @_;
912cdf0e10cSrcweir
913cdf0e10cSrcweir	my @allmodules = ();
914cdf0e10cSrcweir
915cdf0e10cSrcweir	for ( my $i = 0; $i <= $#{$registryitemsref}; $i++ )
916cdf0e10cSrcweir	{
917cdf0e10cSrcweir		$registryitem = ${$registryitemsref}[$i];
918cdf0e10cSrcweir		my $module = $registryitem->{'ModuleID'};
919cdf0e10cSrcweir
920cdf0e10cSrcweir		if ( ! installer::existence::exists_in_array($module, \@allmodules) )
921cdf0e10cSrcweir		{
922cdf0e10cSrcweir			push(@allmodules, $module);
923cdf0e10cSrcweir		}
924cdf0e10cSrcweir	}
925cdf0e10cSrcweir
926cdf0e10cSrcweir	return \@allmodules;
927cdf0e10cSrcweir}
928cdf0e10cSrcweir
929cdf0e10cSrcweir###########################################################
930cdf0e10cSrcweir# Changing the content of the inf file
931cdf0e10cSrcweir###########################################################
932cdf0e10cSrcweir
933cdf0e10cSrcweirsub write_content_into_inf_file
934cdf0e10cSrcweir{
935cdf0e10cSrcweir	my ($templatefile, $filesref, $registryitemsref, $folderref, $folderitemsref, $modulesref, $onelanguage, $inffile, $firstlanguage, $allvariableshashref) = @_;
936cdf0e10cSrcweir
937cdf0e10cSrcweir	# First part: Shellnew files
938cdf0e10cSrcweir	# SHELLNEWFILESPLACEHOLDER
939cdf0e10cSrcweir
940cdf0e10cSrcweir	my $rootmodule = 0;
941cdf0e10cSrcweir	# inf files can be assigned to "gid_Module_Root_Files_2"
942cdf0e10cSrcweir	if ( $inffile->{'modules'} =~ /Module_Root/i ) { $rootmodule = 1; }
943cdf0e10cSrcweir
944cdf0e10cSrcweir	if ( $rootmodule )
945cdf0e10cSrcweir	{
946cdf0e10cSrcweir		my $shellnewstring = "";
947cdf0e10cSrcweir
948cdf0e10cSrcweir		for ( my $i = 0; $i <= $#{$filesref}; $i++ )
949cdf0e10cSrcweir		{
950cdf0e10cSrcweir			my $onefile = ${$filesref}[$i];
951cdf0e10cSrcweir			my $directory = $onefile->{'Dir'};
952cdf0e10cSrcweir
953cdf0e10cSrcweir			if ( $directory =~ /\bPREDEFINED_OSSHELLNEWDIR\b/ )
954cdf0e10cSrcweir			{
955cdf0e10cSrcweir				$shellnewstring = $shellnewstring . $onefile->{'Name'} . "\n";
956cdf0e10cSrcweir				if (( $firstlanguage ) && ( ! $installer::globals::shellnewfilesadded )) { add_shellnewfile_into_filesarray($filesref, $onefile, $inffile); }
957cdf0e10cSrcweir			}
958cdf0e10cSrcweir		}
959cdf0e10cSrcweir
960cdf0e10cSrcweir		$shellnewstring =~ s/\s*$//;
961cdf0e10cSrcweir		replace_in_template_file($templatefile, "SHELLNEWFILESPLACEHOLDER", $shellnewstring);
962cdf0e10cSrcweir
963cdf0e10cSrcweir		$installer::globals::shellnewfilesadded = 1;
964cdf0e10cSrcweir	}
965cdf0e10cSrcweir
966cdf0e10cSrcweir	# Second part: Start menu entries
967cdf0e10cSrcweir
968cdf0e10cSrcweir	# The OfficeMenuFolder is defined as: $productname . " " . $productversion;
969cdf0e10cSrcweir
970cdf0e10cSrcweir	my $productname = $allvariableshashref->{'PRODUCTNAME'};
971cdf0e10cSrcweir	my $productversion = $allvariableshashref->{'PRODUCTVERSION'};
972cdf0e10cSrcweir	my $productkey = $productname . " " . $productversion;
973cdf0e10cSrcweir
974cdf0e10cSrcweir	replace_in_template_file($templatefile, "OFFICEFOLDERPLACEHOLDER", $productkey);
975cdf0e10cSrcweir
976cdf0e10cSrcweir	# Setting name target and infotip for all applications
977cdf0e10cSrcweir
978cdf0e10cSrcweir	for ( my $i = 0; $i <= $#{$folderitemsref}; $i++ )
979cdf0e10cSrcweir	{
980cdf0e10cSrcweir		my $folderitem = ${$folderitemsref}[$i];
981cdf0e10cSrcweir
982cdf0e10cSrcweir		my $styles = "";
983cdf0e10cSrcweir		if ( $folderitem->{'Styles'} ) { $styles = $folderitem->{'Styles'}; }
984cdf0e10cSrcweir		if ( $styles =~ /\bNON_ADVERTISED\b/ ) { next; }	# no entry for non-advertised shortcuts
985cdf0e10cSrcweir
986cdf0e10cSrcweir		if (( ! $folderitem->{'ismultilingual'} ) || (( $folderitem->{'ismultilingual'} ) && ( $folderitem->{'specificlanguage'} eq $onelanguage )))
987cdf0e10cSrcweir		{
988cdf0e10cSrcweir			my $gid = $folderitem->{'gid'};
989cdf0e10cSrcweir			my $app = $gid;
990cdf0e10cSrcweir			$app =~ s/gid_Folderitem_//;
991cdf0e10cSrcweir			$app = uc($app);
992cdf0e10cSrcweir
993cdf0e10cSrcweir			my $name = $folderitem->{'Name'};
994cdf0e10cSrcweir			my $placeholder = "PLACEHOLDER_FOLDERITEM_NAME_" . $app;
995cdf0e10cSrcweir			replace_in_template_file($templatefile, $placeholder, $name);
996cdf0e10cSrcweir
997cdf0e10cSrcweir			my $tooltip = $folderitem->{'Tooltip'};
998cdf0e10cSrcweir			$placeholder = "PLACEHOLDER_FOLDERITEM_TOOLTIP_" . $app;
999cdf0e10cSrcweir			replace_in_template_file($templatefile, $placeholder, $tooltip);
1000cdf0e10cSrcweir
1001cdf0e10cSrcweir			my $executablegid = $folderitem->{'FileID'};
1002cdf0e10cSrcweir			my $exefile = installer::existence::get_specified_file($filesref, $executablegid);
1003cdf0e10cSrcweir			my $exefilename = $exefile->{'Name'};
1004cdf0e10cSrcweir			$placeholder = "PLACEHOLDER_FOLDERITEM_TARGET_" . $app;
1005cdf0e10cSrcweir			replace_in_template_file($templatefile, $placeholder, $exefilename);
1006cdf0e10cSrcweir		}
1007cdf0e10cSrcweir	}
1008cdf0e10cSrcweir
1009cdf0e10cSrcweir	# Third part: Windows registry entries
1010cdf0e10cSrcweir
1011cdf0e10cSrcweir	# collecting all modules
1012cdf0e10cSrcweir
1013cdf0e10cSrcweir	my $allmodules = collect_all_modules($registryitemsref);
1014cdf0e10cSrcweir
1015cdf0e10cSrcweir	my @registryitems = ();
1016cdf0e10cSrcweir	my $allsectionsstring = "";
1017cdf0e10cSrcweir
1018cdf0e10cSrcweir	for ( my $j = 0; $j <= $#{$allmodules}; $j++ )
1019cdf0e10cSrcweir	{
1020cdf0e10cSrcweir		my $moduleid = ${$allmodules}[$j];
1021cdf0e10cSrcweir
1022cdf0e10cSrcweir		my $inffilemodule = $inffile->{'modules'};
1023cdf0e10cSrcweir		# inf files can be assigned to "gid_Module_Root_Files_2", but RegistryItems to "gid_Module_Root"
1024cdf0e10cSrcweir		if ( $inffilemodule =~ /Module_Root/i ) { $inffilemodule = $installer::globals::rootmodulegid; }
1025cdf0e10cSrcweir
1026cdf0e10cSrcweir		if ( ! ( $moduleid eq $inffilemodule )) { next; }
1027cdf0e10cSrcweir
1028cdf0e10cSrcweir		my $shortmodulename = $moduleid;
1029cdf0e10cSrcweir		$shortmodulename =~ s/gid_Module_//;
1030cdf0e10cSrcweir		my $sectionname = "InstRegKeys." . $shortmodulename;
1031cdf0e10cSrcweir		$allsectionsstring = $allsectionsstring . $sectionname . ",";
1032cdf0e10cSrcweir		my $sectionheader = "\[" . $sectionname . "\]" . "\n";
1033cdf0e10cSrcweir		push(@registryitems, $sectionheader);
1034cdf0e10cSrcweir
1035cdf0e10cSrcweir		for ( my $i = 0; $i <= $#{$registryitemsref}; $i++ )
1036cdf0e10cSrcweir		{
1037cdf0e10cSrcweir			my $registryitem = ${$registryitemsref}[$i];
1038cdf0e10cSrcweir
1039cdf0e10cSrcweir			if ( ! ( $registryitem->{'ModuleID'} eq $moduleid )) { next; }
1040cdf0e10cSrcweir
1041cdf0e10cSrcweir			if (( ! $registryitem->{'ismultilingual'} ) || (( $registryitem->{'ismultilingual'} ) && ( $registryitem->{'specificlanguage'} eq $onelanguage )))
1042cdf0e10cSrcweir			{
1043cdf0e10cSrcweir				# Syntax: HKCR,".bau",,,"soffice.StarConfigFile.6"
1044cdf0e10cSrcweir
1045cdf0e10cSrcweir				my $regroot = "";
1046cdf0e10cSrcweir				my $parentid = "";
1047cdf0e10cSrcweir				if ( $registryitem->{'ParentID'} ) { $parentid = $registryitem->{'ParentID'}; }
1048cdf0e10cSrcweir				if ( $parentid eq "PREDEFINED_HKEY_CLASSES_ROOT" ) { $regroot = "HKCR"; }
1049cdf0e10cSrcweir				if ( $parentid eq "PREDEFINED_HKEY_LOCAL_MACHINE" ) { $regroot = "HKCU"; }
1050cdf0e10cSrcweir
1051cdf0e10cSrcweir				my $subkey = "";
1052cdf0e10cSrcweir				if ( $registryitem->{'Subkey'} ) { $subkey = $registryitem->{'Subkey'}; }
1053cdf0e10cSrcweir				if ( $subkey ne "" ) { $subkey = "\"" . $subkey . "\""; }
1054cdf0e10cSrcweir
1055cdf0e10cSrcweir				my $valueentryname = "";
1056cdf0e10cSrcweir				if ( $registryitem->{'Name'} ) { $valueentryname = $registryitem->{'Name'}; }
1057cdf0e10cSrcweir				if ( $valueentryname ne "" ) { $valueentryname = "\"" . $valueentryname . "\""; }
1058cdf0e10cSrcweir
1059cdf0e10cSrcweir				my $flag = "";
1060cdf0e10cSrcweir
1061cdf0e10cSrcweir				my $value = "";
1062cdf0e10cSrcweir				if ( $registryitem->{'Value'} ) { $value = $registryitem->{'Value'}; }
1063cdf0e10cSrcweir				if ( $value =~ /\<progpath\>/ ) { $value =~ s/\\\"/\"\"/g; } # Quoting for INF is done by double ""
1064cdf0e10cSrcweir				$value =~ s/\\\"/\"/g;	# no more masquerading of '"'
1065cdf0e10cSrcweir				$value =~ s/\<progpath\>/\%INSTALLLOCATION\%/g;
1066cdf0e10cSrcweir				if ( $value ne "" ) { $value = "\"" . $value . "\""; }
1067cdf0e10cSrcweir
1068cdf0e10cSrcweir				my $oneline = $regroot . "," . $subkey . "," . $valueentryname . "," . $flag . "," . $value . "\n";
1069cdf0e10cSrcweir
1070cdf0e10cSrcweir				push(@registryitems, $oneline);
1071cdf0e10cSrcweir			}
1072cdf0e10cSrcweir		}
1073cdf0e10cSrcweir
1074cdf0e10cSrcweir		push(@registryitems, "\n"); # empty line after each section
1075cdf0e10cSrcweir	}
1076cdf0e10cSrcweir
1077cdf0e10cSrcweir	# replacing the $allsectionsstring
1078cdf0e10cSrcweir	$allsectionsstring =~ s/\,\s*$//;
1079cdf0e10cSrcweir	replace_in_template_file($templatefile, "ALLREGISTRYSECTIONSPLACEHOLDER", $allsectionsstring);
1080cdf0e10cSrcweir
1081cdf0e10cSrcweir	# replacing the placeholder for all registry keys
1082cdf0e10cSrcweir	replace_array_in_template_file($templatefile, "REGISTRYKEYSPLACEHOLDER", \@registryitems);
1083cdf0e10cSrcweir
1084cdf0e10cSrcweir}
1085cdf0e10cSrcweir
1086cdf0e10cSrcweir###########################################################
1087cdf0e10cSrcweir# Creating inf files for local user system integration
1088cdf0e10cSrcweir###########################################################
1089cdf0e10cSrcweir
1090cdf0e10cSrcweirsub create_inf_file
1091cdf0e10cSrcweir{
1092cdf0e10cSrcweir	my ($filesref, $registryitemsref, $folderref, $folderitemsref, $modulesref, $languagesarrayref, $languagestringref, $allvariableshashref) = @_;
1093cdf0e10cSrcweir
1094cdf0e10cSrcweir	# collecting all files with flag INFFILE
1095cdf0e10cSrcweir
1096cdf0e10cSrcweir	my $inf_files = collect_all_items_with_special_flag($filesref ,"INFFILE");
1097cdf0e10cSrcweir
1098cdf0e10cSrcweir	if ( $#{$inf_files} > -1 )
1099cdf0e10cSrcweir	{
1100cdf0e10cSrcweir		# create new language specific inffile
1101cdf0e10cSrcweir		installer::logger::include_header_into_logfile("Creating inf files:");
1102cdf0e10cSrcweir
1103cdf0e10cSrcweir		my $infdirname = "inffiles";
1104cdf0e10cSrcweir		my $infdir = installer::systemactions::create_directories($infdirname, $languagestringref);
1105cdf0e10cSrcweir
1106cdf0e10cSrcweir		my $infoline = "Number of inf files: $#{$inf_files} + 1 \n";
1107b274bc22SAndre Fischer		$installer::logger::Lang->print($infoline);
1108cdf0e10cSrcweir
1109cdf0e10cSrcweir		# there are inffiles for all modules
1110cdf0e10cSrcweir
1111cdf0e10cSrcweir		for ( my $i = 0; $i <= $#{$inf_files}; $i++ )
1112cdf0e10cSrcweir		{
1113cdf0e10cSrcweir			my $inffile = ${$inf_files}[$i];
1114cdf0e10cSrcweir			my $inf_file_name = $inffile->{'Name'};
1115cdf0e10cSrcweir
1116cdf0e10cSrcweir			my $templatefilename = $inffile->{'sourcepath'};
1117cdf0e10cSrcweir
1118cdf0e10cSrcweir			if ( ! -f $templatefilename ) { installer::exiter::exit_program("ERROR: Could not find file $templatefilename !", "create_inf_file");  }
1119cdf0e10cSrcweir
1120cdf0e10cSrcweir			# iterating over all languages
1121cdf0e10cSrcweir
1122cdf0e10cSrcweir			for ( my $j = 0; $j <= $#{$languagesarrayref}; $j++ )	# iterating over all languages
1123cdf0e10cSrcweir			{
1124cdf0e10cSrcweir				my $firstlanguage = 0;
1125cdf0e10cSrcweir				if ( $j == 0 ) { $firstlanguage = 1; }
1126cdf0e10cSrcweir
1127cdf0e10cSrcweir				my $onelanguage = ${$languagesarrayref}[$j];
1128cdf0e10cSrcweir
1129cdf0e10cSrcweir				$infoline = "Templatefile: $inf_file_name, Language: $onelanguage \n";
1130b274bc22SAndre Fischer				$installer::logger::Lang->print($infoline);
1131cdf0e10cSrcweir
1132cdf0e10cSrcweir				my $templatefile = installer::files::read_file($templatefilename);
1133cdf0e10cSrcweir
1134cdf0e10cSrcweir				my $linesbefore = $#{$templatefile};
1135cdf0e10cSrcweir
1136cdf0e10cSrcweir				write_content_into_inf_file($templatefile, $filesref, $registryitemsref, $folderref, $folderitemsref, $modulesref, $onelanguage, $inffile, $firstlanguage, $allvariableshashref);
1137cdf0e10cSrcweir
1138cdf0e10cSrcweir				$infoline = "Lines change: From $linesbefore to $#{$templatefile}.\n";
1139b274bc22SAndre Fischer				$installer::logger::Lang->print($infoline);
1140cdf0e10cSrcweir
1141cdf0e10cSrcweir				# rename language specific inffile
1142cdf0e10cSrcweir				my $language_inf_file_name = $inf_file_name;
1143cdf0e10cSrcweir				my $windowslanguage = installer::windows::language::get_windows_language($onelanguage);
1144cdf0e10cSrcweir				$language_inf_file_name =~ s/\.inf/_$windowslanguage\.inf/;
1145cdf0e10cSrcweir
1146cdf0e10cSrcweir				my $sourcepath = $infdir . $installer::globals::separator . $language_inf_file_name;
1147cdf0e10cSrcweir				installer::files::save_file($sourcepath, $templatefile);
1148cdf0e10cSrcweir
1149cdf0e10cSrcweir				$infoline = "Saving file: $sourcepath\n";
1150b274bc22SAndre Fischer				$installer::logger::Lang->print($infoline);
1151cdf0e10cSrcweir
1152cdf0e10cSrcweir				# creating new file object
1153cdf0e10cSrcweir
1154cdf0e10cSrcweir				my %languageinffile = ();
1155cdf0e10cSrcweir				my $languageinifileref = \%languageinffile;
1156cdf0e10cSrcweir
1157cdf0e10cSrcweir				if ( $j < $#{$languagesarrayref} ) { installer::converter::copy_item_object($inffile, $languageinifileref); }
1158cdf0e10cSrcweir				else { $languageinifileref = $inffile; }
1159cdf0e10cSrcweir
1160cdf0e10cSrcweir				$languageinifileref->{'Name'} = $language_inf_file_name;
1161cdf0e10cSrcweir				$languageinifileref->{'sourcepath'} = $sourcepath;
1162cdf0e10cSrcweir				# destination and gid also have to be adapted
1163cdf0e10cSrcweir				$languageinifileref->{'gid'} = $languageinifileref->{'gid'} . "_" . $onelanguage;
1164cdf0e10cSrcweir				my $destination = $languageinifileref->{'destination'};
1165cdf0e10cSrcweir				installer::pathanalyzer::get_path_from_fullqualifiedname(\$destination);
1166cdf0e10cSrcweir				$destination = $destination . $language_inf_file_name;
1167cdf0e10cSrcweir				$languageinifileref->{'destination'} = $destination;
1168cdf0e10cSrcweir
1169cdf0e10cSrcweir				# add language specific inffile into filesarray
1170cdf0e10cSrcweir				if ( $j < $#{$languagesarrayref} ) { push(@{$filesref}, $languageinifileref); }
1171cdf0e10cSrcweir			}
1172cdf0e10cSrcweir		}
1173cdf0e10cSrcweir	}
1174cdf0e10cSrcweir}
1175cdf0e10cSrcweir
1176cdf0e10cSrcweir###########################################################
1177cdf0e10cSrcweir# Selecting patch items
1178cdf0e10cSrcweir###########################################################
1179cdf0e10cSrcweir
1180cdf0e10cSrcweirsub select_patch_items
1181cdf0e10cSrcweir{
1182cdf0e10cSrcweir	my ( $itemsref, $itemname ) = @_;
1183cdf0e10cSrcweir
1184cdf0e10cSrcweir	installer::logger::include_header_into_logfile("Selecting items for patches. Item: $itemname");
1185cdf0e10cSrcweir
1186cdf0e10cSrcweir	my @itemsarray = ();
1187cdf0e10cSrcweir
1188cdf0e10cSrcweir	for ( my $i = 0; $i <= $#{$itemsref}; $i++ )
1189cdf0e10cSrcweir	{
1190cdf0e10cSrcweir		my $oneitem = ${$itemsref}[$i];
1191cdf0e10cSrcweir
1192cdf0e10cSrcweir		my $name = $oneitem->{'Name'};
1193cdf0e10cSrcweir		if (( $name =~ /\bLICENSE/ ) || ( $name =~ /\bREADME/ ))
1194cdf0e10cSrcweir		{
1195cdf0e10cSrcweir			push(@itemsarray, $oneitem);
1196cdf0e10cSrcweir			next;
1197cdf0e10cSrcweir		}
1198cdf0e10cSrcweir
1199cdf0e10cSrcweir		# Items with style "PATCH" have to be included into the patch
1200cdf0e10cSrcweir		my $styles = "";
1201cdf0e10cSrcweir		if ( $oneitem->{'Styles'} ) { $styles = $oneitem->{'Styles'}; }
1202cdf0e10cSrcweir		if ( $styles =~ /\bPATCH\b/ ) { push(@itemsarray, $oneitem); }
1203cdf0e10cSrcweir	}
1204cdf0e10cSrcweir
1205cdf0e10cSrcweir	return \@itemsarray;
1206cdf0e10cSrcweir}
1207cdf0e10cSrcweir
1208cdf0e10cSrcweir###########################################################
1209cdf0e10cSrcweir# Selecting patch items
1210cdf0e10cSrcweir###########################################################
1211cdf0e10cSrcweir
1212cdf0e10cSrcweirsub select_patch_items_without_name
1213cdf0e10cSrcweir{
1214cdf0e10cSrcweir	my ( $itemsref, $itemname ) = @_;
1215cdf0e10cSrcweir
1216cdf0e10cSrcweir	installer::logger::include_header_into_logfile("Selecting RegistryItems for patches");
1217cdf0e10cSrcweir
1218cdf0e10cSrcweir	my @itemsarray = ();
1219cdf0e10cSrcweir
1220cdf0e10cSrcweir	for ( my $i = 0; $i <= $#{$itemsref}; $i++ )
1221cdf0e10cSrcweir	{
1222cdf0e10cSrcweir		my $oneitem = ${$itemsref}[$i];
1223cdf0e10cSrcweir
1224cdf0e10cSrcweir		# Items with style "PATCH" have to be included into the patch
1225cdf0e10cSrcweir		my $styles = "";
1226cdf0e10cSrcweir		if ( $oneitem->{'Styles'} ) { $styles = $oneitem->{'Styles'}; }
1227cdf0e10cSrcweir		if ( $styles =~ /\bPATCH\b/ ) { push(@itemsarray, $oneitem); }
1228cdf0e10cSrcweir	}
1229cdf0e10cSrcweir
1230cdf0e10cSrcweir	return \@itemsarray;
1231cdf0e10cSrcweir}
1232cdf0e10cSrcweir
1233cdf0e10cSrcweir###########################################################
1234cdf0e10cSrcweir# Selecting patch items
1235cdf0e10cSrcweir###########################################################
1236cdf0e10cSrcweir
1237cdf0e10cSrcweirsub select_langpack_items
1238cdf0e10cSrcweir{
1239cdf0e10cSrcweir	my ( $itemsref, $itemname ) = @_;
1240cdf0e10cSrcweir
1241cdf0e10cSrcweir	installer::logger::include_header_into_logfile("Selecting RegistryItems for Language Packs");
1242cdf0e10cSrcweir
1243cdf0e10cSrcweir	my @itemsarray = ();
1244cdf0e10cSrcweir
1245cdf0e10cSrcweir	for ( my $i = 0; $i <= $#{$itemsref}; $i++ )
1246cdf0e10cSrcweir	{
1247cdf0e10cSrcweir		my $oneitem = ${$itemsref}[$i];
1248cdf0e10cSrcweir
1249cdf0e10cSrcweir		# Items with style "LANGUAGEPACK" have to be included into the patch
1250cdf0e10cSrcweir		my $styles = "";
1251cdf0e10cSrcweir		if ( $oneitem->{'Styles'} ) { $styles = $oneitem->{'Styles'}; }
1252cdf0e10cSrcweir		if (( $styles =~ /\bLANGUAGEPACK\b/ ) || ( $styles =~ /\bFORCELANGUAGEPACK\b/ )) { push(@itemsarray, $oneitem); }
1253cdf0e10cSrcweir	}
1254cdf0e10cSrcweir
1255cdf0e10cSrcweir	return \@itemsarray;
1256cdf0e10cSrcweir}
1257cdf0e10cSrcweir
1258cdf0e10cSrcweir###########################################################
1259cdf0e10cSrcweir# Searching if LICENSE and README, which are not removed
1260cdf0e10cSrcweir# in select_patch_items are really needed for the patch.
1261cdf0e10cSrcweir# If not, they are removed now.
1262cdf0e10cSrcweir###########################################################
1263cdf0e10cSrcweir
1264cdf0e10cSrcweirsub analyze_patch_files
1265cdf0e10cSrcweir{
1266cdf0e10cSrcweir	my ( $filesref ) = @_;
1267cdf0e10cSrcweir
1268cdf0e10cSrcweir	installer::logger::include_header_into_logfile("Analyzing patch files");
1269cdf0e10cSrcweir
1270cdf0e10cSrcweir	my @filesarray = ();
1271cdf0e10cSrcweir
1272cdf0e10cSrcweir	for ( my $i = 0; $i <= $#{$filesref}; $i++ )
1273cdf0e10cSrcweir	{
1274cdf0e10cSrcweir		my $onefile = ${$filesref}[$i];
1275cdf0e10cSrcweir		my $styles = "";
1276cdf0e10cSrcweir		if ( $onefile->{'Styles'} ) { $styles = $onefile->{'Styles'}; }
1277cdf0e10cSrcweir		if ( !( $styles =~ /\bPATCH\b/) ) { next; }	# removing all files without flag PATCH (LICENSE, README, ...)
1278cdf0e10cSrcweir
1279cdf0e10cSrcweir		if ( $installer::globals::iswindowsbuild )
1280cdf0e10cSrcweir		{
1281cdf0e10cSrcweir			# all files of the Windows patch belong to the root module
1282cdf0e10cSrcweir			$onefile->{'modules'} = $installer::globals::rootmodulegid;
1283cdf0e10cSrcweir		}
1284cdf0e10cSrcweir
1285cdf0e10cSrcweir		push(@filesarray, $onefile);
1286cdf0e10cSrcweir	}
1287cdf0e10cSrcweir
1288cdf0e10cSrcweir	return \@filesarray;
1289cdf0e10cSrcweir}
1290cdf0e10cSrcweir
1291cdf0e10cSrcweir###########################################################
1292cdf0e10cSrcweir# Sorting an array
1293cdf0e10cSrcweir###########################################################
1294cdf0e10cSrcweir
1295cdf0e10cSrcweirsub sort_array
1296cdf0e10cSrcweir{
1297cdf0e10cSrcweir	my ( $arrayref ) = @_;
1298cdf0e10cSrcweir
1299cdf0e10cSrcweir	for ( my $i = 0; $i <= $#{$arrayref}; $i++ )
1300cdf0e10cSrcweir	{
1301cdf0e10cSrcweir		my $under = ${$arrayref}[$i];
1302cdf0e10cSrcweir
1303cdf0e10cSrcweir		for ( my $j = $i + 1; $j <= $#{$arrayref}; $j++ )
1304cdf0e10cSrcweir		{
1305cdf0e10cSrcweir			my $over = ${$arrayref}[$j];
1306cdf0e10cSrcweir
1307cdf0e10cSrcweir			if ( $under gt $over)
1308cdf0e10cSrcweir			{
1309cdf0e10cSrcweir				${$arrayref}[$i] = $over;
1310cdf0e10cSrcweir				${$arrayref}[$j] = $under;
1311cdf0e10cSrcweir				$under = $over;
1312cdf0e10cSrcweir			}
1313cdf0e10cSrcweir		}
1314cdf0e10cSrcweir	}
1315cdf0e10cSrcweir}
1316cdf0e10cSrcweir
1317cdf0e10cSrcweir###########################################################
1318cdf0e10cSrcweir# Renaming linux files with flag LINUXLINK
1319cdf0e10cSrcweir###########################################################
1320cdf0e10cSrcweir
1321cdf0e10cSrcweirsub prepare_linuxlinkfiles
1322cdf0e10cSrcweir{
1323cdf0e10cSrcweir	my ( $filesref ) = @_;
1324cdf0e10cSrcweir
1325cdf0e10cSrcweir	@installer::globals::linuxlinks = (); # empty this array, because it could be already used
1326cdf0e10cSrcweir	@installer::globals::linuxpatchfiles = (); # empty this array, because it could be already used
1327cdf0e10cSrcweir	@installer::globals::allfilessav = (); # empty this array, because it could be already used. Required for forced links
1328cdf0e10cSrcweir
1329cdf0e10cSrcweir	my @filesarray = ();
1330cdf0e10cSrcweir
1331cdf0e10cSrcweir	for ( my $i = 0; $i <= $#{$filesref}; $i++ )
1332cdf0e10cSrcweir	{
1333cdf0e10cSrcweir		my $onefile = ${$filesref}[$i];
1334cdf0e10cSrcweir		my %linkfilehash = ();
1335cdf0e10cSrcweir		my $linkfile = \%linkfilehash;
1336cdf0e10cSrcweir		installer::converter::copy_item_object($onefile, $linkfile);
1337cdf0e10cSrcweir
1338cdf0e10cSrcweir		my $ispatchfile = 0;
1339cdf0e10cSrcweir		my $styles = "";
1340cdf0e10cSrcweir		if ( $onefile->{'Styles'} ) { $styles = $onefile->{'Styles'}; }
1341cdf0e10cSrcweir		if ( $styles =~ /\bPATCH\b/ ) { $ispatchfile = 1; }
1342cdf0e10cSrcweir
1343cdf0e10cSrcweir		# Collecting all files for the mechanism with forced links
1344cdf0e10cSrcweir		# Saving a copy
1345cdf0e10cSrcweir		my %copyfilehash = ();
1346cdf0e10cSrcweir		my $copyfile = \%copyfilehash;
1347cdf0e10cSrcweir		installer::converter::copy_item_object($onefile, $copyfile);
1348cdf0e10cSrcweir		push( @installer::globals::allfilessav, $copyfile);
1349cdf0e10cSrcweir
1350cdf0e10cSrcweir		my $original_destination = $onefile->{'destination'};
1351cdf0e10cSrcweir		# $onefile->{'destination'} is used in the epm list file. This value can be changed now!
1352cdf0e10cSrcweir
1353cdf0e10cSrcweir		if ( $ispatchfile ) { $onefile->{'destination'} = $onefile->{'destination'} . "\.$installer::globals::linuxlibrarypatchlevel"; }
1354cdf0e10cSrcweir		else { $onefile->{'destination'} = $onefile->{'destination'} . "\.$installer::globals::linuxlibrarybaselevel"; }
1355cdf0e10cSrcweir
1356cdf0e10cSrcweir		my $infoline = "LINUXLINK: Changing file destination from $original_destination to $onefile->{'destination'} !\n";
1357b274bc22SAndre Fischer		$installer::logger::Lang->print($infoline);
1358cdf0e10cSrcweir
1359cdf0e10cSrcweir		# all files without PATCH flag are included into the RPM
1360cdf0e10cSrcweir		if ( ! $ispatchfile ) { push( @filesarray, $onefile); }
1361cdf0e10cSrcweir		else { push( @installer::globals::linuxpatchfiles, $onefile); }
1362cdf0e10cSrcweir
1363cdf0e10cSrcweir		# Preparing the collector for the links
1364cdf0e10cSrcweir		# Setting the new file name as destination of the link
1365cdf0e10cSrcweir		my $linkdestination = $linkfile->{'Name'};
1366cdf0e10cSrcweir		installer::pathanalyzer::make_absolute_filename_to_relative_filename(\$linkdestination);
1367cdf0e10cSrcweir		if ( $ispatchfile ) { $linkfile->{'destinationfile'} = $linkdestination . "\.$installer::globals::linuxlibrarypatchlevel"; }
1368cdf0e10cSrcweir		else { $linkfile->{'destinationfile'} = $linkdestination . "\.$installer::globals::linuxlibrarybaselevel"; }
1369cdf0e10cSrcweir		push( @installer::globals::linuxlinks, $linkfile );
1370cdf0e10cSrcweir
1371cdf0e10cSrcweir		$infoline = "LINUXLINK: Created link: $linkfile->{'destination'} pointing to $linkfile->{'destinationfile'} !\n";
1372b274bc22SAndre Fischer		$installer::logger::Lang->print($infoline);
1373cdf0e10cSrcweir	}
1374cdf0e10cSrcweir
1375cdf0e10cSrcweir	return \@filesarray;
1376cdf0e10cSrcweir}
1377cdf0e10cSrcweir
1378cdf0e10cSrcweir###########################################################
1379cdf0e10cSrcweir# Adding links into "u-RPMs", that have the flag
1380cdf0e10cSrcweir# FORCE_INTO_UPDATE_PACKAGE
1381cdf0e10cSrcweir# This is only relevant for Linux
1382cdf0e10cSrcweir###########################################################
1383cdf0e10cSrcweir
1384cdf0e10cSrcweirsub prepare_forced_linuxlinkfiles
1385cdf0e10cSrcweir{
1386cdf0e10cSrcweir	my ( $linksref ) = @_;
1387cdf0e10cSrcweir
1388cdf0e10cSrcweir	my @linksarray = ();
1389cdf0e10cSrcweir
1390cdf0e10cSrcweir	for ( my $i = 0; $i <= $#{$linksref}; $i++ )
1391cdf0e10cSrcweir	{
1392cdf0e10cSrcweir		my $onelink = ${$linksref}[$i];
1393cdf0e10cSrcweir
1394cdf0e10cSrcweir		my $isforcedlink = 0;
1395cdf0e10cSrcweir		my $styles = "";
1396cdf0e10cSrcweir		if ( $onelink->{'Styles'} ) { $styles = $onelink->{'Styles'}; }
1397cdf0e10cSrcweir		if ( $styles =~ /\bFORCE_INTO_UPDATE_PACKAGE\b/ ) { $isforcedlink = 1; }
1398cdf0e10cSrcweir
1399cdf0e10cSrcweir		if ( $isforcedlink )
1400cdf0e10cSrcweir		{
1401cdf0e10cSrcweir			my $fileid = "";
1402cdf0e10cSrcweir
1403cdf0e10cSrcweir			if ( $onelink->{'ShortcutID'} )
1404cdf0e10cSrcweir			{
1405cdf0e10cSrcweir				$fileid = $onelink->{'ShortcutID'};
1406cdf0e10cSrcweir
1407cdf0e10cSrcweir				my $searchedlinkfile = find_file_by_id($linksref, $fileid);
1408cdf0e10cSrcweir
1409cdf0e10cSrcweir				# making a copy!
1410cdf0e10cSrcweir				my %linkfilehash = ();
1411cdf0e10cSrcweir				my $linkfile = \%linkfilehash;
1412cdf0e10cSrcweir				installer::converter::copy_item_object($searchedlinkfile, $linkfile);
1413cdf0e10cSrcweir
1414cdf0e10cSrcweir				$linkfile->{'Name'} = $onelink->{'Name'};
1415cdf0e10cSrcweir				$linkfile->{'destinationfile'} = $linkfile->{'destination'};
1416cdf0e10cSrcweir				my $linkdestination = $linkfile->{'destinationfile'};
1417cdf0e10cSrcweir				installer::pathanalyzer::make_absolute_filename_to_relative_filename(\$linkdestination);
1418cdf0e10cSrcweir				$linkfile->{'destinationfile'} = $linkdestination;
1419cdf0e10cSrcweir
1420cdf0e10cSrcweir				my $localdestination = $linkfile->{'destination'};
1421cdf0e10cSrcweir				# Getting the path
1422cdf0e10cSrcweir				installer::pathanalyzer::get_path_from_fullqualifiedname(\$localdestination);
1423cdf0e10cSrcweir				$localdestination =~ s/\Q$installer::globals::separator\E\s*$//;
1424cdf0e10cSrcweir				$linkfile->{'destination'} = $localdestination . $installer::globals::separator . $onelink->{'Name'};
1425cdf0e10cSrcweir
1426cdf0e10cSrcweir				$infoline = "Forced link into update file: $linkfile->{'destination'} pointing to $linkfile->{'destinationfile'} !\n";
1427b274bc22SAndre Fischer				$installer::logger::Lang->print($infoline);
1428cdf0e10cSrcweir
1429cdf0e10cSrcweir				# The file, defined by the link, has to be included into the
1430cdf0e10cSrcweir				# link array @installer::globals::linuxlinks
1431cdf0e10cSrcweir				push( @installer::globals::linuxlinks, $linkfile );
1432cdf0e10cSrcweir			}
1433cdf0e10cSrcweir
1434cdf0e10cSrcweir			if ( $onelink->{'FileID'} )
1435cdf0e10cSrcweir			{
1436cdf0e10cSrcweir				$fileid = $onelink->{'FileID'};
1437cdf0e10cSrcweir
1438cdf0e10cSrcweir				my $searchedlinkfile = find_file_by_id(\@installer::globals::allfilessav, $fileid);
1439cdf0e10cSrcweir
1440cdf0e10cSrcweir				# making a copy!
1441cdf0e10cSrcweir				my %linkfilehash = ();
1442cdf0e10cSrcweir				my $linkfile = \%linkfilehash;
1443cdf0e10cSrcweir				installer::converter::copy_item_object($searchedlinkfile, $linkfile);
1444cdf0e10cSrcweir
1445cdf0e10cSrcweir				$linkfile->{'Name'} = $onelink->{'Name'};
1446cdf0e10cSrcweir				$linkfile->{'destinationfile'} = $linkfile->{'destination'};
1447cdf0e10cSrcweir				my $linkdestination = $linkfile->{'destinationfile'};
1448cdf0e10cSrcweir				installer::pathanalyzer::make_absolute_filename_to_relative_filename(\$linkdestination);
1449cdf0e10cSrcweir				$linkfile->{'destinationfile'} = $linkdestination;
1450cdf0e10cSrcweir
1451cdf0e10cSrcweir				my $localdestination = $linkfile->{'destination'};
1452cdf0e10cSrcweir				# Getting the path
1453cdf0e10cSrcweir				installer::pathanalyzer::get_path_from_fullqualifiedname(\$localdestination);
1454cdf0e10cSrcweir				$localdestination =~ s/\Q$installer::globals::separator\E\s*$//;
1455cdf0e10cSrcweir				$linkfile->{'destination'} = $localdestination . $installer::globals::separator . $onelink->{'Name'};
1456cdf0e10cSrcweir
1457cdf0e10cSrcweir				$infoline = "Forced link into update file: $linkfile->{'destination'} pointing to $linkfile->{'destinationfile'} !\n";
1458b274bc22SAndre Fischer				$installer::logger::Lang->print($infoline);
1459cdf0e10cSrcweir
1460cdf0e10cSrcweir				# The file, defined by the link, has to be included into the
1461cdf0e10cSrcweir				# link array @installer::globals::linuxlinks
1462cdf0e10cSrcweir				push( @installer::globals::linuxlinks, $linkfile );
1463cdf0e10cSrcweir			 }
1464cdf0e10cSrcweir
1465cdf0e10cSrcweir			if ( $fileid eq "" ) { installer::exiter::exit_program("ERROR: No FileID assigned to forced link $onelink->{'gid'} !", "prepare_forced_linuxlinkfiles"); }
1466cdf0e10cSrcweir
1467cdf0e10cSrcweir		}
1468cdf0e10cSrcweir		else
1469cdf0e10cSrcweir		{
1470cdf0e10cSrcweir			# Links with flag FORCE_INTO_UPDATE_PACKAGE are forced into "u"-RPM. All other
1471cdf0e10cSrcweir			# links are included into the non-"u"-package.
1472cdf0e10cSrcweir			push( @linksarray, $onelink );
1473cdf0e10cSrcweir		}
1474cdf0e10cSrcweir	}
1475cdf0e10cSrcweir
1476cdf0e10cSrcweir	return \@linksarray;
1477cdf0e10cSrcweir}
1478cdf0e10cSrcweir
1479cdf0e10cSrcweir###########################################################
1480cdf0e10cSrcweir# reorganizing the patchfile content,
1481cdf0e10cSrcweir# sorting for directory to decrease the file size
1482cdf0e10cSrcweir###########################################################
1483cdf0e10cSrcweir
1484cdf0e10cSrcweirsub reorg_patchfile
1485cdf0e10cSrcweir{
1486cdf0e10cSrcweir	my ($patchfiles, $patchfiledirectories) = @_;
1487cdf0e10cSrcweir
1488cdf0e10cSrcweir	my @patchfilesarray = ();
1489cdf0e10cSrcweir	my $line = "";
1490cdf0e10cSrcweir	my $directory = "";
1491cdf0e10cSrcweir
1492cdf0e10cSrcweir	# iterating over all directories, writing content into new patchfiles list
1493cdf0e10cSrcweir
1494cdf0e10cSrcweir	for ( my $i = 0; $i <= $#{$patchfiledirectories}; $i++ )
1495cdf0e10cSrcweir	{
1496cdf0e10cSrcweir		$directory = ${$patchfiledirectories}[$i];
1497cdf0e10cSrcweir		$line = "[" . $directory . "]" . "\n";
1498cdf0e10cSrcweir		push(@patchfilesarray, $line);
1499cdf0e10cSrcweir
1500cdf0e10cSrcweir		for ( my $j = 0; $j <= $#{$patchfiles}; $j++ )
1501cdf0e10cSrcweir		{
1502cdf0e10cSrcweir			# "\tXXXXX\t" . $olddestination . "\n";
1503cdf0e10cSrcweir			if ( ${$patchfiles}[$j] =~ /^\s*(.*?)\s*\tXXXXX\t\Q$directory\E\s*$/ )
1504cdf0e10cSrcweir			{
1505cdf0e10cSrcweir				$line = $1 . "\n";
1506cdf0e10cSrcweir				push(@patchfilesarray, $line);
1507cdf0e10cSrcweir			}
1508cdf0e10cSrcweir		}
1509cdf0e10cSrcweir	}
1510cdf0e10cSrcweir
1511cdf0e10cSrcweir	return \@patchfilesarray;
1512cdf0e10cSrcweir}
1513cdf0e10cSrcweir
1514cdf0e10cSrcweir###########################################################
1515cdf0e10cSrcweir# One special file has to be the last in patchfile.txt.
1516cdf0e10cSrcweir# Controlling this file, guarantees, that all files were
1517cdf0e10cSrcweir# patch correctly. Using version.ini makes it easy to
1518cdf0e10cSrcweir# control this by looking into the about box
1519cdf0e10cSrcweir# -> shifting one section to the end
1520cdf0e10cSrcweir###########################################################
1521cdf0e10cSrcweir
1522cdf0e10cSrcweirsub shift_section_to_end
1523cdf0e10cSrcweir{
1524cdf0e10cSrcweir	my ($patchfilelist) = @_;
1525cdf0e10cSrcweir
1526cdf0e10cSrcweir	my @patchfile = ();
1527cdf0e10cSrcweir	my @lastsection = ();
1528cdf0e10cSrcweir	my $lastsection = "program";
1529cdf0e10cSrcweir	my $notlastsection = "Basis\\program";
1530cdf0e10cSrcweir	my $record = 0;
1531cdf0e10cSrcweir
1532cdf0e10cSrcweir	for ( my $i = 0; $i <= $#{$patchfilelist}; $i++ )
1533cdf0e10cSrcweir	{
1534cdf0e10cSrcweir		my $line = ${$patchfilelist}[$i];
1535cdf0e10cSrcweir
1536cdf0e10cSrcweir		if (( $record ) && ( $line =~ /^\s*\[/ )) { $record = 0; }
1537cdf0e10cSrcweir
1538cdf0e10cSrcweir		if (( $line =~ /^\s*\[\Q$lastsection\E\\\]\s*$/ ) && ( ! ( $line =~ /\Q$notlastsection\E\\\]\s*$/ ))) { $record = 1; }
1539cdf0e10cSrcweir
1540cdf0e10cSrcweir		if ( $record ) { push(@lastsection, $line); }
1541cdf0e10cSrcweir		else { push(@patchfile, $line); }
1542cdf0e10cSrcweir	}
1543cdf0e10cSrcweir
1544cdf0e10cSrcweir	if ( $#lastsection > -1 )
1545cdf0e10cSrcweir	{
1546cdf0e10cSrcweir		for ( my $i = 0; $i <= $#lastsection; $i++ )
1547cdf0e10cSrcweir		{
1548cdf0e10cSrcweir			push(@patchfile, $lastsection[$i]);
1549cdf0e10cSrcweir		}
1550cdf0e10cSrcweir	}
1551cdf0e10cSrcweir
1552cdf0e10cSrcweir	return \@patchfile;
1553cdf0e10cSrcweir}
1554cdf0e10cSrcweir
1555cdf0e10cSrcweir###########################################################
1556cdf0e10cSrcweir# One special file has to be the last in patchfile.txt.
1557cdf0e10cSrcweir# Controlling this file, guarantees, that all files were
1558cdf0e10cSrcweir# patch correctly. Using version.ini makes it easy to
1559cdf0e10cSrcweir# control this by looking into the about box
1560cdf0e10cSrcweir# -> shifting one file of the last section to the end
1561cdf0e10cSrcweir###########################################################
1562cdf0e10cSrcweir
1563cdf0e10cSrcweirsub shift_file_to_end
1564cdf0e10cSrcweir{
1565cdf0e10cSrcweir	my ($patchfilelist) = @_;
1566cdf0e10cSrcweir
1567cdf0e10cSrcweir	my @patchfile = ();
1568cdf0e10cSrcweir	my $lastfilename = "version.ini";
1569cdf0e10cSrcweir	my $lastfileline = "";
1570cdf0e10cSrcweir	my $foundfile = 0;
1571cdf0e10cSrcweir
1572cdf0e10cSrcweir	# Only searching this file in the last section
1573cdf0e10cSrcweir	my $lastsectionname = "";
1574cdf0e10cSrcweir
1575cdf0e10cSrcweir	for ( my $i = 0; $i <= $#{$patchfilelist}; $i++ )
1576cdf0e10cSrcweir	{
1577cdf0e10cSrcweir		my $line = ${$patchfilelist}[$i];
1578cdf0e10cSrcweir		if ( $line =~ /^\s*\[(.*?)\]\s*$/ ) { $lastsectionname = $1; }
1579cdf0e10cSrcweir	}
1580cdf0e10cSrcweir
1581cdf0e10cSrcweir	my $record = 0;
1582cdf0e10cSrcweir	for ( my $i = 0; $i <= $#{$patchfilelist}; $i++ )
1583cdf0e10cSrcweir	{
1584cdf0e10cSrcweir		my $line = ${$patchfilelist}[$i];
1585cdf0e10cSrcweir
1586cdf0e10cSrcweir		if ( $line =~ /^\s*\[\Q$lastsectionname\E\]\s*$/ ) { $record = 1; }
1587cdf0e10cSrcweir
1588cdf0e10cSrcweir		if (( $line =~ /^\s*\"\Q$lastfilename\E\"\=/ ) && ( $record ))
1589cdf0e10cSrcweir		{
1590cdf0e10cSrcweir			$lastfileline = $line;
1591cdf0e10cSrcweir			$foundfile = 1;
1592cdf0e10cSrcweir			$record = 0;
1593cdf0e10cSrcweir			next;
1594cdf0e10cSrcweir		}
1595cdf0e10cSrcweir
1596cdf0e10cSrcweir		push(@patchfile, $line);
1597cdf0e10cSrcweir	}
1598cdf0e10cSrcweir
1599cdf0e10cSrcweir	if ( $foundfile ) { push(@patchfile, $lastfileline); }
1600cdf0e10cSrcweir
1601cdf0e10cSrcweir	return 	\@patchfile;
1602cdf0e10cSrcweir}
1603cdf0e10cSrcweir
1604cdf0e10cSrcweir###########################################################
1605cdf0e10cSrcweir# Putting hash content into array and sorting it
1606cdf0e10cSrcweir###########################################################
1607cdf0e10cSrcweir
1608cdf0e10cSrcweirsub sort_hash
1609cdf0e10cSrcweir{
1610cdf0e10cSrcweir	my ( $hashref ) =  @_;
1611cdf0e10cSrcweir
1612cdf0e10cSrcweir	my $item = "";
1613cdf0e10cSrcweir	my @sortedarray = ();
1614cdf0e10cSrcweir
1615cdf0e10cSrcweir	foreach $item (keys %{$hashref}) { push(@sortedarray, $item); }
1616cdf0e10cSrcweir	installer::sorter::sorting_array_of_strings(\@sortedarray);
1617cdf0e10cSrcweir
1618cdf0e10cSrcweir	return \@sortedarray;
1619cdf0e10cSrcweir}
1620cdf0e10cSrcweir
1621cdf0e10cSrcweir###########################################################
1622cdf0e10cSrcweir# Renaming Windows files in Patch and creating file
1623cdf0e10cSrcweir# patchfiles.txt
1624cdf0e10cSrcweir###########################################################
1625cdf0e10cSrcweir
1626cdf0e10cSrcweirsub prepare_windows_patchfiles
1627cdf0e10cSrcweir{
1628cdf0e10cSrcweir	my ( $filesref, $languagestringref, $allvariableshashref ) = @_;
1629cdf0e10cSrcweir
1630cdf0e10cSrcweir	my @patchfiles = ();
1631cdf0e10cSrcweir	my %patchfiledirectories = ();
1632cdf0e10cSrcweir	my $patchfilename = "patchlist.txt";
1633cdf0e10cSrcweir	my $patchfilename2 = "patchmsi.dll";
1634cdf0e10cSrcweir
1635cdf0e10cSrcweir	if ( ! $allvariableshashref->{'WINDOWSPATCHLEVEL'} ) { installer::exiter::exit_program("ERROR: No Windows patch level defined in list file (WINDOWSPATCHLEVEL) !", "prepare_windows_patchfiles"); }
1636cdf0e10cSrcweir	# my $windowspatchlevel = $allvariableshashref->{'WINDOWSPATCHLEVEL'};
1637cdf0e10cSrcweir	my $windowspatchlevel = $installer::globals::buildid;
1638cdf0e10cSrcweir
1639cdf0e10cSrcweir	# the environment variable CWS_WORK_STAMP is set only in CWS
1640cdf0e10cSrcweir	if ( $ENV{'CWS_WORK_STAMP'} ) { $windowspatchlevel = $ENV{'CWS_WORK_STAMP'} . $windowspatchlevel; }
1641cdf0e10cSrcweir
1642cdf0e10cSrcweir	for ( my $i = 0; $i <= $#{$filesref}; $i++ )
1643cdf0e10cSrcweir	{
1644cdf0e10cSrcweir		my $onefile = ${$filesref}[$i];
1645cdf0e10cSrcweir
1646cdf0e10cSrcweir		my $filename = $onefile->{'Name'};
1647cdf0e10cSrcweir		if (( $filename eq $patchfilename ) || ( $filename eq $patchfilename2 )) { next; }
1648cdf0e10cSrcweir
1649cdf0e10cSrcweir		my $styles = "";
1650cdf0e10cSrcweir		if ( $onefile->{'Styles'} ) { $styles = $onefile->{'Styles'}; }
1651cdf0e10cSrcweir		if ( $styles =~ /\bDONTRENAMEINPATCH\b/ ) { next; }
1652cdf0e10cSrcweir
1653cdf0e10cSrcweir		# special handling for files with flag DONTSHOW. This files get the extension ".dontshow" to be filtered by dialogs.
1654cdf0e10cSrcweir		my $localwindowspatchlevel = $windowspatchlevel;
1655cdf0e10cSrcweir		if ( $styles =~ /\bDONTSHOW\b/ ) { $localwindowspatchlevel = $localwindowspatchlevel . "\.dontshow"; }
1656cdf0e10cSrcweir
1657cdf0e10cSrcweir		my $olddestination = $onefile->{'destination'};
1658cdf0e10cSrcweir		my $newdestination = $olddestination . "." . $localwindowspatchlevel;
1659cdf0e10cSrcweir		my $localfilename = $olddestination;
1660cdf0e10cSrcweir		installer::pathanalyzer::make_absolute_filename_to_relative_filename(\$localfilename);	# file name part
1661cdf0e10cSrcweir		my $line = "\"" . $localfilename . "\"" . "=" . "\"" . "\." . $localwindowspatchlevel . "\"";
1662cdf0e10cSrcweir		$onefile->{'destination'} = $newdestination;
1663cdf0e10cSrcweir
1664cdf0e10cSrcweir		my $newfilename = $onefile->{'Name'} . "." . $localwindowspatchlevel;
1665cdf0e10cSrcweir		$onefile->{'Name'} = $newfilename;
1666cdf0e10cSrcweir
1667cdf0e10cSrcweir		# adding section information (section is the directory)
1668cdf0e10cSrcweir		my $origolddestination = $olddestination;
1669cdf0e10cSrcweir		installer::pathanalyzer::get_path_from_fullqualifiedname(\$olddestination);	# directory part
1670cdf0e10cSrcweir		if ( ! $olddestination ) { $olddestination = "_root";  }
1671cdf0e10cSrcweir		if ( ! exists($patchfiledirectories{$olddestination}) ) { $patchfiledirectories{$olddestination} = 1; }
1672cdf0e10cSrcweir		$line = $line . "\tXXXXX\t" . $olddestination . "\n";
1673cdf0e10cSrcweir
1674cdf0e10cSrcweir		push(@patchfiles, $line);
1675cdf0e10cSrcweir
1676cdf0e10cSrcweir		# also collecting all files from patch in @installer::globals::patchfilecollector
1677cdf0e10cSrcweir		my $patchfileline = $origolddestination . "\n";
1678cdf0e10cSrcweir		push(@installer::globals::patchfilecollector, $patchfileline);
1679cdf0e10cSrcweir	}
1680cdf0e10cSrcweir
1681cdf0e10cSrcweir	my $winpatchdirname = "winpatch";
1682cdf0e10cSrcweir	my $winpatchdir = installer::systemactions::create_directories($winpatchdirname, $languagestringref);
1683cdf0e10cSrcweir
1684cdf0e10cSrcweir	my $patchlistfile = installer::existence::get_specified_file_by_name($filesref, $patchfilename);
1685cdf0e10cSrcweir
1686cdf0e10cSrcweir	# reorganizing the patchfile content, sorting for directory to decrease the file size
1687cdf0e10cSrcweir	my $sorteddirectorylist = sort_hash(\%patchfiledirectories);
1688cdf0e10cSrcweir	my $patchfilelist = reorg_patchfile(\@patchfiles, $sorteddirectorylist);
1689cdf0e10cSrcweir
1690cdf0e10cSrcweir	# shifting version.ini to the end of the list, to guarantee, that all files are patched
1691cdf0e10cSrcweir	# if the correct version is shown in the about box
1692cdf0e10cSrcweir	$patchfilelist = shift_section_to_end($patchfilelist);
1693cdf0e10cSrcweir	$patchfilelist = shift_file_to_end($patchfilelist);
1694cdf0e10cSrcweir
1695cdf0e10cSrcweir	# saving the file
1696cdf0e10cSrcweir	$patchfilename = $winpatchdir . $installer::globals::separator . $patchfilename;
1697cdf0e10cSrcweir	installer::files::save_file($patchfilename, $patchfilelist);
1698cdf0e10cSrcweir
1699b274bc22SAndre Fischer	$installer::logger::Lang->print("\n");
1700b274bc22SAndre Fischer	$installer::logger::Lang->printf("Created list of patch files: %s\n", $patchfilename);
1701cdf0e10cSrcweir
1702cdf0e10cSrcweir	# and assigning the new source
1703cdf0e10cSrcweir	$patchlistfile->{'sourcepath'} = $patchfilename;
1704cdf0e10cSrcweir
1705cdf0e10cSrcweir	# and finally checking the file size
1706cdf0e10cSrcweir	if ( -f $patchfilename )	# test of existence
1707cdf0e10cSrcweir	{
1708cdf0e10cSrcweir		my $filesize = ( -s $patchfilename );
1709cdf0e10cSrcweir		$infoline = "Size of patch file list: $filesize\n\n";
1710b274bc22SAndre Fischer		$installer::logger::Lang->print($infoline);
1711b274bc22SAndre Fischer		$installer::logger::Info->print( "... size of patch list file: $filesize Byte ... \n" );
1712cdf0e10cSrcweir
1713cdf0e10cSrcweir		# Win 98: Maximum size of ini file is 65 kB
1714cdf0e10cSrcweir		# if ( $filesize > 64000 ) { installer::exiter::exit_program("ERROR: Maximum size of patch file list is 65 kB (Win98), now reached: $filesize Byte !", "prepare_windows_patchfiles"); }
1715cdf0e10cSrcweir	}
1716cdf0e10cSrcweir
1717cdf0e10cSrcweir}
1718cdf0e10cSrcweir
1719cdf0e10cSrcweir###########################################################
1720cdf0e10cSrcweir# Replacing %-variables with the content
1721cdf0e10cSrcweir# of $allvariableshashref
1722cdf0e10cSrcweir###########################################################
1723cdf0e10cSrcweir
1724cdf0e10cSrcweirsub replace_variables_in_string
1725cdf0e10cSrcweir{
1726cdf0e10cSrcweir	my ( $string, $variableshashref ) = @_;
1727cdf0e10cSrcweir
1728cdf0e10cSrcweir	if ( $string =~ /^.*\%\w+.*$/ )
1729cdf0e10cSrcweir	{
1730cdf0e10cSrcweir		my $key;
1731cdf0e10cSrcweir
1732cdf0e10cSrcweir		foreach $key (keys %{$variableshashref})
1733cdf0e10cSrcweir		{
1734cdf0e10cSrcweir			my $value = $variableshashref->{$key};
1735cdf0e10cSrcweir			$key = "\%" . $key;
1736cdf0e10cSrcweir			$string =~ s/\Q$key\E/$value/g;
1737cdf0e10cSrcweir		}
1738cdf0e10cSrcweir	}
1739cdf0e10cSrcweir
1740cdf0e10cSrcweir	return $string;
1741cdf0e10cSrcweir}
1742cdf0e10cSrcweir
1743cdf0e10cSrcweir###########################################################
1744cdf0e10cSrcweir# Replacing %-variables with the content
1745cdf0e10cSrcweir# of $allvariableshashref
1746cdf0e10cSrcweir###########################################################
1747cdf0e10cSrcweir
1748cdf0e10cSrcweirsub replace_dollar_variables_in_string
1749cdf0e10cSrcweir{
1750cdf0e10cSrcweir	my ( $string, $variableshashref ) = @_;
1751cdf0e10cSrcweir
1752cdf0e10cSrcweir	if ( $string =~ /^.*\$\{\w+\}.*$/ )
1753cdf0e10cSrcweir	{
1754cdf0e10cSrcweir		my $key;
1755cdf0e10cSrcweir
1756cdf0e10cSrcweir		foreach $key (keys %{$variableshashref})
1757cdf0e10cSrcweir		{
1758cdf0e10cSrcweir			my $value = $variableshashref->{$key};
1759cdf0e10cSrcweir			$key = "\$\{" . $key . "\}";
1760cdf0e10cSrcweir			$string =~ s/\Q$key\E/$value/g;
1761cdf0e10cSrcweir		}
1762cdf0e10cSrcweir	}
1763cdf0e10cSrcweir
1764cdf0e10cSrcweir	return $string;
1765cdf0e10cSrcweir}
1766cdf0e10cSrcweir
1767cdf0e10cSrcweir###########################################################
1768cdf0e10cSrcweir# The list file contains the list of packages/RPMs that
1769cdf0e10cSrcweir# have to be copied.
1770cdf0e10cSrcweir###########################################################
1771cdf0e10cSrcweir
1772cdf0e10cSrcweirsub get_all_files_from_filelist
1773cdf0e10cSrcweir{
1774cdf0e10cSrcweir	my ( $listfile, $section ) = @_;
1775cdf0e10cSrcweir
1776cdf0e10cSrcweir	my @allpackages = ();
1777cdf0e10cSrcweir
1778cdf0e10cSrcweir	for ( my $i = 0; $i <= $#{$listfile}; $i++ )
1779cdf0e10cSrcweir	{
1780cdf0e10cSrcweir		my $line = ${$listfile}[$i];
1781cdf0e10cSrcweir		if ( $line =~ /^\s*\#/ ) { next; } # this is a comment line
1782cdf0e10cSrcweir		if ( $line =~ /^\s*$/ ) { next; } # empty line
1783cdf0e10cSrcweir		$line =~ s/^\s*//;
1784cdf0e10cSrcweir		$line =~ s/\s*$//;
1785cdf0e10cSrcweir		push(@allpackages, $line);
1786cdf0e10cSrcweir	}
1787cdf0e10cSrcweir
1788cdf0e10cSrcweir	return \@allpackages;
1789cdf0e10cSrcweir}
1790cdf0e10cSrcweir
1791cdf0e10cSrcweir###########################################################
1792cdf0e10cSrcweir# Getting one section from a file. Section begins with
1793cdf0e10cSrcweir# [xyz] and ends with file end or next [abc].
1794cdf0e10cSrcweir###########################################################
1795cdf0e10cSrcweir
1796cdf0e10cSrcweirsub get_section_from_file
1797cdf0e10cSrcweir{
1798cdf0e10cSrcweir	my ($file, $sectionname) = @_;
1799cdf0e10cSrcweir
1800cdf0e10cSrcweir	my @section = ();
1801cdf0e10cSrcweir	my $record = 0;
1802cdf0e10cSrcweir
1803cdf0e10cSrcweir	for ( my $i = 0; $i <= $#{$file}; $i++ )
1804cdf0e10cSrcweir	{
1805cdf0e10cSrcweir		my $line = ${$file}[$i];
1806cdf0e10cSrcweir
1807cdf0e10cSrcweir		if (( $record ) && ( $line =~ /^\s*\[/ ))
1808cdf0e10cSrcweir		{
1809cdf0e10cSrcweir			$record = 0;
1810cdf0e10cSrcweir			last;
1811cdf0e10cSrcweir		}
1812cdf0e10cSrcweir
1813cdf0e10cSrcweir		if ( $line =~ /^\s*\[\Q$sectionname\E\]\s*$/ ) { $record = 1; }
1814cdf0e10cSrcweir
1815cdf0e10cSrcweir		if ( $line =~ /^\s*\[/ ) { next; } # this is a section line
1816cdf0e10cSrcweir		if ( $line =~ /^\s*\#/ ) { next; } # this is a comment line
1817cdf0e10cSrcweir		if ( $line =~ /^\s*$/ ) { next; }  # empty line
1818cdf0e10cSrcweir		$line =~ s/^\s*//;
1819cdf0e10cSrcweir		$line =~ s/\s*$//;
1820cdf0e10cSrcweir		if ( $record ) { push(@section, $line); }
1821cdf0e10cSrcweir	}
1822cdf0e10cSrcweir
1823cdf0e10cSrcweir	return \@section;
1824cdf0e10cSrcweir
1825cdf0e10cSrcweir}
1826cdf0e10cSrcweir
1827cdf0e10cSrcweir#######################################################
1828cdf0e10cSrcweir# Substituting one variable in the xml file
1829cdf0e10cSrcweir#######################################################
1830cdf0e10cSrcweir
1831cdf0e10cSrcweirsub replace_one_dollar_variable
1832cdf0e10cSrcweir{
1833cdf0e10cSrcweir	my ($file, $variable, $searchstring) = @_;
1834cdf0e10cSrcweir
1835cdf0e10cSrcweir	for ( my $i = 0; $i <= $#{$file}; $i++ )
1836cdf0e10cSrcweir	{
1837cdf0e10cSrcweir		${$file}[$i] =~ s/\$\{$searchstring\}/$variable/g;
1838cdf0e10cSrcweir	}
1839cdf0e10cSrcweir}
1840cdf0e10cSrcweir
1841cdf0e10cSrcweir#######################################################
1842cdf0e10cSrcweir# Substituting the variables in the xml file
1843cdf0e10cSrcweir#######################################################
1844cdf0e10cSrcweir
1845cdf0e10cSrcweirsub substitute_dollar_variables
1846cdf0e10cSrcweir{
1847cdf0e10cSrcweir	my ($file, $variableshashref) = @_;
1848cdf0e10cSrcweir
1849cdf0e10cSrcweir	my $key;
1850cdf0e10cSrcweir
1851cdf0e10cSrcweir	foreach $key (keys %{$variableshashref})
1852cdf0e10cSrcweir	{
1853cdf0e10cSrcweir		my $value = $variableshashref->{$key};
1854cdf0e10cSrcweir		replace_one_dollar_variable($file, $value, $key);
1855cdf0e10cSrcweir	}
1856cdf0e10cSrcweir}
1857cdf0e10cSrcweir
1858cdf0e10cSrcweir#############################################################################
1859cdf0e10cSrcweir# Collecting all packages or rpms located in the installation directory
1860cdf0e10cSrcweir#############################################################################
1861cdf0e10cSrcweir
1862cdf0e10cSrcweirsub get_all_packages_in_installdir
1863cdf0e10cSrcweir{
1864cdf0e10cSrcweir	my ($directory) = @_;
1865cdf0e10cSrcweir
1866cdf0e10cSrcweir	my $infoline = "";
1867cdf0e10cSrcweir
1868cdf0e10cSrcweir	my @allpackages = ();
1869cdf0e10cSrcweir	my $allpackages = \@allpackages;
1870cdf0e10cSrcweir
1871cdf0e10cSrcweir	if ( $installer::globals::islinuxrpmbuild )
1872cdf0e10cSrcweir	{
1873cdf0e10cSrcweir		$allpackages = installer::systemactions::find_file_with_file_extension("rpm", $directory);
1874cdf0e10cSrcweir	}
1875cdf0e10cSrcweir
1876cdf0e10cSrcweir	if ( $installer::globals::issolarisbuild )
1877cdf0e10cSrcweir	{
1878cdf0e10cSrcweir		$allpackages = installer::systemactions::get_all_directories($directory);
1879cdf0e10cSrcweir	}
1880cdf0e10cSrcweir
1881cdf0e10cSrcweir	return $allpackages;
1882cdf0e10cSrcweir}
1883cdf0e10cSrcweir
1884cdf0e10cSrcweir###############################################################
1885cdf0e10cSrcweir# The list of exclude packages can contain the
1886cdf0e10cSrcweir# beginning of the package name, not the complete name.
1887cdf0e10cSrcweir###############################################################
1888cdf0e10cSrcweir
1889cdf0e10cSrcweirsub is_matching
1890cdf0e10cSrcweir{
1891cdf0e10cSrcweir	my ($onepackage, $allexcludepackages ) = @_;
1892cdf0e10cSrcweir
1893cdf0e10cSrcweir	my $matches = 0;
1894cdf0e10cSrcweir
1895cdf0e10cSrcweir	for ( my $i = 0; $i <= $#{$allexcludepackages}; $i++ )
1896cdf0e10cSrcweir	{
1897cdf0e10cSrcweir		my $oneexcludepackage = ${$allexcludepackages}[$i];
1898cdf0e10cSrcweir
1899cdf0e10cSrcweir		if ( $onepackage =~ /^\s*$oneexcludepackage/ )
1900cdf0e10cSrcweir		{
1901cdf0e10cSrcweir			$matches = 1;
1902cdf0e10cSrcweir			last;
1903cdf0e10cSrcweir		}
1904cdf0e10cSrcweir	}
1905cdf0e10cSrcweir
1906cdf0e10cSrcweir	return $matches;
1907cdf0e10cSrcweir}
1908cdf0e10cSrcweir
1909cdf0e10cSrcweir###############################################################
1910cdf0e10cSrcweir# Copying all Solaris packages or RPMs from installation set
1911cdf0e10cSrcweir###############################################################
1912cdf0e10cSrcweir
1913cdf0e10cSrcweirsub copy_all_packages
1914cdf0e10cSrcweir{
1915cdf0e10cSrcweir	my ($allexcludepackages, $sourcedir, $destdir) = @_;
1916cdf0e10cSrcweir
1917cdf0e10cSrcweir	my $infoline = "";
1918cdf0e10cSrcweir
1919cdf0e10cSrcweir	$sourcedir =~ s/\/\s*$//;
1920cdf0e10cSrcweir	$destdir =~ s/\/\s*$//;
1921cdf0e10cSrcweir
1922cdf0e10cSrcweir	# $allexcludepackages is a list of RPMs and packages, that shall NOT be included into jds product
1923cdf0e10cSrcweir	my $allpackages = get_all_packages_in_installdir($sourcedir);
1924cdf0e10cSrcweir
1925cdf0e10cSrcweir	for ( my $i = 0; $i <= $#{$allpackages}; $i++ )
1926cdf0e10cSrcweir	{
1927cdf0e10cSrcweir		my $onepackage = ${$allpackages}[$i];
1928cdf0e10cSrcweir
1929cdf0e10cSrcweir		my $packagename = $onepackage;
1930cdf0e10cSrcweir
1931cdf0e10cSrcweir		if ( $installer::globals::issolarispkgbuild )	# on Solaris $onepackage contains the complete path
1932cdf0e10cSrcweir		{
1933cdf0e10cSrcweir			installer::pathanalyzer::make_absolute_filename_to_relative_filename(\$packagename);
1934cdf0e10cSrcweir		}
1935cdf0e10cSrcweir
1936cdf0e10cSrcweir		if ( ! installer::existence::exists_in_array($packagename, $allexcludepackages))
1937cdf0e10cSrcweir		{
1938cdf0e10cSrcweir			if ( ! is_matching($packagename, $allexcludepackages ) )
1939cdf0e10cSrcweir			{
1940cdf0e10cSrcweir
1941cdf0e10cSrcweir				if ( $installer::globals::islinuxrpmbuild )
1942cdf0e10cSrcweir				{
1943cdf0e10cSrcweir					my $sourcepackage = $sourcedir . $installer::globals::separator . $packagename;
1944cdf0e10cSrcweir					my $destfile = $destdir . $installer::globals::separator . $packagename;
1945cdf0e10cSrcweir					if ( ! -f $sourcepackage ) { installer::exiter::exit_program("ERROR: Could not find RPM $sourcepackage!", "copy_all_packages"); }
1946cdf0e10cSrcweir					installer::systemactions::hardlink_one_file($sourcepackage, $destfile);
1947cdf0e10cSrcweir				}
1948cdf0e10cSrcweir
1949cdf0e10cSrcweir				if ( $installer::globals::issolarispkgbuild )
1950cdf0e10cSrcweir				{
1951cdf0e10cSrcweir					my $destinationdir = $destdir . $installer::globals::separator . $packagename;
1952cdf0e10cSrcweir					if ( ! -d $onepackage ) { installer::exiter::exit_program("ERROR: Could not find Solaris package $onepackage!", "copy_all_packages"); }
1953cdf0e10cSrcweir					# installer::systemactions::hardlink_complete_directory($onepackage, $destinationdir);
1954cdf0e10cSrcweir					# installer::systemactions::copy_complete_directory($onepackage, $destinationdir);
1955cdf0e10cSrcweir
1956cdf0e10cSrcweir					my $systemcall = "cp -p -R $onepackage $destinationdir";
1957cdf0e10cSrcweir			 		make_systemcall($systemcall);
1958cdf0e10cSrcweir				}
1959cdf0e10cSrcweir			}
1960cdf0e10cSrcweir			else
1961cdf0e10cSrcweir			{
1962cdf0e10cSrcweir				$infoline = "Excluding package (matching): $onepackage\n";
1963b274bc22SAndre Fischer				$installer::logger::Lang->print($infoline);
1964cdf0e10cSrcweir			}
1965cdf0e10cSrcweir		}
1966cdf0e10cSrcweir		else
1967cdf0e10cSrcweir		{
1968cdf0e10cSrcweir			$infoline = "Excluding package (precise name): $onepackage\n";
1969b274bc22SAndre Fischer			$installer::logger::Lang->print($infoline);
1970cdf0e10cSrcweir		}
1971cdf0e10cSrcweir	}
1972cdf0e10cSrcweir}
1973cdf0e10cSrcweir
1974cdf0e10cSrcweir######################################################
1975cdf0e10cSrcweir# Making systemcall
1976cdf0e10cSrcweir######################################################
1977cdf0e10cSrcweir
1978cdf0e10cSrcweirsub make_systemcall
1979cdf0e10cSrcweir{
1980cdf0e10cSrcweir	my ($systemcall) = @_;
1981cdf0e10cSrcweir
1982cdf0e10cSrcweir	my $returnvalue = system($systemcall);
1983cdf0e10cSrcweir
1984cdf0e10cSrcweir	my $infoline = "Systemcall: $systemcall\n";
1985b274bc22SAndre Fischer	$installer::logger::Lang->print($infoline);
1986cdf0e10cSrcweir
1987cdf0e10cSrcweir	if ($returnvalue)
1988cdf0e10cSrcweir	{
1989cdf0e10cSrcweir		$infoline = "ERROR: Could not execute \"$systemcall\"!\n";
1990b274bc22SAndre Fischer		$installer::logger::Lang->print($infoline);
1991cdf0e10cSrcweir	}
1992cdf0e10cSrcweir	else
1993cdf0e10cSrcweir	{
1994cdf0e10cSrcweir		$infoline = "Success: Executed \"$systemcall\" successfully!\n";
1995b274bc22SAndre Fischer		$installer::logger::Lang->print($infoline);
1996cdf0e10cSrcweir	}
1997cdf0e10cSrcweir}
1998cdf0e10cSrcweir
1999cdf0e10cSrcweir###########################################################
2000cdf0e10cSrcweir# Copying all Solaris packages or RPMs from solver
2001cdf0e10cSrcweir###########################################################
2002cdf0e10cSrcweir
2003cdf0e10cSrcweirsub copy_additional_packages
2004cdf0e10cSrcweir{
2005cdf0e10cSrcweir	my ($allcopypackages, $destdir, $includepatharrayref) = @_;
2006cdf0e10cSrcweir
2007cdf0e10cSrcweir	my $infoline = "Copy additional packages into installation set.\n";
2008b274bc22SAndre Fischer	$installer::logger::Lang->print($infoline);
2009cdf0e10cSrcweir
2010cdf0e10cSrcweir	$destdir =~ s/\/\s*$//;
2011cdf0e10cSrcweir
2012cdf0e10cSrcweir	for ( my $i = 0; $i <= $#{$allcopypackages}; $i++ )
2013cdf0e10cSrcweir	{
2014cdf0e10cSrcweir		my $onepackage = ${$allcopypackages}[$i];
2015cdf0e10cSrcweir		$infoline = "Copy package: $onepackage\n";
2016b274bc22SAndre Fischer		$installer::logger::Lang->print($infoline);
2017cdf0e10cSrcweir
2018cdf0e10cSrcweir		# this package must be delivered into the solver
2019cdf0e10cSrcweir
2020cdf0e10cSrcweir		my $packagesourceref = installer::scriptitems::get_sourcepath_from_filename_and_includepath(\$onepackage, $includepatharrayref, 0);
2021cdf0e10cSrcweir		if ($$packagesourceref eq "") { installer::exiter::exit_program("ERROR: Could not find jds file $onepackage!", "copy_additional_packages"); }
2022cdf0e10cSrcweir
2023cdf0e10cSrcweir        if ( $onepackage =~ /\.tar\.gz\s*$/ )
2024cdf0e10cSrcweir        {
2025cdf0e10cSrcweir            my $systemcall = "cd $destdir; cat $$packagesourceref | gunzip | tar -xf -";
2026cdf0e10cSrcweir            make_systemcall($systemcall);
2027cdf0e10cSrcweir        }
2028cdf0e10cSrcweir        else
2029cdf0e10cSrcweir        {
2030cdf0e10cSrcweir            my $destfile = $destdir . $installer::globals::separator . $onepackage;
2031cdf0e10cSrcweir            installer::systemactions::copy_one_file($$packagesourceref, $destfile);
2032cdf0e10cSrcweir        }
2033cdf0e10cSrcweir	}
2034cdf0e10cSrcweir}
2035cdf0e10cSrcweir
2036cdf0e10cSrcweir###########################################################
2037cdf0e10cSrcweir# Creating jds installation sets
2038cdf0e10cSrcweir###########################################################
2039cdf0e10cSrcweir
2040cdf0e10cSrcweirsub create_jds_sets
2041cdf0e10cSrcweir{
2042cdf0e10cSrcweir	my ($installationdir, $allvariableshashref, $languagestringref, $languagesarrayref, $includepatharrayref) = @_;
2043cdf0e10cSrcweir
2044b274bc22SAndre Fischer	$installer::logger::Info->print("\n");
2045b274bc22SAndre Fischer	$installer::logger::Info->print("******************************************\n");
2046b274bc22SAndre Fischer	$installer::logger::Info->print("... creating jds installation set ...\n");
2047b274bc22SAndre Fischer	$installer::logger::Info->print("******************************************\n");
2048cdf0e10cSrcweir
2049cdf0e10cSrcweir	installer::logger::include_header_into_logfile("Creating jds installation sets:");
2050cdf0e10cSrcweir
2051cdf0e10cSrcweir	my $firstdir = $installationdir;
2052cdf0e10cSrcweir	installer::pathanalyzer::get_path_from_fullqualifiedname(\$firstdir);
2053cdf0e10cSrcweir
2054cdf0e10cSrcweir	my $lastdir = $installationdir;
2055cdf0e10cSrcweir	installer::pathanalyzer::make_absolute_filename_to_relative_filename(\$lastdir);
2056cdf0e10cSrcweir
2057cdf0e10cSrcweir	if ( $lastdir =~ /\./ ) { $lastdir =~ s/\./_jds_inprogress\./ }
2058cdf0e10cSrcweir	else { $lastdir = $lastdir . "_jds_inprogress"; }
2059cdf0e10cSrcweir
2060cdf0e10cSrcweir	# removing existing directory "_native_packed_inprogress" and "_native_packed_witherror" and "_native_packed"
2061cdf0e10cSrcweir
2062cdf0e10cSrcweir	my $jdsdir = $firstdir . $lastdir;
2063cdf0e10cSrcweir	if ( -d $jdsdir ) { installer::systemactions::remove_complete_directory($jdsdir); }
2064cdf0e10cSrcweir
2065cdf0e10cSrcweir	my $olddir = $jdsdir;
2066cdf0e10cSrcweir	$olddir =~ s/_inprogress/_witherror/;
2067cdf0e10cSrcweir	if ( -d $olddir ) { installer::systemactions::remove_complete_directory($olddir); }
2068cdf0e10cSrcweir
2069cdf0e10cSrcweir	$olddir = $jdsdir;
2070cdf0e10cSrcweir	$olddir =~ s/_inprogress//;
2071cdf0e10cSrcweir	if ( -d $olddir ) { installer::systemactions::remove_complete_directory($olddir); }
2072cdf0e10cSrcweir
2073cdf0e10cSrcweir	# creating the new directory
2074cdf0e10cSrcweir
2075cdf0e10cSrcweir	installer::systemactions::create_directory($jdsdir);
2076cdf0e10cSrcweir
2077cdf0e10cSrcweir	$installer::globals::saveinstalldir = $jdsdir;
2078cdf0e10cSrcweir
2079cdf0e10cSrcweir	# find and read jds files list
2080cdf0e10cSrcweir	my $filelistname = $installer::globals::jdsexcludefilename;
2081cdf0e10cSrcweir
2082cdf0e10cSrcweir	my $filelistnameref = installer::scriptitems::get_sourcepath_from_filename_and_includepath(\$filelistname, "", 0);
2083cdf0e10cSrcweir	if ($$filelistnameref eq "") { installer::exiter::exit_program("ERROR: Could not find jds list file $filelistname!", "create_jds_sets"); }
2084cdf0e10cSrcweir
2085cdf0e10cSrcweir	my $listfile = installer::files::read_file($$filelistnameref);
2086cdf0e10cSrcweir
2087cdf0e10cSrcweir	my $infoline = "Found jds list file: $$filelistnameref\n";
2088b274bc22SAndre Fischer	$installer::logger::Lang->print($infoline);
2089cdf0e10cSrcweir
2090cdf0e10cSrcweir	# substituting the variables
2091cdf0e10cSrcweir	substitute_dollar_variables($listfile, $allvariableshashref);
2092cdf0e10cSrcweir
2093cdf0e10cSrcweir	# determining the packages/RPMs to copy
2094cdf0e10cSrcweir	my $allexcludepackages = get_section_from_file($listfile, "excludefiles");
2095cdf0e10cSrcweir	my $allcopypackages = get_section_from_file($listfile, "copyfiles");
2096cdf0e10cSrcweir
2097cdf0e10cSrcweir	# determining the source directory
2098cdf0e10cSrcweir	my $alldirs = installer::systemactions::get_all_directories($installationdir);
2099cdf0e10cSrcweir	my $sourcedir = ${$alldirs}[0]; # there is only one directory
2100cdf0e10cSrcweir
2101cdf0e10cSrcweir	if ( $installer::globals::issolarisbuild ) { $sourcedir = $installer::globals::saved_packages_path; }
2102cdf0e10cSrcweir
2103cdf0e10cSrcweir	# copy all packages/RPMs
2104cdf0e10cSrcweir	copy_all_packages($allexcludepackages, $sourcedir, $jdsdir);
2105cdf0e10cSrcweir	copy_additional_packages($allcopypackages, $jdsdir, $includepatharrayref);
2106cdf0e10cSrcweir
2107cdf0e10cSrcweir	return $jdsdir;
2108cdf0e10cSrcweir}
2109cdf0e10cSrcweir
2110cdf0e10cSrcweir#############################################################################
2111cdf0e10cSrcweir# Checking, whether this installation set contains the correct languages
2112cdf0e10cSrcweir#############################################################################
2113cdf0e10cSrcweir
2114cdf0e10cSrcweirsub check_jds_language
2115cdf0e10cSrcweir{
2116cdf0e10cSrcweir	my ($allvariableshashref, $languagestringref) = @_;
2117cdf0e10cSrcweir
2118cdf0e10cSrcweir	my $infoline = "";
2119cdf0e10cSrcweir
2120cdf0e10cSrcweir	# languagesarrayref and $allvariableshashref->{'JDSLANG'}
2121cdf0e10cSrcweir
2122cdf0e10cSrcweir	if ( ! $allvariableshashref->{'JDSLANG'} ) { installer::exiter::exit_program("ERROR: For building JDS installation sets \"JDSLANG\" must be defined!", "check_jds_language"); }
2123cdf0e10cSrcweir	my $languagestring = $allvariableshashref->{'JDSLANG'};
2124cdf0e10cSrcweir
2125cdf0e10cSrcweir	my $sortedarray1 = installer::converter::convert_stringlist_into_array(\$languagestring, ",");
2126cdf0e10cSrcweir
2127cdf0e10cSrcweir	installer::sorter::sorting_array_of_strings($sortedarray1);
2128cdf0e10cSrcweir
2129cdf0e10cSrcweir	my $sortedarray2 = installer::converter::convert_stringlist_into_array($languagestringref, "_");
2130cdf0e10cSrcweir	installer::sorter::sorting_array_of_strings($sortedarray2);
2131cdf0e10cSrcweir
2132cdf0e10cSrcweir	my $string1 = installer::converter::convert_array_to_comma_separated_string($sortedarray1);
2133cdf0e10cSrcweir	my $string2 = installer::converter::convert_array_to_comma_separated_string($sortedarray2);
2134cdf0e10cSrcweir
2135cdf0e10cSrcweir	my $arrays_are_equal = compare_arrays($sortedarray1, $sortedarray2);
2136cdf0e10cSrcweir
2137cdf0e10cSrcweir	return $arrays_are_equal;
2138cdf0e10cSrcweir}
2139cdf0e10cSrcweir
2140cdf0e10cSrcweir###################################################################################
2141cdf0e10cSrcweir# Comparing two arrays. The arrays are equal, if the complete content is equal.
2142cdf0e10cSrcweir###################################################################################
2143cdf0e10cSrcweir
2144cdf0e10cSrcweirsub compare_arrays
2145cdf0e10cSrcweir{
2146cdf0e10cSrcweir	my ($array1, $array2) = @_;
2147cdf0e10cSrcweir
2148cdf0e10cSrcweir	my $arrays_are_equal = 1;
2149cdf0e10cSrcweir
2150cdf0e10cSrcweir	# checking the size
2151cdf0e10cSrcweir
2152cdf0e10cSrcweir	if ( ! ( $#{$array1} == $#{$array2} )) { $arrays_are_equal = 0; }	# different size
2153cdf0e10cSrcweir
2154cdf0e10cSrcweir	if ( $arrays_are_equal ) # only make further investigations if size is equal
2155cdf0e10cSrcweir	{
2156cdf0e10cSrcweir		for ( my $i = 0; $i <= $#{$array1}; $i++ )
2157cdf0e10cSrcweir		{
2158cdf0e10cSrcweir			# ingnoring whitespaces at end and beginning
2159cdf0e10cSrcweir			${$array1}[$i] =~ s/^\s*//;
2160cdf0e10cSrcweir			${$array2}[$i] =~ s/^\s*//;
2161cdf0e10cSrcweir			${$array1}[$i] =~ s/\s*$//;
2162cdf0e10cSrcweir			${$array2}[$i] =~ s/\s*$//;
2163cdf0e10cSrcweir
2164cdf0e10cSrcweir			if ( ! ( ${$array1}[$i] eq ${$array2}[$i] ))
2165cdf0e10cSrcweir			{
2166cdf0e10cSrcweir				$arrays_are_equal = 0;
2167cdf0e10cSrcweir				last;
2168cdf0e10cSrcweir			}
2169cdf0e10cSrcweir		}
2170cdf0e10cSrcweir	}
2171cdf0e10cSrcweir
2172cdf0e10cSrcweir	return $arrays_are_equal;
2173cdf0e10cSrcweir}
2174cdf0e10cSrcweir
2175cdf0e10cSrcweir#################################################################
2176cdf0e10cSrcweir# Copying the files defined as ScpActions into the
2177cdf0e10cSrcweir# installation set.
2178cdf0e10cSrcweir#################################################################
2179cdf0e10cSrcweir
2180cdf0e10cSrcweirsub put_scpactions_into_installset
2181cdf0e10cSrcweir{
2182cdf0e10cSrcweir	my ($installdir) = @_;
2183cdf0e10cSrcweir
2184cdf0e10cSrcweir	installer::logger::include_header_into_logfile("Start: Copying scp action files into installation set");
2185cdf0e10cSrcweir
2186cdf0e10cSrcweir	for ( my $i = 0; $i <= $#installer::globals::allscpactions; $i++ )
2187cdf0e10cSrcweir	{
2188cdf0e10cSrcweir		my $onescpaction = $installer::globals::allscpactions[$i];
2189cdf0e10cSrcweir
2190cdf0e10cSrcweir		my $subdir = "";
2191cdf0e10cSrcweir		if ( $onescpaction->{'Subdir'} ) { $subdir = $onescpaction->{'Subdir'}; }
2192cdf0e10cSrcweir
2193cdf0e10cSrcweir		if ( $onescpaction->{'Name'} eq "loader.exe" ) { next; }	# do not copy this ScpAction loader
2194cdf0e10cSrcweir
2195cdf0e10cSrcweir		my $destdir = $installdir;
2196cdf0e10cSrcweir		$destdir =~ s/\Q$installer::globals::separator\E\s*$//;
2197cdf0e10cSrcweir		if ( $subdir ) { $destdir = $destdir . $installer::globals::separator . $subdir; }
2198cdf0e10cSrcweir
2199cdf0e10cSrcweir		my $sourcefile = $onescpaction->{'sourcepath'};
2200cdf0e10cSrcweir		my $destfile = $destdir . $installer::globals::separator . $onescpaction->{'DestinationName'};
2201cdf0e10cSrcweir
2202cdf0e10cSrcweir		my $styles = "";
2203cdf0e10cSrcweir		if ( $onescpaction->{'Styles'} ) { $styles = $onescpaction->{'Styles'}; }
2204cdf0e10cSrcweir		if (( $styles =~ /\bFILE_CAN_MISS\b/ ) && ( $sourcefile eq "" )) { next; }
2205cdf0e10cSrcweir
2206cdf0e10cSrcweir		if (( $subdir =~ /\// ) || ( $subdir =~ /\\/ ))
2207cdf0e10cSrcweir		{
2208cdf0e10cSrcweir			installer::systemactions::create_directory_structure($destdir);
2209cdf0e10cSrcweir		}
2210cdf0e10cSrcweir		else
2211cdf0e10cSrcweir		{
2212cdf0e10cSrcweir			installer::systemactions::create_directory($destdir);
2213cdf0e10cSrcweir		}
2214cdf0e10cSrcweir
2215cdf0e10cSrcweir		installer::systemactions::copy_one_file($sourcefile, $destfile);
2216cdf0e10cSrcweir
2217cdf0e10cSrcweir		if ( $onescpaction->{'UnixRights'} )
2218cdf0e10cSrcweir		{
2219cdf0e10cSrcweir			my $localcall = "chmod $onescpaction->{'UnixRights'} $destfile \>\/dev\/null 2\>\&1";
2220cdf0e10cSrcweir			system($localcall);
2221cdf0e10cSrcweir		}
2222cdf0e10cSrcweir
2223cdf0e10cSrcweir	}
2224cdf0e10cSrcweir
2225cdf0e10cSrcweir	installer::logger::include_header_into_logfile("End: Copying scp action files into installation set");
2226cdf0e10cSrcweir
2227cdf0e10cSrcweir}
2228cdf0e10cSrcweir
2229cdf0e10cSrcweir#################################################################
2230cdf0e10cSrcweir# Collecting scp actions for all languages
2231cdf0e10cSrcweir#################################################################
2232cdf0e10cSrcweir
2233cdf0e10cSrcweirsub collect_scpactions
2234cdf0e10cSrcweir{
2235cdf0e10cSrcweir	my ($allscpactions) = @_;
2236cdf0e10cSrcweir
2237cdf0e10cSrcweir	for ( my $i = 0; $i <= $#{$allscpactions}; $i++ )
2238cdf0e10cSrcweir	{
2239cdf0e10cSrcweir		push(@installer::globals::allscpactions, ${$allscpactions}[$i]);
2240cdf0e10cSrcweir	}
2241cdf0e10cSrcweir}
2242cdf0e10cSrcweir
2243cdf0e10cSrcweir#################################################################
2244cdf0e10cSrcweir# Setting the platform name for download
2245cdf0e10cSrcweir#################################################################
2246cdf0e10cSrcweir
2247cdf0e10cSrcweirsub get_platform_name
2248cdf0e10cSrcweir{
2249cdf0e10cSrcweir	my $platformname = "";
2250cdf0e10cSrcweir
2251cdf0e10cSrcweir	if (( $installer::globals::islinuxintelrpmbuild ) || ( $installer::globals::islinuxinteldebbuild ))
2252cdf0e10cSrcweir	{
2253cdf0e10cSrcweir		$platformname = "LinuxIntel";
2254cdf0e10cSrcweir	}
2255cdf0e10cSrcweir	elsif (( $installer::globals::islinuxppcrpmbuild ) || ( $installer::globals::islinuxppcdebbuild ))
2256cdf0e10cSrcweir	{
2257cdf0e10cSrcweir		$platformname = "LinuxPowerPC";
2258cdf0e10cSrcweir	}
2259cdf0e10cSrcweir	elsif (( $installer::globals::islinuxx86_64rpmbuild ) || ( $installer::globals::islinuxx86_64debbuild ))
2260cdf0e10cSrcweir	{
2261cdf0e10cSrcweir		$platformname = "LinuxX86-64";
2262cdf0e10cSrcweir	}
2263cdf0e10cSrcweir	elsif ( $installer::globals::issolarissparcbuild )
2264cdf0e10cSrcweir	{
2265cdf0e10cSrcweir		$platformname = "SolarisSparc";
2266cdf0e10cSrcweir	}
2267cdf0e10cSrcweir	elsif ( $installer::globals::issolarisx86build )
2268cdf0e10cSrcweir	{
2269cdf0e10cSrcweir		$platformname = "Solarisx86";
2270cdf0e10cSrcweir	}
2271cdf0e10cSrcweir	elsif ( $installer::globals::iswindowsbuild )
2272cdf0e10cSrcweir	{
2273cdf0e10cSrcweir		$platformname = "Win32Intel";
2274cdf0e10cSrcweir	}
22754101619dSHerbert Dürr	elsif(( $installer::globals::compiler =~ /^unxmac.i/ ))
2276cdf0e10cSrcweir	{
2277cdf0e10cSrcweir		$platformname = "MacOSXIntel";
2278cdf0e10cSrcweir	}
22794101619dSHerbert Dürr	elsif ( $installer::globals::compiler =~ /^unxmaccx/ )
22804101619dSHerbert Dürr	{
22814101619dSHerbert Dürr		$platformname = "MacOSXX86-64";
22824101619dSHerbert Dürr	}
2283cdf0e10cSrcweir	elsif ( $installer::globals::compiler =~ /^unxmacxp/ )
2284cdf0e10cSrcweir	{
2285cdf0e10cSrcweir		$platformname = "MacOSXPowerPC";
2286cdf0e10cSrcweir	}
2287cdf0e10cSrcweir	else
2288cdf0e10cSrcweir	{
2289cdf0e10cSrcweir		# $platformname = $installer::globals::packageformat;
2290cdf0e10cSrcweir		$platformname = $installer::globals::compiler;
2291cdf0e10cSrcweir	}
2292cdf0e10cSrcweir
2293cdf0e10cSrcweir	return $platformname;
2294cdf0e10cSrcweir}
2295cdf0e10cSrcweir
2296cdf0e10cSrcweir###########################################################
2297cdf0e10cSrcweir# Adding additional variables into the variableshashref,
2298cdf0e10cSrcweir# that are defined in include files in the solver. The
2299cdf0e10cSrcweir# names of the include files are stored in
2300cdf0e10cSrcweir# ADD_INCLUDE_FILES (comma separated list).
2301cdf0e10cSrcweir###########################################################
2302cdf0e10cSrcweir
2303cdf0e10cSrcweirsub add_variables_from_inc_to_hashref
2304cdf0e10cSrcweir{
2305cdf0e10cSrcweir	my ($allvariables, $includepatharrayref) = @_;
2306cdf0e10cSrcweir
2307cdf0e10cSrcweir	my $infoline = "";
2308cdf0e10cSrcweir	my $includefilelist = "";
2309cdf0e10cSrcweir	if ( $allvariables->{'ADD_INCLUDE_FILES'} ) { $includefilelist = $allvariables->{'ADD_INCLUDE_FILES'}; }
2310cdf0e10cSrcweir
2311cdf0e10cSrcweir	my $includefiles = installer::converter::convert_stringlist_into_array_without_linebreak_and_quotes(\$includefilelist, ",");
2312cdf0e10cSrcweir
2313cdf0e10cSrcweir	for ( my $i = 0; $i <= $#{$includefiles}; $i++ )
2314cdf0e10cSrcweir	{
2315cdf0e10cSrcweir		my $includefilename = ${$includefiles}[$i];
2316cdf0e10cSrcweir		$includefilename =~ s/^\s*//;
2317cdf0e10cSrcweir		$includefilename =~ s/\s*$//;
2318cdf0e10cSrcweir		$includefilenameref = installer::scriptitems::get_sourcepath_from_filename_and_includepath(\$includefilename, $includepatharrayref, 1);
2319cdf0e10cSrcweir		if ( $$includefilenameref eq "" ) { installer::exiter::exit_program("Include file $includefilename not found!\nADD_INCLUDE_FILES = $allvariables->{'ADD_INCLUDE_FILES'}", "add_variables_from_inc_to_hashref"); }
2320cdf0e10cSrcweir
2321b274bc22SAndre Fischer        $installer::logger::Global->printf("Including inc file: %s\n", $$includefilenameref);
2322cdf0e10cSrcweir
2323cdf0e10cSrcweir		my $includefile = installer::files::read_file($$includefilenameref);
2324cdf0e10cSrcweir
2325cdf0e10cSrcweir		for ( my $j = 0; $j <= $#{$includefile}; $j++ )
2326cdf0e10cSrcweir		{
2327cdf0e10cSrcweir			# Analyzing all "key=value" lines
2328cdf0e10cSrcweir			my $oneline = ${$includefile}[$j];
2329cdf0e10cSrcweir
2330cdf0e10cSrcweir			if ( $oneline =~ /^\s*(\S+)\s*\=\s*(.*?)\s*$/ )	# no white space allowed in key
2331cdf0e10cSrcweir			{
2332cdf0e10cSrcweir				my $key = $1;
2333cdf0e10cSrcweir				my $value = $2;
2334cdf0e10cSrcweir				$allvariables->{$key} = $value;
2335b274bc22SAndre Fischer                $installer::logger::Global->printf("Setting of variable: %s = %s\n",
2336b274bc22SAndre Fischer                    $key, $value);
2337cdf0e10cSrcweir			}
2338cdf0e10cSrcweir		}
2339cdf0e10cSrcweir	}
2340cdf0e10cSrcweir
2341cdf0e10cSrcweir	# Allowing different Java versions for Windows and Unix. Instead of "JAVAVERSION"
2342cdf0e10cSrcweir	# the property "WINDOWSJAVAVERSION" has to be used, if it is set.
2343cdf0e10cSrcweir
2344cdf0e10cSrcweir	if ( $installer::globals::iswindowsbuild )
2345cdf0e10cSrcweir	{
2346cdf0e10cSrcweir		if (( exists($allvariables->{'WINDOWSJAVAVERSION'})) && ( $allvariables->{'WINDOWSJAVAVERSION'} ne "" ))
2347cdf0e10cSrcweir		{
2348cdf0e10cSrcweir			$allvariables->{'JAVAVERSION'} = $allvariables->{'WINDOWSJAVAVERSION'};
2349b274bc22SAndre Fischer            $installer::logger::Global->printf(
2350b274bc22SAndre Fischer                "Changing value of property \"JAVAVERSION\" to %s (property \"WINDOWSJAVAVERSION\").\n",
2351b274bc22SAndre Fischer                $allvariables->{'JAVAVERSION'});
2352cdf0e10cSrcweir		}
2353cdf0e10cSrcweir	}
2354cdf0e10cSrcweir}
2355cdf0e10cSrcweir
2356cdf0e10cSrcweir##############################################
235786e1cf34SPedro Giffuni# Collecting all files from include paths
2358cdf0e10cSrcweir##############################################
2359cdf0e10cSrcweir
2360cdf0e10cSrcweirsub collect_all_files_from_includepathes
2361cdf0e10cSrcweir{
2362cdf0e10cSrcweir	my ($patharrayref) = @_;
2363cdf0e10cSrcweir
2364cdf0e10cSrcweir	installer::logger::globallog("Reading all directories: Start");
236586e1cf34SPedro Giffuni	$installer::logger::Info->print( "... reading include paths ...\n" );
2366cdf0e10cSrcweir	# empty the global
2367cdf0e10cSrcweir
2368cdf0e10cSrcweir	@installer::globals::allincludepathes =();
2369cdf0e10cSrcweir	my $infoline;
2370cdf0e10cSrcweir
2371cdf0e10cSrcweir	for ( my $i = 0; $i <= $#{$patharrayref}; $i++ )
2372cdf0e10cSrcweir	{
2373cdf0e10cSrcweir		$includepath = ${$patharrayref}[$i];
2374cdf0e10cSrcweir		installer::remover::remove_leading_and_ending_whitespaces(\$includepath);
2375cdf0e10cSrcweir
2376cdf0e10cSrcweir		if ( ! -d $includepath )
2377cdf0e10cSrcweir		{
2378b274bc22SAndre Fischer            $installer::logger::Global->printf(
2379b274bc22SAndre Fischer                "%s does not exist. (Can be removed from include path list?)\n",
2380b274bc22SAndre Fischer                $includepath);
2381cdf0e10cSrcweir			next;
2382cdf0e10cSrcweir		}
2383cdf0e10cSrcweir
2384cdf0e10cSrcweir		my @sourcefiles = ();
2385cdf0e10cSrcweir		my $pathstring = "";
2386cdf0e10cSrcweir		installer::systemactions::read_full_directory($includepath, $pathstring, \@sourcefiles);
2387cdf0e10cSrcweir
2388cdf0e10cSrcweir		if ( ! ( $#sourcefiles > -1 ))
2389cdf0e10cSrcweir		{
2390b274bc22SAndre Fischer            $installer::logger::Global->printf(
2391b274bc22SAndre Fischer                "%s is empty. (Can be removed from include path list?)\n",
2392b274bc22SAndre Fischer                $includepath);
2393cdf0e10cSrcweir		}
2394cdf0e10cSrcweir		else
2395cdf0e10cSrcweir		{
2396cdf0e10cSrcweir			my $number = $#sourcefiles + 1;
2397b274bc22SAndre Fischer            $installer::logger::Global->printf(
2398b274bc22SAndre Fischer                "Directory %s contains $number files (including subdirs)\n",
2399b274bc22SAndre Fischer                $includepath);
2400cdf0e10cSrcweir
2401cdf0e10cSrcweir			my %allfileshash = ();
2402cdf0e10cSrcweir			$allfileshash{'includepath'} = $includepath;
2403cdf0e10cSrcweir
2404cdf0e10cSrcweir			for ( my $j = 0; $j <= $#sourcefiles; $j++ )
2405cdf0e10cSrcweir			{
2406cdf0e10cSrcweir				$allfileshash{$sourcefiles[$j]} = 1;
2407cdf0e10cSrcweir			}
2408cdf0e10cSrcweir
2409cdf0e10cSrcweir			push(@installer::globals::allincludepathes, \%allfileshash);
2410cdf0e10cSrcweir		}
2411cdf0e10cSrcweir	}
2412cdf0e10cSrcweir
2413cdf0e10cSrcweir	$installer::globals::include_pathes_read = 1;
2414cdf0e10cSrcweir
2415b274bc22SAndre Fischer    installer::logger::globallog("Reading all directories: End");
2416b274bc22SAndre Fischer    $installer::logger::Global->print("\n");
2417cdf0e10cSrcweir}
2418cdf0e10cSrcweir
2419cdf0e10cSrcweir##############################################
2420cdf0e10cSrcweir# Searching for a file with the gid
2421cdf0e10cSrcweir##############################################
2422cdf0e10cSrcweir
2423cdf0e10cSrcweirsub find_file_by_id
2424cdf0e10cSrcweir{
2425cdf0e10cSrcweir	my ( $filesref, $gid ) = @_;
2426cdf0e10cSrcweir
2427cdf0e10cSrcweir	my $foundfile = 0;
2428cdf0e10cSrcweir	my $onefile;
2429cdf0e10cSrcweir
2430cdf0e10cSrcweir	for ( my $i = 0; $i <= $#{$filesref}; $i++ )
2431cdf0e10cSrcweir	{
2432cdf0e10cSrcweir		$onefile = ${$filesref}[$i];
2433cdf0e10cSrcweir		my $filegid = $onefile->{'gid'};
2434cdf0e10cSrcweir
2435cdf0e10cSrcweir		if ( $filegid eq $gid )
2436cdf0e10cSrcweir		{
2437cdf0e10cSrcweir			$foundfile = 1;
2438cdf0e10cSrcweir			last;
2439cdf0e10cSrcweir		}
2440cdf0e10cSrcweir	}
2441cdf0e10cSrcweir
2442cdf0e10cSrcweir	# It does not need to exist. For example products that do not contain the libraries.
2443cdf0e10cSrcweir	# if (! $foundfile ) { installer::exiter::exit_program("ERROR: No unique file name found for $filename !", "get_selfreg_file"); }
2444cdf0e10cSrcweir
2445cdf0e10cSrcweir	if (! $foundfile ) { $onefile  = ""; }
2446cdf0e10cSrcweir
2447cdf0e10cSrcweir	return $onefile;
2448cdf0e10cSrcweir}
2449cdf0e10cSrcweir
2450cdf0e10cSrcweir##############################################
2451cdf0e10cSrcweir# Searching for an item with the gid
2452cdf0e10cSrcweir##############################################
2453cdf0e10cSrcweir
2454cdf0e10cSrcweirsub find_item_by_gid
2455cdf0e10cSrcweir{
2456cdf0e10cSrcweir	my ( $itemsref, $gid ) = @_;
2457cdf0e10cSrcweir
2458cdf0e10cSrcweir	my $founditem = 0;
2459cdf0e10cSrcweir	my $oneitem = "";
2460cdf0e10cSrcweir
2461cdf0e10cSrcweir	for ( my $i = 0; $i <= $#{$itemsref}; $i++ )
2462cdf0e10cSrcweir	{
2463cdf0e10cSrcweir		my $localitem = ${$itemsref}[$i];
2464cdf0e10cSrcweir		my $itemgid = $localitem->{'gid'};
2465cdf0e10cSrcweir
2466cdf0e10cSrcweir		if ( $itemgid eq $gid )
2467cdf0e10cSrcweir		{
2468cdf0e10cSrcweir			$oneitem = $localitem;
2469cdf0e10cSrcweir			$founditem = 1;
2470cdf0e10cSrcweir			last;
2471cdf0e10cSrcweir		}
2472cdf0e10cSrcweir	}
2473cdf0e10cSrcweir
2474cdf0e10cSrcweir	return $oneitem;
2475cdf0e10cSrcweir}
2476cdf0e10cSrcweir
2477cdf0e10cSrcweir#########################################################
2478cdf0e10cSrcweir# Calling sum
2479cdf0e10cSrcweir#########################################################
2480cdf0e10cSrcweir
2481cdf0e10cSrcweirsub call_sum
2482cdf0e10cSrcweir{
2483cdf0e10cSrcweir	my ($filename) = @_;
2484cdf0e10cSrcweir
2485cdf0e10cSrcweir	$sumfile = "/usr/bin/sum";
2486cdf0e10cSrcweir
2487cdf0e10cSrcweir	if ( ! -f $sumfile ) { installer::exiter::exit_program("ERROR: No file /usr/bin/sum", "call_sum"); }
2488cdf0e10cSrcweir
2489cdf0e10cSrcweir	my $systemcall = "$sumfile $filename |";
2490cdf0e10cSrcweir
2491cdf0e10cSrcweir	my $sumoutput = "";
2492cdf0e10cSrcweir
2493cdf0e10cSrcweir	open (SUM, "$systemcall");
2494cdf0e10cSrcweir	$sumoutput = <SUM>;
2495cdf0e10cSrcweir	close (SUM);
2496cdf0e10cSrcweir
2497cdf0e10cSrcweir	my $returnvalue = $?;	# $? contains the return value of the systemcall
2498cdf0e10cSrcweir
2499cdf0e10cSrcweir	my $infoline = "Systemcall: $systemcall\n";
2500b274bc22SAndre Fischer	$installer::logger::Lang->print($infoline);
2501cdf0e10cSrcweir
2502cdf0e10cSrcweir	if ($returnvalue)
2503cdf0e10cSrcweir	{
2504cdf0e10cSrcweir		$infoline = "ERROR: Could not execute \"$systemcall\"!\n";
2505b274bc22SAndre Fischer		$installer::logger::Lang->print($infoline);
2506cdf0e10cSrcweir	}
2507cdf0e10cSrcweir	else
2508cdf0e10cSrcweir	{
2509cdf0e10cSrcweir		$infoline = "Success: Executed \"$systemcall\" successfully!\n";
2510b274bc22SAndre Fischer		$installer::logger::Lang->print($infoline);
2511cdf0e10cSrcweir	}
2512cdf0e10cSrcweir
2513cdf0e10cSrcweir	return $sumoutput;
2514cdf0e10cSrcweir}
2515cdf0e10cSrcweir
2516cdf0e10cSrcweir#########################################################
2517cdf0e10cSrcweir# Calling wc
2518cdf0e10cSrcweir# wc -c pkginfo | cut -f6 -d' '
2519cdf0e10cSrcweir#########################################################
2520cdf0e10cSrcweir
2521cdf0e10cSrcweirsub call_wc
2522cdf0e10cSrcweir{
2523cdf0e10cSrcweir	my ($filename) = @_;
2524cdf0e10cSrcweir
2525cdf0e10cSrcweir	$wcfile = "/usr/bin/wc";
2526cdf0e10cSrcweir
2527cdf0e10cSrcweir	if ( ! -f $wcfile ) { installer::exiter::exit_program("ERROR: No file /usr/bin/wc", "call_wc"); }
2528cdf0e10cSrcweir
2529cdf0e10cSrcweir	my $systemcall = "$wcfile -c $filename |";
2530cdf0e10cSrcweir
2531cdf0e10cSrcweir	my $wcoutput = "";
2532cdf0e10cSrcweir
2533cdf0e10cSrcweir	open (WC, "$systemcall");
2534cdf0e10cSrcweir	$wcoutput = <WC>;
2535cdf0e10cSrcweir	close (WC);
2536cdf0e10cSrcweir
2537cdf0e10cSrcweir	my $returnvalue = $?;	# $? contains the return value of the systemcall
2538cdf0e10cSrcweir
2539cdf0e10cSrcweir	my $infoline = "Systemcall: $systemcall\n";
2540b274bc22SAndre Fischer	$installer::logger::Lang->print($infoline);
2541cdf0e10cSrcweir
2542cdf0e10cSrcweir	if ($returnvalue)
2543cdf0e10cSrcweir	{
2544cdf0e10cSrcweir		$infoline = "ERROR: Could not execute \"$systemcall\"!\n";
2545b274bc22SAndre Fischer		$installer::logger::Lang->print($infoline);
2546cdf0e10cSrcweir	}
2547cdf0e10cSrcweir	else
2548cdf0e10cSrcweir	{
2549cdf0e10cSrcweir		$infoline = "Success: Executed \"$systemcall\" successfully!\n";
2550b274bc22SAndre Fischer		$installer::logger::Lang->print($infoline);
2551cdf0e10cSrcweir	}
2552cdf0e10cSrcweir
2553cdf0e10cSrcweir	return $wcoutput;
2554cdf0e10cSrcweir}
2555cdf0e10cSrcweir
2556cdf0e10cSrcweir##############################################
2557cdf0e10cSrcweir# Setting architecture ARCH=i86pc
2558cdf0e10cSrcweir# instead of ARCH=i386.
2559cdf0e10cSrcweir##############################################
2560cdf0e10cSrcweir
2561cdf0e10cSrcweirsub set_old_architecture_string
2562cdf0e10cSrcweir{
2563cdf0e10cSrcweir	my ($pkginfofile) = @_;
2564cdf0e10cSrcweir
2565cdf0e10cSrcweir	for ( my $i = 0; $i <= $#{$pkginfofile}; $i++ )
2566cdf0e10cSrcweir	{
2567cdf0e10cSrcweir		if ( ${$pkginfofile}[$i] =~ /^\s*ARCH=i386\s*$/ )
2568cdf0e10cSrcweir		{
2569cdf0e10cSrcweir			${$pkginfofile}[$i] =~ s/i386/i86pc/;
2570cdf0e10cSrcweir			last;
2571cdf0e10cSrcweir		}
2572cdf0e10cSrcweir	}
2573cdf0e10cSrcweir}
2574cdf0e10cSrcweir
2575cdf0e10cSrcweir##############################################
2576cdf0e10cSrcweir# For the new copied package, it is necessary
2577cdf0e10cSrcweir# that a value for the key SUNW_REQUIRES
2578cdf0e10cSrcweir# is set. Otherwise this copied package
2579cdf0e10cSrcweir# with ARCH=i86pc would be useless.
2580cdf0e10cSrcweir##############################################
2581cdf0e10cSrcweir
2582cdf0e10cSrcweirsub check_requires_setting
2583cdf0e10cSrcweir{
2584cdf0e10cSrcweir	my ($pkginfofile) = @_;
2585cdf0e10cSrcweir
2586cdf0e10cSrcweir	my $found = 0;
2587cdf0e10cSrcweir	my $patchid = "";
2588cdf0e10cSrcweir
2589cdf0e10cSrcweir	for ( my $i = 0; $i <= $#{$pkginfofile}; $i++ )
2590cdf0e10cSrcweir	{
2591cdf0e10cSrcweir		if ( ${$pkginfofile}[$i] =~ /^\s*SUNW_REQUIRES=(\S*?)\s*$/ )
2592cdf0e10cSrcweir		{
2593cdf0e10cSrcweir			$patchid = $1;
2594cdf0e10cSrcweir			$found = 1;
2595cdf0e10cSrcweir			last;
2596cdf0e10cSrcweir		}
2597cdf0e10cSrcweir	}
2598cdf0e10cSrcweir
2599cdf0e10cSrcweir	if (( ! $found ) || ( $patchid eq "" )) { installer::exiter::exit_program("ERROR: No patch id defined for SUNW_REQUIRES in patch pkginfo file!", "check_requires_setting"); }
2600cdf0e10cSrcweir}
2601cdf0e10cSrcweir
2602cdf0e10cSrcweir##############################################
2603cdf0e10cSrcweir# Setting checksum and wordcount for changed
2604cdf0e10cSrcweir# pkginfo file into pkgmap.
2605cdf0e10cSrcweir##############################################
2606cdf0e10cSrcweir
2607cdf0e10cSrcweirsub set_pkginfo_line
2608cdf0e10cSrcweir{
2609cdf0e10cSrcweir	my ($pkgmapfile, $pkginfofilename) = @_;
2610cdf0e10cSrcweir
2611cdf0e10cSrcweir	# 1 i pkginfo 442 34577 1166716297
2612cdf0e10cSrcweir	# ->
2613cdf0e10cSrcweir	# 1 i pkginfo 443 34737 1166716297
2614cdf0e10cSrcweir	#
2615cdf0e10cSrcweir	# wc -c pkginfo | cut -f6 -d' '  -> 442  (variable)
2616cdf0e10cSrcweir	# sum pkginfo | cut -f1 -d' '  -> 34577  (variable)
2617cdf0e10cSrcweir	# grep 'pkginfo' pkgmap | cut -f6 -d' '  -> 1166716297  (fix)
2618cdf0e10cSrcweir
2619cdf0e10cSrcweir	my $checksum = call_sum($pkginfofilename);
2620cdf0e10cSrcweir	if ( $checksum =~ /^\s*(\d+)\s+.*$/ ) { $checksum = $1; }
2621cdf0e10cSrcweir
2622cdf0e10cSrcweir	my $wordcount = call_wc($pkginfofilename);
2623cdf0e10cSrcweir	if ( $wordcount =~ /^\s*(\d+)\s+.*$/ ) { $wordcount = $1; }
2624cdf0e10cSrcweir
2625cdf0e10cSrcweir	for ( my $i = 0; $i <= $#{$pkgmapfile}; $i++ )
2626cdf0e10cSrcweir	{
2627cdf0e10cSrcweir		if ( ${$pkgmapfile}[$i] =~ /(^.*\bpkginfo\b\s+)(\d+)(\s+)(\d+)(\s+)(\d+)(\s*$)/ )
2628cdf0e10cSrcweir		{
2629cdf0e10cSrcweir			my $newline = $1 . $wordcount . $3 . $checksum . $5 . $6 . $7;
2630cdf0e10cSrcweir			${$pkgmapfile}[$i] = $newline;
2631cdf0e10cSrcweir			last;
2632cdf0e10cSrcweir		}
2633cdf0e10cSrcweir	}
2634cdf0e10cSrcweir}
2635cdf0e10cSrcweir
2636cdf0e10cSrcweir##############################################
2637cdf0e10cSrcweir# Setting time stamp of copied files to avoid
2638cdf0e10cSrcweir# errors from pkgchk.
2639cdf0e10cSrcweir##############################################
2640cdf0e10cSrcweir
2641cdf0e10cSrcweirsub set_time_stamp
2642cdf0e10cSrcweir{
2643cdf0e10cSrcweir	my ($olddir, $newdir, $copyfiles) = @_;
2644cdf0e10cSrcweir
2645cdf0e10cSrcweir	for ( my $i = 0; $i <= $#{$copyfiles}; $i++ )
2646cdf0e10cSrcweir	{
2647cdf0e10cSrcweir		my $sourcefile = $olddir . $installer::globals::separator . ${$copyfiles}[$i];
2648cdf0e10cSrcweir		my $destfile = $newdir . $installer::globals::separator . ${$copyfiles}[$i];
2649cdf0e10cSrcweir
2650cdf0e10cSrcweir		my $systemcall = "touch -r $sourcefile $destfile";
2651cdf0e10cSrcweir
2652cdf0e10cSrcweir		my $returnvalue = system($systemcall);
2653cdf0e10cSrcweir
2654cdf0e10cSrcweir		my $infoline = "Systemcall: $systemcall\n";
2655b274bc22SAndre Fischer		$installer::logger::Lang->print($infoline);
2656cdf0e10cSrcweir
2657cdf0e10cSrcweir		if ($returnvalue)
2658cdf0e10cSrcweir		{
2659cdf0e10cSrcweir			$infoline = "ERROR: \"$systemcall\" failed!\n";
2660b274bc22SAndre Fischer			$installer::logger::Lang->print($infoline);
2661cdf0e10cSrcweir		}
2662cdf0e10cSrcweir		else
2663cdf0e10cSrcweir		{
2664cdf0e10cSrcweir			$infoline = "Success: \"$systemcall\" !\n";
2665b274bc22SAndre Fischer			$installer::logger::Lang->print($infoline);
2666cdf0e10cSrcweir		}
2667cdf0e10cSrcweir	}
2668cdf0e10cSrcweir}
2669cdf0e10cSrcweir
2670cdf0e10cSrcweir############################################################
267186e1cf34SPedro Giffuni# Generating paths for cygwin (first version)
2672cdf0e10cSrcweir# This function has problems with cygwin, if $tmpfilename
2673cdf0e10cSrcweir# contains many thousand files (OpenOffice SDK).
2674cdf0e10cSrcweir############################################################
2675cdf0e10cSrcweir
2676cdf0e10cSrcweirsub generate_cygwin_pathes_old
2677cdf0e10cSrcweir{
2678cdf0e10cSrcweir	my ($filesref) = @_;
2679cdf0e10cSrcweir
2680cdf0e10cSrcweir	my ($tmpfilehandle, $tmpfilename) = tmpnam();
2681cdf0e10cSrcweir	open SOURCEPATHLIST, ">$tmpfilename" or die "oops...\n";
2682cdf0e10cSrcweir	for ( my $i = 0; $i <= $#{$filesref}; $i++ )
2683cdf0e10cSrcweir	{
2684cdf0e10cSrcweir		print SOURCEPATHLIST "${$filesref}[$i]->{'sourcepath'}\n";
2685cdf0e10cSrcweir	}
2686cdf0e10cSrcweir	close SOURCEPATHLIST;
2687cdf0e10cSrcweir	my @cyg_sourcepathlist = qx{cygpath -w -f "$tmpfilename"};
2688cdf0e10cSrcweir	chomp @cyg_sourcepathlist;
2689cdf0e10cSrcweir	unlink "$tmpfilename" or die "oops\n";
2690cdf0e10cSrcweir	for ( my $i = 0; $i <= $#{$filesref}; $i++ )
2691cdf0e10cSrcweir	{
2692cdf0e10cSrcweir		${$filesref}[$i]->{'cyg_sourcepath'} = $cyg_sourcepathlist[$i];
2693cdf0e10cSrcweir	}
2694cdf0e10cSrcweir
2695cdf0e10cSrcweir}
2696cdf0e10cSrcweir
2697cdf0e10cSrcweir#################################################
269886e1cf34SPedro Giffuni# Generating paths for cygwin (second version)
2699cdf0e10cSrcweir# This function generates smaller files for
2700cdf0e10cSrcweir#################################################
2701cdf0e10cSrcweir
2702cdf0e10cSrcweirsub generate_cygwin_pathes
2703cdf0e10cSrcweir{
2704cdf0e10cSrcweir	my ($filesref) = @_;
2705cdf0e10cSrcweir
270686e1cf34SPedro Giffuni	$installer::logger::Lang->add_timestamp("Starting generating cygwin paths");
2707cdf0e10cSrcweir
270886e1cf34SPedro Giffuni	my $infoline = "Generating cygwin paths (generate_cygwin_pathes)\n";
2709b274bc22SAndre Fischer	$installer::logger::Lang->print($infoline);
2710cdf0e10cSrcweir
271186e1cf34SPedro Giffuni	my $max = 5000;  # number of paths in one file
2712cdf0e10cSrcweir
2713cdf0e10cSrcweir	my @pathcollector = ();
2714cdf0e10cSrcweir	my $startnumber = 0;
2715cdf0e10cSrcweir	my $counter = 0;
2716cdf0e10cSrcweir
2717cdf0e10cSrcweir	for ( my $i = 0; $i <= $#{$filesref}; $i++ )
2718cdf0e10cSrcweir	{
27191ba1fd99SAndre Fischer        my $filename = ${$filesref}[$i]->{'sourcepath'};
27201ba1fd99SAndre Fischer		push(@pathcollector, $filename . "\n");
2721cdf0e10cSrcweir		$counter++;
27221ba1fd99SAndre Fischer
2723cdf0e10cSrcweir		if (( $i == $#{$filesref} ) || ((( $counter % $max ) == 0 ) && ( $i > 0 )))
2724cdf0e10cSrcweir		{
2725cdf0e10cSrcweir			my $tmpfilename = "cygwinhelper_" . $i . ".txt";
2726cdf0e10cSrcweir			my $temppath = $installer::globals::temppath;
2727cdf0e10cSrcweir			$temppath =~ s/\Q$installer::globals::separator\E\s*$//;
2728cdf0e10cSrcweir			$tmpfilename = $temppath . $installer::globals::separator . $tmpfilename;
272986e1cf34SPedro Giffuni			$infoline = "Creating temporary file for cygwin conversion: $tmpfilename (contains $counter paths)\n";
2730b274bc22SAndre Fischer			$installer::logger::Lang->print($infoline);
2731cdf0e10cSrcweir			if ( -f $tmpfilename ) { unlink $tmpfilename; }
2732cdf0e10cSrcweir
2733cdf0e10cSrcweir			installer::files::save_file($tmpfilename, \@pathcollector);
2734cdf0e10cSrcweir
2735cdf0e10cSrcweir			my $success = 0;
2736dba1a2e4SAndre Fischer            $installer::logger::Lang->printf(
2737dba1a2e4SAndre Fischer                "Converting %d filenames to cygwin notation\n",
2738dba1a2e4SAndre Fischer                $counter);
2739cdf0e10cSrcweir			my @cyg_sourcepathlist = qx{cygpath -w -f "$tmpfilename"};
2740cdf0e10cSrcweir			chomp @cyg_sourcepathlist;
2741cdf0e10cSrcweir
2742cdf0e10cSrcweir			# Validating the array, it has to contain the correct number of values
2743cdf0e10cSrcweir			my $new_pathes = $#cyg_sourcepathlist + 1;
2744cdf0e10cSrcweir			if ( $new_pathes == $counter ) { $success = 1; }
2745cdf0e10cSrcweir
2746cdf0e10cSrcweir			if ($success)
2747cdf0e10cSrcweir			{
27481ba1fd99SAndre Fischer				$installer::logger::Lang->printf(
2749dba1a2e4SAndre Fischer                    "Successfully converted %d paths to cygwin notation\n",
2750dba1a2e4SAndre Fischer                    $counter);
2751cdf0e10cSrcweir			}
2752cdf0e10cSrcweir			else
2753cdf0e10cSrcweir			{
275486e1cf34SPedro Giffuni                $installer::logger::Lang->print("ERROR: Failed to convert to cygwin paths!\n");
2755dba1a2e4SAndre Fischer                installer::exiter::exit_program(
275686e1cf34SPedro Giffuni                    "ERROR: Failed to convert to cygwin paths!",
2757dba1a2e4SAndre Fischer                    "generate_cygwin_pathes");
2758cdf0e10cSrcweir			}
2759cdf0e10cSrcweir
2760cdf0e10cSrcweir			for ( my $j = 0; $j <= $#cyg_sourcepathlist; $j++ )
2761cdf0e10cSrcweir			{
2762cdf0e10cSrcweir				my $number = $startnumber + $j;
2763cdf0e10cSrcweir				${$filesref}[$number]->{'cyg_sourcepath'} = $cyg_sourcepathlist[$j];
2764cdf0e10cSrcweir			}
2765cdf0e10cSrcweir
2766cdf0e10cSrcweir			if ( -f $tmpfilename ) { unlink $tmpfilename; }
2767cdf0e10cSrcweir
2768cdf0e10cSrcweir			@pathcollector = ();
2769cdf0e10cSrcweir			$startnumber = $startnumber + $max;
2770cdf0e10cSrcweir			$counter = 0;
2771cdf0e10cSrcweir		}
2772cdf0e10cSrcweir	}
2773cdf0e10cSrcweir
2774cdf0e10cSrcweir	# Checking existence fo cyg_sourcepath for every file
2775cdf0e10cSrcweir	for ( my $i = 0; $i <= $#{$filesref}; $i++ )
2776cdf0e10cSrcweir	{
2777cdf0e10cSrcweir		if (( ! exists(${$filesref}[$i]->{'cyg_sourcepath'}) ) || ( ${$filesref}[$i]->{'cyg_sourcepath'} eq "" ))
2778cdf0e10cSrcweir		{
2779cdf0e10cSrcweir			$infoline = "ERROR: No cygwin sourcepath defined for file ${$filesref}[$i]->{'sourcepath'}\n";
2780b274bc22SAndre Fischer			$installer::logger::Lang->print($infoline);
2781cdf0e10cSrcweir			installer::exiter::exit_program("ERROR: No cygwin sourcepath defined for file ${$filesref}[$i]->{'sourcepath'}!", "generate_cygwin_pathes");
2782cdf0e10cSrcweir		}
2783cdf0e10cSrcweir	}
2784cdf0e10cSrcweir
278586e1cf34SPedro Giffuni	$installer::logger::Lang->add_timestamp("Ending generating cygwin paths");
2786cdf0e10cSrcweir}
2787cdf0e10cSrcweir
2788cdf0e10cSrcweir##############################################
2789cdf0e10cSrcweir# Include only files from install directory
2790cdf0e10cSrcweir# in pkgmap file.
2791cdf0e10cSrcweir##############################################
2792cdf0e10cSrcweir
2793cdf0e10cSrcweirsub filter_pkgmapfile
2794cdf0e10cSrcweir{
2795cdf0e10cSrcweir	my ($pkgmapfile) = @_;
2796cdf0e10cSrcweir
2797cdf0e10cSrcweir	my @pkgmap = ();
2798cdf0e10cSrcweir
2799cdf0e10cSrcweir	my $line = ": 1 10\n";
2800cdf0e10cSrcweir	push(@pkgmap, $line);
2801cdf0e10cSrcweir
2802cdf0e10cSrcweir	for ( my $i = 0; $i <= $#{$pkgmapfile}; $i++ )
2803cdf0e10cSrcweir	{
2804cdf0e10cSrcweir		$line = ${$pkgmapfile}[$i];
2805cdf0e10cSrcweir		if ( $line =~ /^\s*1\si\s/ ) { push(@pkgmap, $line); }
2806cdf0e10cSrcweir	}
2807cdf0e10cSrcweir
2808cdf0e10cSrcweir	return \@pkgmap;
2809cdf0e10cSrcweir}
2810cdf0e10cSrcweir
2811cdf0e10cSrcweir##############################################
2812cdf0e10cSrcweir# Creating double packages for Solaris x86.
2813cdf0e10cSrcweir# One package with ARCH=i386 and one with
2814cdf0e10cSrcweir# ARCH=i86pc.
2815cdf0e10cSrcweir##############################################
2816cdf0e10cSrcweir
2817cdf0e10cSrcweirsub fix_solaris_x86_patch
2818cdf0e10cSrcweir{
2819cdf0e10cSrcweir	my ($packagename, $subdir) = @_;
2820cdf0e10cSrcweir
2821cdf0e10cSrcweir	# changing into directory of packages, important for soft linking
2822cdf0e10cSrcweir	my $startdir = cwd();
2823cdf0e10cSrcweir	chdir($subdir);
2824cdf0e10cSrcweir
2825cdf0e10cSrcweir	# $packagename is: "SUNWstaroffice-core01"
2826cdf0e10cSrcweir	# Current working directory is: "<path>/install/en-US_inprogress"
2827cdf0e10cSrcweir
2828cdf0e10cSrcweir	# create new folder in "packages": $packagename . ".i"
2829cdf0e10cSrcweir	my $newpackagename = $packagename . "\.i";
2830cdf0e10cSrcweir	my $newdir = $newpackagename;
2831cdf0e10cSrcweir	installer::systemactions::create_directory($newdir);
2832cdf0e10cSrcweir
2833cdf0e10cSrcweir	# collecting all directories in the package
2834cdf0e10cSrcweir	my $olddir = $packagename;
2835cdf0e10cSrcweir	my $allsubdirs = installer::systemactions::get_all_directories_without_path($olddir);
2836cdf0e10cSrcweir
2837cdf0e10cSrcweir	# link all directories from $packagename to $packagename . ".i"
2838cdf0e10cSrcweir	for ( my $i = 0; $i <= $#{$allsubdirs}; $i++ )
2839cdf0e10cSrcweir	{
2840cdf0e10cSrcweir		my $sourcedir = $olddir . $installer::globals::separator . ${$allsubdirs}[$i];
2841cdf0e10cSrcweir		my $destdir = $newdir . $installer::globals::separator . ${$allsubdirs}[$i];
2842cdf0e10cSrcweir		my $directory_depth = 2; # important for soft links, two directories already exist
2843cdf0e10cSrcweir		installer::systemactions::softlink_complete_directory($sourcedir, $destdir, $directory_depth);
2844cdf0e10cSrcweir	}
2845cdf0e10cSrcweir
2846cdf0e10cSrcweir	# copy "pkginfo" and "pkgmap" from $packagename to $packagename . ".i"
2847cdf0e10cSrcweir	my @allcopyfiles = ("pkginfo", "pkgmap");
2848cdf0e10cSrcweir	for ( my $i = 0; $i <= $#allcopyfiles; $i++ )
2849cdf0e10cSrcweir	{
2850cdf0e10cSrcweir		my $sourcefile = $olddir . $installer::globals::separator . $allcopyfiles[$i];
2851cdf0e10cSrcweir		my $destfile = $newdir . $installer::globals::separator . $allcopyfiles[$i];
2852cdf0e10cSrcweir		installer::systemactions::copy_one_file($sourcefile, $destfile);
2853cdf0e10cSrcweir	}
2854cdf0e10cSrcweir
2855cdf0e10cSrcweir	# change in pkginfo in $packagename . ".i" the value for ARCH from i386 to i86pc
2856cdf0e10cSrcweir	my $pkginfofilename = "pkginfo";
2857cdf0e10cSrcweir	$pkginfofilename = $newdir . $installer::globals::separator . $pkginfofilename;
2858cdf0e10cSrcweir
2859cdf0e10cSrcweir	my $pkginfofile = installer::files::read_file($pkginfofilename);
2860cdf0e10cSrcweir	set_old_architecture_string($pkginfofile);
2861cdf0e10cSrcweir	installer::files::save_file($pkginfofilename, $pkginfofile);
2862cdf0e10cSrcweir
2863cdf0e10cSrcweir	# adapt the values in pkgmap for pkginfo file, because this file was edited
2864cdf0e10cSrcweir	my $pkgmapfilename = "pkgmap";
2865cdf0e10cSrcweir	$pkgmapfilename = $newdir . $installer::globals::separator . $pkgmapfilename;
2866cdf0e10cSrcweir
2867cdf0e10cSrcweir	my $pkgmapfile = installer::files::read_file($pkgmapfilename);
2868cdf0e10cSrcweir	set_pkginfo_line($pkgmapfile, $pkginfofilename);
2869cdf0e10cSrcweir	installer::files::save_file($pkgmapfilename, $pkgmapfile);
2870cdf0e10cSrcweir
2871cdf0e10cSrcweir	# changing back to startdir
2872cdf0e10cSrcweir	chdir($startdir);
2873cdf0e10cSrcweir}
2874cdf0e10cSrcweir
2875cdf0e10cSrcweir###################################################
2876cdf0e10cSrcweir# Creating double core01 package for Solaris x86.
2877cdf0e10cSrcweir# One package with ARCH=i386 and one with
2878cdf0e10cSrcweir# ARCH=i86pc. This is necessary, to inform the
2879cdf0e10cSrcweir# user about the missing "small patch", if
2880cdf0e10cSrcweir# packages with ARCH=i86pc are installed.
2881cdf0e10cSrcweir###################################################
2882cdf0e10cSrcweir
2883cdf0e10cSrcweirsub fix2_solaris_x86_patch
2884cdf0e10cSrcweir{
2885cdf0e10cSrcweir	my ($packagename, $subdir) = @_;
2886cdf0e10cSrcweir
2887cdf0e10cSrcweir	if ( $packagename =~ /-core01\s*$/ )	# only this one package needs to be duplicated
2888cdf0e10cSrcweir	{
2889cdf0e10cSrcweir		my $startdir = cwd();
2890cdf0e10cSrcweir		chdir($subdir);
2891cdf0e10cSrcweir
2892cdf0e10cSrcweir		# $packagename is: "SUNWstaroffice-core01"
2893cdf0e10cSrcweir		# Current working directory is: "<path>/install/en-US_inprogress"
2894cdf0e10cSrcweir
2895cdf0e10cSrcweir		# create new package in "packages": $packagename . ".i"
2896cdf0e10cSrcweir		my $olddir = $packagename;
2897cdf0e10cSrcweir		my $newpackagename = $packagename . "\.i";
2898cdf0e10cSrcweir		my $newdir = $newpackagename;
2899cdf0e10cSrcweir
2900cdf0e10cSrcweir		installer::systemactions::create_directory($newdir);
2901cdf0e10cSrcweir
2902cdf0e10cSrcweir		my $oldinstalldir = $olddir . $installer::globals::separator . "install";
2903cdf0e10cSrcweir		my $newinstalldir = $newdir . $installer::globals::separator . "install";
2904cdf0e10cSrcweir
2905cdf0e10cSrcweir		installer::systemactions::copy_complete_directory($oldinstalldir, $newinstalldir);
2906cdf0e10cSrcweir
2907cdf0e10cSrcweir		# setting time stamp of all copied files to avoid errors from pkgchk
2908cdf0e10cSrcweir		my $allinstallfiles = installer::systemactions::get_all_files_from_one_directory_without_path($newinstalldir);
2909cdf0e10cSrcweir		set_time_stamp($oldinstalldir, $newinstalldir, $allinstallfiles);
2910cdf0e10cSrcweir
2911cdf0e10cSrcweir		# copy "pkginfo" and "pkgmap" from $packagename to $packagename . ".i"
2912cdf0e10cSrcweir		my @allcopyfiles = ("pkginfo", "pkgmap");
2913cdf0e10cSrcweir		for ( my $i = 0; $i <= $#allcopyfiles; $i++ )
2914cdf0e10cSrcweir		{
2915cdf0e10cSrcweir			my $sourcefile = $olddir . $installer::globals::separator . $allcopyfiles[$i];
2916cdf0e10cSrcweir			my $destfile = $newdir . $installer::globals::separator . $allcopyfiles[$i];
2917cdf0e10cSrcweir			installer::systemactions::copy_one_file($sourcefile, $destfile);
2918cdf0e10cSrcweir		}
2919cdf0e10cSrcweir
2920cdf0e10cSrcweir		# change in pkginfo in $packagename . ".i" the value for ARCH from i386 to i86pc
2921cdf0e10cSrcweir		my $pkginfofilename = "pkginfo";
2922cdf0e10cSrcweir		$pkginfofilename = $newdir . $installer::globals::separator . $pkginfofilename;
2923cdf0e10cSrcweir
2924cdf0e10cSrcweir		my $pkginfofile = installer::files::read_file($pkginfofilename);
2925cdf0e10cSrcweir		set_old_architecture_string($pkginfofile);
2926cdf0e10cSrcweir		check_requires_setting($pkginfofile);
2927cdf0e10cSrcweir		installer::files::save_file($pkginfofilename, $pkginfofile);
2928cdf0e10cSrcweir
2929cdf0e10cSrcweir		# adapt the values in pkgmap for pkginfo file, because this file was edited
2930cdf0e10cSrcweir		my $pkgmapfilename = "pkgmap";
2931cdf0e10cSrcweir		$pkgmapfilename = $newdir . $installer::globals::separator . $pkgmapfilename;
2932cdf0e10cSrcweir
2933cdf0e10cSrcweir		my $pkgmapfile = installer::files::read_file($pkgmapfilename);
2934cdf0e10cSrcweir		set_pkginfo_line($pkgmapfile, $pkginfofilename);
2935cdf0e10cSrcweir		$pkgmapfile = filter_pkgmapfile($pkgmapfile);
2936cdf0e10cSrcweir		installer::files::save_file($pkgmapfilename, $pkgmapfile);
2937cdf0e10cSrcweir
2938cdf0e10cSrcweir		# setting time stamp of all copied files to avoid errors from pkgchk
2939cdf0e10cSrcweir		set_time_stamp($olddir, $newdir, \@allcopyfiles);
2940cdf0e10cSrcweir
2941cdf0e10cSrcweir		# changing back to startdir
2942cdf0e10cSrcweir		chdir($startdir);
2943cdf0e10cSrcweir	}
2944cdf0e10cSrcweir}
2945cdf0e10cSrcweir
2946cdf0e10cSrcweir################################################
2947cdf0e10cSrcweir# Files with flag HIDDEN get a dot at the
2948cdf0e10cSrcweir# beginning of the file name. This cannot be
2949cdf0e10cSrcweir# defined in scp2 project, because tooling
2950cdf0e10cSrcweir# cannot handle files with beginning dot
2951cdf0e10cSrcweir# correctly.
2952cdf0e10cSrcweir################################################
2953cdf0e10cSrcweir
2954cdf0e10cSrcweirsub resolving_hidden_flag
2955cdf0e10cSrcweir{
2956cdf0e10cSrcweir	my ($filesarrayref, $variableshashref, $item, $languagestringref) = @_;
2957cdf0e10cSrcweir
2958cdf0e10cSrcweir	my $diritem = lc($item);
2959cdf0e10cSrcweir	my $infoline = "";
2960cdf0e10cSrcweir
2961cdf0e10cSrcweir	my $hiddendirbase = installer::systemactions::create_directories("hidden_$diritem", $languagestringref);
2962cdf0e10cSrcweir
2963cdf0e10cSrcweir	installer::logger::include_header_into_logfile("$item with flag HIDDEN:");
2964cdf0e10cSrcweir
2965cdf0e10cSrcweir	for ( my $i = 0; $i <= $#{$filesarrayref}; $i++ )
2966cdf0e10cSrcweir	{
2967cdf0e10cSrcweir		my $onefile = ${$filesarrayref}[$i];
2968cdf0e10cSrcweir		my $styles = "";
2969cdf0e10cSrcweir
2970cdf0e10cSrcweir		if ( $onefile->{'Styles'} ) { $styles = $onefile->{'Styles'}; }
2971cdf0e10cSrcweir
2972cdf0e10cSrcweir		if ( $styles =~ /\bHIDDEN\b/ )
2973cdf0e10cSrcweir		{
2974cdf0e10cSrcweir			# Language specific subdirectory
2975cdf0e10cSrcweir
2976cdf0e10cSrcweir			my $onelanguage = $onefile->{'specificlanguage'};
2977cdf0e10cSrcweir
2978cdf0e10cSrcweir			if ($onelanguage eq "")
2979cdf0e10cSrcweir			{
2980cdf0e10cSrcweir				$onelanguage = "00";	# files without language into directory "00"
2981cdf0e10cSrcweir			}
2982cdf0e10cSrcweir
2983cdf0e10cSrcweir			my $hiddendir = $hiddendirbase . $installer::globals::separator . $onelanguage . $installer::globals::separator;
2984cdf0e10cSrcweir			installer::systemactions::create_directory($hiddendir);	# creating language specific directories
2985cdf0e10cSrcweir
2986cdf0e10cSrcweir			# copy files and edit them with the variables defined in the zip.lst
2987cdf0e10cSrcweir
2988cdf0e10cSrcweir			my $onefilename = $onefile->{'Name'};
2989cdf0e10cSrcweir			my $newfilename = "\." . $onefilename;
2990cdf0e10cSrcweir			my $sourcefile = $onefile->{'sourcepath'};
2991cdf0e10cSrcweir			my $destfile = $hiddendir . $newfilename;
2992cdf0e10cSrcweir
2993cdf0e10cSrcweir			my $copysuccess = installer::systemactions::copy_one_file($sourcefile, $destfile);
2994cdf0e10cSrcweir
2995cdf0e10cSrcweir			if ( $copysuccess )
2996cdf0e10cSrcweir			{
2997cdf0e10cSrcweir				# $onefile->{'Name'} = $newfilename;
2998cdf0e10cSrcweir				$onefile->{'sourcepath'} = $destfile;
2999cdf0e10cSrcweir				$destination = $onefile->{'destination'};
3000cdf0e10cSrcweir				installer::pathanalyzer::get_path_from_fullqualifiedname(\$destination);
3001cdf0e10cSrcweir				if ( $destination eq "" ) { $onefile->{'destination'} = $newfilename; }
3002cdf0e10cSrcweir				else { $onefile->{'destination'} = $destination . $installer::globals::separator . $newfilename; }
3003cdf0e10cSrcweir
3004cdf0e10cSrcweir				$infoline = "Success: Using file with flag HIDDEN from \"$onefile->{'sourcepath'}\"!\n";
3005b274bc22SAndre Fischer				$installer::logger::Lang->print($infoline);
3006cdf0e10cSrcweir			}
3007cdf0e10cSrcweir			else
3008cdf0e10cSrcweir			{
3009cdf0e10cSrcweir				$infoline = "Error: Failed to copy HIDDEN file from \"$sourcefile\" to \"$destfile\"!\n";
3010b274bc22SAndre Fischer				$installer::logger::Lang->print($infoline);
3011cdf0e10cSrcweir			}
3012cdf0e10cSrcweir		}
3013cdf0e10cSrcweir	}
3014cdf0e10cSrcweir
3015cdf0e10cSrcweir	$infoline = "\n";
3016b274bc22SAndre Fischer	$installer::logger::Lang->print($infoline);
3017cdf0e10cSrcweir}
3018cdf0e10cSrcweir
3019cdf0e10cSrcweir################################################
3020cdf0e10cSrcweir# Controlling that all keys in hash A are
3021cdf0e10cSrcweir# also key in hash B.
3022cdf0e10cSrcweir################################################
3023cdf0e10cSrcweir
3024cdf0e10cSrcweirsub key_in_a_is_also_key_in_b
3025cdf0e10cSrcweir{
3026cdf0e10cSrcweir	my ( $hashref_a, $hashref_b) = @_;
3027cdf0e10cSrcweir
3028cdf0e10cSrcweir	my $returnvalue = 1;
3029cdf0e10cSrcweir
3030cdf0e10cSrcweir	my $key;
3031cdf0e10cSrcweir	foreach $key ( keys %{$hashref_a} )
3032cdf0e10cSrcweir	{
3033cdf0e10cSrcweir		if ( ! exists($hashref_b->{$key}) )
3034cdf0e10cSrcweir		{
3035cdf0e10cSrcweir			print "*****\n";
3036cdf0e10cSrcweir			foreach $keyb ( keys %{$hashref_b} ) { print "$keyb : $hashref_b->{$keyb}\n"; }
3037cdf0e10cSrcweir			print "*****\n";
3038cdf0e10cSrcweir			$returnvalue = 0;
3039cdf0e10cSrcweir		}
3040cdf0e10cSrcweir	}
3041cdf0e10cSrcweir
3042cdf0e10cSrcweir	return $returnvalue;
3043cdf0e10cSrcweir}
3044cdf0e10cSrcweir
3045cdf0e10cSrcweir######################################################
3046cdf0e10cSrcweir# Getting the first entry from a list of languages
3047cdf0e10cSrcweir######################################################
3048cdf0e10cSrcweir
3049cdf0e10cSrcweirsub get_first_from_list
3050cdf0e10cSrcweir{
3051cdf0e10cSrcweir	my ( $list ) = @_;
3052cdf0e10cSrcweir
3053cdf0e10cSrcweir	my $first = $list;
3054cdf0e10cSrcweir
3055cdf0e10cSrcweir	if ( $list =~ /^\s*(.+?),(.+)\s*$/)	# "?" for minimal matching
3056cdf0e10cSrcweir	{
3057cdf0e10cSrcweir		$first = $1;
3058cdf0e10cSrcweir	}
3059cdf0e10cSrcweir
3060cdf0e10cSrcweir	return $first;
3061cdf0e10cSrcweir}
3062cdf0e10cSrcweir
3063cdf0e10cSrcweir################################################
3064cdf0e10cSrcweir# Setting all spellchecker languages
3065cdf0e10cSrcweir################################################
3066cdf0e10cSrcweir
3067cdf0e10cSrcweirsub set_spellcheckerlanguages
3068cdf0e10cSrcweir{
3069cdf0e10cSrcweir	my ( $productlanguagesarrayref, $allvariables ) = @_;
3070cdf0e10cSrcweir
3071cdf0e10cSrcweir	my %productlanguages = ();
3072cdf0e10cSrcweir	for ( my $i = 0; $i <= $#{$productlanguagesarrayref}; $i++ ) { $productlanguages{${$productlanguagesarrayref}[$i]} = 1;  }
3073cdf0e10cSrcweir
3074cdf0e10cSrcweir	my $spellcheckfilename = $allvariables->{'SPELLCHECKERFILE'};
3075cdf0e10cSrcweir
3076cdf0e10cSrcweir	my $spellcheckfileref = installer::scriptitems::get_sourcepath_from_filename_and_includepath(\$spellcheckfilename, "", 1);
3077cdf0e10cSrcweir
3078cdf0e10cSrcweir	if ($$spellcheckfileref eq "") { installer::exiter::exit_program("ERROR: Could not find $spellcheckfilename!", "set_spellcheckerlanguages"); }
3079cdf0e10cSrcweir
3080b274bc22SAndre Fischer    $installer::logger::Global->printf("Using spellchecker file: %s\n", $$spellcheckfileref);
3081cdf0e10cSrcweir
3082cdf0e10cSrcweir	my $spellcheckfile = installer::files::read_file($$spellcheckfileref);
3083cdf0e10cSrcweir	my %spellcheckhash = ();
3084cdf0e10cSrcweir
3085cdf0e10cSrcweir	for ( my $j = 0; $j <= $#{$spellcheckfile}; $j++ )
3086cdf0e10cSrcweir	{
3087cdf0e10cSrcweir		# Analyzing all "key=value" lines
3088cdf0e10cSrcweir		my $oneline = ${$spellcheckfile}[$j];
3089cdf0e10cSrcweir
3090cdf0e10cSrcweir		if ( $oneline =~ /^\s*(\S+)\s*\=\s*\"(.*?)\"\s*$/ )	# no white space allowed in key
3091cdf0e10cSrcweir		{
3092cdf0e10cSrcweir			my $onelang = $1;
3093cdf0e10cSrcweir			my $languagelist = $2;
3094cdf0e10cSrcweir
3095cdf0e10cSrcweir			# Special handling for language packs. Only include the first language of the language list.
3096cdf0e10cSrcweir			# If no spellchecker shall be included, the keyword "EMPTY" can be used.
3097cdf0e10cSrcweir
3098cdf0e10cSrcweir			if ( $installer::globals::languagepack )
3099cdf0e10cSrcweir			{
3100cdf0e10cSrcweir				my $first = get_first_from_list($languagelist);
3101cdf0e10cSrcweir
3102cdf0e10cSrcweir				if ( $first eq "EMPTY" )	 # no spellchecker into language pack
3103cdf0e10cSrcweir				{
3104cdf0e10cSrcweir					$languagelist = "";
3105cdf0e10cSrcweir				}
3106cdf0e10cSrcweir				else
3107cdf0e10cSrcweir				{
3108cdf0e10cSrcweir					$languagelist = $first;
3109cdf0e10cSrcweir				}
3110cdf0e10cSrcweir			}
3111cdf0e10cSrcweir			else  # no language pack, so EMPTY is not required
3112cdf0e10cSrcweir			{
3113cdf0e10cSrcweir				$languagelist =~ s/^\s*EMPTY\s*,//;	# removing the entry EMPTY
3114cdf0e10cSrcweir			}
3115cdf0e10cSrcweir
3116cdf0e10cSrcweir			$spellcheckhash{$onelang} = $languagelist;
3117cdf0e10cSrcweir		}
3118cdf0e10cSrcweir	}
3119cdf0e10cSrcweir
3120cdf0e10cSrcweir	# Collecting all required languages in %installer::globals::spellcheckerlanguagehash
3121cdf0e10cSrcweir
3122cdf0e10cSrcweir	foreach my $lang (keys %productlanguages)
3123cdf0e10cSrcweir	{
3124cdf0e10cSrcweir		my $languagelist = "";
3125cdf0e10cSrcweir		if ( exists($spellcheckhash{$lang}) ) { $languagelist = $spellcheckhash{$lang}; }
3126cdf0e10cSrcweir		else { $languagelist = $spellcheckhash{'en-US'}; }	# defaulting to English
3127cdf0e10cSrcweir
3128cdf0e10cSrcweir		my $langlisthash = installer::converter::convert_stringlist_into_hash(\$languagelist, ",");
3129cdf0e10cSrcweir		foreach my $onelang ( keys %{$langlisthash} ) { $installer::globals::spellcheckerlanguagehash{$onelang} = 1; }
3130cdf0e10cSrcweir	}
3131cdf0e10cSrcweir
3132cdf0e10cSrcweir	$installer::globals::analyze_spellcheckerlanguage = 1;
3133cdf0e10cSrcweir
3134cdf0e10cSrcweir	# Logging
3135cdf0e10cSrcweir
3136cdf0e10cSrcweir	my $langstring = "";
3137cdf0e10cSrcweir	foreach my $lang (sort keys %installer::globals::spellcheckerlanguagehash) { $langstring = $langstring . "," . $lang }
3138cdf0e10cSrcweir	$langstring =~ s/^\s*,//;
3139b274bc22SAndre Fischer
3140b274bc22SAndre Fischer    $installer::logger::Global->printf("Collected spellchecker languages for spellchecker: %s\n", $langstring);
3141cdf0e10cSrcweir}
3142cdf0e10cSrcweir
3143cdf0e10cSrcweir################################################
3144cdf0e10cSrcweir# Including a license text into setup script
3145cdf0e10cSrcweir################################################
3146cdf0e10cSrcweir
3147cdf0e10cSrcweirsub put_license_into_setup
3148cdf0e10cSrcweir{
3149cdf0e10cSrcweir	my ($installdir, $includepatharrayref) = @_;
3150cdf0e10cSrcweir
3151b14cb721SHerbert Dürr	# find and read the license file
3152cdf0e10cSrcweir	my $licenselanguage = "en-US";					# always english !
3153b14cb721SHerbert Dürr	my $licensefilename = "LICENSE";
3154b14cb721SHerbert Dürr#	my $licensefilename = "LICENSE" . ".txt";
3155cdf0e10cSrcweir	my $licenseincludepatharrayref = get_language_specific_include_pathes($includepatharrayref, $licenselanguage);
3156cdf0e10cSrcweir
3157cdf0e10cSrcweir	my $licenseref = installer::scriptitems::get_sourcepath_from_filename_and_includepath(\$licensefilename, $licenseincludepatharrayref, 0);
3158cdf0e10cSrcweir	if ($$licenseref eq "") { installer::exiter::exit_program("ERROR: Could not find License file $licensefilename!", "put_license_into_setup"); }
3159cdf0e10cSrcweir	my $licensefile = installer::files::read_file($$licenseref);
3160cdf0e10cSrcweir
3161cdf0e10cSrcweir	# Read setup
3162cdf0e10cSrcweir	my $setupfilename = $installdir . $installer::globals::separator . "setup";
3163cdf0e10cSrcweir	my $setupfile = installer::files::read_file($setupfilename);
3164cdf0e10cSrcweir
3165cdf0e10cSrcweir	# Replacement
3166cdf0e10cSrcweir	my $infoline = "Adding licensefile into setup script\n";
3167b274bc22SAndre Fischer	$installer::logger::Lang->print($infoline);
3168cdf0e10cSrcweir
3169cdf0e10cSrcweir	my $includestring = "";
3170cdf0e10cSrcweir	for ( my $i = 0; $i <= $#{$licensefile}; $i++ ) { $includestring = $includestring . ${$licensefile}[$i]; }
3171cdf0e10cSrcweir	for ( my $i = 0; $i <= $#{$setupfile}; $i++ ) { ${$setupfile}[$i] =~ s/LICENSEFILEPLACEHOLDER/$includestring/; }
3172cdf0e10cSrcweir
3173cdf0e10cSrcweir	# Write setup
3174cdf0e10cSrcweir	installer::files::save_file($setupfilename, $setupfile);
3175cdf0e10cSrcweir}
3176cdf0e10cSrcweir
3177cdf0e10cSrcweir################################################
3178cdf0e10cSrcweir# Setting global path to getuid.so library
3179cdf0e10cSrcweir################################################
3180cdf0e10cSrcweir
3181cdf0e10cSrcweirsub set_getuid_path
3182cdf0e10cSrcweir{
3183cdf0e10cSrcweir	my ($includepatharrayref) = @_;
3184cdf0e10cSrcweir
3185cdf0e10cSrcweir	my $getuidlibraryname = "getuid.so";
3186cdf0e10cSrcweir	my $getuidlibraryref = installer::scriptitems::get_sourcepath_from_filename_and_includepath(\$getuidlibraryname, $includepatharrayref, 0);
3187cdf0e10cSrcweir	if ($$getuidlibraryref eq "") { installer::exiter::exit_program("ERROR: Could not find $getuidlibraryname!", "set_getuid_path"); }
3188cdf0e10cSrcweir
3189cdf0e10cSrcweir	$installer::globals::getuidpath = $$getuidlibraryref;
3190cdf0e10cSrcweir	$installer::globals::getuidpathset = 1;
3191cdf0e10cSrcweir}
3192cdf0e10cSrcweir
3193cdf0e10cSrcweir#########################################################
3194cdf0e10cSrcweir# Create a tar file from the binary package
3195cdf0e10cSrcweir#########################################################
3196cdf0e10cSrcweir
3197cdf0e10cSrcweirsub tar_package
3198cdf0e10cSrcweir{
3199cdf0e10cSrcweir	my ( $installdir, $packagename, $tarfilename, $getuidlibrary) = @_;
3200cdf0e10cSrcweir
3201*60203e34SJim Jagielski	my $ldpreloadstring = $ENV{'FAKEROOT'};
3202cdf0e10cSrcweir
3203cdf0e10cSrcweir	my $systemcall = "cd $installdir; $ldpreloadstring tar -cf - $packagename > $tarfilename";
3204cdf0e10cSrcweir	# my $systemcall = "cd $installdir; $ldpreloadstring tar -cf - * > $tarfilename";
3205cdf0e10cSrcweir
3206cdf0e10cSrcweir	my $returnvalue = system($systemcall);
3207cdf0e10cSrcweir
3208cdf0e10cSrcweir	my $infoline = "Systemcall: $systemcall\n";
3209b274bc22SAndre Fischer	$installer::logger::Lang->print($infoline);
3210cdf0e10cSrcweir
3211cdf0e10cSrcweir	if ($returnvalue)
3212cdf0e10cSrcweir	{
3213cdf0e10cSrcweir		$infoline = "ERROR: Could not execute \"$systemcall\"!\n";
3214b274bc22SAndre Fischer		$installer::logger::Lang->print($infoline);
3215cdf0e10cSrcweir	}
3216cdf0e10cSrcweir	else
3217cdf0e10cSrcweir	{
3218cdf0e10cSrcweir		$infoline = "Success: Executed \"$systemcall\" successfully!\n";
3219b274bc22SAndre Fischer		$installer::logger::Lang->print($infoline);
3220cdf0e10cSrcweir	}
3221cdf0e10cSrcweir
3222cdf0e10cSrcweir	my $localcall = "chmod 775 $tarfilename \>\/dev\/null 2\>\&1";
3223cdf0e10cSrcweir	$returnvalue = system($localcall);
3224cdf0e10cSrcweir
3225cdf0e10cSrcweir	my $fulltarfile = $installdir . $installer::globals::separator . $tarfilename;
3226cdf0e10cSrcweir	my $filesize = ( -s $fulltarfile );
3227cdf0e10cSrcweir
3228cdf0e10cSrcweir	return $filesize;
3229cdf0e10cSrcweir}
3230cdf0e10cSrcweir
3231cdf0e10cSrcweir#########################################################
3232cdf0e10cSrcweir# Create a tar file from the binary package
3233cdf0e10cSrcweir#########################################################
3234cdf0e10cSrcweir
3235cdf0e10cSrcweirsub untar_package
3236cdf0e10cSrcweir{
3237cdf0e10cSrcweir	my ( $installdir, $tarfilename, $getuidlibrary) = @_;
3238cdf0e10cSrcweir
3239*60203e34SJim Jagielski	my $ldpreloadstring = $ENV{'FAKEROOT'};
3240cdf0e10cSrcweir
3241cdf0e10cSrcweir	my $systemcall = "cd $installdir; $ldpreloadstring tar -xf $tarfilename";
3242cdf0e10cSrcweir
3243cdf0e10cSrcweir	my $returnvalue = system($systemcall);
3244cdf0e10cSrcweir
3245cdf0e10cSrcweir	my $infoline = "Systemcall: $systemcall\n";
3246b274bc22SAndre Fischer	$installer::logger::Lang->print($infoline);
3247cdf0e10cSrcweir
3248cdf0e10cSrcweir	if ($returnvalue)
3249cdf0e10cSrcweir	{
3250cdf0e10cSrcweir		$infoline = "ERROR: Could not execute \"$systemcall\"!\n";
3251b274bc22SAndre Fischer		$installer::logger::Lang->print($infoline);
3252cdf0e10cSrcweir	}
3253cdf0e10cSrcweir	else
3254cdf0e10cSrcweir	{
3255cdf0e10cSrcweir		$infoline = "Success: Executed \"$systemcall\" successfully!\n";
3256b274bc22SAndre Fischer		$installer::logger::Lang->print($infoline);
3257cdf0e10cSrcweir	}
3258cdf0e10cSrcweir
3259cdf0e10cSrcweir	my $localcall = "chmod 775 $tarfilename \>\/dev\/null 2\>\&1";
3260cdf0e10cSrcweir	$returnvalue = system($localcall);
3261cdf0e10cSrcweir}
3262cdf0e10cSrcweir
3263cdf0e10cSrcweir#########################################################
3264cdf0e10cSrcweir# Shuffle an array (Fisher Yates shuffle)
3265cdf0e10cSrcweir#########################################################
3266cdf0e10cSrcweir
3267cdf0e10cSrcweirsub shuffle_array
3268cdf0e10cSrcweir{
3269cdf0e10cSrcweir	my ( $arrayref ) = @_;
3270cdf0e10cSrcweir
3271cdf0e10cSrcweir	# my $counter = 0;
3272cdf0e10cSrcweir	# my $infoline = "Old package order: \n";
3273b274bc22SAndre Fischer	# $installer::logger::Lang->print($infoline);
3274cdf0e10cSrcweir	# foreach my $onepackage ( @{$arrayref} )
3275cdf0e10cSrcweir	# {
3276cdf0e10cSrcweir	#	$counter++;
3277cdf0e10cSrcweir	#	$infoline = "$counter: $onepackage->{'module'}\n";
3278b274bc22SAndre Fischer	#	$installer::logger::Lang->print($infoline);
3279cdf0e10cSrcweir	# }
3280cdf0e10cSrcweir
3281cdf0e10cSrcweir	my $i = @$arrayref;
3282cdf0e10cSrcweir	while (--$i)
3283cdf0e10cSrcweir	{
3284cdf0e10cSrcweir		my $j = int rand ($i+1);
3285cdf0e10cSrcweir		@$arrayref[$i,$j] = @$arrayref[$j,$i];
3286cdf0e10cSrcweir	}
3287cdf0e10cSrcweir
3288cdf0e10cSrcweir	# $counter = 0;
3289cdf0e10cSrcweir	# $infoline = "New package order: \n";
3290b274bc22SAndre Fischer	# $installer::logger::Lang->print($infoline);
3291cdf0e10cSrcweir	# foreach my $onepackage ( @{$arrayref} )
3292cdf0e10cSrcweir	# {
3293cdf0e10cSrcweir	#	$counter++;
3294cdf0e10cSrcweir	#	$infoline = "$counter: $onepackage->{'module'}\n";
3295b274bc22SAndre Fischer	#	$installer::logger::Lang->print($infoline);
3296cdf0e10cSrcweir	# }
3297cdf0e10cSrcweir}
3298cdf0e10cSrcweir
3299cdf0e10cSrcweir################################################
3300cdf0e10cSrcweir# Defining the English license text to add
3301cdf0e10cSrcweir# it into Solaris packages.
3302cdf0e10cSrcweir################################################
3303cdf0e10cSrcweir
3304cdf0e10cSrcweirsub set_english_license
3305cdf0e10cSrcweir{
3306cdf0e10cSrcweir	my $additional_license_name = $installer::globals::englishsolarislicensename;	# always the English file
3307cdf0e10cSrcweir	my $licensefileref = installer::scriptitems::get_sourcepath_from_filename_and_includepath(\$additional_license_name, "" , 0);
3308cdf0e10cSrcweir	if ( $$licensefileref eq "" ) { installer::exiter::exit_program("ERROR: Could not find license file $additional_license_name!", "set_english_license"); }
3309cdf0e10cSrcweir	$installer::globals::englishlicenseset = 1;
3310cdf0e10cSrcweir	$installer::globals::englishlicense = installer::files::read_file($$licensefileref);
3311cdf0e10cSrcweir	installer::scpzipfiles::replace_all_ziplistvariables_in_file($installer::globals::englishlicense, $variableshashref);
3312cdf0e10cSrcweir}
3313cdf0e10cSrcweir
3314cdf0e10cSrcweir##############################################
3315cdf0e10cSrcweir# Setting time stamp of copied files to avoid
3316cdf0e10cSrcweir# errors from pkgchk.
3317cdf0e10cSrcweir##############################################
3318cdf0e10cSrcweir
3319cdf0e10cSrcweirsub set_time_stamp_for_file
3320cdf0e10cSrcweir{
3321cdf0e10cSrcweir	my ($sourcefile, $destfile) = @_;
3322cdf0e10cSrcweir
3323cdf0e10cSrcweir	my $systemcall = "touch -r $sourcefile $destfile";
3324cdf0e10cSrcweir
3325cdf0e10cSrcweir	my $returnvalue = system($systemcall);
3326cdf0e10cSrcweir
3327cdf0e10cSrcweir	my $infoline = "Systemcall: $systemcall\n";
3328b274bc22SAndre Fischer	$installer::logger::Lang->print($infoline);
3329cdf0e10cSrcweir
3330cdf0e10cSrcweir	if ($returnvalue)
3331cdf0e10cSrcweir	{
3332cdf0e10cSrcweir		$infoline = "ERROR: \"$systemcall\" failed!\n";
3333b274bc22SAndre Fischer		$installer::logger::Lang->print($infoline);
3334cdf0e10cSrcweir	}
3335cdf0e10cSrcweir	else
3336cdf0e10cSrcweir	{
3337cdf0e10cSrcweir		$infoline = "Success: \"$systemcall\" !\n";
3338b274bc22SAndre Fischer		$installer::logger::Lang->print($infoline);
3339cdf0e10cSrcweir	}
3340cdf0e10cSrcweir}
3341cdf0e10cSrcweir
3342cdf0e10cSrcweir##############################################
3343cdf0e10cSrcweir# Setting checksum and wordcount for changed
3344cdf0e10cSrcweir# pkginfo file into pkgmap.
3345cdf0e10cSrcweir##############################################
3346cdf0e10cSrcweir
3347cdf0e10cSrcweirsub change_onefile_in_pkgmap
3348cdf0e10cSrcweir{
3349cdf0e10cSrcweir	my ($pkgmapfile, $fullfilename, $shortfilename) = @_;
3350cdf0e10cSrcweir
3351cdf0e10cSrcweir	# 1 i pkginfo 442 34577 1166716297
3352cdf0e10cSrcweir	# ->
3353cdf0e10cSrcweir	# 1 i pkginfo 443 34737 1166716297
3354cdf0e10cSrcweir	#
3355cdf0e10cSrcweir	# wc -c pkginfo | cut -f6 -d' '  -> 442  (variable)
3356cdf0e10cSrcweir	# sum pkginfo | cut -f1 -d' '  -> 34577  (variable)
3357cdf0e10cSrcweir	# grep 'pkginfo' pkgmap | cut -f6 -d' '  -> 1166716297  (fix)
3358cdf0e10cSrcweir
3359cdf0e10cSrcweir	my $checksum = call_sum($fullfilename);
3360cdf0e10cSrcweir	if ( $checksum =~ /^\s*(\d+)\s+.*$/ ) { $checksum = $1; }
3361cdf0e10cSrcweir
3362cdf0e10cSrcweir	my $wordcount = call_wc($fullfilename);
3363cdf0e10cSrcweir	if ( $wordcount =~ /^\s*(\d+)\s+.*$/ ) { $wordcount = $1; }
3364cdf0e10cSrcweir
3365cdf0e10cSrcweir	for ( my $i = 0; $i <= $#{$pkgmapfile}; $i++ )
3366cdf0e10cSrcweir	{
3367cdf0e10cSrcweir		if ( ${$pkgmapfile}[$i] =~ /(^.*\b\Q$shortfilename\E\b\s+)(\d+)(\s+)(\d+)(\s+)(\d+)(\s*$)/ )
3368cdf0e10cSrcweir		{
3369cdf0e10cSrcweir			my $newline = $1 . $wordcount . $3 . $checksum . $5 . $6 . $7;
3370cdf0e10cSrcweir			${$pkgmapfile}[$i] = $newline;
3371cdf0e10cSrcweir			last;
3372cdf0e10cSrcweir		}
3373cdf0e10cSrcweir	}
3374cdf0e10cSrcweir}
3375cdf0e10cSrcweir
3376cdf0e10cSrcweir################################################
3377cdf0e10cSrcweir# Adding the content of the English license
3378cdf0e10cSrcweir# file into the system integration packages.
3379cdf0e10cSrcweir################################################
3380cdf0e10cSrcweir
3381cdf0e10cSrcweirsub add_license_into_systemintegrationpackages
3382cdf0e10cSrcweir{
3383cdf0e10cSrcweir	my ($destdir, $packages) = @_;
3384cdf0e10cSrcweir
3385cdf0e10cSrcweir	for ( my $i = 0; $i <= $#{$packages}; $i++ )
3386cdf0e10cSrcweir	{
3387cdf0e10cSrcweir		my $copyrightfilename = ${$packages}[$i] . $installer::globals::separator . "install" . $installer::globals::separator . "copyright";
3388cdf0e10cSrcweir		if ( ! -f $copyrightfilename ) { installer::exiter::exit_program("ERROR: Could not find license file in system integration package: $copyrightfilename!", "add_license_into_systemintegrationpackages"); }
3389cdf0e10cSrcweir		my $copyrightfile = installer::files::read_file($copyrightfilename);
3390cdf0e10cSrcweir
3391cdf0e10cSrcweir		# Saving time stamp of old copyrightfile
3392cdf0e10cSrcweir		my $savcopyrightfilename = $copyrightfilename . ".sav";
3393cdf0e10cSrcweir		installer::systemactions::copy_one_file($copyrightfilename, $savcopyrightfilename);
3394cdf0e10cSrcweir		set_time_stamp_for_file($copyrightfilename, $savcopyrightfilename); # now $savcopyrightfile has the time stamp of $copyrightfile
3395cdf0e10cSrcweir
3396cdf0e10cSrcweir		# Adding license content to copyright file
3397cdf0e10cSrcweir		push(@{$copyrightfile}, "\n");
3398cdf0e10cSrcweir		for ( my $i = 0; $i <= $#{$installer::globals::englishlicense}; $i++ ) { push(@{$copyrightfile}, ${$installer::globals::englishlicense}[$i]); }
3399cdf0e10cSrcweir		installer::files::save_file($copyrightfilename, $copyrightfile);
3400cdf0e10cSrcweir
3401cdf0e10cSrcweir		# Setting the old time stamp saved with $savcopyrightfilename
3402cdf0e10cSrcweir		set_time_stamp_for_file($savcopyrightfilename, $copyrightfilename); # now $copyrightfile has the time stamp of $savcopyrightfile
3403cdf0e10cSrcweir		unlink($savcopyrightfilename);
3404cdf0e10cSrcweir
3405cdf0e10cSrcweir		# Changing content of copyright file in pkgmap
3406cdf0e10cSrcweir		my $pkgmapfilename = ${$packages}[$i] . $installer::globals::separator . "pkgmap";
3407cdf0e10cSrcweir		if ( ! -f $pkgmapfilename ) { installer::exiter::exit_program("ERROR: Could not find pkgmap in system integration package: $pkgmapfilename!", "add_license_into_systemintegrationpackages"); }
3408cdf0e10cSrcweir		my $pkgmap = installer::files::read_file($pkgmapfilename);
3409cdf0e10cSrcweir		change_onefile_in_pkgmap($pkgmap, $copyrightfilename, "copyright");
3410cdf0e10cSrcweir		installer::files::save_file($pkgmapfilename, $pkgmap);
3411cdf0e10cSrcweir	}
3412cdf0e10cSrcweir}
3413cdf0e10cSrcweir
3414cdf0e10cSrcweir#########################################################
3415cdf0e10cSrcweir# Collecting all pkgmap files from an installation set
3416cdf0e10cSrcweir#########################################################
3417cdf0e10cSrcweir
3418cdf0e10cSrcweirsub collectpackagemaps
3419cdf0e10cSrcweir{
3420cdf0e10cSrcweir	my ( $installdir, $languagestringref, $allvariables ) = @_;
3421cdf0e10cSrcweir
3422cdf0e10cSrcweir	installer::logger::include_header_into_logfile("Collecing all packagemaps (pkgmap):");
3423cdf0e10cSrcweir
3424cdf0e10cSrcweir	my $pkgmapdir = installer::systemactions::create_directories("pkgmap", $languagestringref);
3425cdf0e10cSrcweir	my $subdirname = $allvariables->{'UNIXPRODUCTNAME'} . "_pkgmaps";
3426cdf0e10cSrcweir	my $pkgmapsubdir = $pkgmapdir . $installer::globals::separator . $subdirname;
3427cdf0e10cSrcweir	if ( -d $pkgmapsubdir ) { installer::systemactions::remove_complete_directory($pkgmapsubdir); }
3428cdf0e10cSrcweir	if ( ! -d $pkgmapsubdir ) { installer::systemactions::create_directory($pkgmapsubdir); }
3429cdf0e10cSrcweir
3430cdf0e10cSrcweir	$installdir =~ s/\/\s*$//;
3431cdf0e10cSrcweir	# Collecting all packages in $installdir and its sub package ("packages")
3432cdf0e10cSrcweir	my $searchdir = $installdir . $installer::globals::separator . $installer::globals::epmoutpath;
3433cdf0e10cSrcweir
3434cdf0e10cSrcweir	my $allpackages = installer::systemactions::get_all_directories_without_path($searchdir);
3435cdf0e10cSrcweir
3436cdf0e10cSrcweir	for ( my $i = 0; $i <= $#{$allpackages}; $i++ )
3437cdf0e10cSrcweir	{
3438cdf0e10cSrcweir		my $pkgmapfile = $searchdir . $installer::globals::separator . ${$allpackages}[$i] . $installer::globals::separator . "pkgmap";
3439cdf0e10cSrcweir		my $destfilename = $pkgmapsubdir . $installer::globals::separator . ${$allpackages}[$i] . "_pkgmap";
3440cdf0e10cSrcweir		installer::systemactions::copy_one_file($pkgmapfile, $destfilename);
3441cdf0e10cSrcweir	}
3442cdf0e10cSrcweir
3443cdf0e10cSrcweir	# Create a tar gz file with all package maps
3444cdf0e10cSrcweir	my $tarfilename = $subdirname . ".tar";
3445cdf0e10cSrcweir	my $targzname = $tarfilename . ".gz";
3446cdf0e10cSrcweir	# my $systemcall = "cd $pkgmapdir; tar -cf - $subdirname > $tarfilename";
3447cdf0e10cSrcweir	$systemcall = "cd $pkgmapdir; tar -cf - $subdirname | gzip > $targzname";
3448cdf0e10cSrcweir	make_systemcall($systemcall);
3449cdf0e10cSrcweir	installer::systemactions::remove_complete_directory($pkgmapsubdir, 1);
3450cdf0e10cSrcweir}
3451cdf0e10cSrcweir
3452cdf0e10cSrcweir1;
3453