-
Notifications
You must be signed in to change notification settings - Fork 92
/
ParticleCLISetup.nsi
147 lines (109 loc) · 3.58 KB
/
ParticleCLISetup.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
; Particle CLI installer script
;--------------------------------
; General
; Name and file
!define PRODUCT_NAME "Particle CLI"
!define SHORT_NAME "ParticleCLI"
Name "${PRODUCT_NAME}"
OutFile "ParticleCLISetup.exe"
!define COMPANY_NAME "Particle Industries, Inc"
!define MUI_ICON "assets\particle.ico"
; Installation directory
InstallDir "$LOCALAPPDATA\particle"
!define BINDIR "$INSTDIR\bin"
; CLI Executable
!define EXE "particle.exe"
; Don't request admin privileges
RequestExecutionLevel user
; Show command line with details of the installation
ShowInstDetails show
; Registry Entry for environment
; All users:
;!define Environ 'HKLM "SYSTEM\CurrentControlSet\Control\Session Manager\Environment"'
; Current user only:
!define Environ 'HKCU "Environment"'
; Registry entry for uninstaller
!define UNINSTALL_REG 'HKCU "Software\Microsoft\Windows\CurrentVersion\Uninstall\${SHORT_NAME}"'
; Text to display when the installation is done
CompletedText 'Run "particle login" in the command line to start using the Particle CLI'
;--------------------------------
; Dependencies
; Add JSON and download plugins
; Modern UI
!include "MUI2.nsh"
; Architecture detection
!include "x64.nsh"
!include "TextFunc.nsh"
!include "LogicLib.nsh"
!include "utils.nsh"
; Don't show a certain operation in the details
!macro EchoOff
SetDetailsPrint none
!macroend
!macro EchoOn
SetDetailsPrint both
!macroend
!define EchoOff "!insertmacro EchoOff"
!define EchoOn "!insertmacro EchoOn"
;--------------------------------
; Installer pages
; Welcome page
!define MUI_WELCOMEFINISHPAGE_BITMAP "assets\particle.bmp"
!define MUI_WELCOMEPAGE_TITLE "Install the ${PRODUCT_NAME}"
!define /file MUI_WELCOMEPAGE_TEXT "welcome.txt"
!insertmacro MUI_PAGE_WELCOME
; Open source licenses
!insertmacro MUI_PAGE_LICENSE "licenses.txt"
; Installation details page
!insertmacro MUI_PAGE_INSTFILES
; Finish page
!define MUI_FINISHPAGE_SHOWREADME ""
!define MUI_FINISHPAGE_SHOWREADME_TEXT "Enable automatic updates"
!define MUI_FINISHPAGE_SHOWREADME_FUNCTION EnableAutoUpdates
!insertmacro MUI_PAGE_FINISH
; Uninstall confirm page
!insertmacro MUI_UNPAGE_CONFIRM
; Uninstallation details page
!insertmacro MUI_UNPAGE_INSTFILES
!insertmacro MUI_LANGUAGE "English"
;--------------------------------
; Installer Sections
Section "CLI" CLI_SECTION
SectionIn 1 3
SetOutPath $INSTDIR
Call CopyExecutables
Call DisableAutoUpdates
Call AddCLIToPath
SectionEnd
Section "-Create uninstaller"
WriteRegStr ${UNINSTALL_REG} "DisplayName" "${PRODUCT_NAME}"
WriteRegStr ${UNINSTALL_REG} "Publisher" "${COMPANY_NAME}"
WriteRegStr ${UNINSTALL_REG} "UninstallString" '"$INSTDIR\Uninstall.exe"'
WriteRegDWORD ${UNINSTALL_REG} "NoModify" 1
WriteRegDWORD ${UNINSTALL_REG} "NoRepair" 1
WriteUninstaller "$INSTDIR\Uninstall.exe"
DetailPrint ""
SectionEnd
;--------------------------------
; Uninstaller Sections
Section "Uninstall"
RMDir /r /REBOOTOK "$INSTDIR"
DeleteRegKey ${UNINSTALL_REG}
Push "${BINDIR}"
Call un.RemoveFromPath
SectionEnd
Function CopyExecutables
CreateDirectory "${BINDIR}"
File "/oname=${BINDIR}\${EXE}" "..\..\build\particle-cli-win-x64.exe"
FunctionEnd
Function EnableAutoUpdates
nsExec::ExecToLog "${BINDIR}\${EXE} update-cli --enable-updates"
FunctionEnd
Function DisableAutoUpdates
nsExec::ExecToLog "${BINDIR}\${EXE} update-cli --disable-updates"
FunctionEnd
Function AddCLIToPath
DetailPrint "Adding CLI to path"
Push "${BINDIR}"
Call AddToPath
FunctionEnd