This repository was archived by the owner on Sep 26, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
/
Copy pathToolbox.iss
375 lines (329 loc) · 13.9 KB
/
Toolbox.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
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
#define MyAppName "Docker Toolbox"
#define MyAppPublisher "Docker"
#define MyAppURL "https://docker.com"
#define MyAppContact "https://docker.com"
#define b2dIsoPath "..\bundle\boot2docker.iso"
#define dockerCli "..\bundle\docker.exe"
#define dockerMachineCli "..\bundle\docker-machine.exe"
#define dockerComposeCli "..\bundle\docker-compose.exe"
#define kitematic "..\bundle\kitematic"
#define git "..\bundle\Git.exe"
#define virtualBoxCommon "..\bundle\common.cab"
#define virtualBoxMsi "..\bundle\VirtualBox_amd64.msi"
[Setup]
AppCopyright={#MyAppPublisher}
AppId={{FC4417F0-D7F3-48DB-BCE1-F5ED5BAFFD91}
AppContact={#MyAppContact}
AppComments={#MyAppURL}
AppName={#MyAppName}
AppVersion={#MyAppVersion}
AppPublisher={#MyAppPublisher}
AppPublisherURL={#MyAppURL}
AppSupportURL={#MyAppURL}
AppUpdatesURL={#MyAppURL}
ArchitecturesAllowed=x64
ArchitecturesInstallIn64BitMode=x64
DefaultDirName={pf}\{#MyAppName}
DefaultGroupName=Docker
DisableProgramGroupPage=yes
DisableWelcomePage=no
OutputBaseFilename=DockerToolbox
Compression=lzma
SolidCompression=yes
WizardImageFile=windows-installer-side.bmp
WizardSmallImageFile=windows-installer-logo.bmp
WizardImageStretch=yes
UninstallDisplayIcon={app}\unins000.exe
SetupIconFile=toolbox.ico
ChangesEnvironment=true
[Languages]
Name: "english"; MessagesFile: "compiler:Default.isl"
[Types]
Name: "full"; Description: "Full installation"
Name: "custom"; Description: "Custom installation"; Flags: iscustom
[Run]
Filename: "{win}\explorer.exe"; Parameters: "{userprograms}\Docker\"; Flags: postinstall skipifsilent; Description: "View Shortcuts in File Explorer"
[Tasks]
Name: desktopicon; Description: "{cm:CreateDesktopIcon}"
Name: modifypath; Description: "Add docker binaries to &PATH"
Name: upgradevm; Description: "Upgrade Boot2Docker VM"
Name: vbox_ndis5; Description: "Install VirtualBox with NDIS5 driver[default NDIS6]"; Components: VirtualBox; Flags: unchecked
[Components]
Name: "Docker"; Description: "Docker Client for Windows" ; Types: full custom; Flags: fixed
Name: "DockerMachine"; Description: "Docker Machine for Windows" ; Types: full custom; Flags: fixed
Name: "DockerCompose"; Description: "Docker Compose for Windows" ; Types: full custom
Name: "VirtualBox"; Description: "VirtualBox"; Types: full custom; Flags: disablenouninstallwarning
Name: "Kitematic"; Description: "Kitematic for Windows (Alpha)" ; Types: full custom
Name: "Git"; Description: "Git for Windows"; Types: full custom; Flags: disablenouninstallwarning
[Files]
Source: ".\docker-quickstart-terminal.ico"; DestDir: "{app}"; Flags: ignoreversion
Source: "{#dockerCli}"; DestDir: "{app}"; Flags: ignoreversion; Components: "Docker"
Source: ".\start.sh"; DestDir: "{app}"; Flags: ignoreversion; Components: "Docker"
Source: ".\docker-start.cmd"; DestDir: "{app}"; Flags: ignoreversion; Components: "Docker"
Source: "{#dockerMachineCli}"; DestDir: "{app}"; Flags: ignoreversion; Components: "DockerMachine"
Source: "{#dockerComposeCli}"; DestDir: "{app}"; Flags: ignoreversion; Components: "DockerCompose"
Source: "{#kitematic}\*"; DestDir: "{app}\kitematic"; Flags: ignoreversion recursesubdirs; Components: "Kitematic"
Source: "{#b2dIsoPath}"; DestDir: "{app}"; Flags: ignoreversion; Components: "DockerMachine"; AfterInstall: CopyBoot2DockerISO()
Source: "{#git}"; DestDir: "{app}\installers\git"; DestName: "git.exe"; AfterInstall: RunInstallGit(); Components: "Git"
Source: "{#virtualBoxCommon}"; DestDir: "{app}\installers\virtualbox"; Components: "VirtualBox"
Source: "{#virtualBoxMsi}"; DestDir: "{app}\installers\virtualbox"; DestName: "virtualbox.msi"; AfterInstall: RunInstallVirtualBox(); Components: "VirtualBox"
[Icons]
Name: "{userprograms}\Docker\Kitematic (Alpha)"; WorkingDir: "{app}"; Filename: "{app}\kitematic\Kitematic.exe"; Components: "Kitematic"
Name: "{commondesktop}\Kitematic (Alpha)"; WorkingDir: "{app}"; Filename: "{app}\kitematic\Kitematic.exe"; Tasks: desktopicon; Components: "Kitematic"
Name: "{userprograms}\Docker\Docker Quickstart Terminal"; WorkingDir: "{app}"; Filename: "{pf64}\Git\bin\bash.exe"; Parameters: "--login -i ""{app}\start.sh"""; IconFilename: "{app}/docker-quickstart-terminal.ico"; Components: "Docker"
Name: "{commondesktop}\Docker Quickstart Terminal"; WorkingDir: "{app}"; Filename: "{pf64}\Git\bin\bash.exe"; Parameters: "--login -i ""{app}\start.sh"""; IconFilename: "{app}/docker-quickstart-terminal.ico"; Tasks: desktopicon; Components: "Docker"
[UninstallRun]
Filename: "{app}\docker-machine.exe"; Parameters: "rm -f default"
Filename: "{sys}\reg.exe"; Parameters: "delete HKCU\Environment /F /V DOCKER_CERT_PATH"; WorkingDir: "{sys}"
Filename: "{sys}\reg.exe"; Parameters: "delete HKCU\Environment /F /V DOCKER_HOST"; WorkingDir: "{sys}"
Filename: "{sys}\reg.exe"; Parameters: "delete HKCU\Environment /F /V DOCKER_MACHINE_NAME"; WorkingDir: "{sys}"
Filename: "{sys}\reg.exe"; Parameters: "delete HKCU\Environment /F /V DOCKER_TLS_VERIFY"; WorkingDir: "{sys}"
Filename: "{sys}\reg.exe"; Parameters: "delete HKCU\Environment /F /V NO_PROXY"; WorkingDir: "{sys}"
[UninstallDelete]
Type: filesandordirs; Name: "{localappdata}\..\Roaming\Kitematic"
[Registry]
Root: HKCU; Subkey: "Environment"; ValueType:string; ValueName:"DOCKER_TOOLBOX_INSTALL_PATH"; ValueData:"{app}" ; Flags: preservestringtype uninsdeletevalue;
Root: HKCU; Subkey: "Environment"; ValueType: expandsz; ValueName: "Path"; ValueData: "{olddata};{app}"
[Code]
#include "base64.iss"
#include "guid.iss"
var
TrackingDisabled: Boolean;
TrackingCheckBox: TNewCheckBox;
function uuid(): String;
var
dirpath: String;
filepath: String;
ansiresult: AnsiString;
begin
dirpath := ExpandConstant('{userappdata}\DockerToolbox');
filepath := dirpath + '\id.txt';
ForceDirectories(dirpath);
Result := '';
if FileExists(filepath) then
LoadStringFromFile(filepath, ansiresult);
Result := String(ansiresult)
if Length(Result) = 0 then
Result := GetGuid('');
StringChangeEx(Result, '{', '', True);
StringChangeEx(Result, '}', '', True);
SaveStringToFile(filepath, AnsiString(Result), False);
end;
function WindowsVersionString(): String;
var
ResultCode: Integer;
lines : TArrayOfString;
begin
if not Exec(ExpandConstant('{cmd}'), ExpandConstant('/c wmic os get caption | more +1 > C:\windows-version.txt'), '', SW_HIDE, ewWaitUntilTerminated, ResultCode) then begin
Result := 'N/A';
exit;
end;
if LoadStringsFromFile(ExpandConstant('C:\windows-version.txt'), lines) then begin
Result := lines[0];
end else begin
Result := 'N/A'
end;
end;
procedure TrackEventWithProperties(name: String; properties: String);
var
payload: String;
WinHttpReq: Variant;
begin
if TrackingDisabled or WizardSilent() then
exit;
if Length(properties) > 0 then
properties := ', ' + properties;
try
payload := Encode64(Format(ExpandConstant('{{"event": "%s", "properties": {{"token": "{#MixpanelToken}", "distinct_id": "%s", "os": "win32", "os version": "%s", "version": "{#MyAppVersion}" %s}}'), [name, uuid(), WindowsVersionString(), properties]));
WinHttpReq := CreateOleObject('WinHttp.WinHttpRequest.5.1');
WinHttpReq.Open('POST', 'https://api.mixpanel.com/track/?data=' + payload, false);
WinHttpReq.SetRequestHeader('Content-Type', 'application/json');
WinHttpReq.Send('');
except
end;
end;
procedure TrackEvent(name: String);
begin
TrackEventWithProperties(name, '');
end;
function NeedToInstallVirtualBox(): Boolean;
begin
// TODO: Also compare versions
Result := (
(GetEnv('VBOX_INSTALL_PATH') = '')
and
(GetEnv('VBOX_MSI_INSTALL_PATH') = '')
);
end;
function VBoxPath(): String;
begin
if GetEnv('VBOX_INSTALL_PATH') <> '' then
Result := GetEnv('VBOX_INSTALL_PATH')
else
Result := GetEnv('VBOX_MSI_INSTALL_PATH')
end;
function NeedToInstallGit(): Boolean;
begin
// TODO: Find a better way to see if Git is installed
Result := not DirExists('C:\Program Files\Git') or not FileExists('C:\Program Files\Git\git-bash.exe')
end;
procedure InitializeWizard;
var
WelcomePage: TWizardPage;
TrackingLabel: TLabel;
begin
WelcomePage := PageFromID(wpWelcome)
WizardForm.WelcomeLabel2.AutoSize := True;
TrackingCheckBox := TNewCheckBox.Create(WizardForm);
TrackingCheckBox.Top := WizardForm.WelcomeLabel2.Top + WizardForm.WelcomeLabel2.Height + 10;
TrackingCheckBox.Left := WizardForm.WelcomeLabel2.Left;
TrackingCheckBox.Width := WizardForm.WelcomeLabel2.Width;
TrackingCheckBox.Height := 28;
TrackingCheckBox.Caption := 'Help Docker improve Toolbox.';
TrackingCheckBox.Checked := True;
TrackingCheckBox.Parent := WelcomePage.Surface;
TrackingLabel := TLabel.Create(WizardForm);
TrackingLabel.Parent := WelcomePage.Surface;
TrackingLabel.Font := WizardForm.WelcomeLabel2.Font;
TrackingLabel.Font.Color := clGray;
TrackingLabel.Caption := 'This collects anonymous data to help us detect installation problems and improve the overall experience. We only use it to aggregate statistics and will never share it with third parties.';
TrackingLabel.WordWrap := True;
TrackingLabel.Visible := True;
TrackingLabel.Left := WizardForm.WelcomeLabel2.Left;
TrackingLabel.Width := WizardForm.WelcomeLabel2.Width;
TrackingLabel.Top := TrackingCheckBox.Top + TrackingCheckBox.Height + 5;
TrackingLabel.Height := 100;
// Don't do this until we can compare versions
// Wizardform.ComponentsList.Checked[3] := NeedToInstallVirtualBox();
Wizardform.ComponentsList.ItemEnabled[3] := not NeedToInstallVirtualBox();
Wizardform.ComponentsList.Checked[5] := NeedToInstallGit();
end;
function InitializeSetup(): boolean;
begin
TrackEvent('Installer Started');
Result := True;
end;
function NextButtonClick(CurPageID: Integer): Boolean;
begin
if CurPageID = wpWelcome then begin
if TrackingCheckBox.Checked then begin
TrackEventWithProperties('Continued from Overview', '"Tracking Enabled": "Yes"');
TrackingDisabled := False;
DeleteFile(ExpandConstant('{userappdata}\..\.docker\machine\no-error-report'));
end else begin
TrackEventWithProperties('Continued from Overview', '"Tracking Enabled": "No"');
TrackingDisabled := True;
CreateDir(ExpandConstant('{userappdata}\..\.docker\machine'));
SaveStringToFile(ExpandConstant('{userappdata}\..\.docker\machine\no-error-report'), '', False);
end;
end;
Result := True
end;
procedure RunInstallVirtualBox();
var
ResultCode: Integer;
begin
WizardForm.FilenameLabel.Caption := 'installing VirtualBox'
if IsTaskSelected('vbox_ndis5') then begin
if not Exec(ExpandConstant('msiexec'), ExpandConstant('/qn /i "{app}\installers\virtualbox\virtualbox.msi" NETWORKTYPE=NDIS5 /norestart'), '', SW_HIDE, ewWaitUntilTerminated, ResultCode) then
MsgBox('virtualbox install failure', mbInformation, MB_OK);
end else begin
if not Exec(ExpandConstant('msiexec'), ExpandConstant('/qn /i "{app}\installers\virtualbox\virtualbox.msi" /norestart'), '', SW_HIDE, ewWaitUntilTerminated, ResultCode) then
MsgBox('virtualbox install failure', mbInformation, MB_OK);
end;
end;
procedure RunInstallGit();
var
ResultCode: Integer;
begin
WizardForm.FilenameLabel.Caption := 'installing Git for Windows'
if Exec(ExpandConstant('{app}\installers\git\git.exe'), '/sp- /verysilent /norestart', '', SW_HIDE, ewWaitUntilTerminated, ResultCode) then
begin
// handle success if necessary; ResultCode contains the exit code
//MsgBox('git installed OK', mbInformation, MB_OK);
end
else begin
// handle failure if necessary; ResultCode contains the error code
MsgBox('git install failure', mbInformation, MB_OK);
end;
end;
procedure CopyBoot2DockerISO();
begin
WizardForm.FilenameLabel.Caption := 'copying boot2docker iso'
if not ForceDirectories(ExpandConstant('{userappdata}\..\.docker\machine\cache')) then
MsgBox('Failed to create docker machine cache dir', mbError, MB_OK);
if not FileCopy(ExpandConstant('{app}\boot2docker.iso'), ExpandConstant('{userappdata}\..\.docker\machine\cache\boot2docker.iso'), false) then
MsgBox('File moving failed!', mbError, MB_OK);
end;
function CanUpgradeVM(): Boolean;
var
ResultCode: Integer;
begin
if NeedToInstallVirtualBox() or not FileExists(ExpandConstant('{app}\docker-machine.exe')) then begin
Result := false
exit
end;
ExecAsOriginalUser(VBoxPath() + 'VBoxManage.exe', 'showvminfo default', '', SW_HIDE, ewWaitUntilTerminated, ResultCode)
if ResultCode <> 0 then begin
Result := false
exit
end;
if not DirExists(ExpandConstant('{userappdata}\..\.docker\machine\machines\default')) then begin
Result := false
exit
end;
Result := true
end;
function UpgradeVM() : Boolean;
var
ResultCode: Integer;
begin
TrackEvent('VM Upgrade Started');
WizardForm.StatusLabel.Caption := 'Upgrading Docker Toolbox VM...'
ExecAsOriginalUser(ExpandConstant('{app}\docker-machine.exe'), 'stop default', '', SW_HIDE, ewWaitUntilTerminated, ResultCode)
if (ResultCode = 0) or (ResultCode = 1) then
begin
FileCopy(ExpandConstant('{userappdata}\..\.docker\machine\cache\boot2docker.iso'), ExpandConstant('{userappdata}\..\.docker\machine\machines\default\boot2docker.iso'), false)
TrackEvent('VM Upgrade Succeeded');
end
else begin
TrackEvent('VM Upgrade Failed');
MsgBox('VM Upgrade Failed because the VirtualBox VM could not be stopped.', mbCriticalError, MB_OK);
Result := false
WizardForm.Close;
exit;
end;
Result := true
end;
const
ModPathName = 'modifypath';
ModPathType = 'user';
function ModPathDir(): TArrayOfString;
begin
setArrayLength(Result, 1);
Result[0] := ExpandConstant('{app}');
end;
#include "modpath.iss"
procedure CurStepChanged(CurStep: TSetupStep);
var
Success: Boolean;
begin
Success := True;
if CurStep = ssPostInstall then
begin
trackEvent('Installing Files Succeeded');
if IsTaskSelected(ModPathName) then
ModPath();
if not WizardSilent() then
begin
if IsTaskSelected('upgradevm') then
begin
if CanUpgradeVM() then begin
Success := UpgradeVM();
end;
end;
end;
if Success then
trackEvent('Installer Finished');
end;
end;