Changelog update
[public/netxms.git] / src / agent / install / common.iss
1 [Dirs]
2 Name: "{app}\etc"
3 Name: "{app}\etc\nxagentd.conf.d"
4 Name: "{app}\lib"
5 Name: "{app}\log"
6 Name: "{app}\var"
7
8 [Tasks]
9 Name: sessionagent; Description: "Install session agent (will run in every user session)"; Flags: unchecked
10
11 [Registry]
12 Root: HKLM; Subkey: "Software\NetXMS"; Flags: uninsdeletekeyifempty
13 Root: HKLM; Subkey: "Software\NetXMS\Agent"; Flags: uninsdeletekey
14 Root: HKLM; Subkey: "Software\NetXMS\Agent"; ValueType: string; ValueName: "InstallPath"; ValueData: "{app}"
15 Root: HKLM; Subkey: "Software\NetXMS\Agent"; ValueType: string; ValueName: "ConfigFile"; ValueData: "{app}\etc\nxagentd.conf"
16 Root: HKLM; Subkey: "Software\NetXMS\Agent"; ValueType: string; ValueName: "ConfigIncludeDir"; ValueData: "{app}\etc\nxagentd.conf.d"
17 Root: HKLM; Subkey: "SOFTWARE\Microsoft\Windows\CurrentVersion\Run"; ValueType: string; ValueName: "NetXMSSessionAgent"; ValueData: """{app}\bin\nxsagent.exe"" -c ""{app}\etc\nxagentd.conf"" -H"; Flags: uninsdeletevalue; Tasks: sessionagent
18
19 [Run]
20 Filename: "{app}\bin\nxagentd.exe"; Parameters: "-Z ""{app}\etc\nxagentd.conf"" ""{code:GetMasterServer}"" {{syslog} ""{app}\var"" ""{app}\etc\nxagentd.conf.d"" {code:GetSubagentList}"; WorkingDir: "{app}\bin"; StatusMsg: "Creating agent's config..."; Flags: runhidden
21 Filename: "{app}\bin\nxagentd.exe"; Parameters: "-c ""{app}\etc\nxagentd.conf"" {code:GetCentralConfigOption} {code:GetCustomCmdLine} -I"; WorkingDir: "{app}\bin"; StatusMsg: "Installing service..."; Flags: runhidden
22 Filename: "{app}\bin\nxagentd.exe"; Parameters: "-s"; WorkingDir: "{app}\bin"; StatusMsg: "Starting service..."; Flags: runhidden
23
24 [UninstallRun]
25 Filename: "{app}\bin\nxagentd.exe"; Parameters: "-K"; StatusMsg: "Stopping external subagents..."; RunOnceId: "StopExternalAgents"; Flags: runhidden
26 Filename: "{app}\bin\nxagentd.exe"; Parameters: "-S"; StatusMsg: "Stopping service..."; RunOnceId: "StopService"; Flags: runhidden
27 Filename: "taskkill.exe"; Parameters: "/F /IM nxagentd.exe /T"; StatusMsg: "Killing agent processes..."; RunOnceId: "KillProcess"; Flags: runhidden
28 Filename: "taskkill.exe"; Parameters: "/F /IM nxsagent.exe /T"; StatusMsg: "Killing session agent processes..."; RunOnceId: "KillSessionAgentProcess"; Flags: runhidden
29 Filename: "{app}\bin\nxagentd.exe"; Parameters: "-R"; StatusMsg: "Uninstalling service..."; RunOnceId: "DelService"; Flags: runhidden
30
31 [Code]
32 Var
33 ServerSelectionPage: TWizardPage;
34 editServerName: TNewEdit;
35 cbDownloadConfig: TNewCheckBox;
36 SubagentSelectionPage: TInputOptionWizardPage;
37 serverName, sbECS, sbFileMgr, sbLogWatch, sbPing, sbPortCheck, sbWinPerf, sbWMI, sbUPS, sbDownloadConfig: String;
38
39 #include "..\..\install\windows\firewall.iss"
40
41 Procedure ExecAndLog(execName, options, workingDir: String);
42 Var
43 iResult : Integer;
44 Begin
45 Log('Executing ' + execName + ' ' + options);
46 Log(' Working directory: ' + workingDir);
47 Exec(execName, options, workingDir, 0, ewWaitUntilTerminated, iResult);
48 Log(' Result: ' + IntToStr(iResult));
49 End;
50
51 Procedure StopService;
52 Var
53 strExecName : String;
54 Begin
55 strExecName := ExpandConstant('{app}\bin\nxagentd.exe');
56 If FileExists(strExecName) Then
57 Begin
58 Log('Stopping agent service');
59 ExecAndLog(strExecName, '-K', ExpandConstant('{app}\bin'));
60 ExecAndLog(strExecName, '-S', ExpandConstant('{app}\bin'));
61 ExecAndLog('taskkill.exe', '/IM nxagentd.exe /F', ExpandConstant('{app}\bin'));
62 ExecAndLog('taskkill.exe', '/IM nxsagent.exe /F', ExpandConstant('{app}\bin'));
63 End;
64 End;
65
66 Function PrepareToInstall(var NeedsRestart: Boolean): String;
67 Begin
68 StopService;
69 Result := '';
70 End;
71
72 Function BoolToStr(Val: Boolean): String;
73 Begin
74 If Val Then
75 Result := 'TRUE'
76 Else
77 Result := 'FALSE';
78 End;
79
80 Function StrToBool(Val: String): Boolean;
81 Begin
82 If Val = 'TRUE' Then
83 Result := TRUE
84 Else
85 Result := FALSE;
86 End;
87
88 Function InitializeSetup(): Boolean;
89 Var
90 i, nCount : Integer;
91 param : String;
92 Begin
93 // Check if we are running on 64-bit Windows
94 If (NOT Is64BitInstallMode) AND (ProcessorArchitecture = paX64) Then Begin
95 If MsgBox('You are trying to install 32-bit version of NetXMS agent on 64-bit Windows. It is recommended to install 64-bit version instead. Do you really wish to continue installation?', mbConfirmation, MB_YESNO) = IDYES Then
96 Result := TRUE
97 Else
98 Result := FALSE;
99 End Else Begin
100 Result := TRUE;
101 End;
102
103 // Empty values for installation data
104 serverName := '';
105 sbECS := 'FALSE';
106 sbFileMgr := 'FALSE';
107 sbLogWatch := 'FALSE';
108 sbPing := 'FALSE';
109 sbPortCheck := 'FALSE';
110 sbWinPerf := 'TRUE';
111 sbWMI := 'FALSE';
112 sbUPS := 'FALSE';
113 sbDownloadConfig := 'FALSE';
114
115 // Parse command line parameters
116 nCount := ParamCount;
117 For i := 1 To nCount Do Begin
118 param := ParamStr(i);
119
120 If Pos('/SERVER=', param) = 1 Then Begin
121 serverName := param;
122 Delete(serverName, 1, 8);
123 End;
124
125 If Pos('/CENTRALCONFIG', param) = 1 Then Begin
126 sbDownloadConfig := 'TRUE';
127 End;
128
129 If Pos('/LOCALCONFIG', param) = 1 Then Begin
130 sbDownloadConfig := 'FALSE';
131 End;
132
133 If Pos('/SUBAGENT=', param) = 1 Then Begin
134 Delete(param, 1, 10);
135 param := Uppercase(param);
136 If param = 'ECS' Then
137 sbECS := 'TRUE';
138 If param = 'FILEMGR' Then
139 sbFileMgr := 'TRUE';
140 If param = 'LOGWATCH' Then
141 sbLogWatch := 'TRUE';
142 If param = 'PING' Then
143 sbPing := 'TRUE';
144 If param = 'PORTCHECK' Then
145 sbPortCheck := 'TRUE';
146 If param = 'WINPERF' Then
147 sbWinPerf := 'TRUE';
148 If param = 'WMI' Then
149 sbWMI := 'TRUE';
150 If param = 'UPS' Then
151 sbUPS := 'TRUE';
152 End;
153
154 If Pos('/NOSUBAGENT=', param) = 1 Then Begin
155 Delete(param, 1, 12);
156 param := Uppercase(param);
157 If param = 'ECS' Then
158 sbECS := 'FALSE';
159 If param = 'FILEMGR' Then
160 sbFileMgr := 'FALSE';
161 If param = 'LOGWATCH' Then
162 sbLogWatch := 'FALSE';
163 If param = 'PING' Then
164 sbPing := 'FALSE';
165 If param = 'PORTCHECK' Then
166 sbPortCheck := 'FALSE';
167 If param = 'WINPERF' Then
168 sbWinPerf := 'FALSE';
169 If param = 'WMI' Then
170 sbWMI := 'FALSE';
171 If param = 'UPS' Then
172 sbUPS := 'FALSE';
173 End;
174 End;
175 End;
176
177 Procedure InitializeWizard;
178 Var
179 static: TNewStaticText;
180 Begin
181 ServerSelectionPage := CreateCustomPage(wpSelectTasks,
182 'NetXMS Server', 'Select your management server.');
183
184 static := TNewStaticText.Create(ServerSelectionPage);
185 static.Top := ScaleY(8);
186 static.Caption := 'Please enter host name or IP address of your NetXMS server.';
187 static.AutoSize := True;
188 static.Parent := ServerSelectionPage.Surface;
189
190 editServerName := TNewEdit.Create(ServerSelectionPage);
191 editServerName.Top := static.Top + static.Height + ScaleY(8);
192 editServerName.Width := ServerSelectionPage.SurfaceWidth - ScaleX(8);
193 editServerName.Text := GetPreviousData('MasterServer', serverName);
194 editServerName.Parent := ServerSelectionPage.Surface;
195
196 cbDownloadConfig := TNewCheckBox.Create(ServerSelectionPage);
197 cbDownloadConfig.Top := editServerName.Top + editServerName.Height + ScaleY(12);
198 cbDownloadConfig.Width := ServerSelectionPage.SurfaceWidth;
199 cbDownloadConfig.Height := ScaleY(17);
200 cbDownloadConfig.Caption := 'Download configuration file from management server on startup';
201 cbDownloadConfig.Checked := StrToBool(GetPreviousData('DownloadConfig', sbDownloadConfig));
202 cbDownloadConfig.Parent := ServerSelectionPage.Surface;
203
204
205 SubagentSelectionPage := CreateInputOptionPage(ServerSelectionPage.Id,
206 'Subagent Selection', 'Select desired subagents.',
207 'Please select additional subagents you wish to load.', False, False);
208 SubagentSelectionPage.Add('Extended Checksum Subagent - ecs.nsm');
209 SubagentSelectionPage.Add('File Manager Subagent - filemgr.nsm');
210 SubagentSelectionPage.Add('ICMP Pinger Subagent - ping.nsm');
211 SubagentSelectionPage.Add('Log Monitoring Subagent - logwatch.nsm');
212 SubagentSelectionPage.Add('Port Checker Subagent - portcheck.nsm');
213 SubagentSelectionPage.Add('Windows Performance Subagent - winperf.nsm');
214 SubagentSelectionPage.Add('WMI Subagent - wmi.nsm');
215 SubagentSelectionPage.Add('UPS Monitoring Subagent - ups.nsm');
216 SubagentSelectionPage.Values[0] := StrToBool(GetPreviousData('Subagent_ECS', sbECS));
217 SubagentSelectionPage.Values[1] := StrToBool(GetPreviousData('Subagent_FILEMGR', sbFileMgr));
218 SubagentSelectionPage.Values[2] := StrToBool(GetPreviousData('Subagent_PING', sbPing));
219 SubagentSelectionPage.Values[3] := StrToBool(GetPreviousData('Subagent_LOGWATCH', sbLogWatch));
220 SubagentSelectionPage.Values[4] := StrToBool(GetPreviousData('Subagent_PORTCHECK', sbPortCheck));
221 SubagentSelectionPage.Values[5] := StrToBool(GetPreviousData('Subagent_WINPERF', sbWinPerf));
222 SubagentSelectionPage.Values[6] := StrToBool(GetPreviousData('Subagent_WMI', sbWMI));
223 SubagentSelectionPage.Values[7] := StrToBool(GetPreviousData('Subagent_UPS', sbUPS));
224 End;
225
226 Procedure RegisterPreviousData(PreviousDataKey: Integer);
227 Begin
228 SetPreviousData(PreviousDataKey, 'MasterServer', editServerName.Text);
229 SetPreviousData(PreviousDataKey, 'DownloadConfig', BoolToStr(cbDownloadConfig.Checked));
230 SetPreviousData(PreviousDataKey, 'Subagent_ECS', BoolToStr(SubagentSelectionPage.Values[0]));
231 SetPreviousData(PreviousDataKey, 'Subagent_FILEMGR', BoolToStr(SubagentSelectionPage.Values[1]));
232 SetPreviousData(PreviousDataKey, 'Subagent_PING', BoolToStr(SubagentSelectionPage.Values[2]));
233 SetPreviousData(PreviousDataKey, 'Subagent_LOGWATCH', BoolToStr(SubagentSelectionPage.Values[3]));
234 SetPreviousData(PreviousDataKey, 'Subagent_PORTCHECK', BoolToStr(SubagentSelectionPage.Values[4]));
235 SetPreviousData(PreviousDataKey, 'Subagent_WINPERF', BoolToStr(SubagentSelectionPage.Values[5]));
236 SetPreviousData(PreviousDataKey, 'Subagent_WMI', BoolToStr(SubagentSelectionPage.Values[6]));
237 SetPreviousData(PreviousDataKey, 'Subagent_UPS', BoolToStr(SubagentSelectionPage.Values[7]));
238 End;
239
240 Function GetMasterServer(Param: String): String;
241 Begin
242 Result := editServerName.Text;
243 End;
244
245 Function GetSubagentList(Param: String): String;
246 Begin
247 Result := '';
248 If SubagentSelectionPage.Values[0] Then
249 Result := Result + 'ecs.nsm ';
250 If SubagentSelectionPage.Values[1] Then
251 Result := Result + 'filemgr.nsm ';
252 If SubagentSelectionPage.Values[2] Then
253 Result := Result + 'ping.nsm ';
254 If SubagentSelectionPage.Values[3] Then
255 Result := Result + 'logwatch.nsm ';
256 If SubagentSelectionPage.Values[4] Then
257 Result := Result + 'portcheck.nsm ';
258 If SubagentSelectionPage.Values[5] Then
259 Result := Result + 'winperf.nsm ';
260 If SubagentSelectionPage.Values[6] Then
261 Result := Result + 'wmi.nsm ';
262 If SubagentSelectionPage.Values[7] Then
263 Result := Result + 'ups.nsm ';
264 End;
265
266 Function GetCentralConfigOption(Param: String): String;
267 Var
268 server: String;
269 position: Integer;
270 Begin
271 If cbDownloadConfig.Checked Then Begin
272 server := editServerName.Text;
273 position := Pos(',', server);
274 If position > 0 Then Begin
275 Delete(server, position, 100000);
276 End;
277 Result := '-M "' + server + '"';
278 End
279 Else
280 Result := '';
281 End;
282
283 Procedure CurStepChanged(CurStep: TSetupStep);
284 Begin
285 If CurStep=ssPostInstall Then Begin
286 SetFirewallException('NetXMS Agent', ExpandConstant('{app}')+'\bin\nxagentd.exe');
287 End;
288 End;
289
290 Procedure CurUninstallStepChanged(CurUninstallStep: TUninstallStep);
291 Begin
292 If CurUninstallStep=usPostUninstall Then Begin
293 RemoveFirewallException(ExpandConstant('{app}')+'\bin\nxagentd.exe');
294 End;
295 End;
296
297 Procedure DeinitializeSetup();
298 Var
299 strExecName : String;
300 Begin
301 strExecName := ExpandConstant('{app}\bin\nxagentd.exe');
302 If FileExists(strExecName) Then
303 Begin
304 Log('Starting agent service');
305 ExecAndLog(strExecName, '-s', ExpandConstant('{app}\bin'));
306 End;
307 End;