0
|
1 |
#!/usr/bin/perl
|
|
2 |
#############################################################################
|
|
3 |
##
|
|
4 |
## Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
|
|
5 |
## All rights reserved.
|
|
6 |
## Contact: Nokia Corporation (qt-info@nokia.com)
|
|
7 |
##
|
|
8 |
## This file is part of the S60 port of the Qt Toolkit.
|
|
9 |
##
|
|
10 |
## $QT_BEGIN_LICENSE:LGPL$
|
|
11 |
## No Commercial Usage
|
|
12 |
## This file contains pre-release code and may not be distributed.
|
|
13 |
## You may use this file in accordance with the terms and conditions
|
|
14 |
## contained in the Technology Preview License Agreement accompanying
|
|
15 |
## this package.
|
|
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 |
## If you have questions regarding the use of this file, please contact
|
|
30 |
## Nokia at qt-info@nokia.com.
|
|
31 |
##
|
|
32 |
##
|
|
33 |
##
|
|
34 |
##
|
|
35 |
##
|
|
36 |
##
|
|
37 |
##
|
|
38 |
##
|
|
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 |
|
|
49 |
use strict;
|
|
50 |
|
|
51 |
# use a command-line parsing module
|
|
52 |
use Getopt::Long;
|
|
53 |
# Use file name parsing module
|
|
54 |
use File::Basename;
|
|
55 |
# Use File::Spec services mainly rel2abs
|
|
56 |
use File::Spec;
|
|
57 |
# use CWD abs_bath, which is exported only on request
|
|
58 |
use Cwd 'abs_path';
|
|
59 |
|
|
60 |
|
|
61 |
sub Usage() {
|
|
62 |
print <<ENDUSAGESTRING;
|
|
63 |
|
|
64 |
==============================================================================================
|
|
65 |
Convenience script for creating signed packages you can install on your phone.
|
|
66 |
|
|
67 |
Usage: createpackage.pl [options] templatepkg target-platform [certificate key [passphrase]]
|
|
68 |
|
|
69 |
Where supported optiobns are as follows:
|
|
70 |
[-i|install] = Install the package right away using PC suite
|
|
71 |
[-p|preprocess] = Only preprocess the template .pkg file.
|
|
72 |
[-c|certfile=<file>] = The file containing certificate information for signing.
|
|
73 |
The file can have several certificates, each specified in
|
|
74 |
separate line. The certificate, key and passphrase in line
|
|
75 |
must be ';' separated. Lines starting with '#' are treated
|
|
76 |
as a comments. Also empty lines are ignored. The paths in
|
|
77 |
<file> can be absolute or relative to <file>.
|
|
78 |
Where parameters are as follows:
|
|
79 |
templatepkg = Name of .pkg file template
|
|
80 |
target = Either debug or release
|
|
81 |
platform = One of the supported platform
|
|
82 |
winscw | gcce | armv5 | armv6 | armv7
|
|
83 |
certificate = The certificate file used for signing
|
|
84 |
key = The certificate's private key file
|
|
85 |
passphrase = The certificate's private key file's passphrase
|
|
86 |
|
|
87 |
Example:
|
|
88 |
createpackage.pl fluidlauncher_template.pkg release-armv5
|
|
89 |
|
|
90 |
Example with certfile:
|
|
91 |
createpackage.pl -c=mycerts.txt fluidlauncher_template.pkg release-armv5
|
|
92 |
|
|
93 |
Content of 'mycerts.txt' must be something like this:
|
|
94 |
# This is comment line, also the empty lines are ignored
|
|
95 |
rd.cer;rd-key.pem
|
|
96 |
.\\cert\\mycert.cer;.\\cert\\mykey.key;yourpassword
|
|
97 |
X:\\QtS60\\selfsigned.cer;X:\\QtS60\\selfsigned.key
|
|
98 |
|
|
99 |
If no certificate and key files are provided, either a RnD certificate or
|
|
100 |
a self-signed certificate from Qt installation root directory is used.
|
|
101 |
==============================================================================================
|
|
102 |
|
|
103 |
ENDUSAGESTRING
|
|
104 |
|
|
105 |
exit();
|
|
106 |
}
|
|
107 |
|
|
108 |
# Read given options
|
|
109 |
my $install = "";
|
|
110 |
my $preprocessonly = "";
|
|
111 |
my $certfile = "";
|
|
112 |
|
|
113 |
unless (GetOptions('i|install' => \$install, 'p|preprocess' => \$preprocessonly, 'c|certfile=s' => \$certfile)){
|
|
114 |
Usage();
|
|
115 |
}
|
|
116 |
|
|
117 |
my $certfilepath = abs_path(dirname($certfile));
|
|
118 |
|
|
119 |
# Read params to variables
|
|
120 |
my $templatepkg = $ARGV[0];
|
|
121 |
my $targetplatform = lc $ARGV[1];
|
|
122 |
|
|
123 |
my @tmpvalues = split('-', $targetplatform);
|
|
124 |
my $target = $tmpvalues[0];
|
|
125 |
my $platform = $tmpvalues[1];;
|
|
126 |
|
|
127 |
# Convert visual target to real target (debug->udeb and release->urel)
|
|
128 |
$target =~ s/debug/udeb/i;
|
|
129 |
$target =~ s/release/urel/i;
|
|
130 |
|
|
131 |
my $certificate = $ARGV[2];
|
|
132 |
my $key = $ARGV[3];
|
|
133 |
my $passphrase = $ARGV[4];
|
|
134 |
|
|
135 |
# Generate output pkg basename (i.e. file name without extension)
|
|
136 |
my $pkgoutputbasename = $templatepkg;
|
|
137 |
$pkgoutputbasename =~ s/_template\.pkg/_$targetplatform/g;
|
|
138 |
$pkgoutputbasename = lc($pkgoutputbasename);
|
|
139 |
|
|
140 |
# Store output file names to variables
|
|
141 |
my $pkgoutput = lc($pkgoutputbasename.".pkg");
|
|
142 |
my $unsigned_sis_name = $pkgoutputbasename."_unsigned.sis";
|
|
143 |
my $signed_sis_name = $pkgoutputbasename.".sis";
|
|
144 |
|
|
145 |
# Store some utility variables
|
|
146 |
my $scriptpath = dirname(__FILE__);
|
|
147 |
my $certtext = $certificate;
|
|
148 |
my $certpath = $scriptpath;
|
|
149 |
$certpath =~ s-^(.*[^\\])$-$1\\-o; # ensure path ends with a backslash
|
|
150 |
$certpath =~ s-/-\\-go; # for those working with UNIX shells
|
|
151 |
$certpath =~ s-bin\\$-src\\s60installs\\-; # certificates are one step up in hierarcy
|
|
152 |
|
|
153 |
# Check some pre-conditions and print error messages if needed
|
|
154 |
unless (length($templatepkg) && length($platform) && length($target)) {
|
|
155 |
print "\nError: Template PKG filename, platform or target is not defined!\n";
|
|
156 |
Usage();
|
|
157 |
}
|
|
158 |
|
|
159 |
# Check template exist
|
|
160 |
stat($templatepkg);
|
|
161 |
unless( -e _ ) {
|
|
162 |
print "\nError: Package description file '$templatepkg' does not exist!\n";
|
|
163 |
Usage();
|
|
164 |
}
|
|
165 |
|
|
166 |
# Check certifcate preconditions and set default certificate variables if needed
|
|
167 |
if (length($certificate)) {
|
|
168 |
unless(length($key)) {
|
|
169 |
print "\nError: Custom certificate key file parameter missing.!\n";
|
|
170 |
Usage();
|
|
171 |
}
|
|
172 |
} else {
|
|
173 |
#If no certificate is given, check default options
|
|
174 |
$certtext = "RnD";
|
|
175 |
$certificate = $certpath."rd.cer";
|
|
176 |
$key = $certpath."rd-key.pem";
|
|
177 |
|
|
178 |
stat($certificate);
|
|
179 |
unless( -e _ ) {
|
|
180 |
$certtext = "Self Signed";
|
|
181 |
$certificate = $certpath."selfsigned.cer";
|
|
182 |
$key = $certpath."selfsigned.key";
|
|
183 |
}
|
|
184 |
}
|
|
185 |
|
|
186 |
# Read the certificates from file to two dimensional array
|
|
187 |
my @certificates;
|
|
188 |
if (length($certfile)) {
|
|
189 |
open CERTFILE, "<$certfile" or die $!;
|
|
190 |
while(<CERTFILE>){
|
|
191 |
s/#.*//; # ignore comments by erasing them
|
|
192 |
next if /^(\s)*$/; # skip blank lines
|
|
193 |
chomp; # remove trailing newline characters
|
|
194 |
my @certinfo = split(';', $_); # split row to certinfo
|
|
195 |
|
|
196 |
# Trim spaces
|
|
197 |
for(@certinfo) {
|
|
198 |
s/^\s+//;
|
|
199 |
s/\s+$//;
|
|
200 |
}
|
|
201 |
|
|
202 |
# Do some validation
|
|
203 |
unless(scalar(@certinfo) >= 2 && scalar(@certinfo) <= 3 && length($certinfo[0]) && length($certinfo[1]) ) {
|
|
204 |
print "\nError: $certfile line '$_' does not contain valid information!\n";
|
|
205 |
Usage();
|
|
206 |
}
|
|
207 |
|
|
208 |
push @certificates, [@certinfo]; # push data to two dimensional array
|
|
209 |
}
|
|
210 |
}
|
|
211 |
|
|
212 |
# Remove any existing .sis packages
|
|
213 |
unlink $unsigned_sis_name;
|
|
214 |
unlink $signed_sis_name;
|
|
215 |
unlink $pkgoutput;
|
|
216 |
|
|
217 |
# Preprocess PKG
|
|
218 |
local $/;
|
|
219 |
# read template file
|
|
220 |
open( TEMPLATE, $templatepkg) or die "Error '$templatepkg': $!\n";
|
|
221 |
$_=<TEMPLATE>;
|
|
222 |
close (TEMPLATE);
|
|
223 |
|
|
224 |
# replace the PKG variables
|
|
225 |
s/\$\(PLATFORM\)/$platform/gm;
|
|
226 |
s/\$\(TARGET\)/$target/gm;
|
|
227 |
|
|
228 |
#write the output
|
|
229 |
open( OUTPUT, ">$pkgoutput" ) or die "Error '$pkgoutput' $!\n";
|
|
230 |
print OUTPUT $_;
|
|
231 |
close OUTPUT;
|
|
232 |
|
|
233 |
if ($preprocessonly) {
|
|
234 |
exit;
|
|
235 |
}
|
|
236 |
|
|
237 |
# Create SIS.
|
|
238 |
system ("makesis $pkgoutput $unsigned_sis_name");
|
|
239 |
|
|
240 |
# Sign SIS with certificate info given as an argument.
|
|
241 |
system ("signsis $unsigned_sis_name $signed_sis_name $certificate $key $passphrase");
|
|
242 |
|
|
243 |
# Check if creating signed SIS Succeeded
|
|
244 |
stat($signed_sis_name);
|
|
245 |
if( -e _ ) {
|
|
246 |
print ("\nSuccessfully created $signed_sis_name using certificate: $certtext!\n");
|
|
247 |
|
|
248 |
# Sign with additional certificates & keys
|
|
249 |
for my $row ( @certificates ) {
|
|
250 |
# Get certificate absolute file names, relative paths are relative to certfilepath
|
|
251 |
my $abscert = File::Spec->rel2abs( $row->[0], $certfilepath);
|
|
252 |
my $abskey = File::Spec->rel2abs( $row->[1], $certfilepath);
|
|
253 |
|
|
254 |
system ("signsis $signed_sis_name $signed_sis_name $abscert $abskey $row->[2]");
|
|
255 |
print ("\tAdditionally signed the SIS with certificate: $row->[0]!\n");
|
|
256 |
}
|
|
257 |
|
|
258 |
# remove temporary pkg and unsigned sis
|
|
259 |
unlink $pkgoutput;
|
|
260 |
unlink $unsigned_sis_name;
|
|
261 |
|
|
262 |
# Install the sis if requested
|
|
263 |
if ($install) {
|
|
264 |
print ("\nInstalling $signed_sis_name...\n");
|
|
265 |
system ("$signed_sis_name");
|
|
266 |
}
|
|
267 |
} else {
|
|
268 |
# Lets leave the generated PKG for problem solving purposes
|
|
269 |
print ("\nSIS creation failed!\n");
|
|
270 |
}
|
|
271 |
|
|
272 |
|
|
273 |
#end of file
|