2 # This file is part of the LibreOffice project.
4 # This Source Code Form is subject to the terms of the Mozilla Public
5 # License, v. 2.0. If a copy of the MPL was not distributed with this
6 # file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 # This file incorporates work covered by the following license notice:
10 # Licensed to the Apache Software Foundation (ASF) under one or more
11 # contributor license agreements. See the NOTICE file distributed
12 # with this work for additional information regarding copyright
13 # ownership. The ASF licenses this file to you under the Apache
14 # License, Version 2.0 (the "License"); you may not use this file
15 # except in compliance with the License. You may obtain a copy of
16 # the License at http://www.apache.org/licenses/LICENSE-2.0 .
19 package installer
::setupscript
;
26 use installer
::exiter
;
27 use installer
::globals
;
28 use installer
::logger
qw(globallog);
29 use installer
::remover
;
30 use installer
::scriptitems
;
31 use installer
::ziplist
;
34 add_installationobject_to_variables
35 add_lowercase_productname_setupscriptvariable
37 get_all_items_from_script
38 get_all_scriptvariables_from_installation_object
39 prepare_non_advertised_files
40 replace_all_setupscriptvariables_in_script
41 replace_preset_properties
42 resolve_lowercase_productname_setupscriptvariable
46 #######################################################
47 # Set setup script name, if not defined as parameter
48 #######################################################
50 sub set_setupscript_name
52 my ( $allsettingsarrayref, $includepatharrayref ) = @_;
54 my $scriptnameref = installer
::ziplist
::getinfofromziplist
($allsettingsarrayref, "script");
56 my $scriptname = $$scriptnameref;
58 if ( $scriptname eq "" ) # not defined on command line and not in product list
60 installer
::exiter
::exit_program
("ERROR: Setup script not defined on command line (-l) and not in product list!", "set_setupscript_name");
63 if ( $installer::globals
::os
eq 'WNT')
65 $scriptname .= ".inf";
69 $scriptname .= ".ins";
72 # and now the complete path for the setup script is needed
73 # The log file cannot be used, because this is the language independent section
75 $scriptnameref = installer
::scriptitems
::get_sourcepath_from_filename_and_includepath
(\
$scriptname, $includepatharrayref, 1);
77 $installer::globals
::setupscriptname
= $$scriptnameref;
79 if ( $installer::globals
::setupscriptname
eq "" )
81 installer
::exiter
::exit_program
("ERROR: Script $scriptname not found!", "set_setupscript_name");
85 #####################################################################
86 # Reading script variables from installation object of script file
87 #####################################################################
89 sub get_all_scriptvariables_from_installation_object
93 my @installobjectvariables;
95 for ( my $i = 0; $i <= $#{$scriptref}; $i++ )
97 my $line = ${$scriptref}[$i];
99 if ( $line =~ /^\s*Installation\s+\w+\s*$/ ) # should be the first line
102 my $installline = ${$scriptref}[$counter];
104 while (!($installline =~ /^\s*End\s*$/ ))
106 if ( $installline =~ /^\s*(\w+)\s+\=\s*(.*?)\s*\;\s*$/ )
111 # removing leading and ending " in $value
113 if ( $value =~ /^\s*\"(.*)\"\s*$/ )
118 $key = "\%" . uc($key); # $key is %PRODUCTNAME
120 my $input = $key . " " . $value . "\n"; # $key can only be the first word
122 push(@installobjectvariables ,$input);
126 $installline = ${$scriptref}[$counter];
130 last; # not interesting after installation object
133 return \
@installobjectvariables;
136 ######################################################################
137 # Including LCPRODUCTNAME into the array
138 ######################################################################
140 sub add_lowercase_productname_setupscriptvariable
142 my ( $variablesref ) = @_;
144 for ( my $j = 0; $j <= $#{$variablesref}; $j++ )
146 my $variableline = ${$variablesref}[$j];
150 if ( $variableline =~ /^\s*\%(\w+?)\s+(.*?)\s*$/ )
155 if ( $key eq "PRODUCTNAME" )
157 my $newline = "\%LCPRODUCTNAME " . lc($value) . "\n";
158 push(@
{$variablesref} ,$newline);
159 my $original = $value;
161 $newline = "\%ONEWORDPRODUCTNAME " . $value . "\n";
162 push(@
{$variablesref} ,$newline);
163 $newline = "\%LCONEWORDPRODUCTNAME " . lc($value) . "\n";
164 push(@
{$variablesref} ,$newline);
168 $value =~ s/ /\%20/g;
169 $newline = "\%MASKEDPRODUCTNAME " . $value . "\n";
170 push(@
{$variablesref} ,$newline);
173 $newline = "\%UNIXPRODUCTNAME " . lc($value) . "\n";
174 push(@
{$variablesref} ,$newline);
175 $newline = "\%SYSTEMINTUNIXPACKAGENAME " . lc($value) . "\n";
176 push(@
{$variablesref} ,$newline);
177 $newline = "\%UNIXPACKAGENAME " . lc($value) . "\n";
178 push(@
{$variablesref} ,$newline);
182 $newline = "\%WITHOUTDOTUNIXPRODUCTNAME " . lc($value) . "\n";
183 push(@
{$variablesref} ,$newline);
184 $newline = "\%WITHOUTDOTUNIXPACKAGENAME " . lc($value) . "\n";
185 push(@
{$variablesref} ,$newline);
186 $newline = "\%SOLARISBRANDPACKAGENAME " . lc($value) . "\n";
187 push(@
{$variablesref} ,$newline);
190 elsif ( $key eq "PRODUCTEXTENSION" )
192 my $newline = "\%LCPRODUCTEXTENSION " . lc($value) . "\n";
193 push(@
{$variablesref} ,$newline);
195 elsif ( $key eq "PRODUCTVERSION" )
198 my $newline = "\%WITHOUTDOTPRODUCTVERSION " . $value . "\n";
199 push(@
{$variablesref} ,$newline);
205 ######################################################################
206 # Resolving the new introduced lowercase script variables
207 ######################################################################
209 sub resolve_lowercase_productname_setupscriptvariable
211 my ( $variablesref ) = @_;
215 # First step: Collecting variables
217 for ( my $j = 0; $j <= $#{$variablesref}; $j++ )
219 my $variableline = ${$variablesref}[$j];
223 if ( $variableline =~ /^\s*\%(\w+?)\s+(.*?)\s*$/ )
227 $variables{$key} = $value;
231 # Second step: Resolving variables
233 for ( my $j = 0; $j <= $#{$variablesref}; $j++ )
235 if ( ${$variablesref}[$j] =~ /\$\{(.*?)\}/ )
238 ${$variablesref}[$j] =~ s/\$\{\Q$key\E\}/$variables{$key}/g;
244 ######################################################################
245 # Replacing all setup script variables inside the setup script file
246 ######################################################################
248 sub replace_all_setupscriptvariables_in_script
250 my ( $scriptref, $variablesref ) = @_;
252 globallog
("Replacing variables in setup script (start)");
254 # make hash of variables to be substituted if they appear in the script
256 for ( my $j = 0; $j <= $#{$variablesref}; $j++ )
258 my $variableline = ${$variablesref}[$j];
260 if ( $variableline =~ /^\s*(\%\w+?)\s+(.*?)\s*$/ )
266 # This is far faster than running a regexp for each line
268 for my $line (@
{$scriptref}) { $bigstring = $bigstring . $line; }
270 foreach my $key (sort { length ($b) <=> length ($a) } keys %subs)
272 # Attention: It must be possible to substitute "%PRODUCTNAMEn", "%PRODUCTNAME%PRODUCTVERSIONabc"
273 my $value = $subs{$key};
274 $bigstring =~ s/$key/$value/g;
277 my @newlines = split /\n/, $bigstring;
278 $scriptref = \
@newlines;
280 # now check for any mis-named '%' variables that we have left
282 for my $check (@newlines)
285 if ( $check =~ /^.*\%\w+.*$/ )
287 if (( $check =~ /%1/ ) || ( $check =~ /%2/ ) || ( $check =~ /%verify/ )) { next; }
288 my $infoline = "WARNING: mis-named or un-known '%' variable in setup script at line $num:\n$check\n";
289 push( @installer::globals
::globallogfileinfo
, $infoline);
293 globallog
("Replacing variables in setup script (end)");
298 #######################################################################
299 # Collecting all items of the type "searchitem" from the setup script
300 #######################################################################
302 sub get_all_items_from_script
304 my ($scriptref, $searchitem) = @_;
306 my @allitemarray = ();
308 my ($itemkey, $itemvalue);
310 for ( my $i = 0; $i <= $#{$scriptref}; $i++ )
312 my $line = ${$scriptref}[$i];
314 next unless ($line =~ /^\s*\Q$searchitem\E\s+(\S+)\s*$/);
317 my %oneitemhash = ();
320 $oneitemhash{'gid'} = $gid;
322 while (!( $line =~ /^\s*End\s*$/ ))
324 if ( $i >= $#{$scriptref} ) {
325 installer
::exiter
::exit_program
("Invalid setup script file. End of file reached before 'End' line of '$searchitem' section.", "get_all_items_from_script");
327 $line = ${$scriptref}[++$i];
329 if ( $line =~ /^\s*(.+?)\=\s*(.+?)\;\s*$/ ) # only oneliner!
334 $itemkey =~ s/\s+$//;
335 $itemvalue =~ s/\s+$//;
337 installer
::remover
::remove_leading_and_ending_quotationmarks
(\
$itemvalue);
339 $oneitemhash{$itemkey} = $itemvalue;
341 $ismultilang ||= $itemkey =~ /^\S+\s+\(\S+\)$/;
343 elsif (($searchitem eq "Module") &&
344 ($line =~ /^\s*.+?\s*\=\s*\(/) &&
345 (!($line =~ /\)\;\s*$/))) # more than one line, for instance files at modules!
347 $line =~ /^\s*(.+?)\s*\=\s*(.+?)\s*$/; # the first line
351 # collecting the complete itemvalue
354 if ( $i >= $#{$scriptref} ) {
355 installer
::exiter
::exit_program
("Invalid setup script file. Premature end of file.", "get_all_items_from_script");
357 $line = ${$scriptref}[++$i];
358 installer
::remover
::remove_leading_and_ending_whitespaces
(\
$line);
360 } while (!($line =~ /\)\;\s*$/));
362 # removing ending ";"
363 $itemvalue =~ s/\;\s*$//;
365 $oneitemhash{$itemkey} = $itemvalue;
367 $ismultilang ||= $itemkey =~ /^\S+\s+\(\S+\)$/;
371 $oneitemhash{'ismultilingual'} = $ismultilang+0;
373 push(@allitemarray, \
%oneitemhash);
376 return \
@allitemarray;
379 ######################################################################
380 # Collecting all folder at folderitems, that are predefined values
381 # For example: PREDEFINED_AUTOSTART
382 ######################################################################
384 sub add_predefined_folder
386 my ( $folderitemref, $folderref ) = @_;
388 for my $folderid ( map { $_->{FolderID
} } @
{$folderitemref} ) {
389 # FIXME: Anchor to start of line?
390 next unless ( $folderid =~ /PREDEFINED_/ );
391 next if grep { $_->{gid
} eq $folderid } @
{$folderref};
393 push @
{$folderref}, {
401 #####################################################################################
402 # If folderitems are non-advertised, the component needs to have a registry key
403 # below HKCU as key path. Therefore it is required, to mark the file belonging
404 # to a non-advertised shortcut, that a special userreg_xxx registry key can be
405 # created during packing process.
406 #####################################################################################
408 sub prepare_non_advertised_files
410 my ( $folderitemref, $filesref ) = @_;
412 for ( my $i = 0; $i <= $#{$folderitemref}; $i++ )
414 my $folderitem = ${$folderitemref}[$i];
416 if ( $folderitem->{'Styles'} ) { $styles = $folderitem->{'Styles'}; }
418 if ( $styles =~ /\bNON_ADVERTISED\b/ )
420 my $fileid = $folderitem->{'FileID'};
421 if ( $folderitem->{'ComponentIDFile'} ) { $fileid = $folderitem->{'ComponentIDFile'}; }
422 my $onefile = installer
::worker
::find_file_by_id
($filesref, $fileid);
424 if ( $onefile ne "" ) { $onefile->{'needs_user_registry_key'} = 1; }
426 installer
::exiter
::exit_program
("ERROR: Did not find FileID $fileid in file collection", "prepare_non_advertised_files");
432 #####################################################################################
433 # Adding all variables defined in the installation object into the hash
434 # of all variables from the zip list file.
435 # This is needed if variables are defined in the installation object,
436 # but not in the zip list file.
437 # If there is a definition in the zip list file and in the installation
438 # object, the installation object is more important
439 #####################################################################################
441 sub add_installationobject_to_variables
443 my ($allvariables, $allscriptvariablesref) = @_;
445 for ( my $i = 0; $i <= $#{$allscriptvariablesref}; $i++ )
447 my $line = ${$allscriptvariablesref}[$i];
449 if ( $line =~ /^\s*\%(\w+)\s+(.*?)\s*$/ )
454 $allvariables->{$key} = $value; # overwrite existing values from zip.lst
459 #####################################################################################
460 # Some properties are created automatically. It should be possible to
461 # overwrite them, with PRESET properties. For example UNIXPRODUCTNAME
462 # with PRESETUNIXPRODUCTNAME, if this is defined and the automatic process
463 # does not deliver the desired results.
464 #####################################################################################
466 sub replace_preset_properties
468 my ($allvariables) = @_;
470 # SOLARISBRANDPACKAGENAME
471 # needs to be replaced by
472 # PRESETSOLARISBRANDPACKAGENAME
474 my @presetproperties = ();
475 push(@presetproperties, "SOLARISBRANDPACKAGENAME");
476 push(@presetproperties, "SYSTEMINTUNIXPACKAGENAME");
479 foreach my $property ( @presetproperties )
481 my $presetproperty = "PRESET" . $property;
482 if (( exists($allvariables->{$presetproperty}) ) && ( $allvariables->{$presetproperty} ne "" ))
484 $allvariables->{$property} = $allvariables->{$presetproperty};