-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathnsis.nsi
144 lines (108 loc) · 4.41 KB
/
nsis.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
!include LogicLib.nsh
# define the name of installer
OutFile "dist\Shakecast_Installer.exe"
# define default installation directory
InstallDir "$PROGRAMFILES\Shakecast"
# Get admin level
RequestExecutionLevel admin
!macro VerifyUserIsAdmin
UserInfo::GetAccountType
pop $0
${If} $0 != "admin" ;Require admin rights on NT4+
messageBox mb_iconstop "Administrator rights required!"
setErrorLevel 740 ;ERROR_ELEVATION_REQUIRED
quit
${EndIf}
!macroend
function .onInit
setShellVarContext all
!insertmacro VerifyUserIsAdmin
functionEnd
Function StopShakecast
DetailPrint "Stop ShakeCast if running..."
ExecWait "net stop sc_server"
ExecWait "net stop sc_web_server"
FunctionEnd
Function PythonCheck
IfFileExists "C:\Python27\python.exe" 0 Skip
ExecWait '"$SYSDIR\msiExec" /x "$INSTDIR\python-2.7.13.msi" /qb'
rmDir /r "C:\Python27"
Skip:
FunctionEnd
# start default section
Section "Install ShakeCast" IDOK
# set the installation directory as the destination for the following actions
SetOutPath $INSTDIR
# set environment variable for shakecast home
; 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"'
; set variable for local machine
WriteRegExpandStr ${env_hklm} SC_HOME "$PROFILE\.shakecast"
; and current user
WriteRegExpandStr ${env_hkcu} SC_HOME "$PROFILE\.shakecast"
; make sure windows knows about the change
SendMessage ${HWND_BROADCAST} ${WM_WININICHANGE} 0 "STR:Environment" /TIMEOUT=5000
DetailPrint "Extracting Files into Installation Directory"
# specify files to go into the installation directory path
File "*"
File "..\requirements\python-2.7.13.msi"
Call StopShakecast
Call PythonCheck
# Uninstaller - See function un.onInit and section "uninstall" for configuration
writeUninstaller "$INSTDIR\uninstall.exe"
SectionEnd
Section "Python Installation"
# run the python installer and wait for it to finish
ExecWait '"$SYSDIR\msiExec" /i "$INSTDIR\python-2.7.13.msi" /qb TARGETDIR=C:\Python27 ALLUSERS=1'
# install the windows extensions
ExecWait 'C:\Python27\Scripts\pip.exe install pywin32'
DetailPrint "Python is ready..."
SectionEnd
Section "ShakeCast installation"
DetailPrint "Installing ShakeCast"
ExecDos::exec /DETAILED "C:\Python27\python.exe -m pip install usgs-shakecast --upgrade --no-cache-dir --trusted-host pypi.python.org --trusted-host files.pythonhosted.org --trusted-host pypi.org"
DetailPrint "Initializing ShakeCast..."
ExecDos::exec /DETAILED "C:\Python27\python.exe -m shakecast.app.startup"
DetailPrint "Moved config files."
ExecDos::exec /DETAILED "C:\Python27\python.exe -m shakecast.app.windows.set_paths"
DetailPrint "Paths set."
ExecDos::exec /DETAILED "C:\Python27\python.exe -m shakecast.app.windows install"
DetailPrint "Services installed."
DetailPrint "Starting ShakeCast..."
ExecDos::exec /DETAILED "C:\Python27\python.exe -m shakecast start"
DetailPrint "Started"
# make a link to the python package from the install directory
DetailPrint "Adding links..."
CreateShortCut "$INSTDIR\shakecast.lnk" "C:\Python27\Lib\site-packages\shakecast"
CreateShortCut "$INSTDIR\user-data.lnk" "$PROFILE\.shakecast"
DetailPrint "Finishing up Installation..."
SectionEnd
# Uninstaller
function un.onInit
SetShellVarContext all
#Verify the uninstaller - last chance to back out
MessageBox MB_OKCANCEL "Permanantly remove ShakeCast?" IDOK next
Abort
next:
!insertmacro VerifyUserIsAdmin
functionEnd
section "uninstall"
ExecDos::exec /DETAILED "C:\Python27\python.exe -m shakecast stop"
ExecDos::exec /DETAILED "C:\Python27\python.exe -m shakecast.app.windows uninstall"
ExecDos::exec /DETAILED "C:\Python27\python.exe -m shakecast.app.windows.set_paths remove"
ExecDos::exec /DETAILED "C:\Python27\Scripts\pip.exe uninstall pywin32 -y"
ExecWait '"$SYSDIR\msiExec" /x "$INSTDIR\python-2.7.13.msi"'
# Remove files
delete $INSTDIR\*
# Remove data directory
rmDir /r "$PROFILE\.shakecast"
# Remove python
rmDir /r "C:\Python27"
# Always delete uninstaller as the last action
delete $INSTDIR\uninstall.exe
# Try to remove the install directory
rmDir /r $INSTDIR
sectionEnd