source: ogAgent-Git/windows/ogagent.nsi

qndtest
Last change on this file was 9732c07, checked in by Ramón M. Gómez <ramongomez@…>, 4 years ago

#963: OGAgent Installer for Windows: parameter page is shown after license page.

  • Property mode set to 100644
File size: 9.3 KB
Line 
1# We need http://nsis.sourceforge.net/NSIS_Simple_Firewall_Plugin
2# Copy inside the two x86_xxxxx folders inside nsis plugins folder
3Name "OpenGnsys Agent"
4
5# OpenGnsys Agent version
6!define /file OGA_VERSION "src\VERSION"
7!define /file OGA_WINVERSION "windows\VERSION"
8
9# General Symbol Definitions
10!define REGKEY "SOFTWARE\OGAgent"
11!if ${OGA_VERSION} == ${OGA_WINVERSION}
12  !define VERSION ${OGA_WINVERSION}.0
13!else
14  !define VERSION ${OGA_WINVERSION}.1
15!endif
16!define COMPANY "OpenGnsys Project"
17!define URL https://opengnsys.es
18!define CONFIGFILE "cfg\ogagent.cfg"
19
20# MultiUser Symbol Definitions
21!define MULTIUSER_EXECUTIONLEVEL Admin
22!define MULTIUSER_INSTALLMODE_COMMANDLINE
23!define MULTIUSER_INSTALLMODE_INSTDIR OGAgent
24!define MULTIUSER_INSTALLMODE_INSTDIR_REGISTRY_KEY "${REGKEY}"
25!define MULTIUSER_INSTALLMODE_INSTDIR_REGISTRY_VALUE "Path"
26
27# MUI Symbol Definitions
28!define MUI_ICON "src\img\oga.ico"
29!define MUI_FINISHPAGE_NOAUTOCLOSE
30!define MUI_UNICON "src\img\oga.ico"
31!define MUI_UNFINISHPAGE_NOAUTOCLOSE
32!define MUI_LANGDLL_REGISTRY_ROOT HKLM
33!define MUI_LANGDLL_REGISTRY_KEY ${REGKEY}
34!define MUI_LANGDLL_REGISTRY_VALUENAME InstallerLanguage
35
36# Included files
37!include MultiUser.nsh
38!include Sections.nsh
39!include MUI2.nsh
40!include nsDialogs.nsh
41!include LogicLib.nsh
42!include Filefunc.nsh
43
44# Reserved Files
45!insertmacro MUI_RESERVEFILE_LANGDLL
46
47# Variables
48Var StartMenuGroup
49Var SERVERIP
50Var SERVERIP_VALUE
51
52# Installer pages
53!insertmacro MUI_PAGE_WELCOME
54!insertmacro MUI_PAGE_LICENSE src\license.txt
55Page custom "ParamsPage" "ParamsPageLeave"
56!insertmacro MUI_PAGE_DIRECTORY
57!insertmacro MUI_PAGE_INSTFILES
58!insertmacro MUI_PAGE_FINISH
59!insertmacro MUI_UNPAGE_CONFIRM
60!insertmacro MUI_UNPAGE_INSTFILES
61
62# Installer languages
63!insertmacro MUI_LANGUAGE English
64!insertmacro MUI_LANGUAGE Spanish
65!insertmacro MUI_LANGUAGE French
66!insertmacro MUI_LANGUAGE German
67
68# Installer attributes
69BrandingText "OpenGnsys"
70OutFile OGAgentSetup-${OGA_VERSION}.exe
71InstallDir OGAgent
72CRCCheck on
73XPStyle on
74ShowInstDetails hide
75VIProductVersion "${VERSION}.0.0"
76VIAddVersionKey /LANG=${LANG_ENGLISH} ProductName "OGAgent"
77VIAddVersionKey /LANG=${LANG_ENGLISH} ProductVersion "${VERSION}"
78VIAddVersionKey /LANG=${LANG_ENGLISH} CompanyName "${COMPANY}"
79VIAddVersionKey /LANG=${LANG_ENGLISH} CompanyWebsite "${URL}"
80VIAddVersionKey /LANG=${LANG_ENGLISH} FileVersion "${VERSION}"
81VIAddVersionKey /LANG=${LANG_ENGLISH} FileDescription "OpenGnsys Agent installer"
82VIAddVersionKey /LANG=${LANG_ENGLISH} LegalCopyright "(c) 2015 Virtual Cable S.L.U."
83InstallDirRegKey HKLM "${REGKEY}" Path
84ShowUninstDetails show
85
86# Installer sections
87Section -Main SEC0000
88    SetShellVarContext all
89    SetOutPath $INSTDIR
90    SetOverwrite on
91    File /r bin\*.*
92    File vcredist_x86.exe
93    File src\VERSION
94    WriteRegStr HKLM "${REGKEY}\Components" Main 1
95SectionEnd
96
97Section -post SEC0001
98    WriteIniStr $INSTDIR\${CONFIGFILE} "opengnsys" "remote" "https://$SERVERIP_VALUE/opengnsys/rest"
99    SetShellVarContext current
100    WriteRegStr HKLM "${REGKEY}" Path $INSTDIR
101    SetOutPath $INSTDIR
102    WriteUninstaller $INSTDIR\OGAgentUninstaller.exe
103    SetOutPath $SMPROGRAMS\$StartMenuGroup
104    CreateShortcut "$SMPROGRAMS\$StartMenuGroup\$(^UninstallLink).lnk" $INSTDIR\OGAgentUninstaller.exe
105    WriteRegStr HKLM "SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\$(^Name)" DisplayName "$(^Name)"
106    WriteRegStr HKLM "SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\$(^Name)" DisplayVersion "${VERSION}"
107    WriteRegStr HKLM "SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\$(^Name)" Publisher "${COMPANY}"
108    WriteRegStr HKLM "SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\$(^Name)" URLInfoAbout "${URL}"
109    WriteRegStr HKLM "SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\$(^Name)" DisplayIcon $INSTDIR\OGAgentUninstaller.exe
110    WriteRegStr HKLM "SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\$(^Name)" UninstallString $INSTDIR\OGAgentUninstaller.exe
111    WriteRegStr HKLM "SOFTWARE\Microsoft\Windows\CurrentVersion\Run" OGAgentTool $INSTDIR\OGAgentUser.exe
112    WriteRegDWORD HKLM "SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\$(^Name)" NoModify 1
113    WriteRegDWORD HKLM "SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\$(^Name)" NoRepair 1
114    ExecWait '"$INSTDIR\vcredist_x86.exe" /passive /norestart'
115    # Add the application to the firewall exception list - All Networks - All IP Version - Enabled
116    # SimpleFC::AddApplication "OpenGnsys Agent Service" "$INSTDIR\OGAgentService.exe" 0 2 "" 1
117    # SimpleFC::AdvAddRule [name] [description] [protocol] [direction]
118    #  [status] [profile] [action] [application] [service_name] [icmp_types_and_codes]
119    #  [group] [local_ports] [remote_ports] [local_address] [remote_address]
120    #
121    SimpleFC::AdvAddRule "OpenGnsys Agent Firewall rules" "Firewall rules for OpenGnsys Agent interaction with broker." "6" "1" \
122      "1" "7" "1" "$INSTDIR\OGAgentService.exe" "" "" \
123      "" "" "" "" ""   
124    Pop $0 ; return error(1)/success(0)
125    # Disable fast boot on Windows 10, if registry key exists.
126    ReadRegDWORD $0 HKLM "SYSTEM\CurrentControlSet\Control\Session Manager\Power" HiberbootEnabled
127    IfErrors 0 +2
128    WriteRegDWORD HKLM "SYSTEM\CurrentControlSet\Control\Session Manager\Power" HiberbootEnabled 0
129    # Install service
130    nsExec::Exec /OEM "$INSTDIR\OGAgentService.exe --startup auto install" # Add service after installation
131    # Update recovery options
132    nsExec::Exec /OEM "$INSTDIR\OGAServiceHelper.exe" 
133    Exec "net start ogagent"
134    Exec "$INSTDIR\OGAgentUser.exe"
135SectionEnd
136
137# Macro for selecting uninstaller sections
138!macro SELECT_UNSECTION SECTION_NAME UNSECTION_ID
139    Push $R0
140    ReadRegStr $R0 HKLM "${REGKEY}\Components" "${SECTION_NAME}"
141    StrCmp $R0 1 0 next${UNSECTION_ID}
142    !insertmacro SelectSection "${UNSECTION_ID}"
143    GoTo done${UNSECTION_ID}
144next${UNSECTION_ID}:
145    !insertmacro UnselectSection "${UNSECTION_ID}"
146done${UNSECTION_ID}:
147    Pop $R0
148!macroend
149
150# Uninstaller sections
151Section /o -un.Main UNSEC0000
152    nsExec::Exec "taskkill /F /IM OGAgentUser.exe /T"
153    nsExec::Exec /OEM "$INSTDIR\OGAgentService.exe stop" # Stops the service prior uninstall
154    nsExec::Exec /OEM "$INSTDIR\OGAgentService.exe remove" # Removes the service prior uninstall
155    nsExec::Exec "taskkill /F /IM OGAgentService.exe /T"
156    Delete /REBOOTOK "$INSTDIR\*.*"
157    DeleteRegValue HKLM "${REGKEY}\Components" Main
158    DeleteRegValue HKLM "SOFTWARE\Microsoft\Windows\CurrentVersion\Run" OGAgentTool
159SectionEnd
160
161Section -un.post UNSEC0001
162    # Remove application from the firewall exception list
163    # SimpleFC::RemoveApplication "$INSTDIR\OGAgentService.exe"
164    SimpleFC::AdvRemoveRule "OpenGnsys Agent Firewall rules"
165    Pop $0 ; return error(1)/success(0)
166
167    SetShellVarContext current
168    StrCpy $StartMenuGroup "OpenGnsys Agent"
169    DeleteRegKey HKLM "SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\$(^Name)"
170    Delete /REBOOTOK "$SMPROGRAMS\$StartMenuGroup\$(^UninstallLink).lnk"
171    Delete /REBOOTOK $INSTDIR\OGAgentUninstaller.exe
172    DeleteRegValue HKLM "${REGKEY}" Path
173    DeleteRegKey /IfEmpty HKLM "${REGKEY}\Components"
174    DeleteRegKey /IfEmpty HKLM "${REGKEY}"
175    RmDir /REBOOTOK $SMPROGRAMS\$StartMenuGroup
176    SetShellVarContext all
177    RmDir /r /REBOOTOK $INSTDIR
178SectionEnd
179
180# Installer functions
181Function .onInit
182    InitPluginsDir
183    Call GetParameters
184    StrCpy $StartMenuGroup "OpenGnsys Agent"
185   
186    !insertmacro MUI_LANGDLL_DISPLAY
187    !insertmacro MULTIUSER_INIT
188FunctionEnd
189
190# Uninstaller functions
191Function un.onInit
192    StrCpy $StartMenuGroup "OpenGnsys Agent"
193    !insertmacro MUI_UNGETLANGUAGE
194    !insertmacro MULTIUSER_UNINIT
195    !insertmacro SELECT_UNSECTION Main ${UNSEC0000}
196FunctionEnd
197
198# Parameters dialog box
199Function ParamsPage
200    !insertmacro MUI_HEADER_TEXT "$(PARAMS_TITLE)" ""
201    nsDialogs::Create /NOUNLOAD 1018
202    Pop $0
203    ${If} $0 == error
204        Abort
205    ${EndIf}
206    ${NSD_CreateLabel} 0 0 100% 12u "$(SERVER_LABEL):"
207    Pop $0
208    ${NSD_CreateText} 10% 20u 80% 12u "$SERVERIP_VALUE"
209    Pop $SERVERIP
210    nsDialogs::Show
211FunctionEnd
212
213# Get parameters from the dialog
214Function ParamsPageLeave
215    ${NSD_GetText} $SERVERIP $SERVERIP_VALUE
216FunctionEnd
217
218# Assign input parameters or default values to variables
219Function GetParameters
220    ${GetOptions} $CMDLINE "/server" $SERVERIP_VALUE
221    ${If} $SERVERIP_VALUE == ""
222        StrCpy $SERVERIP_VALUE "192.168.2.10"
223    ${EndIf}
224FunctionEnd
225
226# Installer Language Strings
227LangString PARAMS_TITLE ${LANG_ENGLISH} "Setup parameters"
228LangString PARAMS_TITLE ${LANG_SPANISH} "Parametros de configuracion"
229LangString PARAMS_TITLE ${LANG_FRENCH} "Parametres de configuration"
230LangString PARAMS_TITLE ${LANG_GERMAN} "Setup-Parameter"
231LangString SERVER_LABEL ${LANG_ENGLISH} "OpenGnsys Server IP Address"
232LangString SERVER_LABEL ${LANG_SPANISH} "Direccion IP del Servidor OpenGnsys"
233LangString SERVER_LABEL ${LANG_FRENCH} "Adresse IP du Serveur OpenGnsys"
234LangString SERVER_LABEL ${LANG_GERMAN} "OpenGnsys-Server-IP-Adresse"
235LangString ^UninstallLink ${LANG_ENGLISH} "Uninstall $(^Name)"
236LangString ^UninstallLink ${LANG_SPANISH} "Desinstalar $(^Name)"
237LangString ^UninstallLink ${LANG_FRENCH} "D�sinstaller $(^Name)"
238LangString ^UninstallLink ${LANG_GERMAN} "deinstallieren $(^Name)"
Note: See TracBrowser for help on using the repository browser.