[Greater-commits] r348 - in trunk: . packaging packaging/includes

scm-commit@wald.intevation.org scm-commit at wald.intevation.org
Fri Jul 1 16:57:02 CEST 2011


Author: aheinecke
Date: 2011-07-01 16:57:02 +0200 (Fri, 01 Jul 2011)
New Revision: 348

Added:
   trunk/packaging/
   trunk/packaging/greater-installer.nsi
   trunk/packaging/includes/
   trunk/packaging/includes/uninstalllog.nsh
   trunk/packaging/installer-options.ini
Log:
Add Packaging NSIS Script


Added: trunk/packaging/greater-installer.nsi
===================================================================
--- trunk/packaging/greater-installer.nsi	2011-07-01 12:47:43 UTC (rev 347)
+++ trunk/packaging/greater-installer.nsi	2011-07-01 14:57:02 UTC (rev 348)
@@ -0,0 +1,398 @@
+; GREAT-ER Installer
+;(c)2011, Intevation GmbH
+;Authors:
+; Andre Heinecke aheinecke at intevation.de
+;
+; This program is free software; you can redistribute it and/or modify
+; it under the terms of the GNU General Public License version 2,
+; or, at your option, any later version as published by the Free
+; Software Foundation
+;
+; This program is distributed in the hope that it will be useful,
+; but WITHOUT ANY WARRANTY; without even the implied warranty of
+; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+; GNU General Public License for more details.
+;
+; You should have received a copy of the GNU General Public License
+; along with this program; if not, write to the Free Software
+; Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+;
+;--------------------------------
+;Includes
+
+  ; Modern UI
+  !include "MUI.nsh"
+
+  ; Uninstaller logging to only remove what was installed
+  !include "UninstallLog.nsh"
+
+  ;--------------------------------
+  ; Configure UnInstall log to only remove what is installed
+  ;-------------------------------- 
+  ;Set the name of the uninstall log
+  !define UninstLog "uninstall.log"
+  Var UninstLog
+
+  ;Uninstall log file missing.
+  LangString UninstLogMissing "${UninstLog} not found!$\r$\nUninstallation cannot proceed!"
+
+  ;AddItem macro
+  !define AddItem "!insertmacro AddItem"
+
+  ;File macro
+  !define File "!insertmacro File"
+
+  ;CreateShortcut macro
+  !define CreateShortcut "!insertmacro CreateShortcut"
+
+  ;Copy files macro
+  !define CopyFiles "!insertmacro CopyFiles"
+
+  ;Rename macro
+  !define Rename "!insertmacro Rename"
+
+  ;CreateDirectory macro
+  !define CreateDirectory "!insertmacro CreateDirectory"
+
+  ;SetOutPath macro
+  !define SetOutPath "!insertmacro SetOutPath"
+
+  ;WriteUninstaller macro
+  !define WriteUninstaller "!insertmacro WriteUninstaller"
+
+  ;WriteRegStr macro
+  !define WriteRegStr "!insertmacro WriteRegStr"
+
+  ;WriteRegDWORD macro
+  !define WriteRegDWORD "!insertmacro WriteRegDWORD" 
+
+  Section -openlogfile
+    CreateDirectory "$INSTDIR"
+    IfFileExists "$INSTDIR\${UninstLog}" +3
+      FileOpen $UninstLog "$INSTDIR\${UninstLog}" w
+    Goto +4
+      SetFileAttributes "$INSTDIR\${UninstLog}" NORMAL
+      FileOpen $UninstLog "$INSTDIR\${UninstLog}" a
+      FileSeek $UninstLog 0 END
+  SectionEnd
+
+;--------------------------------
+;Version Information (for installer file properties)
+
+  VIProductVersion "${version_number}" ;needs integer format: x.x.x.x
+  VIAddVersionKey "ProductName" "${productname_short}"
+  VIAddVersionKey "Comments" "${productname_short} is Free Software"
+  VIAddVersionKey "CompanyName" "${company}"
+  VIAddVersionKey "LegalTrademarks" ""
+  VIAddVersionKey "LegalCopyright" "${copyright}"
+  VIAddVersionKey "FileDescription" "${description}"
+  VIAddVersionKey "FileVersion" "${version_number} (build ${version_date})"
+
+
+;--------------------------------
+;General
+
+  ; Define Name, File and Installdir of Installer
+  Name "${productname}"
+  OutFile "${setupname}"
+  InstallDir "$PROGRAMFILES\${productname_short}"
+
+;--------------------------------
+;Interface Settings
+
+  !define MUI_ABORTWARNING
+  BrandingText "GREAT-ER III - PostgreSQL"
+  ; MUI Settings / Header
+  !define MUI_WELCOMEPAGE_TITLE "Welcome to the installation of GREAT-ER III - PostgreSQL"
+  !define MUI_WELCOMEPAGE_TEXT "This Installer will install\r\n\
+  The Geo-referenced Regional Exposure Assesment Tool for European Rivers\r\n
+  using the Postges SQL Database backend."
+  !define MUI_HEADERIMAGE
+
+;--------------------------------
+;Pages
+  !define MUI_PAGE_CUSTOMFUNCTION_SHOW PrintNonAdminWarning
+  !insertmacro MUI_PAGE_WELCOME
+  !insertmacro MUI_PAGE_LICENSE ${license}
+  !insertmacro MUI_PAGE_DIRECTORY
+  Page custom CustomPageOptions
+  !insertmacro MUI_PAGE_INSTFILES
+  !insertmacro MUI_PAGE_FINISH
+
+  !define MUI_PAGE_CUSTOMFUNCTION_SHOW un.PrintNonAdminWarning
+  !insertmacro MUI_UNPAGE_WELCOME
+  !insertmacro MUI_UNPAGE_CONFIRM
+  !insertmacro MUI_UNPAGE_INSTFILES
+  !insertmacro MUI_UNPAGE_FINISH
+
+;--------------------------------
+;Supported Languages
+
+  !insertmacro MUI_LANGUAGE "English"
+
+;-------------------------------
+;Reserve Files
+
+  !insertmacro MUI_RESERVEFILE_LANGDLL
+  !insertmacro MUI_RESERVEFILE_INSTALLOPTIONS
+  ReserveFile "installer-options.ini"
+
+
+;--------------------------------
+;Installer Sections
+
+Section ""
+  SetOutPath "$INSTDIR"
+
+  ; Store installation folder
+  WriteRegStr HKLM "Software\${productname_short}" "" $INSTDIR
+
+  ; Include the input files
+  ; package all files, recursively, preserving attributes
+  ; assume files are in the correct places
+
+  File /a /r /x "*.nsi" /x "${setupname}" "${srcdir}\*"
+
+  ; Create uninstaller
+  WriteUninstaller "$INSTDIR\Uninstall.exe"
+
+  ; Create Registry keys
+  WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\${productname_short}" "DisplayName" "${productname_short} ${version_date}"
+  WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\${productname_short}" "Displayversion_number" "${version_number}"
+  WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\${productname_short}" "Displayversion_date" "${version_date}"
+  WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\${productname_short}" "UninstallString" '"$INSTDIR\uninstall.exe"'
+  WriteRegDWORD HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\${productname_short}" "NoModify" 1
+  WriteRegDWORD HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\${productname_short}" "NoRepair" 1
+
+  ; Set Path to $PROFILE
+  SetOutPath "%HOMEDRIVE%%HOMEPATH%"
+
+  # 'all users' shell folder is used (for $DESKTOP, $SMPROGRAMS, $QUICKLAUNCH,...)
+  SetShellVarContext all
+
+  # ** Start menu **
+  # Delete old Start menu entries.
+  RMDir /R  "$SMPROGRAMS\${productname_short} ${version_number}"
+  # Check if the start menu entries where requested.
+  !insertmacro MUI_INSTALLOPTIONS_READ $R0 "installer-options.ini" \
+    "Field 2" "State"
+  IntCmp $R0 0 no_start_menu
+  # Create new Start menu entries
+  CreateDirectory "$SMPROGRAMS\${productname}"
+  CreateShortCut "$SMPROGRAMS\${productname}\${productname_short}.lnk" "$INSTDIR\bin\greater.exe"
+  no_start_menu:
+
+  # ** Desktop Icon **
+  # Delete old Desktop link
+  Delete "$DESKTOP\${productname_short}.lnk"
+  # Check if the desktop entries where requested.
+  !insertmacro MUI_INSTALLOPTIONS_READ $R0 "installer-options.ini" \
+     "Field 3" "State"
+  IntCmp $R0 0 no_desktop
+  # Create new Desktop link
+  CreateShortCut "$DESKTOP\${productname_short}.lnk" "$INSTDIR\bin\kontact.exe"
+#  no_desktop:
+
+  # ** Quick Launch **
+  # Delete old Quick Launch Bar link
+  Delete "$QUICKLAUNCH\${productname_short}.lnk"
+  # Check if the quick launch bar entries where requested.
+# !insertmacro MUI_INSTALLOPTIONS_READ $R0 "installer-options.ini" \
+#   "Field 4" "State"
+#  IntCmp $R0 0 no_quick_launch
+#  StrCmp $QUICKLAUNCH $TEMP no_quick_launch
+  # Create new Quick Launch Bar link
+  CreateShortCut "$QUICKLAUNCH\${productname_short}.lnk" "$INSTDIR\bin\kontact.exe"
+#  no_quick_launch:
+
+  ; Create killkde.bat 
+  FileOpen $1 "$INSTDIR\bin\killgreater.bat" "w"
+  FileWrite $1 '@echo off $\r$\n'
+  FileWrite $1 'kdeinit4 --terminate'
+  FileClose $1
+
+  Return
+
+SectionEnd
+
+
+
+;--------------------------------
+;Install Functions
+Function ".onInit"
+  ; Language select dialog - not needed!
+;  !insertmacro MUI_LANGDLL_DISPLAY
+  !insertmacro MUI_INSTALLOPTIONS_EXTRACT "installer-options.ini"
+  call CheckExistingVersion
+FunctionEnd
+
+; Check whether application has already been installed.
+Function CheckExistingVersion
+  ClearErrors
+  Push $0
+  ReadRegStr $0 HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\${productname_short}" "Displayversion_number"
+  IfErrors leave 0
+    MessageBox MB_YESNO|MB_ICONEXCLAMATION "${productname_short} $0 \
+    $(T_AlreadyInstalled)" IDYES leave
+    Abort
+  leave:
+FunctionEnd
+
+# PrintNonAdminWarning
+
+# Check whether the current user is in the Administrator group or an
+# OS version without the need for an Administrator is in use. Print a
+# diagnostic if this is not the case and abort installation.
+Function PrintNonAdminWarning
+  ClearErrors
+  UserInfo::GetName
+  IfErrors leave
+  Pop $0
+  UserInfo::GetAccountType
+  Pop $1
+  StrCmp $1 "Admin" leave +1
+  MessageBox MB_OK|MB_ICONEXCLAMATION "$(T_AdminNeeded)"
+  Quit
+ leave:
+FunctionEnd
+
+; Custom Page for add Desktop, Startmenu and Quick Launch links
+Function CustomPageOptions
+  !insertmacro MUI_HEADER_TEXT "$(T_InstallOptions)" "$(T_InstallOptLinks)"
+
+  # Note that the default selection is done in the ini file.
+  !insertmacro MUI_INSTALLOPTIONS_WRITE "installer-options.ini" \
+        "Field 1" "Text" "Install Components"
+  !insertmacro MUI_INSTALLOPTIONS_WRITE "installer-options.ini" \
+        "Field 2" "Text" "GREAT-ER Desktop"
+  !insertmacro MUI_INSTALLOPTIONS_WRITE "installer-options.ini" \
+        "Field 3" "Text" "GREAT-ER Server"
+  !insertmacro MUI_INSTALLOPTIONS_WRITE "installer-options.ini" \
+        "Field 4" "Text" "PostgreSQL Database"
+  !insertmacro MUI_INSTALLOPTIONS_DISPLAY "installer-options.ini"
+FunctionEnd
+
+; AbortDisplayLogOption - give the user the option to display an error log
+; and abort the installation.
+;       R8 - Error message
+;       R9 - Log filename;
+Function AbortDisplayLogOption
+
+  ; Display a message box with the error 
+  MessageBox MB_YESNO|MB_ICONSTOP "$R8$\r$\n$\r$\nDo you ont th open '$R9'?" IDYES adlo_show_error_log
+
+  ; If the user selects NO, simply abort the installation
+  Abort "$R8" 
+  Return
+
+  adlo_show_error_log: 
+    ;Otherwise show the error log first
+    ExecShell "open" "$R9"
+    Abort "$R8"
+    Return
+FunctionEnd
+
+;--------------------------------
+;Uninstaller
+
+
+Section "un."
+  IfFileExists "$INSTDIR\${UninstLog}" +3
+    MessageBox MB_OK|MB_ICONSTOP "$(UninstLogMissing)"
+    Abort
+
+  DetailPrint "Terminating Processes"
+  ExecDos::exec '"$SYSDIR\cmd.exe" /C "$INSTDIR\bin\killgreater.bat"' ""
+
+  ; Delete all files
+
+  Push $R0
+  Push $R1
+  Push $R2
+  SetFileAttributes "$INSTDIR\${UninstLog}" NORMAL
+  FileOpen $UninstLog "$INSTDIR\${UninstLog}" r
+  StrCpy $R1 -1
+
+  GetLineCount:
+    ClearErrors
+    FileRead $UninstLog $R0
+    IntOp $R1 $R1 + 1
+    StrCpy $R0 $R0 -2
+    Push $R0   
+    IfErrors 0 GetLineCount
+
+  Pop $R0
+
+  LoopRead:
+    StrCmp $R1 0 LoopDone
+    Pop $R0
+
+    IfFileExists "$R0\*.*" 0 +3
+      RMDir $R0  #is dir
+    Goto +9
+    IfFileExists $R0 0 +3
+      Delete $R0 #is file
+    Goto +6
+    StrCmp $R0 "${REG_ROOT} ${REG_APP_PATH}" 0 +3
+      DeleteRegKey ${REG_ROOT} "${REG_APP_PATH}" #is Reg Element
+    Goto +3
+    StrCmp $R0 "${REG_ROOT} ${UNINSTALL_PATH}" 0 +2
+      DeleteRegKey ${REG_ROOT} "${UNINSTALL_PATH}" #is Reg Element
+
+    IntOp $R1 $R1 - 1
+    Goto LoopRead
+  LoopDone:
+  FileClose $UninstLog
+  Delete "$INSTDIR\${UninstLog}"
+  Pop $R2
+  Pop $R1
+  Pop $R0
+
+SectionEnd
+
+
+;--------------------------------
+;Uninstall Functions
+
+# PrintNonAdminWarning (uninstall)
+Function un.PrintNonAdminWarning
+  ClearErrors
+  UserInfo::GetName
+  IfErrors leave
+  Pop $0
+  UserInfo::GetAccountType
+  Pop $1
+  StrCmp $1 "Admin" leave +1
+  MessageBox MB_OK|MB_ICONEXCLAMATION "$(T_AdminNeeded_uninstall)"
+  Quit
+
+ leave:
+FunctionEnd
+
+;---------------------------
+; Language Strings
+;---------------------------
+# From Function CheckExistingVersion
+LangString T_AlreadyInstalled ${LANG_ENGLISH} \
+    "has already been installed.$\r$\nDo you want to\
+    continue the installation of ${productname_short} ${version_date}?"
+# From Custom Welcome Page
+#
+# Title
+LangString T_Aboutversion_date ${LANG_ENGLISH} \
+    "Release date: ${version_date}"
+
+# From Function CustomPageOptions
+# English
+LangString T_InstallOptions ${LANG_ENGLISH} "Install Options"
+LangString T_InstallOptLinks ${LANG_ENGLISH} "Start links"
+LangString T_InstOptLabelA  ${LANG_ENGLISH} "Please select where ${productname_short} shall install links:"
+LangString T_InstOptFieldA  ${LANG_ENGLISH} "Start Menu"
+LangString T_InstOptFieldB  ${LANG_ENGLISH} "Desktop"
+LangString T_InstOptFieldC  ${LANG_ENGLISH} "Quick Launch Bar"
+
+# From Function (un.)PrintNonAdminWarning
+LangString T_AdminNeeded ${LANG_ENGLISH} \
+   "Warning: Administrator permissions required for the installation of ${productname_short}."
+LangString T_AdminNeeded_uninstall ${LANG_ENGLISH} \
+   "Warning: Administrator permissions required for the uninstallation of ${productname_short}."

