Version 7.6.3.2-android, tag libreoffice-7.6.3.2-android
[LibreOffice.git] / solenv / bin / modules / installer / parameter.pm
blobb183057eac1efc427a73d6f67ec13d91e0b74d2d
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 strict;
22 use warnings;
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 /;
33 ############################################
34 # Parameter Operations
35 ############################################
37 sub usage
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)
65 Examples for Windows:
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
72 Examples for Non-Windows:
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);
81 #########################################
82 # Writing all parameter into logfile
83 #########################################
85 sub saveparameter
87 my $include = "";
89 installer::logger::globallog("Command line arguments:");
91 for ( my $i = 0; $i <= $#ARGV; $i++ )
93 $include = $ARGV[$i] . "\n";
94 push(@installer::globals::globallogfileinfo, $include);
97 # also saving global settings:
99 $include = "Separator: $installer::globals::separator\n";
100 push(@installer::globals::globallogfileinfo, $include);
104 #####################################
105 # Reading parameter
106 #####################################
108 sub getparameter
110 while ( $#ARGV >= 0 )
112 my $param = shift(@ARGV);
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
137 $installer::globals::rootpath ne "" && die "must set destdir before -i or -simple";
139 my $path = shift(@ARGV);
140 mkdir $path;
141 $installer::globals::destdir = Cwd::realpath($path);
143 elsif ($param eq "-simple") # new parameter for simple installer
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;
152 else
154 installer::logger::print_error( "unknown parameter: $param" );
155 usage();
156 exit(-1);
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
167 ############################################
168 # Controlling the fundamental parameter
169 # (required for every process)
170 ############################################
172 sub control_fundamental_parameter
174 if ($installer::globals::product eq "")
176 installer::logger::print_error( "Product name not set!" );
177 usage();
178 exit(-1);
182 ##########################################################
183 # The path parameters can be relative or absolute.
184 # This function creates absolute paths.
185 ##########################################################
187 sub make_path_absolute
189 my ($pathref) = @_;
191 if ( $installer::globals::isunix )
193 if (!($$pathref =~ /^\s*\//)) # this is a relative unix path
195 $$pathref = cwd() . $installer::globals::separator . $$pathref;
199 if ( $installer::globals::iswin )
201 if ( $^O =~ /cygwin/i )
203 if ( $$pathref !~ /^\s*\// && $$pathref !~ /^\s*\w\:/ ) # not an absolute POSIX or DOS path
205 $$pathref = cwd() . $installer::globals::separator . $$pathref;
207 my $p = $$pathref;
208 chomp( $p );
209 my $q = '';
210 # Avoid the $(LANG) problem.
211 if ($p =~ /(\A.*)(\$\(.*\Z)/) {
212 $p = $1;
213 $q = $2;
215 $p =~ s/\\/\\\\/g;
216 chomp( $p = qx{cygpath -w "$p"} );
217 $$pathref = $p.$q;
218 # Use windows paths, but with '/'s.
219 $$pathref =~ s/\\/\//g;
221 else
223 if (!($$pathref =~ /^\s*\w\:/)) # this is a relative windows path (no dos drive)
225 $$pathref = cwd() . $installer::globals::separator . $$pathref;
227 $$pathref =~ s/\//\\/g;
231 $$pathref =~ s/[\/\\]\s*$//; # removing ending slashes
234 # Setting some global parameters
235 # This has to be expanded with further platforms
237 sub setglobalvariables
239 # Setting the installertype directory corresponding to the environment variable PKGFORMAT
240 # The global variable $installer::globals::packageformat can only contain one package format.
241 # If PKGFORMAT contains more than one format (for example "rpm deb") this is split in the
242 # makefile calling the perl program.
243 $installer::globals::installertypedir = $installer::globals::packageformat;
245 if ( $installer::globals::os eq 'WNT' )
247 $installer::globals::iswindowsbuild = 1;
250 if ( $installer::globals::os eq 'SOLARIS')
252 $installer::globals::issolarisbuild = 1;
253 if ( $installer::globals::packageformat eq "pkg" )
255 $installer::globals::issolarispkgbuild = 1;
256 $installer::globals::epmoutpath = "packages";
258 if ( $installer::globals::cpuname eq 'INTEL')
260 $installer::globals::issolarisx86build = 1;
262 else
264 $installer::globals::issolarissparcbuild = 1;
268 if ( $installer::globals::os eq 'MACOSX' )
270 $installer::globals::ismacbuild = 1;
272 if ( $installer::globals::packageformat eq "dmg" )
274 $installer::globals::ismacdmgbuild = 1;
278 if ( $installer::globals::os eq 'OPENBSD')
280 $installer::globals::epmoutpath = "openbsd";
283 if ( $installer::globals::os eq 'FREEBSD')
285 $installer::globals::isfreebsdbuild = 1;
287 if ( $installer::globals::packageformat eq "bsd" )
289 $installer::globals::epmoutpath = "freebsd";
290 $installer::globals::isfreebsdpkgbuild = 1;
294 if ($installer::globals::os eq 'LINUX')
296 $installer::globals::islinuxbuild = 1;
297 if ( $installer::globals::packageformat eq "rpm" )
299 $installer::globals::isrpmbuild = 1;
300 $installer::globals::epmoutpath = "RPMS";
302 if ( $installer::globals::rpm eq "" ) { installer::exiter::exit_program("ERROR: Environment variable \"\$RPM\" has to be defined!", "setglobalvariables"); }
305 # Creating Debian packages ?
306 if (( $installer::globals::packageformat eq "deb" ) || ( $installer::globals::debian ))
308 $installer::globals::debian = 1;
309 $installer::globals::packageformat = "deb";
310 my $message = "Creating Debian packages";
311 installer::logger::print_message( $message );
312 push(@installer::globals::globallogfileinfo, $message);
313 $installer::globals::isrpmbuild = 0;
314 $installer::globals::isdebbuild = 1;
315 $installer::globals::epmoutpath = "DEBS";
319 # Defaulting to native package format for epm
321 # no languages defined as parameter
322 if ($installer::globals::languagelist eq "") { $installer::globals::languages_defined_in_productlist = 1; }
324 # setting and creating the unpackpath
326 if ($installer::globals::unpackpath eq "") # unpackpath not set
328 $installer::globals::unpackpath = cwd();
331 if ($installer::globals::workpath eq "") # workpath not set
333 $installer::globals::workpath = cwd();
336 if ( $installer::globals::localunpackdir ne "" ) { $installer::globals::unpackpath = $installer::globals::localunpackdir; }
338 if (!($installer::globals::unpackpath eq ""))
340 make_path_absolute(\$installer::globals::unpackpath);
343 $installer::globals::unpackpath =~ s/\Q$installer::globals::separator\E\s*$//;
345 if (! -d $installer::globals::unpackpath ) # create unpackpath
347 installer::systemactions::create_directory($installer::globals::unpackpath);
350 # setting and creating the temppath
352 if ( $ENV{'TMPDIR'} )
354 $installer::globals::temppath = $ENV{'TMPDIR'};
355 $installer::globals::temppath =~ s/\Q$installer::globals::separator\E\s*$//; # removing ending slashes and backslashes
356 $installer::globals::temppath .= $installer::globals::separator . 'ooopackagingXXXXXX';
357 $installer::globals::temppath = mkdtemp($installer::globals::temppath);
359 my $dirsave = $installer::globals::temppath;
361 if ( $installer::globals::platformid eq 'maosx_x86_64')
363 chmod 0777, $installer::globals::temppath;
366 $installer::globals::temppath = $installer::globals::temppath . $installer::globals::separator . "i";
367 $installer::globals::temppath = installer::systemactions::create_pid_directory($installer::globals::temppath);
368 push(@installer::globals::removedirs, $installer::globals::temppath);
370 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 $installer::globals::temppath = $installer::globals::temppath . $installer::globals::separator . $installer::globals::platformid;
373 installer::systemactions::create_directory($installer::globals::temppath);
374 if ( $^O =~ /cygwin/i )
376 $installer::globals::cyg_temppath = $installer::globals::temppath;
377 $installer::globals::cyg_temppath =~ s/\\/\\\\/g;
378 chomp( $installer::globals::cyg_temppath = qx{cygpath -w "$installer::globals::cyg_temppath"} );
380 $installer::globals::temppathdefined = 1;
382 else
384 $installer::globals::temppathdefined = 0;
387 # only one cab file, if Windows msp patches shall be prepared
388 if ( $installer::globals::prepare_winpatch ) { $installer::globals::number_of_cabfiles = 1; }
392 ############################################
393 # Controlling the parameter that are
394 # required for special processes
395 ############################################
397 sub control_required_parameter
399 if (!($installer::globals::is_copy_only_project))
401 ##############################################################################################
402 # idt template path. Only required for Windows build
403 # for the creation of the msi database.
404 ##############################################################################################
406 if (($installer::globals::idttemplatepath eq "") && ($installer::globals::iswindowsbuild))
408 installer::logger::print_error( "idt template path not set (-msitemplate)!" );
409 usage();
410 exit(-1);
413 ##############################################################################################
414 # idt language path. Only required for Windows build
415 # for the creation of the msi database.
416 ##############################################################################################
418 if (($installer::globals::idtlanguagepath eq "") && ($installer::globals::iswindowsbuild))
420 installer::logger::print_error( "idt language path not set (-msilanguage)!" );
421 usage();
422 exit(-1);
425 # Analyzing the idt template path
427 if (!($installer::globals::idttemplatepath eq "")) # idttemplatepath set, relative or absolute?
429 make_path_absolute(\$installer::globals::idttemplatepath);
432 installer::remover::remove_ending_pathseparator(\$installer::globals::idttemplatepath);
434 # Analyzing the idt language path
436 if (!($installer::globals::idtlanguagepath eq "")) # idtlanguagepath set, relative or absolute?
438 make_path_absolute(\$installer::globals::idtlanguagepath);
441 installer::remover::remove_ending_pathseparator(\$installer::globals::idtlanguagepath);
443 # In the msi template directory a files "codes.txt" has to exist, in which the ProductCode
444 # and the UpgradeCode for the product are defined.
445 # The name "codes.txt" can be overwritten in Product definition with CODEFILENAME (msiglobal.pm)
447 if (( $installer::globals::iswindowsbuild ) && ( $installer::globals::packageformat ne "archive" ) && ( $installer::globals::packageformat ne "installed" ))
449 $installer::globals::codefilename = $installer::globals::idttemplatepath . $installer::globals::separator . $installer::globals::codefilename;
450 installer::files::check_file($installer::globals::codefilename);
451 $installer::globals::componentfilename = $installer::globals::idttemplatepath . $installer::globals::separator . $installer::globals::componentfilename;
452 installer::files::check_file($installer::globals::componentfilename);
457 #######################################
458 # Testing existence of files
459 # also for copy-only projects
460 #######################################
462 if ($installer::globals::ziplistname eq "")
464 installer::logger::print_error( "ERROR: Zip list file has to be defined (Parameter -f) !" );
465 usage();
466 exit(-1);
468 else
470 installer::files::check_file($installer::globals::ziplistname);
473 if ($installer::globals::setupscriptname eq "") { $installer::globals::setupscript_defined_in_productlist = 1; }
474 else { installer::files::check_file($installer::globals::setupscriptname); } # if the setupscript file is defined, it has to exist
478 ################################################
479 # Writing parameter to shell and into logfile
480 ################################################
482 sub outputparameter
484 my $element;
486 my @output = ();
488 push(@output, "\n########################################################\n");
489 push(@output, "Product list file: $installer::globals::ziplistname\n");
490 if (!($installer::globals::setupscript_defined_in_productlist))
492 push(@output, "Setup script: $installer::globals::setupscriptname\n");
494 else
496 push(@output, "Taking setup script from workdir\n");
498 push(@output, "Unpackpath: $installer::globals::unpackpath\n");
499 push(@output, "PLATFORMID: $installer::globals::platformid\n");
500 push(@output, "OS: $installer::globals::os\n");
501 push(@output, "CPUNAME: $installer::globals::cpuname\n");
502 push(@output, "COM: $installer::globals::com\n");
503 push(@output, "Product: $installer::globals::product\n");
504 push(@output, "BuildID: $installer::globals::buildid\n");
505 push(@output, "Build: $installer::globals::build\n");
506 if ( $installer::globals::pro ) { push(@output, "Product version\n"); }
507 else { push(@output, "Non-Product version\n"); }
508 if ( $installer::globals::rootpath eq "" ) { push(@output, "Using default installpath\n"); }
509 else { push(@output, "Installpath: $installer::globals::rootpath\n"); }
510 push(@output, "Package format: $installer::globals::packageformat\n");
511 if (!($installer::globals::idttemplatepath eq "")) { push(@output, "msi templatepath: $installer::globals::idttemplatepath\n"); }
512 if ((!($installer::globals::idttemplatepath eq "")) && (!($installer::globals::iswindowsbuild))) { push(@output, "msi template path will be ignored for non Windows builds!\n"); }
513 if (!($installer::globals::idtlanguagepath eq "")) { push(@output, "msi languagepath: $installer::globals::idtlanguagepath\n"); }
514 if ((!($installer::globals::idtlanguagepath eq "")) && (!($installer::globals::iswindowsbuild))) { push(@output, "msi language path will be ignored for non Windows builds!\n"); }
515 if ((!($installer::globals::iswindowsbuild)) && ( $installer::globals::call_epm )) { push(@output, "Calling epm\n"); }
516 if ((!($installer::globals::iswindowsbuild)) && (!($installer::globals::call_epm))) { push(@output, "Not calling epm\n"); }
517 if ( $installer::globals::strip ) { push(@output, "Stripping files\n"); }
518 else { push(@output, "No file stripping\n"); }
519 if ( $installer::globals::debian ) { push(@output, "Linux: Creating Debian packages\n"); }
520 if ( $installer::globals::dounzip ) { push(@output, "Unzip ARCHIVE files\n"); }
521 else { push(@output, "Not unzipping ARCHIVE files\n"); }
522 if (!($installer::globals::languages_defined_in_productlist))
524 push(@output, "Languages:\n");
525 foreach $element (@installer::globals::languageproducts) { push(@output, "\t$element\n"); }
527 else
529 push(@output, "Languages defined in $installer::globals::ziplistname\n");
531 if ( $installer::globals::is_copy_only_project ) { push(@output, "This is a copy only project!\n"); }
532 if ( $installer::globals::languagepack ) { push(@output, "Creating language pack!\n"); }
533 if ( $installer::globals::helppack ) { push(@output, "Creating help pack!\n"); }
534 push(@output, "########################################################\n");
536 # output into shell and into logfile
538 for ( my $i = 0; $i <= $#output; $i++ )
540 installer::logger::print_message( $output[$i] );
541 push(@installer::globals::globallogfileinfo, $output[$i]);