NSIS installer script
/* ADempiere Windows installer, Copyright (C) 2008 Kai Schaeffer - Schaeffer AG * iDempiere Windows installer, Copyright (C) 2011, 2012 Redhuan D. Oon (www.red1.org) * 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. * * 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 US
- /
- Common basic defines
!define PRODUCT_NAME "iDempiere" !define PRODUCT_VERSION "0.9.b" !define PRODUCT_PUBLISHER "Redhuan D. Oon" !define PRODUCT_WEB_SITE "http://wiki.idempiere.org" !define PRODUCT_DIR_REGKEY "Software\Microsoft\Windows\CurrentVersion\App Paths\adempiere.exe" !define PRODUCT_UNINST_KEY "Software\Microsoft\Windows\CurrentVersion\Uninstall\${PRODUCT_NAME}" !define PRODUCT_UNINST_ROOT_KEY "HKLM"
- ADempiere defines
!define SOURCE_FILE_DIR "..\..\iDempiereFiles" !define INSTALLER_SOURCE_DIR "." !define OUT_DIR ${SOURCE_FILE_DIR}
- JDK defines
!define JDK_DEFAULT_DIR "D:\Java" !define JDK_INSTALLER "java6.exe"
- PostgreSQL defines
!define PG_DEFAULT_DIR "D:\PostgreSQL\8.3" !define PG_INSTALLER_BASE "postgresql-8.3"
- Include files
!include "MUI.nsh" !include "LogicLib.nsh" !include "EnvVarUpdate.nsh" !include "nsDialogs.nsh" !include "iDempiereLib.nsh" !include "TextFunc.nsh" !include "WordFunc.nsh"
!insertmacro ConfigWrite !insertmacro ConfigRead
- MUI Settings
!define MUI_ABORTWARNING !define MUI_ICON ..\AD.ico !define MUI_UNICON ..\ADempiere.ico !define MUI_CUSTOMFUNCTION_GUIINIT CustomGUIInit
- Language Selection Dialog Settings
!define MUI_LANGDLL_REGISTRY_ROOT "${PRODUCT_UNINST_ROOT_KEY}" !define MUI_LANGDLL_REGISTRY_KEY "${PRODUCT_UNINST_KEY}" !define MUI_LANGDLL_REGISTRY_VALUENAME "NSIS:Language"
- Needed Variables
VAR JDK_VERSION ; Version of the installed JDK VAR JDK_DIR ; Directory of the installed JDK (empty string if no JDK) VAR JDK_INSTDIR ; Directory to install a new JDK
VAR PG_INSTDIR ; Directory to install PostgreSQL VAR PG_PASSWORD ; Password for PostgreSQL installtion (and all the rest for now) VAR PG_OLD_VERSION ; Version of an installed PG VAR PG_OLD_DIR ; Directory of an installed PG (Empty string if no PG) VAR PG_PORT ; PostgreSQL Port (5432) VAR PG_CREATEUSER ; 1=Create PG system account, 0=Don't create VAR PG_USER ; Username of PG system account
VAR COMPUTER_NAME
- Reserved Files
ReserveFile "${NSISDIR}\Plugins\AdvSplash.dll" !insertmacro VersionCompare
- Welcome page
!insertmacro MUI_PAGE_WELCOME
- License page
!insertmacro MUI_PAGE_LICENSE "${INSTALLER_SOURCE_DIR}\license.txt"
- Insert our own pages
- Directory selection and password query
!include "CustomPages.nsh"
!insertmacro MUI_PAGE_INSTFILES
- Finish page
- !define MUI_FINISHPAGE_RUN "$INSTDIR\AppMainExe.exe"
- !insertmacro MUI_PAGE_FINISH
- Uninstaller pages
!insertmacro MUI_UNPAGE_INSTFILES
- Language files
!insertmacro MUI_LANGUAGE English !insertmacro MUI_LANGUAGE Malay !insertmacro MUI_LANGUAGE Spanish !insertmacro MUI_LANGUAGE German !insertmacro MUI_LANGUAGE PortugueseBR !insertmacro MUI_LANGUAGE SimpChinese !insertmacro MUI_LANGUAGE French !insertmacro MUI_LANGUAGE Arabic !insertmacro MUI_LANGUAGE Italian !insertmacro MUI_LANGUAGE Russian !insertmacro MUI_LANGUAGE Japanese !insertmacro MUI_LANGUAGE Thai !insertmacro MUI_LANGUAGE Korean !include "LangStrings.nsh"
- MUI end ------
Var PRODUCT_VERSION Var EXPECTED_LINES_BUILD Var EXPECTED_LINES_IMPORT
Name "${PRODUCT_NAME} $PRODUCT_VERSION" OutFile "${OUT_DIR}\iDempiere${PRODUCT_VERSION}_Setup.exe" InstallDir "E:\iDempiere" InstallDirRegKey HKLM "${PRODUCT_DIR_REGKEY}" "" ShowInstDetails show ShowUnInstDetails show
Function CustomGUIInit
Push $R6 Push $R7 BgImage::SetReturn /NOUNLOAD on BgImage::SetBg /NOUNLOAD /GRADIENT 0 128 0 0 0 0 Pop $R6 Strcmp $R6 success 0 error File /oname=$PLUGINSDIR\bgimage.bmp ..\InstallerBackground.bmp System::call "user32::GetSystemMetrics(i 0)i.R6" System::call "user32::GetSystemMetrics(i 1)i.R7" IntOp $R6 $R6 - 783 IntOp $R6 $R6 / 2 IntOp $R7 $R7 - 369 IntOp $R7 $R7 / 2 BGImage::AddImage /NOUNLOAD $PLUGINSDIR\bgimage.bmp $R6 $R7 CreateFont $R6 "Times New Roman" 26 700 /ITALIC BGImage::AddText /NOUNLOAD "$(^SetupCaption)" $R6 255 255 255 16 8 500 100 Pop $R6 Strcmp $R6 success 0 error BGImage::Redraw /NOUNLOAD File /oname=$PLUGINSDIR\bgimage.wav ..\promise.wav BGImage::Sound /NOUNLOAD /LOOP $PLUGINSDIR\bgimage.wav Goto done
error:
MessageBox MB_OK|MB_ICONSTOP $R6
done:
Pop $R7 Pop $R6
FunctionEnd
Function .onGUIEnd
BGImage::Sound /NOUNLOAD /STOP BGImage::Destroy
FunctionEnd
Function .onInit
InitPluginsDir Push $R5 File /oname=$PLUGINSDIR\spltmp.bmp ..\ADBox.bmp advsplash::show 2220 999 999 -1 $PLUGINSDIR\spltmp Pop $R5 Pop $R5 !insertmacro MUI_LANGDLL_DISPLAY
;Read Settings from .ini-File
File /oname=$TEMP\InstallerSettings.ini "${INSTALLER_SOURCE_DIR}\InstallerSettings.ini"
${ConfigRead} "$TEMP\InstallerSettings.ini" "Version=" $PRODUCT_VERSION
IfErrors 0 +2
strcpy $PRODUCT_VERSION ${PRODUCT_VERSION}
${ConfigRead} "$TEMP\InstallerSettings.ini" "ExpectedLinesBuild=" $EXPECTED_LINES_BUILD
IfErrors 0 +2
strcpy $EXPECTED_LINES_BUILD "135" ${ConfigRead} "$TEMP\InstallerSettings.ini" "ExpectedLinesImport=" $EXPECTED_LINES_IMPORT
IfErrors 0 +2
strcpy $EXPECTED_LINES_IMPORT "4600"
Delete "$TEMP\InstallerSettings.ini"
!insertmacro IsUserAdmin $0
; Check is User is admin
${if} $0 != "1"
MessageBox MB_ICONEXCLAMATION|MB_OK $(LocS_Admin) Abort ${endif}
; Get computer name
ReadRegStr $COMPUTER_NAME HKLM "SYSTEM\CurrentControlSet\Control\ComputerName\ComputerName" "ComputerName"
; Check if JDK is installed ReadRegStr $JDK_VERSION HKLM "Software\JavaSoft\Java Development Kit" "CurrentVersion"
${VersionCompare} $JDK_VERSION "1.6" $0
; if installed JDK version < 1.5 then install the new one. ${if} $0 == "2"
StrCpy $JDK_VERSION ""
${endif}
ReadRegStr $JDK_DIR HKLM "Software\JavaSoft\Java Development Kit\$JDK_VERSION" "JavaHome" ; Set defaults for PG installation StrCpy $PG_PASSWORD "adempiere"
StrCpy $PG_USER "postgres" StrCpy $PG_PORT "5432"
; Check if another PostgreSQL is installed
EnumRegKey $1 HKLM SOFTWARE\PostgreSQL\Installations\ "0" ${if} $1 != "" ReadRegStr $PG_OLD_VERSION HKLM "SOFTWARE\PostgreSQL\Installations\$1" "Version" ReadRegStr $PG_OLD_DIR HKLM "SOFTWARE\PostgreSQL\Installations\$1" "Base Directory" ; if installed version is < 8.3 then abort ${VersionCompare} $PG_OLD_VERSION "8.3" $0
${if} $0 == "2" MessageBox MB_ICONEXCLAMATION|MB_OK $(LocS_PostgresOld) Abort ${endif} ;MessageBox MB_OKCANCEL|MB_ICONQUESTION "PostgreSQL $PG_OLD_VERSION is already installed on this computer. This installation will be used for ADempiere." IDOK pg_ok ;Abort "Installation aborted!"
pg_ok:
${endif} FunctionEnd
Section "JDK" SEC01
SetOutPath "$INSTDIR"
SetOverwrite ifnewer
; install JDK if no recent is installed
${if} $JDK_DIR == ""
File "${SOURCE_FILE_DIR}\Tools\${JDK_INSTALLER}"
ExecWait '"$INSTDIR\${JDK_INSTALLER}" /s /v "/qr INSTALLDIR=\"$JDK_INSTDIR\""'
StrCpy $JDK_DIR $JDK_INSTDIR
Delete "$INSTDIR\${JDK_INSTALLER}"
${else}
DetailPrint "Skipping JDK installation"
${endif}
; Check JAVA_HOME enviroment variable. If already set to another destination we should correct it
ReadEnvStr $0 "JAVA_HOME"
${if} $0 != $JDK_DIR
${andif} $0 != ""
MessageBox MB_YESNO $(LocS_JavaHome) /SD IDYES IDNO JavaHomeNo
${endif}
; Set JAVA_HOME on the system ...
WriteRegExpandStr HKLM "SYSTEM\CurrentControlSet\Control\Session Manager\Environment" "JAVA_HOME" $JDK_DIR ; ... and for this context
System::Call 'Kernel32::SetEnvironmentVariableA(t, t) i("JAVA_HOME", "$JDK_DIR").r0' ; Update path. We need all this that pl/java is working
${EnvVarUpdate} $0 "PATH" "A" "HKLM" "$JDK_DIR\bin" ; Append ${EnvVarUpdate} $0 "PATH" "A" "HKLM" "$JDK_DIR\jre\bin" ; Append ${EnvVarUpdate} $0 "PATH" "A" "HKLM" "$JDK_DIR\jre\bin\client" ; Append
ReadEnvStr $0 "PATH" StrCpy $1 "$0;$JDK_DIR\bin;$JDK_DIR\jre\bin;$JDK_DIR\jre\bin\client"
System::Call 'Kernel32::SetEnvironmentVariableA(t, t) i("PATH", "$1").r0'
JavaHomeNo:
SectionEnd
Section "PostgreSQL" SEC02 ; Install PostgreSQL if no recent version is installed ${if} $PG_OLD_DIR == ""
File "${SOURCE_FILE_DIR}\Tools\${PG_INSTALLER_BASE}*.*" ExecWait 'msiexec /i "$INSTDIR\${PG_INSTALLER_BASE}-int.msi" /qr INTERNALLAUNCH=1 ADDLOCAL=server,psql,pgadmin SERVICEDOMAIN="$COMPUTER_NAME" SERVICEACCOUNT="$PG_USER" SERVICEPASSWORD="$PG_PASSWORD" SUPERPASSWORD="$PG_PASSWORD" CREATESERVICEUSER=$PG_CREATEUSER PERMITREMOTE=1 ENCODING=UTF-8 BASEDIR="$PG_INSTDIR"' Delete "$INSTDIR\${PG_INSTALLER_BASE}-int.msi" Delete "$INSTDIR\${PG_INSTALLER_BASE}.msi"
${else} DetailPrint "Skipping PostgreSQL installation"
${endif} ; Include the bin dir to the path. Is needed by some ADempiere batch files. ${EnvVarUpdate} $0 "PATH" "A" "HKLM" "$PG_INSTDIR\bin" ; Append
ReadEnvStr $0 "PATH" StrCpy $1 "$0;$PG_INSTDIR\bin"
System::Call 'Kernel32::SetEnvironmentVariableA(t, t) i("PATH", "$1").r0'
SectionEnd
- Helper function for ADempiere database import
- It's called for every line of the output. It writes these lines to
- a log file and updates the %-display. For newer versions the
- "EXPECTED_LINES_*" defines may be adjusted.
Function ImportProgress Pop $0 ; Get output line IntOp $R8 $R8 + 1 FileWrite $R9 $0 FileWriteByte $R9 "13"
FileWriteByte $R9 "10"
SetDetailsPrint textonly IntOp $1 $R8 * 100 IntOp $1 $1 / $EXPECTED_LINES_IMPORT DetailPrint "Importing Database ... $1%"
FunctionEnd
- Helper function for ADempiere build
- It's called for every line of the output. It writes these lines to
- the DetailPrint and updates the %-display. For newer versions the
- "EXPECTED_LINES_*" defines may be adjusted.
Function BuildProgress Pop $0 SetDetailsPrint listonly DetailPrint $0 IntOp $R8 $R8 + 1 SetDetailsPrint textonly IntOp $1 $R8 * 100 IntOp $1 $1 / $EXPECTED_LINES_BUILD DetailPrint "Building ADempiere ... $1%" FunctionEnd
Section "MainSection" SEC03 ; Extract the idempiere-server and adempiere-client folders and their files
File /r "${SOURCE_FILE_DIR}\Main\idempiere-server\*.*" ; Extract new import batch file which is not included in the standard distribution ; This file is not waiting for an input like the original one and is working if the ; "utils"-directory is not the active one. File /oname=StdIn.txt "${INSTALLER_SOURCE_DIR}\HelpBatchFiles\StdIn.txt" File /oname=utils\RUN_RestoreADempiereMSI.bat "${INSTALLER_SOURCE_DIR}\HelpBatchFiles\RUN_RestoreADempiereMSI.bat" ; Get idempiereEnv.properties template for the silent setup
- CopyFiles /SILENT "$INSTDIR\iDempiereEnvTemplate.properties" "$INSTDIR\idempiereEnv.properties" ;console-setup-alt does not need this
; Set ADempiere home enviroment var
WriteRegExpandStr HKLM "SYSTEM\CurrentControlSet\Control\Session Manager\Environment" "IDEMPIERE_HOME" $INSTDIR System::Call 'Kernel32::SetEnvironmentVariableA(t, t) i("IDEMPIERE_HOME", "$INSTDIR").r0'
; Set values in the properties file
${StrReplaceV4} $R0 "\" "\\" $INSTDIR ${StrReplaceV4} $R1 ":" "\:" $R0
; Now start the silent setup. The output is pushed to the function "BuildProgress" SetDetailsPrint both DetailPrint $(LocS_ADempiereBuild)
StrCpy $R8 "0" GetFunctionAddress $0 BuildProgress ExecDos::exec /NOUNLOAD /TOFUNC '"$INSTDIR\console-setup-alt.bat" < $INSTDIR\StdIn.txt' "" $0 Pop $0
SetDetailsPrint listonly ; Could be used the determine the total number for the "EXPECTED_LINES_*" defines DetailPrint "Total lines (Build): $R8"
; Now start the database import. The output is pushed to the function "ImportProgress" DetailPrint $(LocS_ADempiereImport1) DetailPrint $(LocS_ADempiereImport2)
StrCpy $R8 "0" FileOpen $R9 "$INSTDIR\Import.log" w GetFunctionAddress $0 ImportProgress ExecDos::exec /NOUNLOAD /TOFUNC "$INSTDIR\utils\RUN_RestoreADempiereMSI.bat" "" $0 Pop $0 FileClose $R9
SetDetailsPrint both DetailPrint "Total lines (Import): $R8"
; Create entries in the start menu
CreateDirectory "$SMPROGRAMS\iDempiere" CreateShortCut "$SMPROGRAMS\iDempiere\iDempiere Client.lnk" "$INSTDIR\adempiere-client\adempiere-client.bat" CreateShortCut "$SMPROGRAMS\iDempiere\about iDempiere.lnk" "$INSTDIR\index.html" CreateDirectory "$SMPROGRAMS\iDempiere\adempiere-client" CreateShortCut "$SMPROGRAMS\iDempiere\Server\Run iDempiere server.lnk" "$INSTDIR\idempiere-server.bat"
- CreateShortCut "$SMPROGRAMS\ADempiere\Server\Stop ADempiere server.lnk" "$INSTDIR\utils\RUN_Server2Stop.bat"
- CreateShortCut "$SMPROGRAMS\ADempiere\Server\Install ADempiere server as a service.lnk" "$INSTDIR\utils\windows\ADempiere_Service_Install.bat"
- CreateShortCut "$SMPROGRAMS\ADempiere\Server\Remove ADempiere server service.lnk" "$INSTDIR\utils\windows\ADempiere_Service_Uninstall.bat"
SectionEnd
Section -AdditionalIcons
WriteIniStr "$INSTDIR\${PRODUCT_NAME}.url" "InternetShortcut" "URL" "${PRODUCT_WEB_SITE}" CreateShortCut "$SMPROGRAMS\iDempiere\Website.lnk" "$INSTDIR\${PRODUCT_NAME}.url" CreateShortCut "$SMPROGRAMS\iDempiere\Uninstall.lnk" "$INSTDIR\uninst.exe"
SectionEnd
Section -Post
WriteUninstaller "$INSTDIR\uninst.exe" WriteRegStr HKLM "${PRODUCT_DIR_REGKEY}" "" "$INSTDIR" WriteRegStr ${PRODUCT_UNINST_ROOT_KEY} "${PRODUCT_UNINST_KEY}" "DisplayName" "$(^Name)" WriteRegStr ${PRODUCT_UNINST_ROOT_KEY} "${PRODUCT_UNINST_KEY}" "UninstallString" "$INSTDIR\uninst.exe" WriteRegStr ${PRODUCT_UNINST_ROOT_KEY} "${PRODUCT_UNINST_KEY}" "DisplayIcon" "$INSTDIR\idempiere.exe" WriteRegStr ${PRODUCT_UNINST_ROOT_KEY} "${PRODUCT_UNINST_KEY}" "DisplayVersion" "${PRODUCT_VERSION}" WriteRegStr ${PRODUCT_UNINST_ROOT_KEY} "${PRODUCT_UNINST_KEY}" "URLInfoAbout" "${PRODUCT_WEB_SITE}" WriteRegStr ${PRODUCT_UNINST_ROOT_KEY} "${PRODUCT_UNINST_KEY}" "Publisher" "${PRODUCT_PUBLISHER}"
SectionEnd
Function un.onUninstSuccess
HideWindow MessageBox MB_ICONINFORMATION|MB_OK "$(^Name) was successfully removed from your computer."
FunctionEnd
Function un.onInit !insertmacro MUI_UNGETLANGUAGE
MessageBox MB_ICONQUESTION|MB_YESNO|MB_DEFBUTTON2 "Are you sure you want to completely remove $(^Name) and all of its components?" IDYES +2 Abort
FunctionEnd
Section Uninstall
Delete "$INSTDIR\utils\RUN_*" Delete "$INSTDIR\*.properties" Delete "$INSTDIR\*.log" Delete "$INSTDIR\*.xml" Delete "$INSTDIR\index.html" Delete "$INSTDIR\*.bat" Delete "$INSTDIR\*.ini" Delete "$INSTDIR\*.exe" RMDir /r "$INSTDIR\configuration\" RMDir /r "$INSTDIR\data\" RMDir /r "$INSTDIR\features\" RMDir /r "$INSTDIR\p2\" RMDir /r "$INSTDIR\plugins\" RMDir /r "$INSTDIR\utils\" RMDir /r "$INSTDIR\setup\" Delete "$INSTDIR\${PRODUCT_NAME}.url" Delete "$INSTDIR\uninst.exe"
Delete "$SMPROGRAMS\Uninstall.lnk" Delete "$SMPROGRAMS\iDempiere.lnk" Delete "$SMPROGRAMS\Website.lnk" Delete "$SMPROGRAMS\iDempiere Client.lnk"
- Delete "$SMPROGRAMS\About iDempiere.lnk"
Delete "$SMPROGRAMS\Run iDempiere server.lnk"
- Delete "$SMPROGRAMS\Stop ADempiere server.lnk"
- Delete "$SMPROGRAMS\Install ADempiere server as a service.lnk"
- Delete "$SMPROGRAMS\Remove ADempiere server service.lnk"
Delete "$DESKTOP\ADempiere.lnk" Delete "$DESKTOP\ADempiere Web Site.url"
RMDir "$SMPROGRAMS\idempiere-server" RMDir "$INSTDIR"
DeleteRegKey ${PRODUCT_UNINST_ROOT_KEY} "${PRODUCT_UNINST_KEY}" DeleteRegKey HKLM "${PRODUCT_DIR_REGKEY}" SetAutoClose true
SectionEnd