-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathamon-agent.iss
143 lines (119 loc) · 5.14 KB
/
amon-agent.iss
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
; Script generated by the Inno Setup Script Wizard.
; SEE THE DOCUMENTATION FOR DETAILS ON CREATING INNO SETUP SCRIPT FILES!
#define NSSM "nssm.exe"
#define AmonServiceName "AmonAgent"
#define AmonApp "amon-agent.exe"
[Setup]
; NOTE: The value of AppId uniquely identifies this application.
; Do not use the same AppId value in installers for other applications.
; (To generate a new GUID, click Tools | Generate GUID inside the IDE.)
AppId={{33541FBB-1B7C-4C64-8902-420ACE513DF9}
AppName=amon-agent
AppVersion=1.3.1
;AppVerName=amon-agent 1.0
AppPublisher=Simplistic LLC
AppPublisherURL=https://amon.cx
AppSupportURL=https://amon.cx
AppUpdatesURL=https://amon.cx
DefaultDirName={pf}\AmonAgent
DefaultGroupName=amon-agent
OutputBaseFilename=amon-agent-1.3.1
Compression=lzma
SolidCompression=yes
WizardImageFile=welcome.bmp
DisableDirPage=auto
DisableProgramGroupPage=yes
CloseApplications=yes
RestartApplications=yes
AlwaysRestart=no
UninstallDisplayIcon={app}\amon-agent.exe
PrivilegesRequired=admin
[Languages]
Name: "english"; MessagesFile: "compiler:Default.isl"
[Files]
Source: "dist\amon-agent.exe"; DestDir: "{app}"; Flags: ignoreversion restartreplace;
; NOTE: Don't use "Flags: ignoreversion" on any shared system files
Source: "nssm.exe"; DestDir: "{app}"
Source: "amon-agent.ini"; DestDir: "{app}"; Permissions: everyone-full;
[INI]
Filename: {app}\amon-agent.ini; Section: Main; Key: amon_url; String: {code:GetAmonUrl}
Filename: {app}\amon-agent.ini; Section: Main; Key: server_key; String: {code:GetKey}
[Icons]
Name: "{group}\amon-agent"; Filename: "{app}\amon-agent.exe"
[Run]
; post-install
Filename: "{sys}\msiexec.exe"; Parameters: "/package ""{app}\{#AmonApp}"" /qn /norestart /nocloseapplications /passive"; Flags: shellexec waituntilterminated;
Filename: "{sys}\netsh.exe"; Parameters: "advfirewall firewall add rule name=""AmonAgent Out"" program=""{app}\{#AmonApp}"" dir=out action=allow enable=yes"; Flags: runhidden;
Filename: "{app}\{#NSSM}"; Parameters: "install {#AmonServiceName} ""{app}\{#AmonApp}"" "; Flags: runhidden;
Filename: "{app}\{#NSSM}"; Parameters: "set {#AmonServiceName} AppDirectory {app}"; Flags: runhidden;
Filename: "{app}\{#NSSM}"; Parameters: "set {#AmonServiceName} AppStdout {userappdata}\Amon\amon.log"; Flags: runhidden;
Filename: "{app}\{#NSSM}"; Parameters: "set {#AmonServiceName} AppStderr {userappdata}\Amon\amon.log"; Flags: runhidden;
Filename: "{app}\{#NSSM}"; Parameters: "start {#AmonServiceName}"; Flags: runhidden;
[UninstallDelete]
Type: filesandordirs; Name: "{app}"
[UninstallRun]
; pre-uninstall
Filename: "{app}\{#NSSM}"; Parameters: "stop {#AmonServiceName}"; Flags: runhidden;
Filename: "{app}\{#NSSM}"; Parameters: "remove {#AmonServiceName} confirm"; Flags: runhidden;
[InstallDelete]
Type: files; Name: "{app}\amon-agent.exe"
[Code]
var
UserPage: TInputQueryWizardPage;
procedure InitializeWizard;
begin
{ Create the pages }
UserPage := CreateInputQueryPage(wpWelcome,
'Amon Information', '',
'Please specify the URL where your Amon instance is running and the agent server key, then click Next.');
UserPage.Add('Amon URL:', False);
UserPage.Add('Server Key:', False);
UserPage.Values[0] := GetIniString('Main', 'amon_url', '', WizardDirValue + '\amon-agent.ini');
UserPage.Values[1] := GetIniString('Main', 'server_key', '', WizardDirValue + '\amon-agent.ini');
end;
function GetAmonUrl(Param: String): string;
begin
result := UserPage.Values[0];
end;
function GetKey(Param: String): string;
begin
result := UserPage.Values[1];
end;
function GetUninstallString: string;
var
sUnInstPath: string;
sUnInstallString: String;
begin
Result := '';
sUnInstPath := ExpandConstant('Software\Microsoft\Windows\CurrentVersion\Uninstall\33541FBB-1B7C-4C64-8902-420ACE513DF9_is1'); //Your App GUID/ID
sUnInstallString := '';
if not RegQueryStringValue(HKLM, sUnInstPath, 'UninstallString', sUnInstallString) then
RegQueryStringValue(HKCU, sUnInstPath, 'UninstallString', sUnInstallString);
Result := sUnInstallString;
end;
function IsUpgrade: Boolean;
begin
Result := (GetUninstallString() <> '');
end;
function InitializeSetup: Boolean;
var
V: Integer;
iResultCode: Integer;
sUnInstallString: string;
begin
Result := True; // in case when no previous version is found
if RegValueExists(HKEY_LOCAL_MACHINE,'Software\Microsoft\Windows\CurrentVersion\Uninstall\33541FBB-1B7C-4C64-8902-420ACE513DF9_is1', 'UninstallString') then //Your App GUID/ID
begin
V := MsgBox(ExpandConstant('An old version of the Amon Agent was detected. Do you want to uninstall it?'), mbInformation, MB_YESNO); //Custom Message if App installed
if V = IDYES then
begin
sUnInstallString := GetUninstallString();
sUnInstallString := RemoveQuotes(sUnInstallString);
Exec(ExpandConstant(sUnInstallString), '', '', SW_SHOW, ewWaitUntilTerminated, iResultCode);
Result := True; //if you want to proceed after uninstall
//Exit; //if you want to quit after uninstall
end
else
Result := False; //when older version present and not uninstalled
end;
end;