summaryrefslogtreecommitdiff
path: root/packaging/windows-exe/rabbitmq_nsi.in
blob: d46d2dc5f022969ea98783652dee04da5a3caa3b (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
; Use the "Modern" UI
!include MUI2.nsh
!include LogicLib.nsh
!include "winmessages.nsh"

!define env_hklm 'HKLM "SYSTEM\CurrentControlSet\Control\Session Manager\Environment"'

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

; The name of the installer
Name "RabbitMQ"

; The file to write
OutFile "rabbitmq-server-v%%VERSION%%.exe"

; The default installation directory
InstallDir $PROGRAMFILES\RabbitMQ

; Registry key to check for directory (so if you install again, it will
; overwrite the old one automatically)
InstallDirRegKey HKLM "Software\RabbitMQ" "Install_Dir"

; Request application privileges for Windows Vista
RequestExecutionLevel admin

VIProductVersion "%%VERSION%%.0"
VIAddVersionKey /LANG=${LANG_ENGLISH} "ProductVersion" "%%VERSION%%"
VIAddVersionKey /LANG=${LANG_ENGLISH} "ProductName" "RabbitMQ"
;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-2011 VMware, Inc.  All rights reserved."
VIAddVersionKey /LANG=${LANG_ENGLISH} "FileDescription" "RabbitMQ"
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
;  !insertmacro MUI_UNPAGE_FINISH

;--------------------------------
;Languages

  !insertmacro MUI_LANGUAGE "English"

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

; The stuff to install
Section "RabbitMQ (required)" Rabbit

  SectionIn RO

  ; Set output path to the installation directory.
  SetOutPath $INSTDIR

  Call findErlang

  ; Put files there
  File /r "rabbitmq_server-%%VERSION%%"

  ; Write the installation path into the registry
  WriteRegStr HKLM SOFTWARE\RabbitMQ "Install_Dir" "$INSTDIR"

  ; Write the uninstall keys for Windows
  WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\RabbitMQ" "DisplayName" "RabbitMQ"
  WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\RabbitMQ" "UninstallString" '"$INSTDIR\uninstall.exe"'
  WriteRegDWORD HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\RabbitMQ" "NoModify" 1
  WriteRegDWORD HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\RabbitMQ" "NoRepair" 1
  WriteUninstaller "uninstall.exe"
SectionEnd

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

Section "RabbitMQ Service" RabbitService
  ExecWait "$INSTDIR\rabbitmq_server-%%VERSION%%\sbin\rabbitmq-service.bat install"
  ExecWait "$INSTDIR\rabbitmq_server-%%VERSION%%\sbin\rabbitmq-service.bat start"
  CopyFiles "$WINDIR\.erlang.cookie" "$PROFILE\.erlang.cookie"
  CopyFiles "$WINDIR\.erlang.cookie" "$APPDATA\.erlang.cookie"
SectionEnd

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

Section "Start Menu" RabbitStartMenu
  CreateDirectory "$SMPROGRAMS\RabbitMQ"
  CreateShortCut "$SMPROGRAMS\RabbitMQ\Uninstall.lnk" "$INSTDIR\uninstall.exe" "" "$INSTDIR\uninstall.exe" 0
  CreateShortCut "$SMPROGRAMS\RabbitMQ\Plugins Directory.lnk" "$INSTDIR\rabbitmq_server-%%VERSION%%\plugins"
  CreateShortCut "$SMPROGRAMS\RabbitMQ\Database and Log Directory.lnk" "$APPDATA\RabbitMQ"
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 "Software\Microsoft\Windows\CurrentVersion\Uninstall\RabbitMQ"
  DeleteRegKey HKLM SOFTWARE\RabbitMQ

  ; TODO these will fail if the service is not installed - do we care?
  ExecWait "$INSTDIR\rabbitmq_server-%%VERSION%%\sbin\rabbitmq-service.bat stop"
  ExecWait "$INSTDIR\rabbitmq_server-%%VERSION%%\sbin\rabbitmq-service.bat remove"

  ; Remove files and uninstaller
  RMDir /r "$INSTDIR"

  ; Remove shortcuts
  Delete "$SMPROGRAMS\RabbitMQ\*.*"

  ; Remove directories used
  RMDir "$SMPROGRAMS\RabbitMQ"

  ; TODO: unset ERLANG_HOME?

SectionEnd

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

; Functions

Function .onInit
  ReadRegStr $0 HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\RabbitMQ" "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." IDOK uninst

    Abort

    ;Run the uninstaller
    uninst:
      ClearErrors
      Exec $INSTDIR\uninstall.exe
  ${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_OK "Erlang could not be detected. Please install it."
    Abort
  ${Else}
    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
  ${EndIf}

FunctionEnd