File: installer.nsi

package info (click to toggle)
elixir-lang 1.19.5.dfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: experimental
  • size: 15,524 kB
  • sloc: erlang: 12,234; sh: 321; makefile: 288
file content (293 lines) | stat: -rw-r--r-- 8,639 bytes parent folder | download
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
# SPDX-License-Identifier: Apache-2.0
# SPDX-FileCopyrightText: 2021 The Elixir Team
# SPDX-FileCopyrightText: 2012 Plataformatec

!include "MUI2.nsh"
!include "StrFunc.nsh"
${Using:StrFunc} UnStrStr

Name "Elixir"
ManifestDPIAware true
Unicode True
InstallDir "$PROGRAMFILES64\Elixir"
!define MUI_ICON "assets\Elixir.ico"
!define MUI_UNICON "assets\Elixir.ico"

; Install Page: Install Erlang/OTP

Page custom CheckOTPPageShow CheckOTPPageLeave

var InstalledOTPRelease
var OTPPath

var Dialog
var NoOTPLabel
var NoOTPLabelCreated
var OTPMismatchLabel
var OTPMismatchLabelCreated
var DownloadOTPLink
var DownloadOTPLinkCreated
var VerifyOTPButton
var VerifyOTPButtonCreated
Function CheckOTPPageShow
  !insertmacro MUI_HEADER_TEXT "Checking Erlang/OTP" ""

  nsDialogs::Create 1018
  Pop $Dialog

  ${If} $Dialog == error
    Abort
  ${EndIf}

  Call VerifyOTP

  nsDialogs::Show
FunctionEnd

Function VerifyOTP
  ${If} $NoOTPLabelCreated == "true"
    ShowWindow $NoOTPLabel ${SW_HIDE}
  ${EndIf}

  ${If} $OTPMismatchLabelCreated == "true"
    ShowWindow $OTPMismatchLabel ${SW_HIDE}
  ${EndIf}

  ${If} $DownloadOTPLinkCreated == "true"
    ShowWindow $DownloadOTPLink ${SW_HIDE}
  ${Else}
    StrCpy $DownloadOTPLinkCreated "true"
    ${NSD_CreateLink}  0 60u 100% 20u "Download Erlang/OTP ${OTP_RELEASE}"
    Pop $DownloadOTPLink
    ${NSD_OnClick} $DownloadOTPLink OpenOTPDownloads
    ShowWindow $DownloadOTPLink ${SW_HIDE}
  ${EndIf}

  ${If} $VerifyOTPButtonCreated == "true"
    ShowWindow $VerifyOTPButton ${SW_HIDE}
  ${Else}
    StrCpy $VerifyOTPButtonCreated "true"
    ${NSD_CreateButton} 0 80u 25% 12u "Verify Erlang/OTP"
    Pop $VerifyOTPButton
    ${NSD_OnClick} $VerifyOTPButton VerifyOTP
    ShowWindow $VerifyOTPButton ${SW_HIDE}
  ${EndIf}

  StrCpy $0 0
  loop:
    EnumRegKey $1 HKLM "SOFTWARE\WOW6432NODE\Ericsson\Erlang" $0
    StrCmp $1 "" done
    ReadRegStr $1 HKLM "SOFTWARE\WOW6432NODE\Ericsson\Erlang\$1" ""
    StrCpy $OTPPath $1
    IntOp $0 $0 + 1
    goto loop
  done:

  ${If} $OTPPath == ""
    ${If} $NoOTPLabelCreated != "true"
      StrCpy $NoOTPLabelCreated "true"
      ${NSD_CreateLabel} 0 0   100% 20u "Couldn't find existing Erlang/OTP installation. Click the link below to download and install it before proceeding."
      Pop $NoOTPLabel
    ${EndIf}

    ShowWindow $NoOTPLabel ${SW_SHOW}
    ShowWindow $DownloadOTPLink ${SW_SHOW}
    ShowWindow $VerifyOTPButton ${SW_SHOW}

  ${Else}
    nsExec::ExecToStack `$OTPPath\bin\erl.exe -noinput -eval "\
    io:put_chars(erlang:system_info(otp_release)),\
    halt()."`
    Pop $0
    Pop $1

    ${If} $0 == 0
      StrCpy $InstalledOTPRelease $1
      ${If} $InstalledOTPRelease == ${OTP_RELEASE}
        ${NSD_CreateLabel} 0 0 100% 60u "Found existing Erlang/OTP $InstalledOTPRelease installation at $OTPPath. Please proceed."

      ${Else}
        ${If} $OTPMismatchLabelCreated != "true"
          StrCpy $OTPMismatchLabelCreated "true"
          ${NSD_CreateLabel} 0 0 100% 60u "Found existing Erlang/OTP $InstalledOTPRelease installation at $OTPPath but this Elixir installer was precompiled for Erlang/OTP ${OTP_RELEASE}. \
          $\r$\n$\r$\nYou can either search for another Elixir installer precompiled for Erlang/OTP $InstalledOTPRelease or download Erlang/OTP ${OTP_RELEASE} and install before proceeding."
          Pop $OTPMismatchLabel
        ${EndIf}

        ShowWindow $OTPMismatchLabel ${SW_SHOW}
        ShowWindow $DownloadOTPLink  ${SW_SHOW}
        ShowWindow $VerifyOTPButton  ${SW_SHOW}
      ${EndIf}
    ${Else}
      SetErrorlevel 5
      MessageBox MB_ICONSTOP "Found existing Erlang/OTP installation at $OTPPath but checking it exited with $0: $1"
    ${EndIf}
  ${EndIf}
