summaryrefslogtreecommitdiff
path: root/packaging/windows-exe/rabbitmq_nsi.in
blob: 91510991cc942195f6e55bcaeab61bf2bfa1deff (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
; 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