2 eval 'exec perl -wS $0 ${1+"$@"}'
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 #*************************************************************************
35 my $max_files = 20; # sign $max_files with one command line
40 my $opt_exclude = ""; # file with a list of not signable dll and exe files
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";
50 my @files_to_sign = ();
53 $myname = script_id
();
58 @args = parse_options
();
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
73 ( my $script_name = $0 ) =~ s/^.*[\\\/]([\w\.]+)$/$1/;
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";
83 ############################################################################
84 sub parse_options
#09.07.2007 08:13
85 ############################################################################
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 ) {
96 if ( !$opt_exclude || !$opt_pfxfile || !$opt_pass || !$opt_timestamp_url) {
97 print "ERROR: Parameter missing!\n!";
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
> ) {
113 $exclude_files{$line} = 1; # fill hash
114 print "$line - $exclude_files{$line}\n" if ($debug);
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 ############################################################################
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} ) {
143 print "exclude=$lib\n" if ($opt_verbose);
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
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";
167 print_error
("Can't get password!\n") if ( !$pass ); # exit here
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);
179 exec_single_sign
($files_to_sign, $commandline_base);
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
190 my $commandline = "";
192 foreach $file (@
$files_to_sign)
194 $commandline = $commandline_base . " $file";
195 print "$commandline\n" if ($debug);
196 execute
($commandline);
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
211 foreach $file (@
$files_to_sign)
213 $commandline .= " $file";
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);
224 ############################################################################
225 sub execute
#11.07.2007 10:02
226 ############################################################################
228 my $commandline = shift;
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\:/ ) {
237 print_error
( "$result\n" );
243 ############################################################################
244 sub print_error
#09.07.2007 11:21
245 ############################################################################
248 print "ERROR: $text\n";
249 print LOG
"ERROR: $text\n" if ($opt_log); # logging
250 close LOG
if ($opt_log); # logging
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";
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";