2 #############################################################################
4 ## Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
5 ## All rights reserved.
6 ## Contact: Nokia Corporation (qt-info@nokia.com)
8 ## This file is part of the S60 port of the Qt Toolkit.
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
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.
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.
29 ## If you have questions regarding the use of this file, please contact
30 ## Nokia at qt-info@nokia.com.
41 #############################################################################
43 ############################################################################################
45 # Convenience script for creating signed packages you can install on your phone.
47 ############################################################################################
51 # use a command-line parsing module
53 # Use file name parsing module
55 # Use File::Spec services mainly rel2abs
57 # use CWD abs_bath, which is exported only on request
62 print <<ENDUSAGESTRING;
64 ==============================================================================================
65 Convenience script for creating signed packages you can install on your phone.
67 Usage: createpackage.pl [options] templatepkg target-platform [certificate key [passphrase]]
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
88 createpackage.pl fluidlauncher_template.pkg release-armv5
90 Example with certfile:
91 createpackage.pl -c=mycerts.txt fluidlauncher_template.pkg release-armv5
93 Content of 'mycerts.txt' must be something like this:
94 # This is comment line, also the empty lines are ignored
96 .\\cert\\mycert.cer;.\\cert\\mykey.key;yourpassword
97 X:\\QtS60\\selfsigned.cer;X:\\QtS60\\selfsigned.key
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 ==============================================================================================
110 my $preprocessonly = "";
113 unless (GetOptions
('i|install' => \
$install, 'p|preprocess' => \
$preprocessonly, 'c|certfile=s' => \
$certfile)){
117 my $certfilepath = abs_path
(dirname
($certfile));
119 # Read params to variables
120 my $templatepkg = $ARGV[0];
121 my $targetplatform = lc $ARGV[1];
123 my @tmpvalues = split('-', $targetplatform);
124 my $target = $tmpvalues[0];
125 my $platform = $tmpvalues[1];;
127 # Convert visual target to real target (debug->udeb and release->urel)
128 $target =~ s/debug/udeb/i;
129 $target =~ s/release/urel/i;
131 my $certificate = $ARGV[2];
133 my $passphrase = $ARGV[4];
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);
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";
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
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";
159 # Check template exist
162 print "\nError: Package description file '$templatepkg' does not exist!\n";
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";
173 #If no certificate is given, check default options
175 $certificate = $certpath."rd.cer";
176 $key = $certpath."rd-key.pem";
180 $certtext = "Self Signed";
181 $certificate = $certpath."selfsigned.cer";
182 $key = $certpath."selfsigned.key";
186 # Read the certificates from file to two dimensional array
188 if (length($certfile)) {
189 open CERTFILE
, "<$certfile" or die $!;
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
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";
208 push @certificates, [@certinfo]; # push data to two dimensional array
212 # Remove any existing .sis packages
213 unlink $unsigned_sis_name;
214 unlink $signed_sis_name;
220 open( TEMPLATE
, $templatepkg) or die "Error '$templatepkg': $!\n";
224 # replace the PKG variables
225 s/\$\(PLATFORM\)/$platform/gm;
226 s/\$\(TARGET\)/$target/gm;
229 open( OUTPUT
, ">$pkgoutput" ) or die "Error '$pkgoutput' $!\n";
233 if ($preprocessonly) {
238 system ("makesis $pkgoutput $unsigned_sis_name");
240 # Sign SIS with certificate info given as an argument.
241 system ("signsis $unsigned_sis_name $signed_sis_name $certificate $key $passphrase");
243 # Check if creating signed SIS Succeeded
244 stat($signed_sis_name);
246 print ("\nSuccessfully created $signed_sis_name using certificate: $certtext!\n");
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);
254 system ("signsis $signed_sis_name $signed_sis_name $abscert $abskey $row->[2]");
255 print ("\tAdditionally signed the SIS with certificate: $row->[0]!\n");
258 # remove temporary pkg and unsigned sis
260 unlink $unsigned_sis_name;
262 # Install the sis if requested
264 print ("\nInstalling $signed_sis_name...\n");
265 system ("$signed_sis_name");
268 # Lets leave the generated PKG for problem solving purposes
269 print ("\nSIS creation failed!\n");