Skip to content

Commit f867b65

Browse files
committed
creatensis.pl: create signed installer
1 parent bb8203b commit f867b65

File tree

3 files changed

+132
-60
lines changed

3 files changed

+132
-60
lines changed

ms-windows/Installer-Files/QGIS.ico

0 Bytes
Binary file not shown.

ms-windows/QGIS-Installer.nsi

+25-9
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,6 @@ RequestExecutionLevel admin
3535

3636
;Set the installer variables, depending on the selected version to build
3737

38-
!define COMPLETE_NAME "${QGIS_BASE} ${VERSION_NUMBER} ${VERSION_NAME}"
39-
4038
!addplugindir osgeo4w/untgz
4139
!addplugindir osgeo4w/nsis
4240

@@ -58,7 +56,6 @@ Name "${DISPLAYED_NAME}"
5856
;Name of the output file (installer executable)
5957
OutFile "${INSTALLER_NAME}"
6058

61-
6259
;Tell the installer to show Install and Uninstall details as default
6360
ShowInstDetails hide
6461
ShowUnInstDetails hide
@@ -88,6 +85,10 @@ ShowUnInstDetails hide
8885
; if the uninstall procedure succeeded, call the current installer asking for the install PATH
8986

9087
Function .onInit
88+
!ifdef INNER
89+
WriteUninstaller "${UNINSTALLERDEST}\uninstall.exe"
90+
Quit
91+
!endif
9192
${If} ${ARCH} == "x86_64"
9293
${If} ${RunningX64}
9394
DetailPrint "Installer running on 64-bit host"
@@ -199,7 +200,6 @@ Function .onInit
199200
Abort
200201
${EndIf}
201202
${EndIf}
202-
203203
FunctionEnd
204204

205205
;----------------------------------------------------------------------------------------------------------------------------
@@ -280,6 +280,7 @@ Var /GLOBAL ARCHIVE_SIZE_KB
280280
Var /GLOBAL ARCHIVE_SIZE_MB
281281
Var /GLOBAL DOWNLOAD_MESSAGE_
282282

283+
!ifndef INNER
283284
Section "QGIS" SecQGIS
284285
SectionIn RO
285286

@@ -320,8 +321,10 @@ Section "QGIS" SecQGIS
320321
SetOutPath "$INSTALL_DIR"
321322
File /r ${PACKAGE_FOLDER}\*.*
322323

323-
;Create the Uninstaller
324-
WriteUninstaller "$INSTALL_DIR\Uninstall-QGIS.exe"
324+
!ifndef INNER
325+
SetOutPath $INSTDIR
326+
File uninstall.exe
327+
!endif
325328

326329
;Registry Key Entries
327330

@@ -337,8 +340,8 @@ Section "QGIS" SecQGIS
337340
WriteRegStr HKLM "Software\${QGIS_BASE}" "InstallPath" "$INSTALL_DIR"
338341

339342
;HKEY_LOCAL_MACHINE Uninstall entries
340-
WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\${QGIS_BASE}" "DisplayName" "${COMPLETE_NAME}"
341-
WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\${QGIS_BASE}" "UninstallString" "$INSTALL_DIR\Uninstall-QGIS.exe"
343+
WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\${QGIS_BASE}" "DisplayName" "${DISPLAYED_NAME}"
344+
WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\${QGIS_BASE}" "UninstallString" "$INSTALL_DIR\uninstall.exe"
342345
WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\${QGIS_BASE}" "DisplayIcon" "$INSTALL_DIR\icons\QGIS.ico"
343346
WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\${QGIS_BASE}" "EstimatedSize" 1
344347
WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\${QGIS_BASE}" "HelpLink" "${WIKI_PAGE}"
@@ -371,6 +374,7 @@ RebootNecessary:
371374
NoRebootNecessary:
372375

373376
SectionEnd
377+
!endif
374378

375379
Function DownloadDataSet
376380

@@ -481,7 +485,15 @@ SectionEnd
481485

482486
;Uninstaller Section
483487

488+
!ifdef INNER
484489
Section "Uninstall"
490+
${If} ${ARCH} == "x86_64"
491+
${If} ${RunningX64}
492+
DetailPrint "Installer running on 64-bit host"
493+
; disable registry redirection (enable access to 64-bit portion of registry)
494+
SetRegView 64
495+
${EndIf}
496+
${EndIf}
485497

486498
GetFullPathName /SHORT $0 $INSTDIR
487499
System::Call 'Kernel32::SetEnvironmentVariableA(t, t) i("OSGEO4W_ROOT", "$0").r0'
@@ -493,12 +505,13 @@ Section "Uninstall"
493505
ReadEnvStr $0 COMSPEC
494506
nsExec::ExecToLog '"$0" /c "$INSTDIR\preremove.bat"'
495507

496-
Delete "$INSTDIR\Uninstall-QGIS.exe"
508+
Delete "$INSTDIR\uninstall.exe"
497509
Delete "$INSTDIR\*.bat.done"
498510
Delete "$INSTDIR\*.log"
499511
Delete "$INSTDIR\*.txt"
500512
Delete "$INSTDIR\*.ico"
501513
Delete "$INSTDIR\*.bat"
514+
Delete "$INSTDIR\*.dll"
502515

503516
RMDir /r "$INSTDIR\bin"
504517
RMDir /r "$INSTDIR\apps"
@@ -529,15 +542,18 @@ Section "Uninstall"
529542
DeleteRegKey HKLM "Software\${QGIS_BASE}"
530543
DeleteRegKey HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\${QGIS_BASE}"
531544
SectionEnd
545+
!endif
532546

533547
;----------------------------------------------------------------------------------------------------------------------------
534548

549+
!ifndef INNER
535550
;Installer Section Descriptions
536551
!insertmacro MUI_FUNCTION_DESCRIPTION_BEGIN
537552
!insertmacro MUI_DESCRIPTION_TEXT ${SecQGIS} "Install ${QGIS_BASE}"
538553
!insertmacro MUI_DESCRIPTION_TEXT ${SecNorthCarolinaSDB} "Download and install the North Carolina sample data set"
539554
!insertmacro MUI_DESCRIPTION_TEXT ${SecSpearfishSDB} "Download and install the South Dakota (Spearfish) sample data set"
540555
!insertmacro MUI_DESCRIPTION_TEXT ${SecAlaskaSDB} "Download and install the Alaska sample database (shapefiles and TIFF data)"
541556
!insertmacro MUI_FUNCTION_DESCRIPTION_END
557+
!endif
542558

543559
;----------------------------------------------------------------------------------------------------------------------------

ms-windows/osgeo4w/creatensis.pl

+107-51
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
# This program is free software; you can redistribute it and/or modify
88
# it under the terms of the GNU General Public License as published by
99
# the Free Software Foundation; either version 2 of the License, or
10-
# (at your option) any later version.
10+
# (at your option) any later version.
1111

1212
#
1313
# Download OSGeo4W packages
@@ -29,11 +29,15 @@
2929
my $root = "http://download.osgeo.org/osgeo4w";
3030
my $ininame = "setup.ini";
3131
my $arch = "x86_64";
32+
my $signwith;
33+
my $signpass;
3234
my $help;
3335

3436
my $result = GetOptions(
3537
"verbose+" => \$verbose,
3638
"keep" => \$keep,
39+
"signwith=s" => \$signwith,
40+
"signpass=s" => \$signpass,
3741
"releasename=s" => \$releasename,
3842
"version=s" => \$version,
3943
"binary=i" => \$binary,
@@ -45,6 +49,8 @@
4549
"help" => \$help
4650
);
4751

52+
die "certificate not found" if defined $signwith && ! -f $signwith;
53+
4854
pod2usage(1) if $help;
4955

5056
my $wgetopt = $verbose ? "" : "-nv";
@@ -265,6 +271,38 @@ sub getDeps {
265271
chdir "..";
266272
}
267273

274+
my($major, $minor, $patch);
275+
276+
open F, "../../CMakeLists.txt";
277+
while(<F>) {
278+
if(/SET\(CPACK_PACKAGE_VERSION_MAJOR "(\d+)"\)/) {
279+
$major = $1;
280+
} elsif(/SET\(CPACK_PACKAGE_VERSION_MINOR "(\d+)"\)/) {
281+
$minor = $1;
282+
} elsif(/SET\(CPACK_PACKAGE_VERSION_PATCH "(\d+)"\)/) {
283+
$patch = $1;
284+
} elsif(/SET\(RELEASE_NAME "(.+)"\)/) {
285+
$releasename = $1 unless defined $releasename;
286+
}
287+
}
288+
close F;
289+
290+
$version = "$major.$minor.$patch" unless defined $version;
291+
292+
my($pmajor,$pminor,$ppatch) = $version =~ /^(\d+)\.(\d+)\.(\d+)$/;
293+
die "Invalid version $version" unless defined $ppatch;
294+
295+
unless( defined $binary ) {
296+
if( -f "binary$archpostfix-$version" ) {
297+
open P, "binary$archpostfix-$version";
298+
$binary = <P>;
299+
close P;
300+
$binary++;
301+
} else {
302+
$binary = 1;
303+
}
304+
}
305+
268306
#
269307
# Create postinstall.bat
270308
#
@@ -290,7 +328,7 @@ sub getDeps {
290328
print F "echo OSGEO4W_STARTMENU=%OSGEO4W_STARTMENU%$r";
291329
print F "echo OSGEO4W_DESKTOP=%OSGEO4W_DESKTOP%$r";
292330
print F "PATH %OSGEO4W_ROOT%\\bin;%PATH%$r";
293-
print F "cd %OSGEO4W_ROOT%$r";
331+
print F "cd /d %OSGEO4W_ROOT%$r";
294332

295333
chdir $unpacked;
296334
for my $p (<etc/postinstall/*.bat>) {
@@ -320,7 +358,7 @@ sub getDeps {
320358
print F "if \"%OSGEO4W_ROOT_MSYS:~1,1%\"==\":\" set OSGEO4W_ROOT_MSYS=/%OSGEO4W_ROOT_MSYS:~0,1%/%OSGEO4W_ROOT_MSYS:~3%$r";
321359
print F "echo OSGEO4W_ROOT_MSYS=%OSGEO4W_ROOT_MSYS%$r";
322360
print F "PATH %OSGEO4W_ROOT%\\bin;%PATH%$r";
323-
print F "cd %OSGEO4W_ROOT%$r";
361+
print F "cd /d \"%OSGEO4W_ROOT%\"$r";
324362

325363
chdir $unpacked;
326364
for my $p (<etc/preremove/*.bat>) {
@@ -337,38 +375,6 @@ sub getDeps {
337375

338376
close F;
339377

340-
my($major, $minor, $patch);
341-
342-
open F, "../../CMakeLists.txt";
343-
while(<F>) {
344-
if(/SET\(CPACK_PACKAGE_VERSION_MAJOR "(\d+)"\)/) {
345-
$major = $1;
346-
} elsif(/SET\(CPACK_PACKAGE_VERSION_MINOR "(\d+)"\)/) {
347-
$minor = $1;
348-
} elsif(/SET\(CPACK_PACKAGE_VERSION_PATCH "(\d+)"\)/) {
349-
$patch = $1;
350-
} elsif(/SET\(RELEASE_NAME "(.+)"\)/) {
351-
$releasename = $1 unless defined $releasename;
352-
}
353-
}
354-
close F;
355-
356-
$version = "$major.$minor.$patch" unless defined $version;
357-
358-
my($pmajor,$pminor,$ppatch) = $version =~ /^(\d+)\.(\d+)\.(\d+)$/;
359-
die "Invalid version $version" unless defined $ppatch;
360-
361-
unless( defined $binary ) {
362-
if( -f "binary$archpostfix-$version" ) {
363-
open P, "binary$archpostfix-$version";
364-
$binary = <P>;
365-
close P;
366-
$binary++;
367-
} else {
368-
$binary = 1;
369-
}
370-
}
371-
372378
unless(-d "untgz") {
373379
system "unzip $packages/Untgz.zip";
374380
die "unpacking Untgz.zip failed" if $?;
@@ -438,29 +444,77 @@ sub getDeps {
438444

439445
print "Running NSIS\n" if $verbose;
440446

441-
my $cmd = "makensis";
442-
$cmd .= " -V$verbose";
443-
$cmd .= " -DVERSION_NAME='$releasename'";
444-
$cmd .= " -DVERSION_NUMBER='$version'";
445-
$cmd .= " -DBINARY_REVISION=$binary";
446-
$cmd .= sprintf( " -DVERSION_INT='%d%02d%02d%02d'", $pmajor, $pminor, $ppatch, $binary );
447-
$cmd .= sprintf( " -DQGIS_BASE='$packagename %d.%d'", $pmajor, $pminor );
448-
$cmd .= " -DINSTALLER_NAME='$packagename-OSGeo4W-$version-$binary-Setup$archpostfix.exe'";
449-
$cmd .= " -DDISPLAYED_NAME=\"$packagename '$releasename' ($version)\"";
450-
$cmd .= " -DSHORTNAME='$shortname'";
451-
$cmd .= " -DINSTALLER_TYPE=OSGeo4W";
452-
$cmd .= " -DPACKAGE_FOLDER=osgeo4w/$unpacked";
453-
$cmd .= " -DLICENSE_FILE='$license'";
454-
$cmd .= " -DARCH='$arch'";
455-
$cmd .= " QGIS-Installer.nsi";
447+
my $installerbase = "$packagename-OSGeo4W-$version-$binary-Setup$archpostfix";
448+
449+
my $run;
450+
my $instdest;
451+
unless($^O =~ /win/i) {
452+
$run = "wine ";
453+
$instdest = `winepath -w \$PWD`;
454+
$instdest =~ s/\s+$//;
455+
$instdest =~ s/\\/\\\\/g;
456+
} else {
457+
$run = "";
458+
$instdest = ".";
459+
}
460+
456461

462+
my $args = "";
463+
$args .= " -V$verbose";
464+
$args .= " -DVERSION_NAME='$releasename'";
465+
$args .= " -DVERSION_NUMBER='$version'";
466+
$args .= " -DBINARY_REVISION=$binary";
467+
$args .= sprintf( " -DVERSION_INT='%d%02d%02d%02d'", $pmajor, $pminor, $ppatch, $binary );
468+
$args .= sprintf( " -DQGIS_BASE='$packagename %d.%d'", $pmajor, $pminor );
469+
$args .= " -DDISPLAYED_NAME=\"$packagename $version '$releasename'\"";
470+
$args .= " -DPACKAGE_FOLDER=osgeo4w/$unpacked";
471+
$args .= " -DLICENSE_FILE='$license'";
472+
$args .= " -DARCH='$arch'";
473+
$args .= " QGIS-Installer.nsi";
474+
475+
sub sign {
476+
my $base = shift;
477+
478+
my $cmd = "osslsigncode sign";
479+
$cmd .= " -pkcs12 \"$signwith\"";
480+
$cmd .= " -pass \"$signpass\"" if defined $signpass;
481+
$cmd .= " -n \"$packagename $version '$releasename'\"";
482+
$cmd .= " -h sha256";
483+
$cmd .= " -i \"https://qgis.org\"";
484+
$cmd .= " -t \"http://timestamp.digicert.com\"";
485+
$cmd .= " -in \"$base.exe\"";
486+
$cmd .= " $base-signed.exe";
487+
system $cmd;
488+
die "signing failed [$cmd]" if $?;
489+
490+
rename("$base-signed.exe", "$base.exe") or die "rename failed: $!";
491+
}
492+
493+
my $cmd;
494+
unlink "makeuinst.exe";
495+
$cmd = "makensis -DINNER=1 -DUNINSTALLERDEST='$instdest' -DINSTALLER_NAME='makeuinst.exe' $args";
457496
system $cmd;
458-
die "running nsis failed [$cmd]" if $?;
497+
die "running makensis failed [$cmd]" if $?;
498+
die "makeuinst.exe not created" unless -f "makeuinst.exe";
499+
500+
unlink "uninstall.exe";
501+
system "${run}makeuinst.exe";
502+
die "uninstall.exe not created" unless -f "uninstall.exe";
503+
unlink "makeuinst.exe";
504+
505+
sign "uninstall" if $signwith;
506+
507+
$cmd = "makensis -DINSTALLER_NAME='$installerbase.exe' $args";
508+
system $cmd;
509+
die "running makensis failed [$cmd]" if $?;
510+
511+
sign "$installerbase" if $signwith;
459512

460513
open P, ">osgeo4w/binary$archpostfix-$version";
461514
print P $binary;
462515
close P;
463516

517+
system "md5sum $installerbase.exe >$installerbase.exe.md5sum";
464518

465519
__END__
466520
@@ -476,6 +530,8 @@ =head1 SYNOPSIS
476530
-verbose increase verbosity
477531
-releasename=name name of release (defaults to CMakeLists.txt setting)
478532
-keep don't start with a fresh unpacked directory
533+
-signwith=cert.p12 optionall sign package with certificate (requires osslsigncode)
534+
-signpass=password password of certificate
479535
-version=m.m.p package version (defaults to CMakeLists.txt setting)
480536
-binary=b binary version of package
481537
-ininame=filename name of the setup.ini (defaults to setup.ini)

0 commit comments

Comments
 (0)