Created
February 20, 2018 09:13
-
-
Save vfuse/81eca9e399f9c2a3919d746ff04368ae to your computer and use it in GitHub Desktop.
Windows installer, compile with NSIS
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
;-------------------------------- | |
;Include Modern UI | |
!include "MUI2.nsh" | |
!include "Sections.nsh" | |
!include nsDialogs.nsh | |
!include LogicLib.nsh | |
!include x64.nsh | |
;-------------------------------- | |
;General | |
;Name and file | |
Name "Nixstats" | |
OutFile "nixstatsagent-setup.exe" | |
;Default installation folder | |
InstallDir "c:\nixstatsagent" | |
;Request application privileges | |
RequestExecutionLevel admin | |
;admin | |
!define PRODUCT_NAME "Nixstats" | |
!define PRODUCT_VERSION "1.0" | |
!define PRODUCT_UNINST_KEY "Software\Microsoft\Windows\CurrentVersion\Uninstall\${PRODUCT_NAME}" | |
!define PRODUCT_UNINST_ROOT_KEY "HKLM" | |
!define MUI_ICON "favicon.ico" | |
!define MUI_UNICON "favicon.ico" | |
;-------------------------------- | |
;Interface Settings | |
!define MUI_ABORTWARNING | |
;-------------------------------- | |
;-------------------------------- | |
;Pages | |
Page custom MyPageFunc MyPageFuncLeave | |
!insertmacro MUI_PAGE_INSTFILES | |
;-------------------------------- | |
;Languages | |
!insertmacro MUI_LANGUAGE "English" | |
Var USERTOKEN | |
Var myTextBox1 | |
;-------------------------------- | |
;Installer Sections | |
Section "Main" | |
SetOutPath "$INSTDIR" | |
CreateDirectory $INSTDIR | |
${If} ${RunningX64} | |
inetc::get "https://www.python.org/ftp/python/2.7.14/python-2.7.14.amd64.msi" "$INSTDIR\python.msi" | |
${Else} | |
inetc::get "https://www.python.org/ftp/python/2.7.14/python-2.7.14.msi" "$INSTDIR\python.msi" | |
${EndIf} | |
ExecWait '"msiexec" /x "$INSTDIR\python.msi" /qn' | |
ExecWait '"msiexec" /i "$INSTDIR\python.msi" InstallAllUsers=1 TargetDir=$INSTDIR DefaultAllUsersTargetDir=$INSTDIR /qb!' | |
ExecWait `"$INSTDIR\Scripts\pip.exe" install nixstatsagent --upgrade` | |
ExecWait `"$INSTDIR\Scripts\nixstatshello.exe" $USERTOKEN $INSTDIR\Lib\site-packages\nixstatsagent\nixstats-token.ini` | |
inetc::get "http://nixstats.com/nixstats.ini" "$INSTDIR\Lib\site-packages\nixstatsagent\nixstats.ini" | |
SetOutPath "$WINDIR" | |
File .\service\*.* | |
ExecWait `instsrv.exe "NixStats" $WINDIR\srvany.exe` | |
WriteRegStr HKLM "SYSTEM\CurrentControlSet\Services\NixStats\Parameters" 'Application' '$INSTDIR\Scripts\nixstatsagent.exe' | |
ExecWait `net start NixStats` | |
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}" "DisplayVersion" "${PRODUCT_VERSION}" | |
SectionEnd | |
Function un.onUninstSuccess | |
HideWindow | |
MessageBox MB_ICONINFORMATION|MB_OK "$(^Name) was successfully removed from your computer." | |
FunctionEnd | |
Function un.onInit | |
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 | |
ExecWait 'cmd.exe /c net stop NixStats' | |
ExecWait 'sc.exe delete NixStats' | |
SetRegView 32 | |
DeleteRegKey ${PRODUCT_UNINST_ROOT_KEY} "${PRODUCT_UNINST_KEY}" | |
SetAutoClose true | |
Delete "$INSTDIR\uninst.exe" | |
SectionEnd | |
;-------------------------------- | |
;Functions | |
Function MyPageFunc | |
!insertmacro MUI_HEADER_TEXT "NixStats UserID Token" "Please enter the required configuration options" | |
nsDialogs::Create 1018 | |
${NSD_CreateLabel} 25 50 50u 10u "UserID" | |
${NSD_CreateText} 100 50 200u 12u "" | |
Pop $myTextBox1 | |
nsDialogs::Show | |
FunctionEnd | |
Function MyPageFuncLeave | |
${NSD_GetText} $myTextBox1 $0 | |
${If} $0 == "" | |
MessageBox MB_OK "Please enter a UserID" | |
Abort | |
${EndIf} | |
${NSD_GetText} $myTextBox1 $USERTOKEN | |
FunctionEnd |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment