Debian Codegraph @

solenv/bin/modules/installer/parameter.pm

raw
1 #
2 # This file is part of the LibreOffice project.
3 #
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/.
7 #
8 # This file incorporates work covered by the following license notice:
9 #
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 .
17 #
18
19 package installer::parameter;
20
21 use strict;
22 use warnings;
23
24 use Cwd;
25 use installer::exiter;
26 use installer::files;
27 use installer::globals;
28 use installer::logger;
29 use installer::remover;
30 use installer::systemactions;
31 use File::Temp qw/ :mktemp /;
32
33 ############################################
34 # Parameter Operations
35 ############################################
36
37 sub usage
38 {
39 print <<End;
40 --------------------------------------------------------------------------------
41 The following parameter are needed:
42 -f: Path to the product list (required)
43 -s: Path to the setup script (optional, if defined in product list)
44 -i: Install path of the product (/opt/openofficeorg20) (optional)
45 -p: Product from product list to be created (required)
46 -l: Language of the product (comma and hash) (optional, defined in productlist)
47 -simple: Path to do a simple install to
48 -u: Path, in which zipfiles are unpacked (optional)
49 -msitemplate: Source of the msi file templates (Windows compiler only)
50 -msilanguage: Source of the msi file templates (Windows compiler only)
51 -buildid: Current BuildID (optional)
52 -pro: Product version
53 -format: Package format
54 -debian: Create Debian packages for Linux
55 -dontunzip: do not unzip all files with flag ARCHIVE
56 -dontcallepm : do not call epm to create install sets (opt., non-Windows only)
57 -ispatchedepm : Usage of a patched (non-standard) epm (opt., non-Windows only)
58 -copyproject : is set for projects that are only used for copying (optional)
59 -languagepack : do create a languagepack, no product pack (optional)
60 -helppack : do create a helppack, no product pack (optional)
61 -strip: Stripping files (Unix only)
62 -packer: Path and parameters for tarball packaging tool (default: gzip (Unix only))
63 -log : Logging all available information (optional)
64
65 Examples for Windows:
66
67 perl make_epmlist.pl -f zip.lst -p OfficeFAT -l en-US
68 -u /export/unpack -buildid 8712
69 -msitemplate /export/msi_files
70 -msilanguage /export/msi_languages
71
72 Examples for Non-Windows:
73
74 perl make_epmlist.pl -f zip.lst -p OfficeFAT -l en-US -format rpm
75 -u /export/unpack -buildid 8712 -ispatchedepm
76 --------------------------------------------------------------------------------
77 End
78 exit(-1);
79 }
80
81 #########################################
82 # Writing all parameter into logfile
83 #########################################
84
85 sub saveparameter
86 {
87 my $include = "";
88
89 installer::logger::globallog("Command line arguments:");
90
91 for ( my $i = 0; $i <= $#ARGV; $i++ )
92 {
93 $include = $ARGV[$i] . "\n";
94 push(@installer::globals::globallogfileinfo, $include);
95 }
96
97 # also saving global settings:
98
99 $include = "Separator: $installer::globals::separator\n";
100 push(@installer::globals::globallogfileinfo, $include);
101
102 }
103
104 #####################################
105 # Reading parameter
106 #####################################
107
108 sub getparameter
109 {
110 while ( $#ARGV >= 0 )
111 {
112 my $param = shift(@ARGV);
113
114 if ($param eq "-f") { $installer::globals::ziplistname = shift(@ARGV); }
115 elsif ($param eq "-s") { $installer::globals::setupscriptname = shift(@ARGV); }
116 elsif ($param eq "-p") { $installer::globals::product = shift(@ARGV); }
117 elsif ($param eq "-l") { $installer::globals::languagelist = shift(@ARGV); }
118 elsif ($param eq "-dontunzip") { $installer::globals::dounzip = 0; }
119 elsif ($param eq "-pro") { $installer::globals::pro = 1; }
120 elsif ($param eq "-format") { $installer::globals::packageformat = shift(@ARGV); }
121 elsif ($param eq "-quiet") { $installer::globals::quiet = 1; }
122 elsif ($param eq "-verbose") { $installer::globals::quiet = 0; }
123 elsif ($param eq "-u") { $installer::globals::unpackpath = shift(@ARGV); }
124 elsif ($param eq "-i") { $installer::globals::rootpath = shift(@ARGV); }
125 elsif ($param eq "-dontcallepm") { $installer::globals::call_epm = 0; }
126 elsif ($param eq "-msitemplate") { $installer::globals::idttemplatepath = shift(@ARGV); }
127 elsif ($param eq "-msilanguage") { $installer::globals::idtlanguagepath = shift(@ARGV); }
128 elsif ($param eq "-buildid") { $installer::globals::buildid = shift(@ARGV); }
129 elsif ($param eq "-copyproject") { $installer::globals::is_copy_only_project = 1; }
130 elsif ($param eq "-languagepack") { $installer::globals::languagepack = 1; }
131 elsif ($param eq "-helppack") { $installer::globals::helppack = 1;}
132 elsif ($param eq "-debian") { $installer::globals::debian = 1; }
133 elsif ($param eq "-strip") { $installer::globals::strip = 1; }
134 elsif ($param eq "-packer") { $installer::globals::packertool = shift(@ARGV); }
135 elsif ($param eq "-destdir") # new parameter for simple installer
136 {
137 $installer::globals::rootpath ne "" && die "must set destdir before -i or -simple";
138
139 my $path = shift(@ARGV);
140 mkdir $path;
141 $installer::globals::destdir = Cwd::realpath($path);
142 }
143 elsif ($param eq "-simple") # new parameter for simple installer
144 {
145 $installer::globals::simple = 1;
146 $installer::globals::call_epm = 0;
147 $installer::globals::makedownload = 0;
148 my $path = shift(@ARGV);
149 $path =~ s/^\Q$installer::globals::destdir\E//;
150 $installer::globals::rootpath = $path;
151 }
152 else
153 {
154 installer::logger::print_error( "unknown parameter: $param" );
155 usage();
156 exit(-1);
157 }
158 }
159
160 # Usage of simple installer (not for Windows):
161 # $PERL -w $SRCDIR/solenv/bin/make_installer.pl \
162 # -f openoffice.lst -l en-US -p OpenOffice \
163 # -buildid $BUILD -rpm \
164 # -destdir /tmp/nurk -simple $INSTALL_PATH
165 }
166
167 ############################################
168 # Controlling the fundamental parameter
169 # (required for every process)
170 ############################################
171
172 sub control_fundamental_parameter
173 {
174 if ($installer::globals::product eq "")
175 {
176 installer::logger::print_error( "Product name not set!" );
177 usage();
178 exit(-1);
179 }
180 }
181
182 ##########################################################
183 # The path parameters can be relative or absolute.
184 # This function creates absolute paths.
185 ##########################################################
186
187 sub make_path_absolute
188 {
189 my ($pathref) = @_;
190 return if ( $^O =~ /MSWin/i ); # no need to do anything here
191
192 if ( $installer::globals::isunix )
193 {
194 if (!($$pathref =~ /^\s*\//)) # this is a relative unix path
195 {
196 $$pathref = cwd() . $installer::globals::separator . $$pathref;
197 }
198 }
199
200 if ( $installer::globals::iswin )
201 {
202 if ( $^O =~ /cygwin/i )
203 {
204 if ( $$pathref !~ /^\s*\// && $$pathref !~ /^\s*\w\:/ ) # not an absolute POSIX or DOS path
205 {
206 $$pathref = cwd() . $installer::globals::separator . $$pathref;
207 }
208 my $p = $$pathref;
209 chomp( $p );
210 my $q = '';
211 # Avoid the $(LANG) problem.
212 if ($p =~ /(\A.*)(\$\(.*\Z)/) {
213 $p = $1;
214 $q = $2;
215 }
216 $p =~ s/\\/\\\\/g;
217 chomp( $p = qx{cygpath -w "$p"} );
218 $$pathref = $p.$q;
219 # Use windows paths, but with '/'s.
220 $$pathref =~ s/\\/\//g;
221 }
222 else
223 {
224 if (!($$pathref =~ /^\s*\w\:/)) # this is a relative windows path (no dos drive)
225 {
226 $$pathref = cwd() . $installer::globals::separator . $$pathref;
227
228 $$pathref =~ s/\//\\/g;
229 }
230 }
231 }
232 $$pathref =~ s/[\/\\]\s*$//; # removing ending slashes
233 }
234
235 # Setting some global parameters
236 # This has to be expanded with further platforms
237
238 sub setglobalvariables
239 {
240 # Setting the installertype directory corresponding to the environment variable PKGFORMAT
241 # The global variable $installer::globals::packageformat can only contain one package format.
242 # If PKGFORMAT contains more than one format (for example "rpm deb") this is split in the
243 # makefile calling the perl program.
244 $installer::globals::installertypedir = $installer::globals::packageformat;
245
246 if ( $installer::globals::os eq 'WNT' )
247 {
248 $installer::globals::iswindowsbuild = 1;
249 }
250
251 if ( $installer::globals::os eq 'SOLARIS')
252 {
253 $installer::globals::issolarisbuild = 1;
254 if ( $installer::globals::packageformat eq "pkg" )
255 {
256 $installer::globals::issolarispkgbuild = 1;
257 $installer::globals::epmoutpath = "packages";
258 }
259 if ( $installer::globals::cpuname eq 'INTEL')
260 {
261 $installer::globals::issolarisx86build = 1;
262 }
263 else
264 {
265 $installer::globals::issolarissparcbuild = 1;
266 }
267 }
268
269 if ( $installer::globals::os eq 'MACOSX' )
270 {
271 $installer::globals::ismacbuild = 1;
272
273 if ( $installer::globals::packageformat eq "dmg" )
274 {
275 $installer::globals::ismacdmgbuild = 1;
276 }
277 }
278
279 if ( $installer::globals::os eq 'OPENBSD')
280 {
281 $installer::globals::epmoutpath = "openbsd";
282 }
283
284 if ( $installer::globals::os eq 'FREEBSD')
285 {
286 $installer::globals::isfreebsdbuild = 1;
287
288 if ( $installer::globals::packageformat eq "bsd" )
289 {
290 $installer::globals::epmoutpath = "freebsd";
291 $installer::globals::isfreebsdpkgbuild = 1;
292 }
293 }
294
295 if ($installer::globals::os eq 'LINUX')
296 {
297 $installer::globals::islinuxbuild = 1;
298 if ( $installer::globals::packageformat eq "rpm" )
299 {
300 $installer::globals::isrpmbuild = 1;
301 $installer::globals::epmoutpath = "RPMS";
302
303 if ( $installer::globals::rpm eq "" ) { installer::exiter::exit_program("ERROR: Environment variable \"\$RPM\" has to be defined!", "setglobalvariables"); }
304 }
305
306 # Creating Debian packages ?
307 if (( $installer::globals::packageformat eq "deb" ) || ( $installer::globals::debian ))
308 {
309 $installer::globals::debian = 1;
310 $installer::globals::packageformat = "deb";
311 my $message = "Creating Debian packages";
312 installer::logger::print_message( $message );
313 push(@installer::globals::globallogfileinfo, $message);
314 $installer::globals::isrpmbuild = 0;
315 $installer::globals::isdebbuild = 1;
316 $installer::globals::epmoutpath = "DEBS";
317 }
318 }
319
320 # Defaulting to native package format for epm
321
322 # no languages defined as parameter
323 if ($installer::globals::languagelist eq "") { $installer::globals::languages_defined_in_productlist = 1; }
324
325 # setting and creating the unpackpath
326
327 if ($installer::globals::unpackpath eq "") # unpackpath not set
328 {
329 $installer::globals::unpackpath = cwd();
330 }
331
332 if ($installer::globals::workpath eq "") # workpath not set
333 {
334 $installer::globals::workpath = cwd();
335 }
336
337 if ( $installer::globals::localunpackdir ne "" ) { $installer::globals::unpackpath = $installer::globals::localunpackdir; }
338
339 if (!($installer::globals::unpackpath eq ""))
340 {
341 make_path_absolute(\$installer::globals::unpackpath);
342 }
343
344 $installer::globals::unpackpath =~ s/\Q$installer::globals::separator\E\s*$//;
345
346 if (! -d $installer::globals::unpackpath ) # create unpackpath
347 {
348 installer::systemactions::create_directory($installer::globals::unpackpath);
349 }
350
351 # setting and creating the temppath
352
353 if ( $ENV{'TMPDIR'} )
354 {
355 $installer::globals::temppath = $ENV{'TMPDIR'};
356 $installer::globals::temppath =~ s/\Q$installer::globals::separator\E\s*$//; # removing ending slashes and backslashes
357 $installer::globals::temppath .= $installer::globals::separator . 'ooopackagingXXXXXX';
358 $installer::globals::temppath = mkdtemp($installer::globals::temppath);
359
360 my $dirsave = $installer::globals::temppath;
361
362 if ( $installer::globals::platformid eq 'maosx_x86_64')
363 {
364 chmod 0777, $installer::globals::temppath;
365 }
366
367 $installer::globals::temppath = $installer::globals::temppath . $installer::globals::separator . "i";
368 $installer::globals::temppath = installer::systemactions::create_pid_directory($installer::globals::temppath);
369 push(@installer::globals::removedirs, $installer::globals::temppath);
370
371 if ( ! -d $installer::globals::temppath ) { installer::exiter::exit_program("ERROR: Failed to create directory $installer::globals::temppath ! Possible reason: Wrong privileges in directory $dirsave .", "setglobalvariables"); }
372
373 $installer::globals::temppath = $installer::globals::temppath . $installer::globals::separator . $installer::globals::platformid;
374 installer::systemactions::create_directory($installer::globals::temppath);
375 if ( $^O =~ /cygwin/i )
376 {
377 $installer::globals::cyg_temppath = $installer::globals::temppath;
378 $installer::globals::cyg_temppath =~ s/\\/\\\\/g;
379 chomp( $installer::globals::cyg_temppath = qx{cygpath -w "$installer::globals::cyg_temppath"} );
380 }
381 $installer::globals::temppathdefined = 1;
382 }
383 else
384 {
385 $installer::globals::temppathdefined = 0;
386 }
387
388 # only one cab file, if Windows msp patches shall be prepared
389 if ( $installer::globals::prepare_winpatch ) { $installer::globals::number_of_cabfiles = 1; }
390
391 }
392
393 ############################################
394 # Controlling the parameter that are
395 # required for special processes
396 ############################################
397
398 sub control_required_parameter
399 {
400 if (!($installer::globals::is_copy_only_project))
401 {
402 ##############################################################################################
403 # idt template path. Only required for Windows build
404 # for the creation of the msi database.
405 ##############################################################################################
406
407 if (($installer::globals::idttemplatepath eq "") && ($installer::globals::iswindowsbuild))
408 {
409 installer::logger::print_error( "idt template path not set (-msitemplate)!" );
410 usage();
411 exit(-1);
412 }
413
414 ##############################################################################################
415 # idt language path. Only required for Windows build
416 # for the creation of the msi database.
417 ##############################################################################################
418
419 if (($installer::globals::idtlanguagepath eq "") && ($installer::globals::iswindowsbuild))
420 {
421 installer::logger::print_error( "idt language path not set (-msilanguage)!" );
422 usage();
423 exit(-1);
424 }
425
426 # Analyzing the idt template path
427
428 if (!($installer::globals::idttemplatepath eq "")) # idttemplatepath set, relative or absolute?
429 {
430 make_path_absolute(\$installer::globals::idttemplatepath);
431 }
432
433 installer::remover::remove_ending_pathseparator(\$installer::globals::idttemplatepath);
434
435 # Analyzing the idt language path
436
437 if (!($installer::globals::idtlanguagepath eq "")) # idtlanguagepath set, relative or absolute?
438 {
439 make_path_absolute(\$installer::globals::idtlanguagepath);
440 }
441
442 installer::remover::remove_ending_pathseparator(\$installer::globals::idtlanguagepath);
443
444 # In the msi template directory a files "codes.txt" has to exist, in which the ProductCode
445 # and the UpgradeCode for the product are defined.
446 # The name "codes.txt" can be overwritten in Product definition with CODEFILENAME (msiglobal.pm)
447
448 if (( $installer::globals::iswindowsbuild ) && ( $installer::globals::packageformat ne "archive" ) && ( $installer::globals::packageformat ne "installed" ))
449 {
450 $installer::globals::codefilename = $installer::globals::idttemplatepath . $installer::globals::separator . $installer::globals::codefilename;
451 installer::files::check_file($installer::globals::codefilename);
452 $installer::globals::componentfilename = $installer::globals::idttemplatepath . $installer::globals::separator . $installer::globals::componentfilename;
453 installer::files::check_file($installer::globals::componentfilename);
454 }
455
456 }
457
458 #######################################
459 # Testing existence of files
460 # also for copy-only projects
461 #######################################
462
463 if ($installer::globals::ziplistname eq "")
464 {
465 installer::logger::print_error( "ERROR: Zip list file has to be defined (Parameter -f) !" );
466 usage();
467 exit(-1);
468 }
469 else
470 {
471 installer::files::check_file($installer::globals::ziplistname);
472 }
473
474 if ($installer::globals::setupscriptname eq "") { $installer::globals::setupscript_defined_in_productlist = 1; }
475 else { installer::files::check_file($installer::globals::setupscriptname); } # if the setupscript file is defined, it has to exist
476
477 }
478
479 ################################################
480 # Writing parameter to shell and into logfile
481 ################################################
482
483 sub outputparameter
484 {
485 my $element;
486
487 my @output = ();
488
489 push(@output, "\n########################################################\n");
490 push(@output, "Product list file: $installer::globals::ziplistname\n");
491 if (!($installer::globals::setupscript_defined_in_productlist))
492 {
493 push(@output, "Setup script: $installer::globals::setupscriptname\n");
494 }
495 else
496 {
497 push(@output, "Taking setup script from workdir\n");
498 }
499 push(@output, "Unpackpath: $installer::globals::unpackpath\n");
500 push(@output, "PLATFORMID: $installer::globals::platformid\n");
501 push(@output, "OS: $installer::globals::os\n");
502 push(@output, "CPUNAME: $installer::globals::cpuname\n");
503 push(@output, "COM: $installer::globals::com\n");
504 push(@output, "Product: $installer::globals::product\n");
505 push(@output, "BuildID: $installer::globals::buildid\n");
506 push(@output, "Build: $installer::globals::build\n");
507 if ( $installer::globals::pro ) { push(@output, "Product version\n"); }
508 else { push(@output, "Non-Product version\n"); }
509 if ( $installer::globals::rootpath eq "" ) { push(@output, "Using default installpath\n"); }
510 else { push(@output, "Installpath: $installer::globals::rootpath\n"); }
511 push(@output, "Package format: $installer::globals::packageformat\n");
512 if (!($installer::globals::idttemplatepath eq "")) { push(@output, "msi templatepath: $installer::globals::idttemplatepath\n"); }
513 if ((!($installer::globals::idttemplatepath eq "")) && (!($installer::globals::iswindowsbuild))) { push(@output, "msi template path will be ignored for non Windows builds!\n"); }
514 if (!($installer::globals::idtlanguagepath eq "")) { push(@output, "msi languagepath: $installer::globals::idtlanguagepath\n"); }
515 if ((!($installer::globals::idtlanguagepath eq "")) && (!($installer::globals::iswindowsbuild))) { push(@output, "msi language path will be ignored for non Windows builds!\n"); }
516 if ((!($installer::globals::iswindowsbuild)) && ( $installer::globals::call_epm )) { push(@output, "Calling epm\n"); }
517 if ((!($installer::globals::iswindowsbuild)) && (!($installer::globals::call_epm))) { push(@output, "Not calling epm\n"); }
518 if ( $installer::globals::strip ) { push(@output, "Stripping files\n"); }
519 else { push(@output, "No file stripping\n"); }
520 if ( $installer::globals::debian ) { push(@output, "Linux: Creating Debian packages\n"); }
521 if ( $installer::globals::dounzip ) { push(@output, "Unzip ARCHIVE files\n"); }
522 else { push(@output, "Not unzipping ARCHIVE files\n"); }
523 if (!($installer::globals::languages_defined_in_productlist))
524 {
525 push(@output, "Languages:\n");
526 foreach $element (@installer::globals::languageproducts) { push(@output, "\t$element\n"); }
527 }
528 else
529 {
530 push(@output, "Languages defined in $installer::globals::ziplistname\n");
531 }
532 if ( $installer::globals::is_copy_only_project ) { push(@output, "This is a copy only project!\n"); }
533 if ( $installer::globals::languagepack ) { push(@output, "Creating language pack!\n"); }
534 if ( $installer::globals::helppack ) { push(@output, "Creating help pack!\n"); }
535 push(@output, "########################################################\n");
536
537 # output into shell and into logfile
538
539 for ( my $i = 0; $i <= $#output; $i++ )
540 {
541 installer::logger::print_message( $output[$i] );
542 push(@installer::globals::globallogfileinfo, $output[$i]);
543 }
544 }
545
546 1;