Added: trunk/packaging/includes/uninstalllog.nsh
===================================================================
--- trunk/packaging/includes/uninstalllog.nsh	2011-07-01 12:47:43 UTC (rev 347)
+++ trunk/packaging/includes/uninstalllog.nsh	2011-07-01 14:57:02 UTC (rev 348)
@@ -0,0 +1,62 @@
+;AddItem macro
+  !macro AddItem Path
+    FileWrite $UninstLog "${Path}$\r$\n"
+  !macroend
+ 
+;File macro
+  !macro File FilePath FileName
+     IfFileExists "$OUTDIR\${FileName}" +2
+     FileWrite $UninstLog "$OUTDIR\${FileName}$\r$\n"
+     File "${FilePath}${FileName}"
+  !macroend
+ 
+;CreateShortcut macro
+  !macro CreateShortcut FilePath FilePointer Pamameters Icon IconIndex
+    FileWrite $UninstLog "${FilePath}$\r$\n"
+    CreateShortcut "${FilePath}" "${FilePointer}" "${Pamameters}" "${Icon}" "${IconIndex}"
+  !macroend
+ 
+;Copy files macro
+  !macro CopyFiles SourcePath DestPath
+    IfFileExists "${DestPath}" +2
+    FileWrite $UninstLog "${DestPath}$\r$\n"
+    CopyFiles "${SourcePath}" "${DestPath}"
+  !macroend
+ 
+;Rename macro
+  !macro Rename SourcePath DestPath
+    IfFileExists "${DestPath}" +2
+    FileWrite $UninstLog "${DestPath}$\r$\n"
+    Rename "${SourcePath}" "${DestPath}"
+  !macroend
+ 
+;CreateDirectory macro
+  !macro CreateDirectory Path
+    CreateDirectory "${Path}"
+    FileWrite $UninstLog "${Path}$\r$\n"
+  !macroend
+ 
+;SetOutPath macro
+  !macro SetOutPath Path
+    SetOutPath "${Path}"
+    FileWrite $UninstLog "${Path}$\r$\n"
+  !macroend
+ 
+;WriteUninstaller macro
+  !macro WriteUninstaller Path
+    WriteUninstaller "${Path}"
+    FileWrite $UninstLog "${Path}$\r$\n"
+  !macroend
+ 
+;WriteRegStr macro
+  !macro WriteRegStr RegRoot UnInstallPath Key Value
+     FileWrite $UninstLog "${RegRoot} ${UnInstallPath}$\r$\n"
+     WriteRegStr "${RegRoot}" "${UnInstallPath}" "${Key}" "${Value}"
+  !macroend
+ 
+ 
+;WriteRegDWORD macro
+  !macro WriteRegDWORD RegRoot UnInstallPath Key Value
+     FileWrite $UninstLog "${RegRoot} ${UnInstallPath}$\r$\n"
+     WriteRegStr "${RegRoot}" "${UnInstallPath}" "${Key}" "${Value}"
+  !macroend

Added: trunk/packaging/installer-options.ini
===================================================================
--- trunk/packaging/installer-options.ini	2011-07-01 12:47:43 UTC (rev 347)
+++ trunk/packaging/installer-options.ini	2011-07-01 14:57:02 UTC (rev 348)
@@ -0,0 +1,40 @@
+[Settings]
+NumFields=3
+
+; The number of the fields here is known in installer.nsi.
+; The tags must be "[Field N]" with N=1..NumFields
+
+[Field 1]
+Type=Label
+Left=0
+Right=-1
+Top=0
+Bottom=20
+;Install components
+
+[Field 2]
+Type=Checkbox
+Left=0
+Right=-1
+Top=30
+Bottom=40
+;GREAT-ER Desktop
+State=1
+
+[Field 3]
+Type=Checkbox
+Left=0
+Right=-1
+Top=50
+Bottom=60
+;GREAT-ER Server
+State=1
+
+[Field 4]
+Type=Checkbox
+Left=0
+Right=-1
+Top=70
+Bottom=80
+;Text=PostgresSQL Database
+State=0



More information about the Greater-commits mailing list