gnumake3: remove comphelper version; fix including extract.hxx
[LibreOffice.git] / postprocess / signing / signing.pl
blobf28d348a022fb4dc0b49f8ff7c76d9d0ac6809ff
2 eval 'exec perl -wS $0 ${1+"$@"}'
3 if 0;
4 #*************************************************************************
6 # DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
8 # Copyright 2000, 2010 Oracle and/or its affiliates.
10 # OpenOffice.org - a multi-platform office productivity suite
12 # This file is part of OpenOffice.org.
14 # OpenOffice.org is free software: you can redistribute it and/or modify
15 # it under the terms of the GNU Lesser General Public License version 3
16 # only, as published by the Free Software Foundation.
18 # OpenOffice.org is distributed in the hope that it will be useful,
19 # but WITHOUT ANY WARRANTY; without even the implied warranty of
20 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 # GNU Lesser General Public License version 3 for more details
22 # (a copy is included in the LICENSE file that accompanied this code).
24 # You should have received a copy of the GNU Lesser General Public License
25 # version 3 along with OpenOffice.org. If not, see
26 # <http://www.openoffice.org/license.html>
27 # for a copy of the LGPLv3 License.
29 #*************************************************************************
31 use strict;
32 use Getopt::Long;
34 my $debug = 0;
35 my $max_files = 20; # sign $max_files with one command line
37 #### globals #####
38 my $myname = "";
39 my $opt_dir = "";
40 my $opt_exclude = ""; # file with a list of not signable dll and exe files
41 my $opt_verbose = 0;
42 my $opt_help = 0;
43 my $opt_log = ""; # for logging
44 my $opt_pass = ""; # password for signing
45 my $opt_pfxfile = ""; # Personal Information Exchange file
46 my $opt_timestamp_url = ""; # timestamp url
47 my %exclude_files = (); # list of not signable dll and exe files
48 my $signtool = "signtool.exe sign";
49 my @args = ();
50 my @files_to_sign = ();
52 #### main #####
53 $myname = script_id();
54 if ( $#ARGV < 2 ) {
55 usage();
56 exit(1);
58 @args = parse_options();
59 get_exclude_files();
60 @files_to_sign = get_files(\@args);
61 if ( $opt_log ) { # logging
62 open(LOG,">$opt_log") || die "Can't open log file $opt_log\n";
64 sign_files(\@files_to_sign);
65 close LOG if ($opt_log); # logging
66 exit 0;
69 #### subroutines ####
71 sub script_id
73 ( my $script_name = $0 ) =~ s/^.*[\\\/]([\w\.]+)$/$1/;
75 my $script_rev;
76 my $id_str = ' $Revision$ ';
77 $id_str =~ /Revision:\s+(\S+)\s+\$/
78 ? ($script_rev = $1) : ($script_rev = "-");
79 # print "\n$script_name -- version: $script_rev\n";
80 return $script_name;
83 ############################################################################
84 sub parse_options #09.07.2007 08:13
85 ############################################################################
87 # e exclude list file
88 # v verbose
89 my $success = GetOptions('h' => \$opt_help,
90 'd=s' => \$opt_dir, 'e=s'=>\$opt_exclude, 'f=s'=>\$opt_pfxfile, 'l=s'=>\$opt_log,
91 'p=s'=>\$opt_pass,'v'=>\$opt_verbose, 't=s'=>\$opt_timestamp_url);
92 if ( !$success || $opt_help ) {
93 usage();
94 exit(1);
96 if ( !$opt_exclude || !$opt_pfxfile || !$opt_pass || !$opt_timestamp_url) {
97 print "ERROR: Parameter missing!\n!";
98 usage();
99 exit(1);
101 return @ARGV;
102 } ##parse_options
104 ############################################################################
105 sub get_exclude_files #09.07.2007 10:12
106 ############################################################################
108 if ( -e $opt_exclude ) {
109 # get data from cache file
110 open( IN, "<$opt_exclude") || die "Can't open exclude file $opt_exclude\n";
111 while ( my $line = <IN> ) {
112 chomp($line);
113 $exclude_files{$line} = 1; # fill hash
114 print "$line - $exclude_files{$line}\n" if ($debug);
116 } else
118 print_error("Can't open $opt_exclude file!\n");
120 } ##get_exclude_files
122 ############################################################################
123 sub get_files #10.07.2007 10:19
124 ############################################################################
126 use File::Basename;
127 my $target = shift;
128 my $file_pattern;
129 my $file;
130 my @files = ();
131 print "\n";
132 foreach $file_pattern ( @$target )
134 print "Files: $file_pattern\n";
135 foreach $file ( glob( $file_pattern ) )
137 my $lib = File::Basename::basename $file;
138 if ( ! $exclude_files{$lib} ) {
139 push @files,$file;
141 else
143 print "exclude=$lib\n" if ($opt_verbose);
147 print "\n";
148 return @files;
149 } ##get_files
151 ############################################################################
152 sub sign_files #09.07.2007 10:36
153 ############################################################################
155 my $files_to_sign = shift;
156 my $commandline_base = ""; # contains whole stuff without the file name
157 my $file = "";
158 my $result = "";
160 print_error("Can't open PFX file: $opt_pfxfile\n") if ( ! -e $opt_pfxfile );
161 print_error("Password is empty\n") if ( !$opt_pass );
162 if ( $opt_pass =~ /\.exe$/ ) {
163 # get password by tool
164 open(PIPE, "$opt_pass 2>&1 |") || die "Can't open PIPE!\n";
165 my $pass = <PIPE>;
166 close PIPE;
167 print_error("Can't get password!\n") if ( !$pass ); # exit here
168 $opt_pass = $pass;
170 $signtool .= " -v" if ($opt_verbose);
171 $commandline_base = $signtool . " " . "-f $opt_pfxfile -p $opt_pass -t $opt_timestamp_url";
173 # Here switch between:
174 # one command line for muliple files (all doesn't work, too much) / for each file one command line
175 if ( $max_files > 1 ) {
176 exec_multi_sign($files_to_sign, $commandline_base);
177 } else
179 exec_single_sign($files_to_sign, $commandline_base);
181 } ##sign_files
183 ############################################################################
184 sub exec_single_sign #11.07.2007 09:05
185 ############################################################################
187 my $files_to_sign = shift;
188 my $commandline_base = shift; # contains whole stuff without the file name
189 my $file = "";
190 my $commandline = "";
192 foreach $file (@$files_to_sign)
194 $commandline = $commandline_base . " $file";
195 print "$commandline\n" if ($debug);
196 execute($commandline);
197 } #foreach
198 } ##exec_single_sign
200 ############################################################################
201 sub exec_multi_sign #11.07.2007 08:56
202 ############################################################################
204 # sign multiple file with one command line
205 my $files_to_sign = shift;
206 my $commandline_base = shift; # contains whole stuff without the file name
207 my $commandline = $commandline_base; # contains stuff which will be executed
208 my $file = "";
209 my $counter = 0;
211 foreach $file (@$files_to_sign)
213 $commandline .= " $file";
214 ++$counter;
215 if ( $counter >= $max_files ) {
216 execute($commandline);
217 $counter = 0; # reset counter
218 $commandline = $commandline_base; # reset command line
221 execute($commandline) if ($counter > 0);
222 } ##exec_multi_sign
224 ############################################################################
225 sub execute #11.07.2007 10:02
226 ############################################################################
228 my $commandline = shift;
229 my $result = "";
231 print "$commandline\n" if ($debug);
232 open(PIPE, "$commandline 2>&1 |") || die "Error: Cant open pipe!\n";
233 while ( $result = <PIPE> ) {
234 print LOG "$result" if ($opt_log); # logging
235 if ( $result =~ /SignTool Error\:/ ) {
236 close PIPE;
237 print_error( "$result\n" );
238 } # if error
239 } # while
240 close PIPE;
241 } ##execute
243 ############################################################################
244 sub print_error #09.07.2007 11:21
245 ############################################################################
247 my $text = shift;
248 print "ERROR: $text\n";
249 print LOG "ERROR: $text\n" if ($opt_log); # logging
250 close LOG if ($opt_log); # logging
251 exit(1);
252 } ##print_error
254 ############################################################################
255 sub usage #09.07.2007 08:39
256 ############################################################################
258 print "Usage:\t $myname <-e filename> <-f filename> <-p password> <-t timestamp> [-l filename] [-v] <file[list]> \n";
259 print "Options:\n";
260 print "\t -e filename\t\t\tFile which contains a list of files which don't have to be signed.\n";
261 print "Mandatory.\n";
262 print "\t -f pfx_filename\t\t\"Personal Information Exchange\" file. ";
263 print "Mandatory.\n";
264 print "\t -p password\t\t\tPassword for \"Personal Information Exchange\" file. Mandatory.\n";
265 print "\t -t timestamp\t\t\tTimestamp URL e.g. \"http://timestamp.verisign.com/scripts/timstamp.dll\"\n";
266 print "\t\t\t\t\tMandatory.\n";
267 print "\t -l log_filename\t\tFile for logging.\n";
268 print "\t -v\t\t\t\tVerbose.\n";
269 } ##usage