Version 6.1.4.1, tag libreoffice-6.1.4.1
[LibreOffice.git] / solenv / bin / modules / installer / parameter.pm
blob352b6f94c19b0a56bb50dffcb2e448e94dd8e0c9
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::parameter;
21 use Cwd;
22 use installer::exiter;
23 use installer::files;
24 use installer::globals;
25 use installer::logger;
26 use installer::remover;
27 use installer::systemactions;
28 use File::Temp qw/ :mktemp /;
30 ############################################
31 # Parameter Operations
32 ############################################
34 sub usage
36 print <<Ende;
37 --------------------------------------------------------------------------------
38 The following parameter are needed:
39 -f: Path to the product list (required)
40 -s: Path to the setup script (optional, if defined in product list)
41 -i: Install path of the product (/opt/openofficeorg20) (optional)
42 -p: Product from product list to be created (required)
43 -l: Language of the product (comma and hash) (optional, defined in productlist)
44 -simple: Path to do a simple install to
45 -u: Path, in which zipfiles are unpacked (optional)
46 -msitemplate: Source of the msi file templates (Windows compiler only)
47 -msilanguage: Source of the msi file templates (Windows compiler only)
48 -buildid: Current BuildID (optional)
49 -pro: Product version
50 -format: Package format
51 -debian: Create Debian packages for Linux
52 -dontunzip: do not unzip all files with flag ARCHIVE
53 -dontcallepm : do not call epm to create install sets (opt., non-Windows only)
54 -ispatchedepm : Usage of a patched (non-standard) epm (opt., non-Windows only)
55 -copyproject : is set for projects that are only used for copying (optional)
56 -languagepack : do create a languagepack, no product pack (optional)
57 -helppack : do create a helppack, no product pack (optional)
58 -strip: Stripping files (Unix only)
59 -log : Logging all available information (optional)
61 Examples for Windows:
63 perl make_epmlist.pl -f zip.lst -p OfficeFAT -l en-US
64 -u /export/unpack -buildid 8712
65 -msitemplate /export/msi_files
66 -msilanguage /export/msi_languages
68 Examples for Non-Windows:
70 perl make_epmlist.pl -f zip.lst -p OfficeFAT -l en-US -format rpm
71 -u /export/unpack -buildid 8712 -ispatchedepm
72 --------------------------------------------------------------------------------
73 Ende
74 exit(-1);
77 #########################################
78 # Writing all parameter into logfile
79 #########################################
81 sub saveparameter
83 my $include = "";
85 installer::logger::globallog("Command line arguments:");
87 for ( my $i = 0; $i <= $#ARGV; $i++ )
89 $include = $ARGV[$i] . "\n";
90 push(@installer::globals::globallogfileinfo, $include);
93 # also saving global settings:
95 $include = "Separator: $installer::globals::separator\n";
96 push(@installer::globals::globallogfileinfo, $include);
100 #####################################
101 # Reading parameter
102 #####################################
104 sub getparameter
106 while ( $#ARGV >= 0 )
108 my $param = shift(@ARGV);
110 if ($param eq "-f") { $installer::globals::ziplistname = shift(@ARGV); }
111 elsif ($param eq "-s") { $installer::globals::setupscriptname = shift(@ARGV); }
112 elsif ($param eq "-p") { $installer::globals::product = shift(@ARGV); }
113 elsif ($param eq "-l") { $installer::globals::languagelist = shift(@ARGV); }
114 elsif ($param eq "-dontunzip") { $installer::globals::dounzip = 0; }
115 elsif ($param eq "-pro") { $installer::globals::pro = 1; }
116 elsif ($param eq "-format") { $installer::globals::packageformat = shift(@ARGV); }
117 elsif ($param eq "-quiet") { $installer::globals::quiet = 1; }
118 elsif ($param eq "-verbose") { $installer::globals::quiet = 0; }
119 elsif ($param eq "-u") { $installer::globals::unpackpath = shift(@ARGV); }
120 elsif ($param eq "-i") { $installer::globals::rootpath = shift(@ARGV); }
121 elsif ($param eq "-dontcallepm") { $installer::globals::call_epm = 0; }
122 elsif ($param eq "-msitemplate") { $installer::globals::idttemplatepath = shift(@ARGV); }
123 elsif ($param eq "-msilanguage") { $installer::globals::idtlanguagepath = shift(@ARGV); }
124 elsif ($param eq "-buildid") { $installer::globals::buildid = shift(@ARGV); }
125 elsif ($param eq "-copyproject") { $installer::globals::is_copy_only_project = 1; }
126 elsif ($param eq "-languagepack") { $installer::globals::languagepack = 1; }
127 elsif ($param eq "-helppack") { $installer::globals::helppack = 1;}
128 elsif ($param eq "-debian") { $installer::globals::debian = 1; }
129 elsif ($param eq "-strip") { $installer::globals::strip = 1; }
130 elsif ($param eq "-destdir") # new parameter for simple installer
132 $installer::globals::rootpath ne "" && die "must set destdir before -i or -simple";
134 my $path = shift(@ARGV);
135 mkdir $path;
136 $installer::globals::destdir = Cwd::realpath($path);
138 elsif ($param eq "-simple") # new parameter for simple installer
140 $installer::globals::simple = 1;
141 $installer::globals::call_epm = 0;
142 $installer::globals::makedownload = 0;
143 my $path = shift(@ARGV);
144 $path =~ s/^\Q$installer::globals::destdir\E//;
145 $installer::globals::rootpath = $path;
147 else
149 installer::logger::print_error( "unknown parameter: $param" );
150 usage();
151 exit(-1);
155 # Usage of simple installer (not for Windows):
156 # $PERL -w $SRCDIR/solenv/bin/make_installer.pl \
157 # -f openoffice.lst -l en-US -p OpenOffice \
158 # -buildid $BUILD -rpm \
159 # -destdir /tmp/nurk -simple $INSTALL_PATH
162 ############################################
163 # Controlling the fundamental parameter
164 # (required for every process)
165 ############################################
167 sub control_fundamental_parameter
169 if ($installer::globals::product eq "")
171 installer::logger::print_error( "Product name not set!" );
172 usage();
173 exit(-1);
177 ##########################################################
178 # The path parameters can be relative or absolute.
179 # This function creates absolute paths.
180 ##########################################################
182 sub make_path_absolute
184 my ($pathref) = @_;
186 if ( $installer::globals::isunix )
188 if (!($$pathref =~ /^\s*\//)) # this is a relative unix path
190 $$pathref = cwd() . $installer::globals::separator . $$pathref;
194 if ( $installer::globals::iswin )
196 if ( $^O =~ /cygwin/i )
198 if ( $$pathref !~ /^\s*\// && $$pathref !~ /^\s*\w\:/ ) # not an absolute POSIX or DOS path
200 $$pathref = cwd() . $installer::globals::separator . $$pathref;
202 my $p = $$pathref;
203 chomp( $p );
204 my $q = '';
205 # Avoid the $(LANG) problem.
206 if ($p =~ /(\A.*)(\$\(.*\Z)/) {
207 $p = $1;
208 $q = $2;
210 $p =~ s/\\/\\\\/g;
211 chomp( $p = qx{cygpath -w "$p"} );
212 $$pathref = $p.$q;
213 # Use windows paths, but with '/'s.
214 $$pathref =~ s/\\/\//g;
216 else
218 if (!($$pathref =~ /^\s*\w\:/)) # this is a relative windows path (no dos drive)
220 $$pathref = cwd() . $installer::globals::separator . $$pathref;
222 $$pathref =~ s/\//\\/g;
226 $$pathref =~ s/[\/\\]\s*$//; # removing ending slashes
229 # Setting some global parameters
230 # This has to be expanded with further platforms
232 sub setglobalvariables
234 # Setting the installertype directory corresponding to the environment variable PKGFORMAT
235 # The global variable $installer::globals::packageformat can only contain one package format.
236 # If PKGFORMAT contains more than one format (for example "rpm deb") this is splitted in the
237 # makefile calling the perl program.
238 $installer::globals::installertypedir = $installer::globals::packageformat;
240 if ( $installer::globals::os eq 'WNT' )
242 if ( $installer::globals::cpuname eq 'INTEL')
244 $installer::globals::iswindowsbuild = 1;
245 $installer::globals::iswin64build = 0;
247 else
249 $installer::globals::iswindowsbuild = 1;
250 $installer::globals::iswin64build = 1;
254 if ( $installer::globals::os eq 'SOLARIS')
256 $installer::globals::issolarisbuild = 1;
257 if ( $installer::globals::packageformat eq "pkg" )
259 $installer::globals::issolarispkgbuild = 1;
260 $installer::globals::epmoutpath = "packages";
262 if ( $installer::globals::cpuname eq 'INTEL')
264 $installer::globals::issolarisx86build = 1;
266 else
268 $installer::globals::issolarissparcbuild = 1;
272 if ( $installer::globals::platformid eq 'macosx_x86_64')
274 $installer::globals::ismacbuild = 1;
276 if ( $installer::globals::packageformat eq "dmg" )
278 $installer::globals::ismacdmgbuild = 1;
282 if ( $installer::globals::os eq 'OPENBSD')
284 $installer::globals::epmoutpath = "openbsd";
287 if ( $installer::globals::os eq 'FREEBSD')
289 $installer::globals::isfreebsdbuild = 1;
291 if ( $installer::globals::packageformat eq "bsd" )
293 $installer::globals::epmoutpath = "freebsd";
294 $installer::globals::isfreebsdpkgbuild = 1;
298 if ($installer::globals::os eq 'AIX')
300 if ( $installer::globals::packageformat eq "rpm" )
302 $installer::globals::isrpmbuild = 1;
303 $installer::globals::epmoutpath = "RPMS";
305 if ( $installer::globals::rpm eq "" ) { installer::exiter::exit_program("ERROR: Environment variable \"\$RPM\" has to be defined!", "setglobalvariables"); }
308 if ($installer::globals::os eq 'LINUX')
310 $installer::globals::islinuxbuild = 1;
311 if ( $installer::globals::packageformat eq "rpm" )
313 $installer::globals::isrpmbuild = 1;
314 $installer::globals::epmoutpath = "RPMS";
316 if ( $installer::globals::rpm eq "" ) { installer::exiter::exit_program("ERROR: Environment variable \"\$RPM\" has to be defined!", "setglobalvariables"); }
319 # Creating Debian packages ?
320 if (( $installer::globals::packageformat eq "deb" ) || ( $installer::globals::debian ))
322 $installer::globals::debian = 1;
323 $installer::globals::packageformat = "deb";
324 my $message = "Creating Debian packages";
325 installer::logger::print_message( $message );
326 push(@installer::globals::globallogfileinfo, $message);
327 $installer::globals::isrpmbuild = 0;
328 $installer::globals::isdebbuild = 1;
329 $installer::globals::epmoutpath = "DEBS";
333 # Defaulting to native package format for epm
335 # no languages defined as parameter
336 if ($installer::globals::languagelist eq "") { $installer::globals::languages_defined_in_productlist = 1; }
338 # setting and creating the unpackpath
340 if ($installer::globals::unpackpath eq "") # unpackpath not set
342 $installer::globals::unpackpath = cwd();
345 if ($installer::globals::workpath eq "") # workpath not set
347 $installer::globals::workpath = cwd();
350 if ( $installer::globals::localunpackdir ne "" ) { $installer::globals::unpackpath = $installer::globals::localunpackdir; }
352 if (!($installer::globals::unpackpath eq ""))
354 make_path_absolute(\$installer::globals::unpackpath);
357 $installer::globals::unpackpath =~ s/\Q$installer::globals::separator\E\s*$//;
359 if (! -d $installer::globals::unpackpath ) # create unpackpath
361 installer::systemactions::create_directory($installer::globals::unpackpath);
364 # setting and creating the temppath
366 if ( $ENV{'TMPDIR'} )
368 $installer::globals::temppath = $ENV{'TMPDIR'};
369 $installer::globals::temppath =~ s/\Q$installer::globals::separator\E\s*$//; # removing ending slashes and backslashes
370 $installer::globals::temppath .= $installer::globals::separator . 'ooopackagingXXXXXX';
371 $installer::globals::temppath = mkdtemp($installer::globals::temppath);
373 my $dirsave = $installer::globals::temppath;
375 if ( $installer::globals::platformid eq 'maosx_x86_64')
377 chmod 0777, $installer::globals::temppath;
380 $installer::globals::temppath = $installer::globals::temppath . $installer::globals::separator . "i";
381 $installer::globals::temppath = installer::systemactions::create_pid_directory($installer::globals::temppath);
382 push(@installer::globals::removedirs, $installer::globals::temppath);
384 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"); }
386 $installer::globals::temppath = $installer::globals::temppath . $installer::globals::separator . $installer::globals::platformid;
387 installer::systemactions::create_directory($installer::globals::temppath);
388 if ( $^O =~ /cygwin/i )
390 $installer::globals::cyg_temppath = $installer::globals::temppath;
391 $installer::globals::cyg_temppath =~ s/\\/\\\\/g;
392 chomp( $installer::globals::cyg_temppath = qx{cygpath -w "$installer::globals::cyg_temppath"} );
394 $installer::globals::temppathdefined = 1;
396 else
398 $installer::globals::temppathdefined = 0;
401 # only one cab file, if Windows msp patches shall be prepared
402 if ( $installer::globals::prepare_winpatch ) { $installer::globals::number_of_cabfiles = 1; }
406 ############################################
407 # Controlling the parameter that are
408 # required for special processes
409 ############################################
411 sub control_required_parameter
413 if (!($installer::globals::is_copy_only_project))
415 ##############################################################################################
416 # idt template path. Only required for Windows build
417 # for the creation of the msi database.
418 ##############################################################################################
420 if (($installer::globals::idttemplatepath eq "") && ($installer::globals::iswindowsbuild))
422 installer::logger::print_error( "idt template path not set (-msitemplate)!" );
423 usage();
424 exit(-1);
427 ##############################################################################################
428 # idt language path. Only required for Windows build
429 # for the creation of the msi database.
430 ##############################################################################################
432 if (($installer::globals::idtlanguagepath eq "") && ($installer::globals::iswindowsbuild))
434 installer::logger::print_error( "idt language path not set (-msilanguage)!" );
435 usage();
436 exit(-1);
439 # Analyzing the idt template path
441 if (!($installer::globals::idttemplatepath eq "")) # idttemplatepath set, relative or absolute?
443 make_path_absolute(\$installer::globals::idttemplatepath);
446 installer::remover::remove_ending_pathseparator(\$installer::globals::idttemplatepath);
448 # Analyzing the idt language path
450 if (!($installer::globals::idtlanguagepath eq "")) # idtlanguagepath set, relative or absolute?
452 make_path_absolute(\$installer::globals::idtlanguagepath);
455 installer::remover::remove_ending_pathseparator(\$installer::globals::idtlanguagepath);
457 # In the msi template directory a files "codes.txt" has to exist, in which the ProductCode
458 # and the UpgradeCode for the product are defined.
459 # The name "codes.txt" can be overwritten in Product definition with CODEFILENAME (msiglobal.pm)
461 if (( $installer::globals::iswindowsbuild ) && ( $installer::globals::packageformat ne "archive" ) && ( $installer::globals::packageformat ne "installed" ))
463 $installer::globals::codefilename = $installer::globals::idttemplatepath . $installer::globals::separator . $installer::globals::codefilename;
464 installer::files::check_file($installer::globals::codefilename);
465 $installer::globals::componentfilename = $installer::globals::idttemplatepath . $installer::globals::separator . $installer::globals::componentfilename;
466 installer::files::check_file($installer::globals::componentfilename);
471 #######################################
472 # Testing existence of files
473 # also for copy-only projects
474 #######################################
476 if ($installer::globals::ziplistname eq "")
478 installer::logger::print_error( "ERROR: Zip list file has to be defined (Parameter -f) !" );
479 usage();
480 exit(-1);
482 else
484 installer::files::check_file($installer::globals::ziplistname);
487 if ($installer::globals::setupscriptname eq "") { $installer::globals::setupscript_defined_in_productlist = 1; }
488 else { installer::files::check_file($installer::globals::setupscriptname); } # if the setupscript file is defined, it has to exist
492 ################################################
493 # Writing parameter to shell and into logfile
494 ################################################
496 sub outputparameter
498 my $element;
500 my @output = ();
502 push(@output, "\n########################################################\n");
503 push(@output, "Product list file: $installer::globals::ziplistname\n");
504 if (!($installer::globals::setupscript_defined_in_productlist))
506 push(@output, "Setup script: $installer::globals::setupscriptname\n");
508 else
510 push(@output, "Taking setup script from workdir\n");
512 push(@output, "Unpackpath: $installer::globals::unpackpath\n");
513 push(@output, "PLATFORMID: $installer::globals::platformid\n");
514 push(@output, "OS: $installer::globals::os\n");
515 push(@output, "CPUNAME: $installer::globals::cpuname\n");
516 push(@output, "COM: $installer::globals::com\n");
517 push(@output, "Product: $installer::globals::product\n");
518 push(@output, "BuildID: $installer::globals::buildid\n");
519 push(@output, "Build: $installer::globals::build\n");
520 if ( $installer::globals::pro ) { push(@output, "Product version\n"); }
521 else { push(@output, "Non-Product version\n"); }
522 if ( $installer::globals::rootpath eq "" ) { push(@output, "Using default installpath\n"); }
523 else { push(@output, "Installpath: $installer::globals::rootpath\n"); }
524 push(@output, "Package format: $installer::globals::packageformat\n");
525 if (!($installer::globals::idttemplatepath eq "")) { push(@output, "msi templatepath: $installer::globals::idttemplatepath\n"); }
526 if ((!($installer::globals::idttemplatepath eq "")) && (!($installer::globals::iswindowsbuild))) { push(@output, "msi template path will be ignored for non Windows builds!\n"); }
527 if (!($installer::globals::idtlanguagepath eq "")) { push(@output, "msi languagepath: $installer::globals::idtlanguagepath\n"); }
528 if ((!($installer::globals::idtlanguagepath eq "")) && (!($installer::globals::iswindowsbuild))) { push(@output, "msi language path will be ignored for non Windows builds!\n"); }
529 if ((!($installer::globals::iswindowsbuild)) && ( $installer::globals::call_epm )) { push(@output, "Calling epm\n"); }
530 if ((!($installer::globals::iswindowsbuild)) && (!($installer::globals::call_epm))) { push(@output, "Not calling epm\n"); }
531 if ( $installer::globals::strip ) { push(@output, "Stripping files\n"); }
532 else { push(@output, "No file stripping\n"); }
533 if ( $installer::globals::debian ) { push(@output, "Linux: Creating Debian packages\n"); }
534 if ( $installer::globals::dounzip ) { push(@output, "Unzip ARCHIVE files\n"); }
535 else { push(@output, "Not unzipping ARCHIVE files\n"); }
536 if (!($installer::globals::languages_defined_in_productlist))
538 push(@output, "Languages:\n");
539 foreach $element (@installer::globals::languageproducts) { push(@output, "\t$element\n"); }
541 else
543 push(@output, "Languages defined in $installer::globals::ziplistname\n");
545 if ( $installer::globals::is_copy_only_project ) { push(@output, "This is a copy only project!\n"); }
546 if ( $installer::globals::languagepack ) { push(@output, "Creating language pack!\n"); }
547 if ( $installer::globals::helppack ) { push(@output, "Creating help pack!\n"); }
548 push(@output, "########################################################\n");
550 # output into shell and into logfile
552 for ( my $i = 0; $i <= $#output; $i++ )
554 installer::logger::print_message( $output[$i] );
555 push(@installer::globals::globallogfileinfo, $output[$i]);