Skip to content

Instantly share code, notes, and snippets.

@maxlapshin
Created June 7, 2016 07:55
Show Gist options
  • Save maxlapshin/da5adabf88e7cb105785f7342cf9124a to your computer and use it in GitHub Desktop.
Save maxlapshin/da5adabf88e7cb105785f7342cf9124a to your computer and use it in GitHub Desktop.
;!define VERSION "1.5.2"
; version is set via command line
Name "Flussonic" ; The name of the installation
OutFile "..\flussonic-${VERSION}.exe" ; The name of the unistaller file to write
InstallDir "C:\Program Files\Flussonic"
!verbose 1
!define MUI_MANUALVERBOSE 1
!define MUI_PRODUCT "Flussonic"
!define TEMP $R0
;!include "MUI.nsh"
!include "EnvVarUpdate.nsh"
;!insertmacro MUI_PAGE_LICENSE "eula.txt"
;!insertmacro MUI_TEXT_LICENSE_TITLE "Read flussonic license please"
!include nsDialogs.nsh
!include LogicLib.nsh
;RequestExecutionLevel admin
Page directory
;Page license
Page custom GetLicense ValidateLicense
Page instfiles
XPStyle on
RequestExecutionLevel admin
!define UNINST_REG "Software\Microsoft\Windows\CurrentVersion\Uninstall\$(^Name)"
!define UNINST_EXE "FlussonicUninstall.exe"
!define SERVICE_PARAM "System\CurrentControlSet\Services\$(^Name)\Parameters"
Function .onInit
InitPluginsDir
File /oname=$PLUGINSDIR\win32-license.ini "win32-license.ini"
FunctionEnd
var Label
var Text
var License
Function GetLicense
WriteRegStr HKCU "SOFTWARE\Flussonic" "installation" "going"
ReadRegStr $License HKLM Software\Flussonic "license"
;WriteINIStr "$PLUGINSDIR\win32-license.ini" "Field 2" "Text" $0
;InstallOptions::dialog "$PLUGINSDIR\win32-license.ini"
nsDialogs::Create 1018
${NSD_CreateLabel} 0 0 100% 12u "Your license key"
Pop $Label
${NSD_CreateText} 0 13u 100% 15u "$License"
Pop $Text
nsDialogs::Show
FunctionEnd
Function ValidateLicense
${NSD_GetText} $Text $0
${If} $0 == ""
MessageBox MB_OK "You need to enter license key"
Abort
${Endif}
WriteRegStr HKLM "SOFTWARE\Flussonic" "license" $0
;ReadINIStr $R0 "$PLUGINSDIR\win32-license.ini" "Field 1" "State"
;ReadRegStr $R0 HKLM "Software\Flussonic" "license"
;${If} $R0 == ""
; ;WriteRegStr HKLM "Software\Flussonic" "license" "empty-license"
; DetailPrint "No license in registry"
;${EndIf}
FunctionEnd
Section "Install"
SetOutPath $INSTDIR
WriteRegStr HKLM "SOFTWARE\Flussonic" "" $INSTDIR
WriteUninstaller "$INSTDIR\uninstall.exe"
WriteRegStr HKLM "${UNINST_REG}" "DisplayName" "Flussonic"
WriteRegStr HKLM "${UNINST_REG}" "DisplayVersion" "${VERSION}"
WriteRegStr HKLM "${UNINST_REG}" "InstallLocation" "$INSTDIR"
WriteRegStr HKLM "${UNINST_REG}" "Published" "Flussonic"
WriteRegStr HKLM "${UNINST_REG}" "UninstallString" "$INSTDIR\${UNINST_EXE}"
WriteRegStr HKLM "${UNINST_REG}" "URLInfoAbout" "http://flussonic.com/"
WriteRegDWORD HKLM "${UNINST_REG}" "NoModify" 1
WriteRegDWORD HKLM "${UNINST_REG}" "NoRepair" 1
${EnvVarUpdate} $0 "PATH" "R" "HKLM" "C:\Program Files\erl7.2.1\bin"
${EnvVarUpdate} $0 "PATH" "R" "HKLM" "C:\Program Files\erl7.2.1\erts-7.2.1\bin"
${EnvVarUpdate} $0 "PATH" "A" "HKLM" "C:\Program Files\erl7.2.1\bin"
${EnvVarUpdate} $0 "PATH" "A" "HKLM" "C:\Program Files\erl7.2.1\erts-7.2.1\bin"
ReadEnvStr $R0 "PATH"
StrCpy $R0 "$R0;C:\Program Files\erl7.2.1\bin;C:\Program Files\erl7.2.1\erts-7.2.1\bin"
System::Call 'Kernel32::SetEnvironmentVariableA(t, t) i("PATH", R0).r0'
File /r ..\tmproot\opt\flussonic\*.*
File /oname=run.bat run.bat
File /oname=priv\flussonic.conf ..\deploy\sample\flussonic-win32.conf
; WriteRegStr HKLM "${SERVICE_PARAM}" "Application" "$INSTDIR\Flussonic.exe"
; WriteRegStr HKLM "${SERVICE_PARAM}" "AppParameters" ""
; WriteRegStr HKLM "${SERVICE_PARAM}" "AppDirectory" "$INSTDIR"
createShortCut "$SMPROGRAMS\FlussonicUninstall.lnk" "$INSTDIR\uninstall.exe"
ExecWait 'erlsrv.exe add Flussonic -stop "erlang:halt(0)" -onfail restart -env "ERL_LIBS=apps;libs" -workdir "C:\Program Files\Flussonic" -sname flussonic -args "-boot start_sasl -pa apps\*\ebin -pa libs\*\ebin -s flussonic -sasl errlog_type error" -debugtype reuse' $0
DetailPrint "Flussonic service returned $0"
ExecWait 'erlsrv start Flussonic' $0
DetailPrint "Flussonic starting: $0"
ReadRegStr $R0 HKLM "Software\Flussonic" "license"
SectionEnd
; Set prompt text for uninstall window
UninstallText "This will uninstall Flussonic. Press 'Uninstall' to continue."
; Define steps to unistall everything installed.
Section "Uninstall"
ExecWait 'erlsrv stop Flussonic'
ExecWait 'erlsrv remove Flussonic'
${un.EnvVarUpdate} $0 "PATH" "R" "HKLM" "C:\Program Files\erl7.2.1\bin"
${un.EnvVarUpdate} $0 "PATH" "R" "HKLM" "C:\Program Files\erl7.2.1\erts-7.2.1\bin"
DeleteRegKey HKLM "${UNINST_REG}"
;DeleteRegKey HKLM "System\CurrentControlSet\Services\$(^Name)"
Delete "$INSTDIR\uninstall.exe"
Delete "$SMPROGRAMS\FlussonicUninstall.lnk"
DetailPrint "$(^Name) removing"
RMDir /r /REBOOTOK $INSTDIR
SectionEnd
; eof
@unStatiK
Copy link

unStatiK commented Jul 16, 2016

Hello, hardcoded PROGRAM_FILES path not canonical way, you should use predefined variables $PROGRAMFILES, $PROGRAMFILES32 or $PROGRAMFILES64.
For more info about that http://nsis.sourceforge.net/Reference/$PROGRAMFILES .
Of course, in 99% this path will be correct on target system, but if user changed it this script will be broken.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment