Skip to content

Commit

Permalink
add script to build nsis standalone installer from OSGeo4W packages
Browse files Browse the repository at this point in the history
git-svn-id: http://svn.osgeo.org/qgis/trunk/qgis@13664 c8812cc2-4d05-0410-92ff-de0c093fc19c
  • Loading branch information
jef committed Jun 5, 2010
1 parent 4f64b9e commit 2c24391
Show file tree
Hide file tree
Showing 2 changed files with 269 additions and 8 deletions.
65 changes: 57 additions & 8 deletions ms-windows/QGIS-Installer.nsi
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@
;Quantum GIS Installer for Windows
;Written by Marco Pasetti
;Mail to: marco.pasetti@alice.it
;
;Extended for creatensis.pl by Jürgen E. Fischer <jef@norbit.de>

;----------------------------------------------------------------------------------------------------------------------------

;Select if you are building a "Development Version" or a "Release Version" of the Quantum GIS Installer
;Change the INSTALLER_TYPE variable to Release or Development

!define INSTALLER_TYPE "Release-NoGrass"

;----------------------------------------------------------------------------------------------------------------------------

;Version variables
Expand Down Expand Up @@ -43,13 +43,10 @@ RequestExecutionLevel admin

;----------------------------------------------------------------------------------------------------------------------------

;define the QGIS Base Name
!define RELEASE_QGIS_BASE "Quantum GIS Enceladus"
!define DEV_QGIS_BASE "Quantum GIS Unstable Dev"

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

!if ${INSTALLER_TYPE} == "Release"
!define RELEASE_QGIS_BASE "Quantum GIS Enceladus"
!define VERSION_NUMBER "${RELEASE_VERSION_NUMBER}"
!define VERSION_NAME "${RELEASE_VERSION_NAME}"
!define COMPLETE_NAME "${RELEASE_QGIS_BASE} ${RELEASE_VERSION_NUMBER} ${RELEASE_VERSION_NAME}"
Expand All @@ -74,6 +71,7 @@ RequestExecutionLevel admin
!define INSTALLER_DISPLAYED_NAME "${COMPLETE_NAME}"
!define PACKAGE_FOLDER ".\QGIS-Release-Package-No-Grass"
!else if ${INSTALLER_TYPE} == "Development"
!define DEV_QGIS_BASE "Quantum GIS Unstable Dev"
!define VERSION_NUMBER "${DEV_VERSION_NUMBER}"
!define VERSION_NAME "${DEV_VERSION_NAME}"
!define COMPLETE_NAME "${DEV_QGIS_BASE} ${DEV_VERSION_NUMBER} ${DEV_VERSION_NAME}"
Expand All @@ -85,6 +83,12 @@ RequestExecutionLevel admin
!define CHECK_INSTALL_NAME "${DEV_QGIS_BASE}"
!define INSTALLER_DISPLAYED_NAME "${DISPLAYED_NAME}"
!define PACKAGE_FOLDER ".\QGIS-Dev-Package"
!else if ${INSTALLER_TYPE} == "OSGeo4W"
!define COMPLETE_NAME "${QGIS_BASE} ${VERSION_NUMBER} ${VERSION_NAME}"
!define CHECK_INSTALL_NAME "${QGIS_BASE}"
!define INSTALLER_DISPLAYED_NAME "${DISPLAYED_NAME}"

!addplugindir osgeo4w/untgz
!endif

;----------------------------------------------------------------------------------------------------------------------------
Expand Down Expand Up @@ -352,6 +356,10 @@ Section "Quantum GIS" SecQGIS
File .\Installer-Files\QGIS_Web.ico
SetOutPath "$INSTALL_DIR"
File .\Installer-Files\QGIS-WebSite.url
!if ${INSTALLER_TYPE} == "OSGeo4W"
File .\Installer-Files\postinstall.bat
File .\Installer-Files\preremove.bat
!endif

;add Quantum GIS files
SetOutPath "$INSTALL_DIR"
Expand Down Expand Up @@ -394,23 +402,39 @@ Section "Quantum GIS" SecQGIS
;Create the Desktop Shortcut
SetShellVarContext current

!if ${INSTALLER_TYPE} == "OSGeo4W"
CreateShortCut "$DESKTOP\${QGIS_BASE}.lnk" "$INSTALL_DIR\bin\nircmd.exe" 'exec hide "$INSTALL_DIR\bin\qgis-dev.bat"' \
"$INSTALL_DIR\icons\QGIS.ico" "" SW_SHOWNORMAL "" "Launch ${COMPLETE_NAME}"
!else
CreateShortCut "$DESKTOP\${QGIS_BASE}.lnk" "$INSTALL_DIR\bin\qgis.exe" ""\
"$INSTALL_DIR\icons\QGIS.ico" "" SW_SHOWNORMAL "" "Launch ${COMPLETE_NAME}"
!endif

;Create the Windows Start Menu Shortcuts
SetShellVarContext all

CreateDirectory "$SMPROGRAMS\${QGIS_BASE}"

!if ${INSTALLER_TYPE} == "OSGeo4W"
CreateShortCut "$SMPROGRAMS\${QGIS_BASE}\${QGIS_BASE}.lnk" "$INSTALL_DIR\bin\nircmd.exe" 'exec hide "$INSTALL_DIR\bin\qgis-dev.bat"' \
"$INSTALL_DIR\icons\QGIS.ico" "" SW_SHOWNORMAL "" "Launch ${COMPLETE_NAME}"
!else
CreateShortCut "$SMPROGRAMS\${QGIS_BASE}\${QGIS_BASE}.lnk" "$INSTALL_DIR\bin\qgis.exe" ""\
"$INSTALL_DIR\icons\QGIS.ico" "" SW_SHOWNORMAL "" "Launch ${COMPLETE_NAME}"
!endif

CreateShortCut "$SMPROGRAMS\${QGIS_BASE}\Quantum GIS Web Site.lnk" "$INSTALL_DIR\QGIS-WebSite.url" ""\
"$INSTALL_DIR\icons\QGIS_Web.ico" "" SW_SHOWNORMAL "" "Visit the Quantum GIS Web Site"

CreateShortCut "$SMPROGRAMS\${QGIS_BASE}\Uninstall ${QGIS_BASE}.lnk" "$INSTALL_DIR\Uninstall-QGIS.exe" ""\
"$INSTALL_DIR\Uninstall-QGIS.exe" "" SW_SHOWNORMAL "" "Uninstall ${COMPLETE_NAME}"


GetFullPathName /SHORT $0 $INSTALL_DIR
System::Call 'Kernel32::SetEnvironmentVariableA(t, t) i("OSGEO4W_ROOT", "$0").r0'
System::Call 'Kernel32::SetEnvironmentVariableA(t, t) i("OSGEO4W_STARTMENU", "$SMPROGRAMS\${QGIS_BASE}").r0'

ReadEnvStr $0 COMSPEC
nsExec::ExecToLog '"$0" /c "$INSTALL_DIR\postinstall.bat"'
SectionEnd

Function DownloadDataSet
Expand Down Expand Up @@ -524,6 +548,31 @@ SectionEnd

Section "Uninstall"

!if ${INSTALLER_TYPE} == "OSGeo4W"
GetFullPathName /SHORT $0 $INSTDIR
System::Call 'Kernel32::SetEnvironmentVariableA(t, t) i("OSGEO4W_ROOT", "$0").r0'
System::Call 'Kernel32::SetEnvironmentVariableA(t, t) i("OSGEO4W_STARTMENU", "$SMPROGRAMS\${QGIS_BASE}").r0'

ReadEnvStr $0 COMSPEC
nsExec::ExecToLog '"$0" /c "$INSTALL_DIR\preremove.bat"'

Delete "$INSTDIR\Uninstall-QGIS.exe"
Delete "$INSTDIR\postinstall.bat.done"
Delete "$INSTDIR\postinstall.bat"
Delete "$INSTDIR\postinstall.log"

Delete "$INSTDIR\preremove.bat.done"
Delete "$INSTDIR\preremove.bat"
Delete "$INSTDIR\preremove.log"

RMDir /r "$INSTDIR\bin"
RMDir /r "$INSTDIR\apps"
RMDir /r "$INSTDIR\etc"
RMDir /r "$INSTDIR\include"
RMDir /r "$INSTDIR\lib"
RMDir /r "$INSTDIR\share"
RMDir /r "$INSTDIR\icons"
!else
;remove files
Delete "$INSTDIR\Uninstall-QGIS.exe"