FunctionEnd

Function OpenOTPDownloads
  ExecShell "open" "https://www.erlang.org/downloads/${OTP_RELEASE}"
FunctionEnd

Function CheckOTPPageLeave
FunctionEnd

; Install Page: Files

!insertmacro MUI_PAGE_DIRECTORY
!insertmacro MUI_PAGE_INSTFILES

; Install Page: Finish

Page custom FinishPageShow FinishPageLeave

var AddOTPToPathCheckbox
var AddElixirToPathCheckbox
Function FinishPageShow
  !insertmacro MUI_HEADER_TEXT "Finish Setup" ""

  nsDialogs::Create 1018
  Pop $Dialog

  ${If} $Dialog == error
    Abort
  ${EndIf}

  ; we add to PATH using erlang, so there must be an OTP installed to do so.
  ${If} "$OTPPath" != ""
    ${NSD_CreateCheckbox} 0 0 195u 10u "&Add $INSTDIR\bin to %PATH%"
    Pop $AddElixirToPathCheckbox
    SendMessage $AddElixirToPathCheckbox ${BM_SETCHECK} ${BST_CHECKED} 0

    ${NSD_CreateCheckbox} 0 20u 195u 10u "&Add $OTPPath\bin to %PATH%"
    Pop $AddOTPToPathCheckbox
    SendMessage $AddOTPToPathCheckbox ${BM_SETCHECK} ${BST_CHECKED} 0

    ${NSD_CreateLabel} 0 40u 100% 20u "Note: you need to restart your shell for the environment variable changes to take effect."
  ${EndIf}

  nsDialogs::Show
FunctionEnd

var PathsToAdd
Function FinishPageLeave
  ${NSD_GetState} $AddOTPToPathCheckbox $0
  ${If} $0 <> ${BST_UNCHECKED}
    StrCpy $PathsToAdd ";$OTPPath\bin"
  ${EndIf}

  ${NSD_GetState} $AddElixirToPathCheckbox $0
  ${If} $0 <> ${BST_UNCHECKED}
    StrCpy $PathsToAdd "$PathsToAdd;$INSTDIR\bin"
  ${EndIf}

  ${If} "$PathsToAdd" != ""
    nsExec::ExecToStack `"$OTPPath\bin\escript.exe" "$INSTDIR\update_system_path.erl" add "$PathsToAdd"`
    Pop $0
    Pop $1
    ${If} $0 != 0
      SetErrorlevel 5
      MessageBox MB_ICONSTOP "adding paths failed with $0: $1"
      Quit
    ${EndIf}
  ${EndIf}
FunctionEnd

