Update ooo320-m1
[ooovba.git] / solenv / bin / modules / installer / setupscript.pm
bloba058807bd8a6a002981677fab24a723a71daee6e
1 #*************************************************************************
3 # DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 #
5 # Copyright 2008 by Sun Microsystems, Inc.
7 # OpenOffice.org - a multi-platform office productivity suite
9 # $RCSfile: setupscript.pm,v $
11 # $Revision: 1.19 $
13 # This file is part of OpenOffice.org.
15 # OpenOffice.org is free software: you can redistribute it and/or modify
16 # it under the terms of the GNU Lesser General Public License version 3
17 # only, as published by the Free Software Foundation.
19 # OpenOffice.org is distributed in the hope that it will be useful,
20 # but WITHOUT ANY WARRANTY; without even the implied warranty of
21 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 # GNU Lesser General Public License version 3 for more details
23 # (a copy is included in the LICENSE file that accompanied this code).
25 # You should have received a copy of the GNU Lesser General Public License
26 # version 3 along with OpenOffice.org. If not, see
27 # <http://www.openoffice.org/license.html>
28 # for a copy of the LGPLv3 License.
30 #*************************************************************************
32 package installer::setupscript;
34 use installer::existence;
35 use installer::exiter;
36 use installer::globals;
37 use installer::logger;
38 use installer::remover;
39 use installer::scriptitems;
40 use installer::ziplist;
42 #######################################################
43 # Set setup script name, if not defined as parameter
44 #######################################################
46 sub set_setupscript_name
48 my ( $allsettingsarrayref, $includepatharrayref ) = @_;
50 my $scriptnameref = installer::ziplist::getinfofromziplist($allsettingsarrayref, "script");
52 my $scriptname = $$scriptnameref;
54 if ( $scriptname eq "" ) # not defined on command line and not in product list
56 installer::exiter::exit_program("ERROR: Setup script not defined on command line (-l) and not in product list!", "set_setupscript_name");
59 if ( $installer::globals::compiler =~ /wnt/ )
61 $scriptname .= ".inf";
63 else
65 $scriptname .= ".ins";
68 # and now the complete path for the setup script is needed
69 # The log file cannot be used, because this is the language independent section
71 $scriptnameref = installer::scriptitems::get_sourcepath_from_filename_and_includepath(\$scriptname, $includepatharrayref, 1);
73 $installer::globals::setupscriptname = $$scriptnameref;
75 if ( $installer::globals::setupscriptname eq "" )
77 installer::exiter::exit_program("ERROR: Script $scriptname not found!", "set_setupscript_name");
81 #####################################################################
82 # Reading script variables from installation object of script file
83 #####################################################################
85 sub get_all_scriptvariables_from_installation_object
87 my ($scriptref) = @_;
89 my @installobjectvariables;
91 for ( my $i = 0; $i <= $#{$scriptref}; $i++ )
93 my $line = ${$scriptref}[$i];
95 if ( $line =~ /^\s*Installation\s+\w+\s*$/ ) # should be the first line
97 my $counter = $i+1;
98 my $installline = ${$scriptref}[$counter];
100 while (!($installline =~ /^\s*End\s*$/ ))
102 if ( $installline =~ /^\s*(\w+)\s+\=\s*(.*?)\s*\;\s*$/ )
104 my $key = $1;
105 my $value = $2;
107 # removing leading and ending " in $value
109 if ( $value =~ /^\s*\"(.*)\"\s*$/ )
111 $value = $1;
114 $key = "\%" . uc($key); # $key is %PRODUCTNAME
116 my $input = $key . " " . $value . "\n"; # $key can only be the first word
118 push(@installobjectvariables ,$input);
121 $counter++;
122 $installline = ${$scriptref}[$counter];
126 last; # not interesting after installation object
129 return \@installobjectvariables;
132 ######################################################################
133 # Including LCPRODUCTNAME into the array
134 ######################################################################
136 sub add_lowercase_productname_setupscriptvariable
138 my ( $variablesref ) = @_;
140 for ( my $j = 0; $j <= $#{$variablesref}; $j++ )
142 my $variableline = ${$variablesref}[$j];
144 my ($key, $value);
146 if ( $variableline =~ /^\s*\%(\w+?)\s+(.*?)\s*$/ )
148 $key = $1;
149 $value = $2;
151 if ( $key eq "PRODUCTNAME" )
153 my $newline = "\%LCPRODUCTNAME " . lc($value) . "\n";
154 push(@{$variablesref} ,$newline);
155 my $original = $value;
156 $value =~ s/\s*//g;
157 $newline = "\%ONEWORDPRODUCTNAME " . $value . "\n";
158 push(@{$variablesref} ,$newline);
159 $newline = "\%LCONEWORDPRODUCTNAME " . lc($value) . "\n";
160 push(@{$variablesref} ,$newline);
161 $value = $original;
162 $value =~ s/\s/\_/g;
163 $newline = "\%UNIXPRODUCTNAME " . lc($value) . "\n";
164 push(@{$variablesref} ,$newline);
165 $value = $original;
166 $value =~ s/\s/\_/g;
167 $value =~ s/\.//g;
168 $newline = "\%WITHOUTDOTUNIXPRODUCTNAME " . lc($value) . "\n";
169 push(@{$variablesref} ,$newline);
171 elsif ( $key eq "PRODUCTEXTENSION" )
173 my $newline = "\%LCPRODUCTEXTENSION " . lc($value) . "\n";
174 push(@{$variablesref} ,$newline);
176 elsif ( $key eq "PRODUCTVERSION" )
178 $value =~ s/\.//g;
179 my $newline = "\%WITHOUTDOTPRODUCTVERSION " . $value . "\n";
180 push(@{$variablesref} ,$newline);
182 elsif ( $key eq "OOOBASEVERSION" )
184 $value =~ s/\.//g;
185 my $newline = "\%WITHOUTDOTOOOBASEVERSION " . $value . "\n";
186 push(@{$variablesref} ,$newline);
193 ######################################################################
194 # Resolving the new introduced lowercase script variables
195 ######################################################################
197 sub resolve_lowercase_productname_setupscriptvariable
199 my ( $variablesref ) = @_;
201 my %variables = ();
203 # First step: Collecting variables
205 for ( my $j = 0; $j <= $#{$variablesref}; $j++ )
207 my $variableline = ${$variablesref}[$j];
209 my ($key, $value);
211 if ( $variableline =~ /^\s*\%(\w+?)\s+(.*?)\s*$/ )
213 $key = $1;
214 $value = $2;
215 $variables{$key} = $value;
219 # Second step: Resolving variables
221 for ( my $j = 0; $j <= $#{$variablesref}; $j++ )
223 if ( ${$variablesref}[$j] =~ /\$\{(.*?)\}/ )
225 my $key = $1;
226 ${$variablesref}[$j] =~ s/\$\{\Q$key\E\}/$variables{$key}/g;
232 ######################################################################
233 # Replacing all setup script variables inside the setup script file
234 ######################################################################
236 sub replace_all_setupscriptvariables_in_script
238 my ( $scriptref, $variablesref ) = @_;
240 installer::logger::include_header_into_globallogfile("Replacing variables in setup script (start)");
242 # make hash of variables to be substituted if they appear in the script
243 my %subs;
244 for ( my $j = 0; $j <= $#{$variablesref}; $j++ )
246 my $variableline = ${$variablesref}[$j];
248 if ( $variableline =~ /^\s*(\%\w+?)\s+(.*?)\s*$/ )
250 $subs{$1}= $2;
254 # This is far faster than running a regexp for each line
255 my $bigstring = '';
256 for my $line (@{$scriptref}) { $bigstring = $bigstring . $line; }
258 foreach my $key ( keys %subs )
260 # Attention: It must be possible to substitute "%PRODUCTNAMEn", "%PRODUCTNAME%PRODUCTVERSIONabc"
261 my $value = $subs{$key};
262 $bigstring =~ s/$key/$value/g;
265 my @newlines = split /\n/, $bigstring;
266 $scriptref = \@newlines;
268 # now check for any mis-named '%' variables that we have left
269 my $num = 0;
270 for my $check (@newlines)
272 $num++;
273 if ( $check =~ /^.*\%\w+.*$/ )
275 if (( $check =~ /%1/ ) || ( $check =~ /%2/ ) || ( $check =~ /%verify/ )) { next; }
276 my $infoline = "WARNING: mis-named or un-known '%' variable in setup script at line $num:\n$check\n";
277 push( @installer::globals::globallogfileinfo, $infoline);
278 # print STDERR "Warning: mis-named or un-known '%' variable at line $num:\n$check\n";
282 installer::logger::include_header_into_globallogfile("Replacing variables in setup script (end)");
284 return $scriptref;
287 #######################################################################
288 # Collecting all items of the type "searchitem" from the setup script
289 #######################################################################
291 sub get_all_items_from_script
293 my ($scriptref, $searchitem) = @_;
295 my @allitemarray = ();
297 my ($itemkey, $itemvalue, $valuecounter);
299 for ( my $i = 0; $i <= $#{$scriptref}; $i++ )
301 my $line = ${$scriptref}[$i];
303 if ( $line =~ /^\s*\Q$searchitem\E\s+(\S+)\s*$/ )
305 my $gid = $1;
306 my $counter = $i + 1;
308 my %oneitemhash = ();
309 my $ismultilang = 0;
311 $oneitemhash{'gid'} = $gid;
313 while (!( $line =~ /^\s*End\s*$/ ))
315 if ( $counter > $#{$scriptref} ) {
316 installer::exiter::exit_program("Invalid setup script file. End of file reached before 'End' line of '$searchitem' section.", "get_all_items_from_script");
318 $line = ${$scriptref}[$counter];
319 $counter++;
321 if ( $line =~ /^\s*(.+?)\s*\=\s*(.+?)\s*\;\s*$/ ) # only oneliner!
323 $itemkey = $1;
324 $itemvalue = $2;
326 installer::remover::remove_leading_and_ending_quotationmarks(\$itemvalue);
327 $itemvalue =~ s/\s*$//; # removing ending whitespaces. Could be introduced by empty variables.
329 $oneitemhash{$itemkey} = $itemvalue;
331 if ( $itemkey =~ /^\s*\S+\s+\(\S+\)\s*$/ )
333 $ismultilang = 1;
336 else
338 if ( $searchitem eq "Module" ) # more than one line, for instance files at modules!
340 if (( $line =~ /^\s*(.+?)\s*\=\s*\(/ ) && (!($line =~ /\)\;\s*$ / )))
342 if ( $line =~ /^\s*(.+?)\s*\=\s*(.+)/ ) # the first line
344 $itemkey = $1;
345 $itemvalue = $2;
346 $itemvalue =~ s/\s*$//;
349 # collecting the complete itemvalue
351 $valuecounter = $counter;
352 $line = ${$scriptref}[$valuecounter];
353 installer::remover::remove_leading_and_ending_whitespaces(\$line);
354 $itemvalue = $itemvalue . $line;
356 while (!( $line =~ /\)\;\s*$/ ))
358 $valuecounter++;
359 $line = ${$scriptref}[$valuecounter];
360 installer::remover::remove_leading_and_ending_whitespaces(\$line);
361 $itemvalue = $itemvalue . $line;
364 # removing ending ";"
365 $itemvalue =~ s/\;\s*$//;
367 $oneitemhash{$itemkey} = $itemvalue;
369 if ( $itemkey =~ /^\s*\S+\s+\(\S+\)\s*$/ )
371 $ismultilang = 1;
378 $oneitemhash{'ismultilingual'} = $ismultilang;
380 push(@allitemarray, \%oneitemhash);
384 return \@allitemarray;
387 ######################################################################
388 # Collecting all folder at folderitems, that are predefined values
389 # For example: PREDEFINED_AUTOSTART
390 ######################################################################
392 sub add_predefined_folder
394 my ( $folderitemref, $folderref ) = @_;
396 for ( my $i = 0; $i <= $#{$folderitemref}; $i++ )
398 my $folderitem = ${$folderitemref}[$i];
399 my $folderid = $folderitem->{'FolderID'};
401 if ( $folderid =~ /PREDEFINED_/ )
403 if (! installer::existence::exists_in_array_of_hashes("gid", $folderid, $folderref))
405 my %folder = ();
406 $folder{'ismultilingual'} = "0";
407 $folder{'Name'} = "";
408 $folder{'gid'} = $folderid;
410 push(@{$folderref}, \%folder);
416 #####################################################################################
417 # If folderitems are non-advertised, the component needs to have a registry key
418 # below HKCU as key path. Therefore it is required, to mark the file belonging
419 # to a non-advertised shortcut, that a special userreg_xxx registry key can be
420 # created during packing process.
421 #####################################################################################
423 sub prepare_non_advertised_files
425 my ( $folderitemref, $filesref ) = @_;
427 for ( my $i = 0; $i <= $#{$folderitemref}; $i++ )
429 my $folderitem = ${$folderitemref}[$i];
430 my $styles = "";
431 if ( $folderitem->{'Styles'} ) { $styles = $folderitem->{'Styles'}; }
433 if ( $styles =~ /\bNON_ADVERTISED\b/ )
435 my $fileid = $folderitem->{'FileID'};
436 if ( $folderitem->{'ComponentIDFile'} ) { $fileid = $folderitem->{'ComponentIDFile'}; }
437 my $onefile = installer::worker::find_file_by_id($filesref, $fileid);
439 # Attention: If $onefile with "FileID" is not found, this is not always an error.
440 # FileID can also contain an executable file, for example msiexec.exe.
441 if ( $onefile ne "" ) { $onefile->{'needs_user_registry_key'} = 1; }
446 #####################################################################################
447 # Adding all variables defined in the installation object into the hash
448 # of all variables from the zip list file.
449 # This is needed if variables are defined in the installation object,
450 # but not in the zip list file.
451 # If there is a definition in the zip list file and in the installation
452 # object, the installation object is more important
453 #####################################################################################
455 sub add_installationobject_to_variables
457 my ($allvariables, $allscriptvariablesref) = @_;
459 for ( my $i = 0; $i <= $#{$allscriptvariablesref}; $i++ )
461 my $line = ${$allscriptvariablesref}[$i];
463 if ( $line =~ /^\s*\%(\w+)\s+(.*?)\s*$/ )
465 my $key = $1;
466 my $value = $2;
468 $allvariables->{$key} = $value; # overwrite existing values from zip.lst
473 #####################################################################################
474 # Adding all variables, that must be defined, but are not defined until now.
475 # List of this varibles: @installer::globals::forced_properties
476 #####################################################################################
478 sub add_forced_properties
480 my ($allvariables) = @_;
482 my $property;
483 foreach $property ( @installer::globals::forced_properties )
485 if ( ! exists($allvariables->{$property}) ) { $allvariables->{$property} = ""; }