-
-
Notifications
You must be signed in to change notification settings - Fork 236
/
Server.wxs
135 lines (128 loc) · 6.77 KB
/
Server.wxs
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
<?xml version="1.0" encoding="UTF-8"?>
<!--
SPDX-FileCopyrightText: 2020 Frans van Dorsselaer
SPDX-License-Identifier: GPL-3.0-only
-->
<Wix
xmlns="http://wixtoolset.org/schemas/v4/wxs"
xmlns:fw="http://wixtoolset.org/schemas/v4/wxs/firewall"
>
<Fragment>
<DirectoryRef Id="APPLICATIONFOLDER" FileSource="$(var.PublishDir)">
<!--
The product name is 'usbipd-win', but our users are well aware they are
running a Windows operating system. Hence, the executable, service name,
and firewall rule do not use the '-win' postfix.
-->
<Component Id="usbipd.exe">
<File Id="usbipd.exe" Name="usbipd.exe">
<fw:FirewallException
Id="usbipd"
Name="usbipd"
Protocol="tcp"
Port="3240"
Profile="all"
Scope="localSubnet"
Description="Allow computers on local subnets to access the USBIP Device Host service."
/>
</File>
<ServiceInstall
Type="ownProcess"
ErrorControl="ignore"
Name="usbipd"
Arguments="server"
Start="auto"
Vital="yes"
DisplayName="USBIP Device Host"
Description="Enables sharing of locally connected USB devices to other machines. If this service is stopped, clients will not be able to attach shared devices."
>
<ServiceDependency Id="VBoxUsbMon" />
</ServiceInstall>
<!-- Stop and remove the old service of version <= 0.3.1, if any -->
<ServiceControl
Id="usbipd_old"
Name="usbipd-win"
Remove="both"
Stop="both"
/>
<ServiceControl
Id="usbipd"
Name="usbipd"
Remove="uninstall"
Stop="both"
/>
<!--
We have our own VBoxUSBMon custom action service installer for this one, which may clash with
VirtualBox or older installations. Therefore, we always create a fresh service instance;
we remove the old one and the custom action will set it up correctly no matter what we had before.
-->
<ServiceControl
Id="VBoxUSBMon"
Name="VBoxUSBMon"
Remove="both"
Stop="both"
/>
<!--
The registry uses the full product name by convention.
-->
<RegistryKey Root="HKLM" Key="SOFTWARE\usbipd-win" ForceDeleteOnUninstall="yes">
<RegistryValue Name="APPLICATIONFOLDER" Type="string" Value="[APPLICATIONFOLDER]" />
<RegistryValue Name="Version" Type="string" Value="$(var.GitVersion_MajorMinorPatch)" />
<RegistryKey
Key="Devices"
ForceCreateOnInstall="yes"
/>
<RegistryKey
Key="Policy"
ForceCreateOnInstall="yes"
/>
</RegistryKey>
<Environment
Id="PATH"
Name="PATH"
Action="set"
Permanent="no"
System="yes"
Part="last"
Value="[APPLICATIONFOLDER]"
/>
</Component>
<Component Id="COPYING.md">
<File Id="COPYING.md" Name="COPYING.md" />
</Component>
</DirectoryRef>
<!-- This will restore the original Windows drivers for devices that were forced bound. -->
<SetProperty Id="UnbindAll" Value=""[#usbipd.exe]" unbind --all" Sequence="execute" Before="UnbindAll" Condition="(?usbipd.exe=3) AND ($usbipd.exe=2)" />
<CustomAction Id="UnbindAll" BinaryRef="Wix4UtilCA_X64" DllEntry="WixQuietExec" Return="ignore" Impersonate="no" Execute="deferred" />
<!-- This will uninstall the drivers. -->
<SetProperty Id="UninstallDrivers" Value=""[#usbipd.exe]" uninstall" Sequence="execute" Before="UninstallDrivers" Condition="(?usbipd.exe=3) AND ($usbipd.exe=2)" />
<CustomAction Id="UninstallDrivers" BinaryRef="Wix4UtilCA_X64" DllEntry="WixQuietExec" Return="ignore" Impersonate="no" Execute="deferred" />
<!-- This will install the drivers. -->
<SetProperty Id="InstallDrivers" Value=""[#usbipd.exe]" install" Sequence="execute" Before="InstallDrivers" Condition="$usbipd.exe=3" />
<CustomAction Id="InstallDrivers" BinaryRef="Wix4UtilCA_X64" DllEntry="WixQuietExec" Return="check" Impersonate="no" Execute="deferred" />
<!--
This will *try to* start the service. However, unlike ServiceControl, it will not fail if it can't.
Now that usbipd depends on VBoxUsbMon, sometimes Windows requires a reboot before the service can start.
The CLI tool will inform the user if the service is not running and that a reboot should fix that.
-->
<SetProperty Id="TryStartService" Value=""[System64Folder]\sc.exe" start usbipd" Sequence="execute" Before="TryStartService" Condition="$usbipd.exe=3" />
<CustomAction Id="TryStartService" BinaryRef="Wix4UtilCA_X64" DllEntry="WixQuietExec" Return="ignore" Impersonate="no" Execute="deferred" />
<InstallExecuteSequence>
<!-- Condition: usbipd.exe is installed and will be uninstalled -->
<!-- NOTE: first make sure that no devices are using VBoxUSB, or else VBoxUSBMon does not stop -->
<Custom Action="UnbindAll" Before="StopServices" Condition="(?usbipd.exe=3) AND ($usbipd.exe=2)" />
<!-- Condition: usbipd.exe is installed and will be uninstalled -->
<Custom Action="UninstallDrivers" After="StopServices" Condition="(?usbipd.exe=3) AND ($usbipd.exe=2)" />
<!-- Condition: usbipd.exe will be (or remains) installed -->
<Custom Action="InstallDrivers" Before="InstallServices" Condition="$usbipd.exe=3" />
<!-- Condition: usbipd.exe will be (or remains) installed -->
<Custom Action="TryStartService" After="StartServices" Condition="$usbipd.exe=3" />
</InstallExecuteSequence>
</Fragment>
<Fragment>
<ComponentGroup Id="usbipd">
<ComponentRef Id="COPYING.md" />
<ComponentRef Id="usbipd.exe" />
</ComponentGroup>
</Fragment>
</Wix>