Section "Install Elixir" SectionElixir
  SetOutPath "$INSTDIR"
  File /r "${ELIXIR_DIR}\"
  File "assets\Elixir.ico"
  File "update_system_path.erl"
  WriteRegStr   HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\Elixir" "DisplayName" "Elixir"
  WriteRegStr   HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\Elixir" "DisplayVersion" "${ELIXIR_VERSION}"
  WriteRegStr   HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\Elixir" "DisplayIcon" "$INSTDIR\Elixir.ico"
  WriteRegStr   HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\Elixir" "Publisher" "The Elixir Team"
  WriteRegStr   HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\Elixir" "UninstallString" '"$INSTDIR\Uninstall.exe"'
  WriteRegDWORD HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\Elixir" "NoModify" 1
  WriteRegDWORD HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\Elixir" "NoRepair" 1

  WriteRegStr   HKLM "Software\Elixir\Elixir" "InstallRoot" "$INSTDIR"

  WriteUninstaller "Uninstall.exe"
SectionEnd

; Uninstall Page: Remove from %PATH%

var RemoveOTPFromPathCheckbox
var RemoveElixirFromPathCheckbox
Function un.FinishPageShow
  !insertmacro MUI_HEADER_TEXT "Remove from %PATH%" ""

  StrCpy $0 0
  loop:
    EnumRegKey $1 HKLM "SOFTWARE\WOW6432NODE\Ericsson\Erlang" $0
    StrCmp $1 "" done
    ReadRegStr $1 HKLM "SOFTWARE\WOW6432NODE\Ericsson\Erlang\$1" ""
    StrCpy $OTPPath $1
    IntOp $0 $0 + 1
    goto loop
  done:

  nsDialogs::Create 1018
  Pop $Dialog

  ${If} $Dialog == error
    Abort
  ${EndIf}

  ReadRegStr $0 HKCU "Environment" "Path"

  ${UnStrStr} $1 "$0" "$INSTDIR\bin"
  ${If} $1 != ""
    ${NSD_CreateCheckbox} 0 0 195u 10u "&Remove $INSTDIR\bin from %PATH%"
    Pop $RemoveElixirFromPathCheckbox
    SendMessage $RemoveElixirFromPathCheckbox ${BM_SETCHECK} ${BST_CHECKED} 0
  ${EndIf}

  ${UnStrStr} $1 "$0" "$OTPPath\bin"
  ${If} $1 != ""
    ${NSD_CreateCheckbox} 0 20u 195u 10u "&Remove $OTPPath\bin from %PATH%"
    Pop $RemoveOTPFromPathCheckbox
    SendMessage $RemoveOTPFromPathCheckbox ${BM_SETCHECK} ${BST_CHECKED} 0
  ${EndIf}

  nsDialogs::Show
FunctionEnd

var PathsToRemove
Function un.FinishPageLeave
  ${NSD_GetState} $RemoveOTPFromPathCheckbox $1
  ${If} $1 <> ${BST_UNCHECKED}
    StrCpy $PathsToRemove ";$OTPPath\bin"
  ${EndIf}

  ${NSD_GetState} $RemoveElixirFromPathCheckbox $1
  ${If} $1 <> ${BST_UNCHECKED}
    StrCpy $PathsToRemove "$PathsToRemove;$INSTDIR\bin"
  ${EndIf}

  ${If} "$PathsToRemove" != ""
    nsExec::ExecToStack `"$OTPPath\bin\escript.exe" "$INSTDIR\update_system_path.erl" remove "$PathsToRemove"`
    Pop $0
    Pop $1
    ${If} $0 != 0
      SetErrorlevel 5
      MessageBox MB_ICONSTOP "removing paths failed with $0: $1"
      Quit
    ${EndIf}
  ${EndIf}
FunctionEnd

UninstPage custom un.FinishPageShow un.FinishPageLeave

!insertmacro MUI_UNPAGE_DIRECTORY
!insertmacro MUI_UNPAGE_INSTFILES

Section "Uninstall"
  RMDir /r "$INSTDIR"
  DeleteRegKey HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\Elixir"
  DeleteRegKey HKLM "Software\Elixir\Elixir"
  DeleteRegKey /ifempty HKLM "Software\Elixir"
SectionEnd

!insertmacro MUI_LANGUAGE "English"