source: trunk/bin/createpackage.pl@ 814

Last change on this file since 814 was 769, checked in by Dmitry A. Kuminov, 15 years ago

trunk: Merged in qt 4.6.3 sources from branches/vendor/nokia/qt.

  • Property svn:eol-style set to native
  • Property svn:executable set to *
File size: 11.1 KB
Line 
1#!/usr/bin/perl
2#############################################################################
3##
4## Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
5## All rights reserved.
6## Contact: Nokia Corporation ([email protected])
7##
8## This file is part of the S60 port of the Qt Toolkit.
9##
10## $QT_BEGIN_LICENSE:LGPL$
11## Commercial Usage
12## Licensees holding valid Qt Commercial licenses may use this file in
13## accordance with the Qt Commercial License Agreement provided with the
14## Software or, alternatively, in accordance with the terms contained in
15## a written agreement between you and Nokia.
16##
17## GNU Lesser General Public License Usage
18## Alternatively, this file may be used under the terms of the GNU Lesser
19## General Public License version 2.1 as published by the Free Software
20## Foundation and appearing in the file LICENSE.LGPL included in the
21## packaging of this file. Please review the following information to
22## ensure the GNU Lesser General Public License version 2.1 requirements
23## will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
24##
25## In addition, as a special exception, Nokia gives you certain additional
26## rights. These rights are described in the Nokia Qt LGPL Exception
27## version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
28##
29## GNU General Public License Usage
30## Alternatively, this file may be used under the terms of the GNU
31## General Public License version 3.0 as published by the Free Software
32## Foundation and appearing in the file LICENSE.GPL included in the
33## packaging of this file. Please review the following information to
34## ensure the GNU General Public License version 3.0 requirements will be
35## met: http://www.gnu.org/copyleft/gpl.html.
36##
37## If you have questions regarding the use of this file, please contact
38## Nokia at [email protected].
39## $QT_END_LICENSE$
40##
41#############################################################################
42
43############################################################################################
44#
45# Convenience script for creating signed packages you can install on your phone.
46#
47############################################################################################
48
49use strict;
50
51# use a command-line parsing module
52use Getopt::Long;
53# Use file name parsing module
54use File::Basename;
55# Use File::Spec services mainly rel2abs
56use File::Spec;
57# Use File::Path - to make stub sis target directory
58use File::Path;
59# use CWD abs_bath, which is exported only on request
60use Cwd 'abs_path';
61
62
63sub Usage() {
64 print <<ENDUSAGESTRING;
65
66==============================================================================================
67Convenience script for creating signed packages you can install on your phone.
68
69Usage: createpackage.pl [options] templatepkg [target]-[platform] [certificate key [passphrase]]
70
71Where supported optiobns are as follows:
72 [-i|install] = Install the package right away using PC suite
73 [-p|preprocess] = Only preprocess the template .pkg file.
74 [-c|certfile=<file>] = The file containing certificate information for signing.
75 The file can have several certificates, each specified in
76 separate line. The certificate, key and passphrase in line
77 must be ';' separated. Lines starting with '#' are treated
78 as a comments. Also empty lines are ignored. The paths in
79 <file> can be absolute or relative to <file>.
80 [-u|unsigned] = Preserves the unsigned package
81Where parameters are as follows:
82 templatepkg = Name of .pkg file template
83 target = Either debug or release
84 platform = One of the supported platform
85 winscw | gcce | armv5 | armv6 | armv7
86 certificate = The certificate file used for signing
87 key = The certificate's private key file
88 passphrase = The certificate's private key file's passphrase
89
90Example:
91 createpackage.pl fluidlauncher_template.pkg release-armv5
92
93Example with certfile:
94 createpackage.pl -c=mycerts.txt fluidlauncher_template.pkg release-armv5
95
96 Content of 'mycerts.txt' must be something like this:
97 # This is comment line, also the empty lines are ignored
98 rd.cer;rd-key.pem
99 .\\cert\\mycert.cer;.\\cert\\mykey.key;yourpassword
100 X:\\QtS60\\s60installs\\selfsigned.cer;X:\\QtS60\\s60installs\\selfsigned.key
101
102If no certificate and key files are provided, either a RnD certificate or
103a self-signed certificate from QtDir\\src\\s60installs directory is used.
104==============================================================================================
105
106ENDUSAGESTRING
107
108 exit();
109}
110
111# Read given options
112my $install = "";
113my $preprocessonly = "";
114my $certfile = "";
115my $preserveUnsigned = "";
116my $stub = "";
117
118unless (GetOptions('i|install' => \$install,
119 'p|preprocess' => \$preprocessonly,
120 'c|certfile=s' => \$certfile,
121 'u|unsigned' => \$preserveUnsigned,
122 's|stub' => \$stub,)){
123 Usage();
124}
125
126my $certfilepath = abs_path(dirname($certfile));
127
128# Read params to variables
129my $templatepkg = $ARGV[0];
130my $targetplatform = lc $ARGV[1];
131
132my @tmpvalues = split('-', $targetplatform);
133my $target = $tmpvalues[0];
134my $platform = $tmpvalues[1];;
135
136# Convert visual target to real target (debug->udeb and release->urel)
137$target =~ s/debug/udeb/i;
138$target =~ s/release/urel/i;
139
140my $certificate = $ARGV[2];
141my $key = $ARGV[3];
142my $passphrase = $ARGV[4];
143
144# Generate output pkg basename (i.e. file name without extension)
145my $pkgoutputbasename = $templatepkg;
146my $preservePkgOutput = "";
147$pkgoutputbasename =~ s/_template/_$targetplatform/g;
148if ($pkgoutputbasename eq $templatepkg) {
149 $preservePkgOutput = "1";
150}
151$pkgoutputbasename =~ s/\.pkg//g;
152$pkgoutputbasename = lc($pkgoutputbasename);
153
154# Store output file names to variables
155my $pkgoutput = lc($pkgoutputbasename.".pkg");
156my $sisoutputbasename = lc($pkgoutputbasename);
157$sisoutputbasename =~ s/_$targetplatform//g;
158my $unsigned_sis_name = $sisoutputbasename."_unsigned.sis";
159my $signed_sis_name = $sisoutputbasename.".sis";
160my $stub_sis_name = $sisoutputbasename."_stub.sis";
161
162# Store some utility variables
163my $scriptpath = dirname(__FILE__);
164my $certtext = $certificate;
165my $certpath = $scriptpath;
166$certpath =~ s-^(.*[^\\])$-$1\\-o; # ensure path ends with a backslash
167$certpath =~ s-/-\\-go; # for those working with UNIX shells
168$certpath =~ s-bin\\$-src\\s60installs\\-; # certificates are one step up in hierarcy
169
170# Check some pre-conditions and print error messages if needed.
171unless (length($templatepkg)) {
172 print "\nError: Template PKG filename is not defined!\n";
173 Usage();
174}
175
176# If the pkg file is not actually a template, there is no need for plaform or target.
177if ($templatepkg =~ m/_template\.pkg/i) {
178 unless (length($platform) && length($target)) {
179 print "\nError: Platform or target is not defined!\n";
180 Usage();
181 }
182}
183
184# Check template exist
185stat($templatepkg);
186unless( -e _ ) {
187 print "\nError: Package description file '$templatepkg' does not exist!\n";
188 Usage();
189}
190
191# Check certifcate preconditions and set default certificate variables if needed
192if (length($certificate)) {
193 unless(length($key)) {
194 print "\nError: Custom certificate key file parameter missing.!\n";
195 Usage();
196 }
197} else {
198 #If no certificate is given, check default options
199 $certtext = "RnD";
200 $certificate = $certpath."rd.cer";
201 $key = $certpath."rd-key.pem";
202
203 stat($certificate);
204 unless( -e _ ) {
205 $certtext = "Self Signed";
206 $certificate = $certpath."selfsigned.cer";
207 $key = $certpath."selfsigned.key";
208 }
209}
210
211# Read the certificates from file to two dimensional array
212my @certificates;
213if (length($certfile)) {
214 open CERTFILE, "<$certfile" or die $!;
215 while(<CERTFILE>){
216 s/#.*//; # ignore comments by erasing them
217 next if /^(\s)*$/; # skip blank lines
218 chomp; # remove trailing newline characters
219 my @certinfo = split(';', $_); # split row to certinfo
220
221 # Trim spaces
222 for(@certinfo) {
223 s/^\s+//;
224 s/\s+$//;
225 }
226
227 # Do some validation
228 unless(scalar(@certinfo) >= 2 && scalar(@certinfo) <= 3 && length($certinfo[0]) && length($certinfo[1]) ) {
229 print "\nError: $certfile line '$_' does not contain valid information!\n";
230 Usage();
231 }
232
233 push @certificates, [@certinfo]; # push data to two dimensional array
234 }
235}
236
237# Remove any existing .sis packages
238unlink $unsigned_sis_name;
239unlink $signed_sis_name;
240if (!$preservePkgOutput) {
241 unlink $pkgoutput;
242}
243
244# Preprocess PKG
245local $/;
246# read template file
247open( TEMPLATE, $templatepkg) or die "Error '$templatepkg': $!\n";
248$_=<TEMPLATE>;
249close (TEMPLATE);
250
251# replace the PKG variables
252s/\$\(PLATFORM\)/$platform/gm;
253s/\$\(TARGET\)/$target/gm;
254
255#write the output
256open( OUTPUT, ">$pkgoutput" ) or die "Error '$pkgoutput' $!\n";
257print OUTPUT $_;
258close OUTPUT;
259
260if ($preprocessonly) {
261 exit;
262}
263
264if($stub) {
265 if(!($ENV{EPOCROOT})) { die("EPOCROOT must be set to create stub sis files"); }
266 my $systeminstall = "$ENV{EPOCROOT}epoc32/data/z/system/install";
267 mkpath($systeminstall);
268 my $stub_sis_name = $systeminstall."/".$stub_sis_name;
269 # Create stub SIS.
270 system ("makesis -s $pkgoutput $stub_sis_name");
271} else {
272 # Create SIS.
273 system ("makesis $pkgoutput $unsigned_sis_name");
274 print("\n");
275
276 # Sign SIS with certificate info given as an argument.
277 system ("signsis $unsigned_sis_name $signed_sis_name $certificate $key $passphrase");
278
279 # Check if creating signed SIS Succeeded
280 stat($signed_sis_name);
281 if( -e _ ) {
282 my $targetInsert = "";
283 if ($targetplatform ne "-") {
284 $targetInsert = "for $targetplatform ";
285 }
286 print ("Successfully created $signed_sis_name ${targetInsert}using certificate: $certtext!\n");
287
288 # Sign with additional certificates & keys
289 for my $row ( @certificates ) {
290 # Get certificate absolute file names, relative paths are relative to certfilepath
291 my $abscert = File::Spec->rel2abs( $row->[0], $certfilepath);
292 my $abskey = File::Spec->rel2abs( $row->[1], $certfilepath);
293
294 system ("signsis $signed_sis_name $signed_sis_name $abscert $abskey $row->[2]");
295 print ("\tAdditionally signed the SIS with certificate: $row->[0]!\n");
296 }
297
298 # remove temporary pkg and unsigned sis
299 if (!$preservePkgOutput) {
300 unlink $pkgoutput;
301 }
302 if (!$preserveUnsigned) {
303 unlink $unsigned_sis_name;
304 }
305
306 # Install the sis if requested
307 if ($install) {
308 print ("\nInstalling $signed_sis_name...\n");
309 system ("$signed_sis_name");
310 }
311 } else {
312 # Lets leave the generated PKG for problem solving purposes
313 print ("\nSIS creation failed!\n");
314 }
315}
316
317#end of file
Note: See TracBrowser for help on using the repository browser.