forked from getupcloud/openshift-rhc-installer
-
Notifications
You must be signed in to change notification settings - Fork 0
/
rhc.nsi
408 lines (332 loc) · 11.8 KB
/
rhc.nsi
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
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
; Script generated by the HM NIS Edit Script Wizard.
SetCompressor /SOLID lzma
; HM NIS Edit Wizard helper defines
!define PRODUCT_NAME "OpenShift-RHC"
!define PRODUCT_VERSION "1.0.8"
!define PRODUCT_PUBLISHER "OpenShift Origin"
!define PRODUCT_WEB_SITE "http://github.com/openshift/rhc/"
!define PRODUCT_DIR_REGKEY "Software\Microsoft\Windows\CurrentVersion\App Paths\${PRODUCT_NAME}"
!define PRODUCT_UNINST_KEY "Software\Microsoft\Windows\CurrentVersion\Uninstall\${PRODUCT_NAME}"
!define PRODUCT_UNINST_ROOT_KEY "HKLM"
!define GIT_INSTALLER "Git-1.9.4-preview20140611.exe"
!define RUBY_INSTALLER "rubyinstaller-1.9.3-p545.exe"
!define TORTOISE_INSTALLER "TortoiseGit-1.8.11.0-64bit.msi"
; MUI 1.67 compatible ------
!include "MUI.nsh"
!define LOGICLIB_STRCMP
!include LogicLib.nsh
!include nsDialogs.nsh
!addincludedir .\include
!include EnvVarUpdate.nsh
!include CharToASCII.nsh
!include Base64.nsh
!addplugindir .\plugins\Inetc\plugins
# inetc need a clear stack
!macro ClearStack
${Do}
Pop $0
IfErrors send
${Loop}
send:
!macroend
; MUI Settings
!define MUI_ABORTWARNING
!define MUI_ICON "openshift.ico"
!define MUI_UNICON "${NSISDIR}\Contrib\Graphics\Icons\modern-uninstall.ico"
; 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"
; Welcome page
!insertmacro MUI_PAGE_WELCOME
; License page
!insertmacro MUI_PAGE_LICENSE "LICENSE"
; Directory page
!insertmacro MUI_PAGE_DIRECTORY
Page custom proxyPage proxyPageLeave
Page custom libraServerPage libraServerPageLeave
; Instfiles page
!insertmacro MUI_PAGE_INSTFILES
; Finish page
!define MUI_FINISHPAGE_RUN
!define MUI_FINISHPAGE_RUN_TEXT "Run Initial RHC Setup (recomended)"
!define MUI_FINISHPAGE_RUN_FUNCTION "RHC_Setup"
!insertmacro MUI_PAGE_FINISH
Var fullname
Var rhlogin
Var password
Var libraServerURL
Function RHC_Setup
ExecWait '"$PROGRAMFILES\git\bin\bash.exe" "$INSTDIR\post-install.sh" "$fullname" "$rhlogin" "$libraServerURL" "$rhlogin" "$password"'
MessageBox MB_OK 'Installation has finished. Run "Git Bash" and type "rhc apps" to list all your applications.'
FunctionEnd
; Uninstaller pages
!insertmacro MUI_UNPAGE_INSTFILES
; Language files
!insertmacro MUI_LANGUAGE "English"
; include for some of the windows messages defines
!include "winmessages.nsh"
; HKLM (all users) vs HKCU (current user) defines
!define env_hklm 'HKLM "SYSTEM\CurrentControlSet\Control\Session Manager\Environment"'
!define env_hkcu 'HKCU "Environment"'
; MUI end ------
Name "${PRODUCT_NAME} ${PRODUCT_VERSION}"
OutFile "RHC-Tools-Installer.exe"
XPStyle on
InstallDir "$PROGRAMFILES\${PRODUCT_NAME}"
InstallDirRegKey HKLM "${PRODUCT_DIR_REGKEY}" ""
ShowInstDetails show
ShowUnInstDetails show
Var HTTP_PROXY
Var proxyDialog
Var proxyLabel
Var proxyTextBox
Var proxyCheckbox
; dialog create function
Function proxyPage
; === libra_server (type: Dialog) ===
nsDialogs::Create 1018
Pop $proxyDialog
${If} $proxyDialog == error
Abort
${EndIf}
!insertmacro MUI_HEADER_TEXT "Configure HTTP Proxy (for gem install)" ""
; === Label ===
${NSD_CreateLabel} 8u 5u 200u 9u "Are you behind a HTTP Proxy server?"
${NSD_CreateLabel} 8u 15u 200u 9u "If unsure or connected from home, it's safe to leave it blank."
Pop $proxyLabel
; === TextBox ===
${NSD_CreateText} 8u 26u 124u 11u ""
Pop $proxyTextBox
; === Checkbox ===
${NSD_CreateCheckbox} 8u 42u 250u 11u " OpenShift Server is inside my local network (non-proxied)"
Pop $proxyCheckbox
nsDialogs::Show $proxyDialog
FunctionEnd
; dialog leave function
Function proxyPageLeave
${NSD_GetText} $proxyTextBox $HTTP_PROXY
${NSD_GetState} $proxyCheckbox $0
${If} $0 <> 0
WriteRegExpandStr ${env_hklm} "LIBRA_SERVER_PROXY" "$HTTP_PROXY"
${Else}
WriteRegExpandStr ${env_hklm} "LIBRA_SERVER_PROXY" ""
${EndIf}
FunctionEnd
Var libraServerDialog
Var libraServerLabel
Var getupLibraServerRadio
Var redhatLibraServerRadio
Var customLibraServerRadio
Var customLibraServerTextBox
Var fullnameTextBox
Var rhloginTextBox
Var passwordTextBox
Var basic_auth
Var ret
; dialog create function
Function libraServerPage
; === libra_server (type: Dialog) ===
nsDialogs::Create 1018
Pop $libraServerDialog
${If} $libraServerDialog == error
Abort
${EndIf}
!insertmacro MUI_HEADER_TEXT "Configure OpenShift RHC" ""
${NSD_CreateLabel} 8u 3u 91u 11u "OpenShift Broker URL:"
Pop $libraServerLabel
${NSD_CreateRadioButton} 8u 16u 300u 11u "Getup Cloud's OpenShift - https://broker.getupcloud.com"
Pop $getupLibraServerRadio
${NSD_Check} $getupLibraServerRadio
${NSD_CreateRadioButton} 8u 32u 300u 11u "Red Hat's OpenShift Online - https://openshift.redhat.com"
Pop $redhatLibraServerRadio
${NSD_CreateRadioButton} 8u 48u 38u 11u "Custom:"
Pop $customLibraServerRadio
${NSD_CreateText} 50u 48u 155u 11u ""
Pop $customLibraServerTextBox
${NSD_OnChange} $customLibraServerTextBox Custom_Libra_Server_Radio_Changed
${NSD_CreateHLine} 8u 70u 200u 11u
; ---------------------------------------- ;
ExpandEnvStrings $fullname "%USERNAME%"
${NSD_CreateLabel} 8u 82u 72u 11u "Your Name"
Pop $0
${NSD_CreateText} 80u 82u 125u 11u $fullname
Pop $fullnameTextBox
${NSD_CreateLabel} 8u 98u 72u 11u "OpenShift Login"
Pop $0
${NSD_CreateText} 80u 98u 125u 11u ""
Pop $rhloginTextBox
${NSD_CreateLabel} 8u 114u 72u 11u "OpenShift Password"
Pop $0
${NSD_CreatePassword} 80u 114u 125u 11u ""
Pop $passwordTextBox
${NSD_SetFocus} $getupLibraServerRadio
nsDialogs::Show $libraServerDialog
FunctionEnd
Function Custom_Libra_Server_Radio_Changed
${NSD_Check} $customLibraServerRadio
${NSD_Uncheck} $getupLibraServerRadio
${NSD_Uncheck} $redhatLibraServerRadio
FunctionEnd
; dialog leave function
Function libraServerPageLeave
${NSD_GetText} $customLibraServerTextBox $libraServerURL
${NSD_GetState} $getupLibraServerRadio $0
${If} $0 == ${BST_CHECKED}
StrCpy $libraServerURL "https://broker.getupcloud.com"
${EndIf}
${NSD_GetState} $redhatLibraServerRadio $0
${If} $0 == ${BST_CHECKED}
StrCpy $libraServerURL "https://openshift.redhat.com"
${EndIf}
${NSD_GetState} $customLibraServerRadio $0
${If} $0 == ${BST_CHECKED}
${NSD_GetText} $customLibraServerTextBox $libraServerURL
${EndIf}
${If} $libraServerURL == ""
MessageBox MB_OK "Please, select one or insert a valid OpenShift broker URL."
Abort
${EndIf}
${NSD_GetText} $fullnameTextBox $fullname
${If} $fullname == ""
MessageBox MB_OK "Please, inform your name."
${NSD_SetFocus} $fullnameTextBox
Abort
${EndIf}
${NSD_GetText} $rhloginTextBox $rhlogin
${If} $rhlogin == ""
MessageBox MB_OK "Please, inform your login/email."
${NSD_SetFocus} $rhloginTextBox
Abort
${EndIf}
${NSD_GetText} $passwordTextBox $password
${If} $password == ""
MessageBox MB_OK "Please, inform your password."
${NSD_SetFocus} $passwordTextBox
Abort
${EndIf}
${Base64_Encode} "$rhlogin:$password"
Pop $basic_auth
!insertmacro ClearStack
${If} $HTTP_PROXY == ''
inetc::get /banner "Checking your credentials..." /header "Authorization: Basic $basic_auth$\r$\nAccept: */*" "$libraServerURL/broker/rest/user.json" /end
Pop $ret
${Else}
inetc::get /banner "Checking your credentials..." /header "Authorization: Basic $basic_auth$\r$\nAccept: */*" /proxy $HTTP_PROXY "$libraServerURL/broker/rest/user.json" /end
Pop $ret
${EndIf}
${If} $ret != "OK"
MessageBox MB_OK "Unable to authenticate. Please check your connection or credentials."
${NSD_SetFocus} $passwordTextBox
Abort
${EndIf}
#MessageBox MB_OK "server: [$libraServerURL], name: [$fullname], login: [$rhlogin], passwd: [$password], auth: [$basic_auth]"
; set variable
WriteRegExpandStr ${env_hklm} "LIBRA_SERVER" "$libraServerURL"
FunctionEnd
Function .onInit
!insertmacro MUI_LANGDLL_DISPLAY
FunctionEnd
Section "copy files" SEC01
SetOutPath "$INSTDIR"
SetOverwrite ifnewer
File "rhc"
File "rhc.bat"
File "openshift.ico"
File "post-install.sh"
CreateDirectory "$SMPROGRAMS\OpenShift"
CreateShortCut "$SMPROGRAMS\OpenShift\rhc.lnk" "$INSTDIR\rhc.bat"
CreateShortCut "$DESKTOP\rhc.lnk" "$INSTDIR\rhc.bat"
SectionEnd
Var status
Section "install git bash" SEC02
SetOutPath "$INSTDIR"
File "dist\${GIT_INSTALLER}"
File "dist\git-install.cfg"
; run the one click installer
ExecWait '"$INSTDIR\${GIT_INSTALLER}" /sp- /silent /nocancel "/loadinf=$INSTDIR\git-install.cfg"'
IfErrors onError
Return
onError:
MessageBox MB_ICONEXCLAMATION "Git install failed. Please try again."
Quit
SectionEnd
Section "install ruby" SEC03
SetOutPath "$INSTDIR"
File "dist\${RUBY_INSTALLER}"
File "dist\ruby-install.cfg"
; run the one click installer
;ExecWait "$INSTDIR\${RUBY_INSTALLER} /verysilent /noreboot /nocancel /noicons /dir=$INSTDIR\ruby /loadinf=$INSTDIR\ruby-install.cfg"
ExecWait '"$INSTDIR\${RUBY_INSTALLER}" /verysilent /noreboot /nocancel /noicons "/dir=$INSTDIR/ruby" "/loadinf=$INSTDIR\ruby-install.cfg"'
IfErrors onError
Return
onError:
MessageBox MB_ICONEXCLAMATION "Ruby install failed. Please try again."
Quit
SectionEnd
Section "install rhc" SEC04
SetOutPath "$INSTDIR"
StrCpy $status ''
; install rhc locally
${If} $HTTP_PROXY == ''
ExecWait '"$INSTDIR\ruby\bin\gem.bat" install rhc --no-rdoc --no-ri -V'
${Else}
ExecWait '"$INSTDIR\ruby\bin\gem.bat" install --http-proxy "$HTTP_PROXY" rhc --no-rdoc --no-ri -V'
${EndIf}
IfErrors onError
Return
onError:
MessageBox MB_ICONEXCLAMATION 'Gem install failed. Please install the rhc gem manually: "$INSTDIR\ruby\bin\gem.bat" install rhc'
SectionEnd
Section "install tortoise" SEC05
SetOutPath "$INSTDIR"
File "dist\${TORTOISE_INSTALLER}"
; run the one click installer
ExecWait '"$SYSDIR\msiExec" /i "$INSTDIR\${TORTOISE_INSTALLER}" /qr'
IfErrors onError
WriteRegStr HKCU "Software\TortoiseGit" 'SSH' 'ssh.exe'
Return
onError:
MessageBox MB_ICONEXCLAMATION "TortoiseGit install failed. You need to install it manually."
SectionEnd
Section -AdditionalIcons
CreateShortCut "$SMPROGRAMS\rhc\Uninstall.lnk" "$INSTDIR\uninst.exe"
SectionEnd
Section -Post
WriteUninstaller "$INSTDIR\uninst.exe"
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\openshift.ico"
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}"
${EnvVarUpdate} $0 "PATH" "A" "HKCU" "$INSTDIR"
SectionEnd
Function un.onUninstSuccess
HideWindow
MessageBox MB_ICONINFORMATION|MB_OK "You have successfully uninstalled $(^Name)."
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\${PRODUCT_NAME}.url"
Delete "$INSTDIR\uninst.exe"
Delete "$INSTDIR\rhc.bat"
Delete "$INSTDIR\rhc"
Delete "$INSTDIR\post-install.sh"
#RMDir /r "$INSTDIR\ruby"
Delete "$SMPROGRAMS\rhc\Uninstall.lnk"
Delete "$SMPROGRAMS\rhc\Website.lnk"
Delete "$DESKTOP\rhc.lnk"
Delete "$SMPROGRAMS\rhc\rhc.lnk"
Delete "$INSTDIR\openshift.ico"
RMDir "$SMPROGRAMS\rhc"
RMDir "$INSTDIR"
DeleteRegKey ${PRODUCT_UNINST_ROOT_KEY} "${PRODUCT_UNINST_KEY}"
DeleteRegKey HKLM "${PRODUCT_DIR_REGKEY}"
SetAutoClose true
${un.EnvVarUpdate} $0 "PATH" "R" "HKCU" "$INSTDIR"
SectionEnd