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