2 eval 'exec perl -wS $0 ${1+"$@"}'
4 #*************************************************************************
6 # DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
8 # Copyright 2008 by Sun Microsystems, Inc.
10 # OpenOffice.org - a multi-platform office productivity suite
12 # $RCSfile: signing.pl,v $
16 # This file is part of OpenOffice.org.
18 # OpenOffice.org is free software: you can redistribute it and/or modify
19 # it under the terms of the GNU Lesser General Public License version 3
20 # only, as published by the Free Software Foundation.
22 # OpenOffice.org is distributed in the hope that it will be useful,
23 # but WITHOUT ANY WARRANTY; without even the implied warranty of
24 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
25 # GNU Lesser General Public License version 3 for more details
26 # (a copy is included in the LICENSE file that accompanied this code).
28 # You should have received a copy of the GNU Lesser General Public License
29 # version 3 along with OpenOffice.org. If not, see
30 # <http://www.openoffice.org/license.html>
31 # for a copy of the LGPLv3 License.
33 #*************************************************************************
39 my $max_files = 20; # sign $max_files with one command line
44 my $opt_exclude = ""; # file with a list of not signable dll and exe files
47 my $opt_log = ""; # for logging
48 my $opt_pass = ""; # password for signing
49 my $opt_pfxfile = ""; # Personal Information Exchange file
50 my $opt_timestamp_url = ""; # timestamp url
51 my %exclude_files = (); # list of not signable dll and exe files
52 my $signtool = "signtool.exe sign";
54 my @files_to_sign = ();
57 $myname = script_id
();
62 @args = parse_options
();
64 @files_to_sign = get_files
(\
@args);
65 if ( $opt_log ) { # logging
66 open(LOG
,">$opt_log") || die "Can't open log file $opt_log\n";
68 sign_files
(\
@files_to_sign);
69 close LOG
if ($opt_log); # logging
77 ( my $script_name = $0 ) =~ s/^.*[\\\/]([\w\.]+)$/$1/;
80 my $id_str = ' $Revision$ ';
81 $id_str =~ /Revision:\s+(\S+)\s+\$/
82 ?
($script_rev = $1) : ($script_rev = "-");
83 # print "\n$script_name -- version: $script_rev\n";
87 ############################################################################
88 sub parse_options
#09.07.2007 08:13
89 ############################################################################
93 my $success = GetOptions
('h' => \
$opt_help,
94 'd=s' => \
$opt_dir, 'e=s'=>\
$opt_exclude, 'f=s'=>\
$opt_pfxfile, 'l=s'=>\
$opt_log,
95 'p=s'=>\
$opt_pass,'v'=>\
$opt_verbose, 't=s'=>\
$opt_timestamp_url);
96 if ( !$success || $opt_help ) {
100 if ( !$opt_exclude || !$opt_pfxfile || !$opt_pass || !$opt_timestamp_url) {
101 print "ERROR: Parameter missing!\n!";
108 ############################################################################
109 sub get_exclude_files
#09.07.2007 10:12
110 ############################################################################
112 if ( -e
$opt_exclude ) {
113 # get data from cache file
114 open( IN
, "<$opt_exclude") || die "Can't open exclude file $opt_exclude\n";
115 while ( my $line = <IN
> ) {
117 $exclude_files{$line} = 1; # fill hash
118 print "$line - $exclude_files{$line}\n" if ($debug);
122 print_error
("Can't open $opt_exclude file!\n");
124 } ##get_exclude_files
126 ############################################################################
127 sub get_files
#10.07.2007 10:19
128 ############################################################################
136 foreach $file_pattern ( @
$target )
138 print "Files: $file_pattern\n";
139 foreach $file ( glob( $file_pattern ) )
141 my $lib = File
::Basename
::basename
$file;
142 if ( ! $exclude_files{$lib} ) {
147 print "exclude=$lib\n" if ($opt_verbose);
155 ############################################################################
156 sub sign_files
#09.07.2007 10:36
157 ############################################################################
159 my $files_to_sign = shift;
160 my $commandline_base = ""; # contains whole stuff without the file name
164 print_error
("Can't open PFX file: $opt_pfxfile\n") if ( ! -e
$opt_pfxfile );
165 print_error
("Password is empty\n") if ( !$opt_pass );
166 if ( $opt_pass =~ /\.exe$/ ) {
167 # get password by tool
168 open(PIPE
, "$opt_pass 2>&1 |") || die "Can't open PIPE!\n";
171 print_error
("Can't get password!\n") if ( !$pass ); # exit here
174 $signtool .= " -v" if ($opt_verbose);
175 $commandline_base = $signtool . " " . "-f $opt_pfxfile -p $opt_pass -t $opt_timestamp_url";
177 # Here switch between:
178 # one command line for muliple files (all doesn't work, too much) / for each file one command line
179 if ( $max_files > 1 ) {
180 exec_multi_sign
($files_to_sign, $commandline_base);
183 exec_single_sign
($files_to_sign, $commandline_base);
187 ############################################################################
188 sub exec_single_sign
#11.07.2007 09:05
189 ############################################################################
191 my $files_to_sign = shift;
192 my $commandline_base = shift; # contains whole stuff without the file name
194 my $commandline = "";
196 foreach $file (@
$files_to_sign)
198 $commandline = $commandline_base . " $file";
199 print "$commandline\n" if ($debug);
200 execute
($commandline);
204 ############################################################################
205 sub exec_multi_sign
#11.07.2007 08:56
206 ############################################################################
208 # sign multiple file with one command line
209 my $files_to_sign = shift;
210 my $commandline_base = shift; # contains whole stuff without the file name
211 my $commandline = $commandline_base; # contains stuff which will be executed
215 foreach $file (@
$files_to_sign)
217 $commandline .= " $file";
219 if ( $counter >= $max_files ) {
220 execute
($commandline);
221 $counter = 0; # reset counter
222 $commandline = $commandline_base; # reset command line
225 execute
($commandline) if ($counter > 0);
228 ############################################################################
229 sub execute
#11.07.2007 10:02
230 ############################################################################
232 my $commandline = shift;
235 print "$commandline\n" if ($debug);
236 open(PIPE
, "$commandline 2>&1 |") || die "Error: Cant open pipe!\n";
237 while ( $result = <PIPE
> ) {
238 print LOG
"$result" if ($opt_log); # logging
239 if ( $result =~ /SignTool Error\:/ ) {
241 print_error
( "$result\n" );
247 ############################################################################
248 sub print_error
#09.07.2007 11:21
249 ############################################################################
252 print "ERROR: $text\n";
253 print LOG
"ERROR: $text\n" if ($opt_log); # logging
254 close LOG
if ($opt_log); # logging
258 ############################################################################
259 sub usage
#09.07.2007 08:39
260 ############################################################################
262 print "Usage:\t $myname <-e filename> <-f filename> <-p password> <-t timestamp> [-l filename] [-v] <file[list]> \n";
264 print "\t -e filename\t\t\tFile which contains a list of files which don't have to be signed.\n";
265 print "Mandatory.\n";
266 print "\t -f pfx_filename\t\t\"Personal Information Exchange\" file. ";
267 print "Mandatory.\n";
268 print "\t -p password\t\t\tPassword for \"Personal Information Exchange\" file. Mandatory.\n";
269 print "\t -t timestamp\t\t\tTimestamp URL e.g. \"http://timestamp.verisign.com/scripts/timstamp.dll\"\n";
270 print "\t\t\t\t\tMandatory.\n";
271 print "\t -l log_filename\t\tFile for logging.\n";
272 print "\t -v\t\t\t\tVerbose.\n";