Expand Down Expand Up @@ -563,6 +612,7 @@ Section "Uninstall"
RMDir /r "$INSTDIR\themes"
RMDir /r "$INSTDIR\proj"
RMDir /r "$INSTDIR\epsg_csv"
!endif

;if empty, remove the install folder
RMDir "$INSTDIR"
Expand All @@ -578,7 +628,6 @@ Section "Uninstall"
;remove the Registry Entries
DeleteRegKey HKLM "Software\${QGIS_BASE}"
DeleteRegKey HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\${QGIS_BASE}"

SectionEnd

;----------------------------------------------------------------------------------------------------------------------------
Expand Down
212 changes: 212 additions & 0 deletions ms-windows/osgeo4w/creatensis.pl
Original file line number Diff line number Diff line change
@@ -0,0 +1,212 @@
#!/usr/bin/perl
# creates a NSIS installer from OSGeo4W packages
# note: works also on Unix

# Copyright (C) 2010 Jürgen E. Fischer <jef@norbit.de>

# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.

#
# Download OSGeo4W packages
#

mkdir "packages", 0755 unless -d "packages";
chdir "packages";

my $root = "http://download.osgeo.org/osgeo4w";

system "wget -q -c http://nsis.sourceforge.net/mediawiki/images/9/9d/Untgz.zip" unless -f "Untgz.zip";
system "wget -q -c http://www.nirsoft.net/utils/nircmd.zip" unless -f "nircmd.zip";

my %dep;
my %file;

system "wget -q -c $root/setup.ini";
open F, "setup.ini" || die "setup.ini not found";
while(<F>) {
chop;
if(/^@ (\S+)/) {
$package = $1;
} elsif( /^requires: (.*)$/ ) {
@{$dep{$package}} = split / /, $1;
} elsif( /^install:\s+(\S+)\s+/) {
$file{$package} = $1 unless exists $file{$package};
}
}
close F;

my %pkgs;

sub getDeps {
my ($pkg) = @_;

return if exists $pkgs{$pkg};

$pkgs{$pkg} = 1;

foreach my $p ( @{ $dep{$pkg} } ) {
getDeps($p);
}
}

getDeps("qgis-dev");

if(-f "../addons/bin/NCSEcw.dll") {
print "Enabling ECW support...\n";
getDeps("gdal16-ecw")
}

if(-f "../addons/bin/lti_dsdk_dll.dll") {
print "Enabling MrSID support...\n";
getDeps("gdal16-mrsid")
}

delete $pkgs{"qgis-dev"};


foreach my $p ( keys %pkgs ) {
$f = "$root/$file{$p}";
$f =~ s/\/\.\//\//g;

my($file) = $f =~ /([^\/]+)$/;

next if -f $file;

print "Downloading $file [$f]...\n";
system "wget -q -c $f";
}

chdir "..";

#
# Unpack them
# Add nircmd
# Add addons
#


system "rm -rf unpacked" if -d "unpacked" && !grep(/^-k$/, @ARGV);

