setupscript.pm (dba1a2e4) | setupscript.pm (1ba1fd99) |
---|---|
1#************************************************************** 2# 3# Licensed to the Apache Software Foundation (ASF) under one 4# or more contributor license agreements. See the NOTICE file 5# distributed with this work for additional information 6# regarding copyright ownership. The ASF licenses this file 7# to you under the Apache License, Version 2.0 (the 8# "License"); you may not use this file except in compliance --- 66 unchanged lines hidden (view full) --- 75##################################################################### 76# Reading script variables from installation object of script file 77##################################################################### 78 79sub get_all_scriptvariables_from_installation_object ($$) 80{ 81 my ($scriptref, $script_filename) = @_; 82 | 1#************************************************************** 2# 3# Licensed to the Apache Software Foundation (ASF) under one 4# or more contributor license agreements. See the NOTICE file 5# distributed with this work for additional information 6# regarding copyright ownership. The ASF licenses this file 7# to you under the Apache License, Version 2.0 (the 8# "License"); you may not use this file except in compliance --- 66 unchanged lines hidden (view full) --- 75##################################################################### 76# Reading script variables from installation object of script file 77##################################################################### 78 79sub get_all_scriptvariables_from_installation_object ($$) 80{ 81 my ($scriptref, $script_filename) = @_; 82 |
83 my @installobjectvariables; | 83 my $installobjectvariables = {}; |
84 | 84 |
85 for ( my $i = 0; $i <= $#{$scriptref}; $i++ ) 86 { 87 my $line = ${$scriptref}[$i]; | 85 my $firstline = $scriptref->[0]; 86 if ($firstline !~ /^\s*Installation\s+\w+\s*$/) 87 { 88 installer::logger::PrintError("did not find 'Installation' keyword in first line of %s\n", 89 $script_filename); 90 } 91 foreach my $line (@$scriptref) 92 { 93 next if $line =~ /^\s*Installation\s+\w+\s*$/; # Already processed. 94 last if $line =~ /^\s*End\s*$/; |
88 | 95 |
89 if ( $line =~ /^\s*Installation\s+\w+\s*$/ ) # should be the first line 90 { 91 my $counter = $i+1; 92 my $installline = ${$scriptref}[$counter]; 93 94 while (!($installline =~ /^\s*End\s*$/ )) 95 { 96 if ( $installline =~ /^\s*(\w+)\s+\=\s*(.*?)\s*\;\s*$/ ) 97 { 98 my $key = $1; 99 my $value = $2; | 96 if ($line =~ /^\s*(\w+)\s+\=\s*\"?(.*?)\"?\s*\;\s*$/ ) 97 { 98 my ($key, $value) = ($1, $2); |
100 | 99 |
101 # removing leading and ending " in $value 102 103 if ( $value =~ /^\s*\"(.*)\"\s*$/ ) 104 { 105 $value = $1; 106 } 107 108 $key = "\%" . uc($key); # $key is %PRODUCTNAME 109 110 my $input = $key . " " . $value . "\n"; # $key can only be the first word 111 112 push(@installobjectvariables ,$input); 113 } | 100 $installobjectvariables->{uc($key)} = $value; 101 } |
114 | 102 |
115 $counter++; 116 $installline = ${$scriptref}[$counter]; 117 } 118 } 119 120 last; # not interesting after installation object | |
121 } 122 | 103 } 104 |
123 return \@installobjectvariables; | 105 return $installobjectvariables; |
124} 125 126###################################################################### 127# Including LCPRODUCTNAME into the array 128###################################################################### 129 | 106} 107 108###################################################################### 109# Including LCPRODUCTNAME into the array 110###################################################################### 111 |
130sub add_lowercase_productname_setupscriptvariable | 112sub add_lowercase_productname_setupscriptvariable ($) |
131{ 132 my ( $variablesref ) = @_; 133 | 113{ 114 my ( $variablesref ) = @_; 115 |
134 for ( my $j = 0; $j <= $#{$variablesref}; $j++ ) | 116 my %additional_variables = (); 117 118 while (my ($key, $value) = each %$variablesref) |
135 { | 119 { |
136 my $variableline = ${$variablesref}[$j]; 137 138 my ($key, $value); 139 140 if ( $variableline =~ /^\s*\%(\w+?)\s+(.*?)\s*$/ ) 141 { 142 $key = $1; 143 $value = $2; 144 145 if ( $key eq "PRODUCTNAME" ) 146 { 147 my $newline = "\%LCPRODUCTNAME " . lc($value) . "\n"; 148 push(@{$variablesref} ,$newline); 149 my $original = $value; 150 $value =~ s/\s*//g; 151 $newline = "\%ONEWORDPRODUCTNAME " . $value . "\n"; 152 push(@{$variablesref} ,$newline); 153 $newline = "\%LCONEWORDPRODUCTNAME " . lc($value) . "\n"; 154 push(@{$variablesref} ,$newline); 155 $value = $original; 156 $value =~ s/\s*$//g; 157 $value =~ s/^\s*//g; 158 $value =~ s/ /\%20/g; 159 $newline = "\%MASKEDPRODUCTNAME " . $value . "\n"; 160 push(@{$variablesref} ,$newline); 161 $value = $original; 162 $value =~ s/\s/\_/g; 163 # if ( $value =~ /^\s*(.*?)\_(\w)(.*?)\_(\w)(.*)\s*$/ ) { $value = $1 . $2 . $4; } 164 $newline = "\%UNIXPRODUCTNAME " . lc($value) . "\n"; 165 push(@{$variablesref} ,$newline); 166 $newline = "\%SYSTEMINTUNIXPACKAGENAME " . lc($value) . "\n"; 167 push(@{$variablesref} ,$newline); 168 # if ( $value =~ /^\s*(.*?)\_(\w)(.*?)\_(\w)(.*)\s*$/ ) { $value = $1 . $2 . $4; } 169 # if ( $value =~ /^\s*(.*?)\_(\w)(.*?)\_(\w)(.*)\s*$/ ) { $value = $2 . $4; } 170 $newline = "\%UNIXPACKAGENAME " . lc($value) . "\n"; 171 push(@{$variablesref} ,$newline); 172 $value = $original; 173 $value =~ s/\s/\_/g; 174 $value =~ s/\.//g; 175 # if ( $value =~ /^\s*(.*?)\_(\w)(.*?)\_(\w)(.*)\s*$/ ) { $value = $1 . $2 . $4; } 176 $newline = "\%WITHOUTDOTUNIXPRODUCTNAME " . lc($value) . "\n"; 177 push(@{$variablesref} ,$newline); 178 # if ( $value =~ /^\s*(.*?)\_(\w)(.*?)\_(\w)(.*)\s*$/ ) { $value = $1 . $2 . $4; } 179 # if ( $value =~ /^\s*(.*?)\_(\w)(.*?)\_(\w)(.*)\s*$/ ) { $value = $2 . $4; } 180 $newline = "\%WITHOUTDOTUNIXPACKAGENAME " . lc($value) . "\n"; 181 push(@{$variablesref} ,$newline); 182 $newline = "\%SOLARISBRANDPACKAGENAME " . lc($value) . "\n"; 183 push(@{$variablesref} ,$newline); 184 $value = $original; 185 } 186 elsif ( $key eq "PRODUCTEXTENSION" ) 187 { 188 my $newline = "\%LCPRODUCTEXTENSION " . lc($value) . "\n"; 189 push(@{$variablesref} ,$newline); 190 } 191 elsif ( $key eq "PRODUCTVERSION" ) 192 { 193 $value =~ s/\.//g; 194 my $newline = "\%WITHOUTDOTPRODUCTVERSION " . $value . "\n"; 195 push(@{$variablesref} ,$newline); 196 } 197 elsif ( $key eq "OOOBASEVERSION" ) 198 { 199 $value =~ s/\.//g; 200 my $newline = "\%WITHOUTDOTOOOBASEVERSION " . $value . "\n"; 201 push(@{$variablesref} ,$newline); 202 } 203 | 120 if ($key eq "PRODUCTNAME") 121 { 122 $additional_variables{"LCPRODUCTNAME"} = lc($value); 123 my $original = $value; 124 $value =~ s/\s+//g; 125 $additional_variables{"ONEWORDPRODUCTNAME"} = $value; 126 $additional_variables{"LCONEWORDPRODUCTNAME"} = lc($value); 127 $value = $original; 128 $value =~ s/(^\s+|\s+$)//g; 129 $value =~ s/ /\%20/g; 130 $additional_variables{"MASKEDPRODUCTNAME"} = $value; 131 $value = $original; 132 $value =~ s/\s/\_/g; 133 $additional_variables{"UNIXPRODUCTNAME"} = lc($value); 134 $additional_variables{"SYSTEMINTUNIXPACKAGENAME"} = lc($value); 135 $additional_variables{"UNIXPACKAGENAME"} = lc($value); 136 $value = $original; 137 $value =~ s/\s/\_/g; 138 $value =~ s/\.//g; 139 $additional_variables{"WITHOUTDOTUNIXPRODUCTNAME"} = lc($value); 140 $additional_variables{"WITHOUTDOTUNIXPACKAGENAME"} = lc($value); 141 $additional_variables{"SOLARISBRANDPACKAGENAME"} = lc($value); 142 } 143 elsif ($key eq "PRODUCTEXTENSION") 144 { 145 $additional_variables{"LCPRODUCTEXTENSION"} = lc($value); 146 } 147 elsif ($key eq "PRODUCTVERSION") 148 { 149 $value =~ s/\.//g; 150 $additional_variables{"WITHOUTDOTPRODUCTVERSION"} = $value; 151 } 152 elsif ($key eq "OOOBASEVERSION") 153 { 154 $value =~ s/\.//g; 155 $additional_variables{"WITHOUTDOTOOOBASEVERSION"} = $value; |
204 } 205 } | 156 } 157 } |
158 159 while (my ($key, $value) = each %additional_variables) 160 { 161 $variablesref->{$key} = $value; 162 } |
|
206} 207 208###################################################################### 209# Resolving the new introduced lowercase script variables 210###################################################################### 211 | 163} 164 165###################################################################### 166# Resolving the new introduced lowercase script variables 167###################################################################### 168 |
212sub resolve_lowercase_productname_setupscriptvariable | 169sub resolve_lowercase_productname_setupscriptvariable ($) |
213{ | 170{ |
214 my ( $variablesref ) = @_; | 171 my ($variablesref) = @_; |
215 | 172 |
216 my %variables = (); 217 218 # First step: Collecting variables 219 220 for ( my $j = 0; $j <= $#{$variablesref}; $j++ ) 221 { 222 my $variableline = ${$variablesref}[$j]; 223 224 my ($key, $value); 225 226 if ( $variableline =~ /^\s*\%(\w+?)\s+(.*?)\s*$/ ) | 173 while (my ($key,$value) = each %$variablesref) 174 { 175 if ($value =~ /\$\{(.*?)\}/) |
227 { | 176 { |
228 $key = $1; 229 $value = $2; 230 $variables{$key} = $value; | 177 my $varname = $1; 178 my $replacement = $variablesref->{$varname}; 179 my $new_value = $value; 180 $new_value =~ s/\$\{\Q$varname\E\}/$replacement/g; 181 $variablesref->{$key} = $new_value; |
231 } 232 } | 182 } 183 } |
233 234 # Second step: Resolving variables 235 236 for ( my $j = 0; $j <= $#{$variablesref}; $j++ ) 237 { 238 if ( ${$variablesref}[$j] =~ /\$\{(.*?)\}/ ) 239 { 240 my $key = $1; 241 ${$variablesref}[$j] =~ s/\$\{\Q$key\E\}/$variables{$key}/g; 242 } 243 } 244 | |
245} 246 | 184} 185 |
186 187 188 |
|
247###################################################################### 248# Replacing all setup script variables inside the setup script file 249###################################################################### 250 | 189###################################################################### 190# Replacing all setup script variables inside the setup script file 191###################################################################### 192 |
251sub replace_all_setupscriptvariables_in_script | 193sub replace_all_setupscriptvariables_in_script ($$) |
252{ | 194{ |
253 my ( $scriptref, $variablesref ) = @_; | 195 my ($script_lines, $variables) = @_; |
254 255 installer::logger::include_header_into_globallogfile("Replacing variables in setup script (start)"); 256 | 196 197 installer::logger::include_header_into_globallogfile("Replacing variables in setup script (start)"); 198 |
257 # make hash of variables to be substituted if they appear in the script 258 my %subs; 259 for ( my $j = 0; $j <= $#{$variablesref}; $j++ ) 260 { 261 my $variableline = ${$variablesref}[$j]; 262 263 if ( $variableline =~ /^\s*(\%\w+?)\s+(.*?)\s*$/ ) 264 { 265 $subs{$1}= $2; 266 } 267 } 268 | |
269 # This is far faster than running a regexp for each line | 199 # This is far faster than running a regexp for each line |
270 my $bigstring = ''; 271 for my $line (@{$scriptref}) { $bigstring = $bigstring . $line; } | 200 my $bigstring = join("", @$script_lines); |
272 | 201 |
273 foreach my $key ( keys %subs ) | 202 while (my ($key,$value) = each %$variables) |
274 { 275 # Attention: It must be possible to substitute "%PRODUCTNAMEn", "%PRODUCTNAME%PRODUCTVERSIONabc" | 203 { 204 # Attention: It must be possible to substitute "%PRODUCTNAMEn", "%PRODUCTNAME%PRODUCTVERSIONabc" |
276 my $value = $subs{$key}; 277 $bigstring =~ s/$key/$value/g; | 205 my $count = ($bigstring =~ s/%$key/$value/g); 206 if ($count > 0) 207 { 208 $installer::logger::Lang->printf("replaced %s %d times\n", $key, $count); 209 } |
278 } 279 280 my @newlines = split /\n/, $bigstring; | 210 } 211 212 my @newlines = split /\n/, $bigstring; |
281 $scriptref = \@newlines; | |
282 283 # now check for any mis-named '%' variables that we have left 284 my $num = 0; | 213 214 # now check for any mis-named '%' variables that we have left 215 my $num = 0; |
285 for my $check (@newlines) | 216 foreach my $line (@newlines) |
286 { 287 $num++; | 217 { 218 $num++; |
288 if ( $check =~ /^.*\%\w+.*$/ ) | 219 if ($line =~ /\%\w+/) |
289 { | 220 { |
290 if (( $check =~ /%1/ ) || ( $check =~ /%2/ ) || ( $check =~ /%verify/ )) | 221 if (( $line =~ /%1/ ) || ( $line =~ /%2/ ) || ( $line =~ /%verify/ )) |
291 { 292 next; 293 } | 222 { 223 next; 224 } |
294 $installer::logger::Global->printf( 295 "WARNING: mis-named or un-known '%s' variable in setup script at line %s:\n", 296 "%", $num); 297 $installer::logger::Global->printf("%s\n", $check); | 225 $installer::logger::Info->printf( 226 "WARNING: mis-named or un-known %%-variable in setup script at line %s:\n",$num); 227 $installer::logger::Info->printf("%s\n", $line); |
298 } 299 } 300 301 installer::logger::include_header_into_globallogfile("Replacing variables in setup script (end)"); 302 | 228 } 229 } 230 231 installer::logger::include_header_into_globallogfile("Replacing variables in setup script (end)"); 232 |
303 return $scriptref; | 233 return \@newlines; |
304} 305 306####################################################################### 307# Collecting all items of the type "searchitem" from the setup script 308####################################################################### 309 310sub get_all_items_from_script 311{ --- 154 unchanged lines hidden (view full) --- 466# Adding all variables defined in the installation object into the hash 467# of all variables from the zip list file. 468# This is needed if variables are defined in the installation object, 469# but not in the zip list file. 470# If there is a definition in the zip list file and in the installation 471# object, the installation object is more important 472##################################################################################### 473 | 234} 235 236####################################################################### 237# Collecting all items of the type "searchitem" from the setup script 238####################################################################### 239 240sub get_all_items_from_script 241{ --- 154 unchanged lines hidden (view full) --- 396# Adding all variables defined in the installation object into the hash 397# of all variables from the zip list file. 398# This is needed if variables are defined in the installation object, 399# but not in the zip list file. 400# If there is a definition in the zip list file and in the installation 401# object, the installation object is more important 402##################################################################################### 403 |
474sub add_installationobject_to_variables | 404sub add_installationobject_to_variables ($$) |
475{ | 405{ |
476 my ($allvariables, $allscriptvariablesref) = @_; | 406 my ($variables, $script_variables) = @_; |
477 | 407 |
478 for ( my $i = 0; $i <= $#{$allscriptvariablesref}; $i++ ) | 408 while (my ($key, $value) = each %$script_variables) |
479 { | 409 { |
480 my $line = ${$allscriptvariablesref}[$i]; 481 482 if ( $line =~ /^\s*\%(\w+)\s+(.*?)\s*$/ ) 483 { 484 my $key = $1; 485 my $value = $2; 486 487 $allvariables->{$key} = $value; # overwrite existing values from zip.lst 488 } | 410 $variables->{$key} = $value; # overwrite existing values from zip.lst |
489 } 490} 491 492##################################################################################### 493# Adding all variables, that must be defined, but are not defined until now. 494# List of this varibles: @installer::globals::forced_properties 495##################################################################################### 496 --- 42 unchanged lines hidden --- | 411 } 412} 413 414##################################################################################### 415# Adding all variables, that must be defined, but are not defined until now. 416# List of this varibles: @installer::globals::forced_properties 417##################################################################################### 418 --- 42 unchanged lines hidden --- |