; Use the "Modern" UI !include MUI2.nsh !include LogicLib.nsh !include WinMessages.nsh !include FileFunc.nsh !include WordFunc.nsh !define env_hklm 'HKLM "SYSTEM\CurrentControlSet\Control\Session Manager\Environment"' !define uninstall "Software\Microsoft\Windows\CurrentVersion\Uninstall\RabbitMQ" ;-------------------------------- ; The name of the installer Name "RabbitMQ Server %%VERSION%%" ; The file to write OutFile "rabbitmq-server-%%VERSION%%.exe" ; Icons !define MUI_ICON "rabbitmq.ico" ; The default installation directory InstallDir "$PROGRAMFILES\RabbitMQ Server" ; Registry key to check for directory (so if you install again, it will ; overwrite the old one automatically) InstallDirRegKey HKLM "Software\VMware, Inc.\RabbitMQ Server" "Install_Dir" ; Request application privileges for Windows Vista RequestExecutionLevel admin SetCompressor /solid lzma VIProductVersion "%%VERSION%%.0" VIAddVersionKey /LANG=${LANG_ENGLISH} "ProductVersion" "%%VERSION%%" VIAddVersionKey /LANG=${LANG_ENGLISH} "ProductName" "RabbitMQ Server" ;VIAddVersionKey /LANG=${LANG_ENGLISH} "Comments" "" VIAddVersionKey /LANG=${LANG_ENGLISH} "CompanyName" "VMware, Inc" ;VIAddVersionKey /LANG=${LANG_ENGLISH} "LegalTrademarks" "" ; TODO ? VIAddVersionKey /LANG=${LANG_ENGLISH} "LegalCopyright" "Copyright (c) 2007-2012 VMware, Inc. All rights reserved." VIAddVersionKey /LANG=${LANG_ENGLISH} "FileDescription" "RabbitMQ Server" VIAddVersionKey /LANG=${LANG_ENGLISH} "FileVersion" "%%VERSION%%" ;-------------------------------- ; Pages ; !insertmacro MUI_PAGE_LICENSE "..\..\LICENSE-MPL-RabbitMQ" !insertmacro MUI_PAGE_COMPONENTS !insertmacro MUI_PAGE_DIRECTORY !insertmacro MUI_PAGE_INSTFILES !insertmacro MUI_PAGE_FINISH !insertmacro MUI_UNPAGE_CONFIRM !insertmacro MUI_UNPAGE_INSTFILES !define MUI_FINISHPAGE_TEXT "RabbitMQ Server %%VERSION%% has been uninstalled from your computer.$\n$\nPlease note that the log and database directories located at $APPDATA\RabbitMQ have not been removed. You can remove them manually if desired." !insertmacro MUI_UNPAGE_FINISH ;-------------------------------- ;Languages !insertmacro MUI_LANGUAGE "English" ;-------------------------------- ; The stuff to install Section "RabbitMQ Server (required)" Rabbit SectionIn RO ; Set output path to the installation directory. SetOutPath $INSTDIR ; Put files there File /r "rabbitmq_server-%%VERSION%%" File "rabbitmq.ico" ; Write the installation path into the registry WriteRegStr HKLM "SOFTWARE\VMware, Inc.\RabbitMQ Server" "Install_Dir" "$INSTDIR" ; Write the uninstall keys for Windows WriteRegStr HKLM ${uninstall} "DisplayName" "RabbitMQ Server" WriteRegStr HKLM ${uninstall} "UninstallString" "$INSTDIR\uninstall.exe" WriteRegStr HKLM ${uninstall} "DisplayIcon" "$INSTDIR\uninstall.exe,0" WriteRegStr HKLM ${uninstall} "Publisher" "VMware, Inc." WriteRegStr HKLM ${uninstall} "DisplayVersion" "%%VERSION%%" WriteRegDWORD HKLM ${uninstall} "NoModify" 1 WriteRegDWORD HKLM ${uninstall} "NoRepair" 1 ${GetSize} "$INSTDIR" "/S=0K" $0 $1 $2 IntFmt $0 "0x%08X" $0 WriteRegDWORD HKLM "${uninstall}" "EstimatedSize" "$0" WriteUninstaller "uninstall.exe" SectionEnd ;-------------------------------- Section "RabbitMQ Service" RabbitService ExpandEnvStrings $0 %COMSPEC% ExecWait '"$0" /C "$INSTDIR\rabbitmq_server-%%VERSION%%\sbin\rabbitmq-service.bat" install' ExecWait '"$0" /C "$INSTDIR\rabbitmq_server-%%VERSION%%\sbin\rabbitmq-service.bat" start' CopyFiles "$WINDIR\.erlang.cookie" "$PROFILE\.erlang.cookie" SectionEnd ;-------------------------------- Section "Start Menu" RabbitStartMenu ; In case the service is not installed, or the service installation fails, ; make sure these exist or Explorer will get confused. CreateDirectory "$APPDATA\RabbitMQ\log" CreateDirectory "$APPDATA\RabbitMQ\db" CreateDirectory "$SMPROGRAMS\RabbitMQ Server" CreateShortCut "$SMPROGRAMS\RabbitMQ Server\Uninstall RabbitMQ.lnk" "$INSTDIR\uninstall.exe" "" "$INSTDIR\uninstall.exe" 0 CreateShortCut "$SMPROGRAMS\RabbitMQ Server\RabbitMQ Plugins.lnk" "$INSTDIR\rabbitmq_server-%%VERSION%%\plugins" CreateShortCut "$SMPROGRAMS\RabbitMQ Server\RabbitMQ Logs.lnk" "$APPDATA\RabbitMQ\log" CreateShortCut "$SMPROGRAMS\RabbitMQ Server\RabbitMQ Database Directory.lnk" "$APPDATA\RabbitMQ\db" CreateShortCut "$SMPROGRAMS\RabbitMQ Server\RabbitMQ Service - (re)install.lnk" "$INSTDIR\rabbitmq_server-%%VERSION%%\sbin\rabbitmq-service.bat" "install" "$INSTDIR\rabbitmq.ico" CreateShortCut "$SMPROGRAMS\RabbitMQ Server\RabbitMQ Service - remove.lnk" "$INSTDIR\rabbitmq_server-%%VERSION%%\sbin\rabbitmq-service.bat" "remove" "$INSTDIR\rabbitmq.ico" CreateShortCut "$SMPROGRAMS\RabbitMQ Server\RabbitMQ Service - start.lnk" "$INSTDIR\rabbitmq_server-%%VERSION%%\sbin\rabbitmq-service.bat" "start" "$INSTDIR\rabbitmq.ico" CreateShortCut "$SMPROGRAMS\RabbitMQ Server\RabbitMQ Service - stop.lnk" "$INSTDIR\rabbitmq_server-%%VERSION%%\sbin\rabbitmq-service.bat" "stop" "$INSTDIR\rabbitmq.ico" SetOutPath "$INSTDIR\rabbitmq_server-%%VERSION%%\sbin" CreateShortCut "$SMPROGRAMS\RabbitMQ Server\RabbitMQ Command Prompt (sbin dir).lnk" "$WINDIR\system32\cmd.exe" "" "$WINDIR\system32\cmd.exe" SetOutPath $INSTDIR SectionEnd ;-------------------------------- ; Section descriptions LangString DESC_Rabbit ${LANG_ENGLISH} "The RabbitMQ Server." LangString DESC_RabbitService ${LANG_ENGLISH} "Set up RabbitMQ as a Windows Service." LangString DESC_RabbitStartMenu ${LANG_ENGLISH} "Add some useful links to the start menu." !insertmacro MUI_FUNCTION_DESCRIPTION_BEGIN !insertmacro MUI_DESCRIPTION_TEXT ${Rabbit} $(DESC_Rabbit) !insertmacro MUI_DESCRIPTION_TEXT ${RabbitService} $(DESC_RabbitService) !insertmacro MUI_DESCRIPTION_TEXT ${RabbitStartMenu} $(DESC_RabbitStartMenu) !insertmacro MUI_FUNCTION_DESCRIPTION_END ;-------------------------------- ; Uninstaller Section "Uninstall" ; Remove registry keys DeleteRegKey HKLM ${uninstall} DeleteRegKey HKLM "SOFTWARE\VMware, Inc.\RabbitMQ Server" ; TODO these will fail if the service is not installed - do we care? ExpandEnvStrings $0 %COMSPEC% ExecWait '"$0" /C "$INSTDIR\rabbitmq_server-%%VERSION%%\sbin\rabbitmq-service.bat" stop' ExecWait '"$0" /C "$INSTDIR\rabbitmq_server-%%VERSION%%\sbin\rabbitmq-service.bat" remove' ; Remove files and uninstaller RMDir /r "$INSTDIR\rabbitmq_server-%%VERSION%%" Delete "$INSTDIR\rabbitmq.ico" Delete "$INSTDIR\uninstall.exe" ; Remove start menu items RMDir /r "$SMPROGRAMS\RabbitMQ Server" DeleteRegValue ${env_hklm} ERLANG_HOME SendMessage ${HWND_BROADCAST} ${WM_WININICHANGE} 0 "STR:Environment" /TIMEOUT=5000 SectionEnd ;-------------------------------- ; Functions Function .onInit Call findErlang ReadRegStr $0 HKLM ${uninstall} "UninstallString" ${If} $0 != "" MessageBox MB_OKCANCEL|MB_ICONEXCLAMATION "RabbitMQ is already installed. $\n$\nClick 'OK' to remove the previous version or 'Cancel' to cancel this installation." IDCANCEL norun ;Run the uninstaller ClearErrors ExecWait $INSTDIR\uninstall.exe norun: Abort ${EndIf} FunctionEnd Function findErlang StrCpy $0 0 StrCpy $2 "not-found" ${Do} EnumRegKey $1 HKLM Software\Ericsson\Erlang $0 ${If} $1 = "" ${Break} ${EndIf} ${If} $1 <> "ErlSrv" StrCpy $2 $1 ${EndIf} IntOp $0 $0 + 1 ${Loop} ${If} $2 = "not-found" MessageBox MB_YESNO|MB_ICONEXCLAMATION "Erlang could not be detected.$\nYou must install Erlang before installing RabbitMQ. Would you like the installer to open a browser window to the Erlang download site?" IDNO abort ExecShell "open" "http://www.erlang.org/download.html" abort: Abort ${Else} ${VersionCompare} $2 "5.6.3" $0 ${VersionCompare} $2 "5.8.1" $1 ${If} $0 = 2 MessageBox MB_OK|MB_ICONEXCLAMATION "Your installed version of Erlang ($2) is too old. Please install a more recent version." Abort ${ElseIf} $1 = 2 MessageBox MB_YESNO|MB_ICONEXCLAMATION "Your installed version of Erlang ($2) is comparatively old.$\nFor best results, please install a newer version.$\nDo you wish to continue?" IDYES no_abort Abort no_abort: ${EndIf} ReadRegStr $0 HKLM "Software\Ericsson\Erlang\$2" "" ; See http://nsis.sourceforge.net/Setting_Environment_Variables WriteRegExpandStr ${env_hklm} ERLANG_HOME $0 SendMessage ${HWND_BROADCAST} ${WM_WININICHANGE} 0 "STR:Environment" /TIMEOUT=5000 ; On Windows XP changing the permanent environment does not change *our* ; environment, so do that as well. System::Call 'Kernel32::SetEnvironmentVariableA(t, t) i("ERLANG_HOME", "$0").r0' ${EndIf} FunctionEnd