unless(-d "unpacked") {
mkdir "unpacked", 0755;

for my $p (<packages/*.tar.bz2>) {
print "Unpacking $p...\n";
system "tar -C unpacked -xjf $p";
}

chdir "unpacked";

mkdir "bin", 0755;
mkdir "apps", 0755;
mkdir "apps/nircmd", 0755;

system "cd apps/nircmd; unzip ../../../packages/nircmd.zip && mv nircmd.exe ../../bin";

system "tar -C ../addons -cf . | tar -xf -" if -d "../addons";

chdir "..";
}

#
# Create postinstall.bat
#

unless(-f "../Installer-Files/postinstall.bat") {
open F, ">../Installer-Files/postinstall.bat";

print F "\@echo off\r\n";
print F "del postinstall.log>>postinstall.log\r\n";
print F "echo OSGEO4W_ROOT=%OSGEO4W_ROOT%>>postinstall.log 2>&1\r\n";
print F "echo OSGEO4W_STARTMENU=%OSGEO4W_STARTMENU%>>postinstall.log 2>&1\r\n";
print F "set OSGEO4W_ROOT_MSYS=%OSGEO4W_ROOT:\\=/%\r\n";
print F "if \"%OSGEO4W_ROOT_MSYS:~1,1%\"==\":\" set OSGEO4W_ROOT_MSYS=/%OSGEO4W_ROOT_MSYS:~0,1%/%OSGEO4W_ROOT_MSYS:~3%\r\n";
print F "echo OSGEO4W_ROOT_MSYS=%OSGEO4W_ROOT_MSYS%>>postinstall.log 2>&1\r\n";
print F "PATH %OSGEO4W_ROOT%\\bin;%PATH%>>postinstall.log 2>&1\r\n";
print F "cd %OSGEO4W_ROOT%>>postinstall.log 2>&1\r\n";

chdir "unpacked";
for my $p (<etc/postinstall/*.bat>) {
$p =~ s/\//\\/g;
my($dir,$file) = $p =~ /^(.+)\\([^\\]+)$/;

print F "echo Running postinstall $file...\r\n";
print F "%COMSPEC% /c $p>>postinstall.log 2>&1\r\n";
print F "ren $p $file.done>>postinstall.log 2>&1\r\n";
}
chdir "..";

print F "ren postinstall.bat postinstall.bat.done\r\n";

close F;
}

unless(-f "../Installer-Files/preremove.bat") {
open F, ">../Installer-Files/preremove.bat";

print F "\@echo off\r\n";
print F "del preremove.log>>preremove.log\r\n";
print F "echo OSGEO4W_ROOT=%OSGEO4W_ROOT%>>preremove.log 2>&1\r\n";
print F "echo OSGEO4W_STARTMENU=%OSGEO4W_STARTMENU%>>preremove.log 2>&1\r\n";
print F "set OSGEO4W_ROOT_MSYS=%OSGEO4W_ROOT:\\=/%\r\n";
print F "if \"%OSGEO4W_ROOT_MSYS:~1,1%\"==\":\" set OSGEO4W_ROOT_MSYS=/%OSGEO4W_ROOT_MSYS:~0,1%/%OSGEO4W_ROOT_MSYS:~3%\r\n";
print F "echo OSGEO4W_ROOT_MSYS=%OSGEO4W_ROOT_MSYS%>>preremove.log 2>&1\r\n";
print F "PATH %OSGEO4W_ROOT%\\bin;%PATH%>>preremove.log 2>&1\r\n";
print F "cd %OSGEO4W_ROOT%>>preremove.log 2>&1\r\n";

chdir "unpacked";
for my $p (<etc/preremove/*.bat>) {
$p =~ s/\//\\/g;
my($dir,$file) = $p =~ /^(.+)\\([^\\]+)$/;

print F "echo Running preremove $file...\r\n";
print F "%COMSPEC% /c $p>>preremove.log 2>&1\r\n";
print F "ren $p $file.done>>preremove.log 2>&1\r\n";
}
chdir "..";

print F "ren preremove.bat preremove.bat.done\r\n";

close F;
}

my($major, $minor, $patch, $release, $revision);

open F, "../../CMakeLists.txt";
while(<F>) {
print;
if(/SET\(CPACK_PACKAGE_VERSION_MAJOR "(\d+)"\)/) {
$major = $1;
} elsif(/SET\(CPACK_PACKAGE_VERSION_MINOR "(\d+)"\)/) {
$minor = $1;
} elsif(/SET\(CPACK_PACKAGE_VERSION_PATCH "(\d+)"\)/) {
$patch = $1;
} elsif(/SET\(RELEASE_NAME "(.+)"\)/) {
$release = $1;
}
}
close F;

open F, "svnversion|";
$revision = <F>;
$revision =~ s/\D+$//g;
close F;

chdir "..";

my $cmd = "makensis";
$cmd .= " -DVERSION_NUMBER='$major.$minor.$patch'";
$cmd .= " -DVERSION_NAME='$release'";
$cmd .= " -DSVN_REVISION='$revision'";
$cmd .= " -DQGIS_BASE='Quantum GIS $release'";
$cmd .= " -DINSTALLER_NAME='QGIS-OSGeo4W-$major.$minor.$patch-$revision-Setup.exe'";
$cmd .= " -DDISPLAYED_NAME='Quantum GIS OSGeo4W ($release)'";
$cmd .= " -DBINARY_REVISION=1";
$cmd .= " -DINSTALLER_TYPE=OSGeo4W";
$cmd .= " -DPACKAGE_FOLDER=osgeo4w/unpacked";
$cmd .= " QGIS-Installer.nsi";

system $cmd;

0 comments on commit 2c24391

Please sign in to comment.