Skip to content

Commit

Permalink
Merge pull request #832 from dorssel/improve_installer
Browse files Browse the repository at this point in the history
Improve installer
  • Loading branch information
dorssel authored Jan 17, 2024
2 parents c9e35b6 + d8a16f9 commit a52ac33
Show file tree
Hide file tree
Showing 15 changed files with 133 additions and 65 deletions.
1 change: 1 addition & 0 deletions Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ SPDX-License-Identifier: GPL-3.0-only
<SelfContained>false</SelfContained>
<IsPackable>false</IsPackable>
<IsPublishable>false</IsPublishable>
<GenerateDependencyFile>false</GenerateDependencyFile>

<Product>usbipd-win</Product>
<Company>Frans van Dorsselaer</Company>
Expand Down
1 change: 0 additions & 1 deletion Directory.Packages.props
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ SPDX-License-Identifier: GPL-3.0-only
<!-- Installer -->
<PackageVersion Include="WixToolset.DifxApp.wixext" Version="4.0.3" />
<PackageVersion Include="WixToolset.Firewall.wixext" Version="4.0.3" />
<PackageVersion Include="WixToolset.Heat" Version="4.0.3" />
<PackageVersion Include="WixToolset.UI.wixext" Version="4.0.3" />
<PackageVersion Include="WixToolset.Util.wixext" Version="4.0.3" />
<!-- UnitTests -->
Expand Down
6 changes: 3 additions & 3 deletions Installer/Drivers.wxs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ SPDX-License-Identifier: GPL-3.0-only
</Fragment>
<Fragment>
<DirectoryRef Id="Drivers" FileSource="$(var.DriversDir)">
<Component Id="README.md">
<Component Id="Drivers_README.md">
<File Name="README.md" />
</Component>
</DirectoryRef>
Expand Down Expand Up @@ -54,15 +54,15 @@ SPDX-License-Identifier: GPL-3.0-only
</Fragment>
<Fragment>
<ComponentGroup Id="VBoxUSB">
<ComponentRef Id="README.md" />
<ComponentRef Id="Drivers_README.md" />
<ComponentRef Id="VBoxUSB.cat" />
<ComponentRef Id="VBoxUSB.sys" />
<ComponentRef Id="VBoxUSB.inf" />
</ComponentGroup>
</Fragment>
<Fragment>
<ComponentGroup Id="VBoxUSBMon">
<ComponentRef Id="README.md" />
<ComponentRef Id="Drivers_README.md" />
<ComponentRef Id="VBoxUSBMon.cat" />
<ComponentRef Id="VBoxUSBMon.sys" />
<ComponentRef Id="VBoxUSBMon.inf" />
Expand Down
26 changes: 0 additions & 26 deletions Installer/HarvestTransform.xslt

This file was deleted.

25 changes: 2 additions & 23 deletions Installer/Installer.wixproj
Original file line number Diff line number Diff line change
Expand Up @@ -16,30 +16,9 @@ SPDX-License-Identifier: GPL-3.0-only
<SuppressSpecificWarnings>1130</SuppressSpecificWarnings>
<Pedantic>true</Pedantic>
</PropertyGroup>
<ItemGroup>
<Content Include="HarvestTransform.xslt" />
<HarvestDirectory Include="$(PublishDir)" Visible="false">
<DirectoryRefId>APPLICATIONFOLDER</DirectoryRefId>
<SuppressRootDirectory>true</SuppressRootDirectory>
<SuppressCOM>true</SuppressCOM>
<SuppressRegistry>true</SuppressRegistry>
<ComponentGroupName>Usbipd</ComponentGroupName>
<PreprocessorVariable>var.PublishDir</PreprocessorVariable>
<Transforms>HarvestTransform.xslt</Transforms>
</HarvestDirectory>
<HarvestDirectory Include="$(PowerShellDir)" Visible="false">
<DirectoryRefId>PowerShell</DirectoryRefId>
<SuppressRootDirectory>true</SuppressRootDirectory>
<SuppressCOM>true</SuppressCOM>
<SuppressRegistry>true</SuppressRegistry>
<ComponentGroupName>PowerShell</ComponentGroupName>
<PreprocessorVariable>var.PowerShellDir</PreprocessorVariable>
</HarvestDirectory>
</ItemGroup>
<ItemGroup>
<PackageReference Include="WixToolset.DifxApp.wixext" />
<PackageReference Include="WixToolset.Firewall.wixext" />
<PackageReference Include="Wixtoolset.Heat" />
<PackageReference Include="WixToolset.UI.wixext" />
<PackageReference Include="WixToolset.Util.wixext" />
</ItemGroup>
Expand Down Expand Up @@ -74,8 +53,8 @@ SPDX-License-Identifier: GPL-3.0-only
</Target>
<Target Name="PublishUsbipd" BeforeTargets="BeforeBuild">
<Message Importance="high" Text="Publishing pre-built usbipd-win" />
<RemoveDir Directories="..\Usbipd\bin\publish" />
<MakeDir Directories="..\Usbipd\bin\publish" />
<RemoveDir Directories="$(PublishDir)" />
<MakeDir Directories="$(PublishDir)" />
<Exec Command="dotnet publish --nologo --no-restore --no-build --framework $(MainTargetFramework) ..\Usbipd" />
</Target>
</Project>
32 changes: 32 additions & 0 deletions Installer/PowerShell.wxs
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
SPDX-FileCopyrightText: 2024 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">
<Directory Id="PowerShell" Name="PowerShell" />
</DirectoryRef>
</Fragment>
<Fragment>
<DirectoryRef Id="PowerShell" FileSource="$(PowerShellDir)">
<Component Id="Usbipd.Automation.dll">
<File Name="Usbipd.Automation.dll" />
</Component>
<Component Id="Usbipd.PowerShell.dll">
<File Name="Usbipd.PowerShell.dll" />
</Component>
</DirectoryRef>
</Fragment>
<Fragment>
<ComponentGroup Id="PowerShell">
<ComponentRef Id="Usbipd.Automation.dll" />
<ComponentRef Id="Usbipd.PowerShell.dll" />
</ComponentGroup>
</Fragment>
</Wix>
17 changes: 12 additions & 5 deletions Installer/Product.wxs
Original file line number Diff line number Diff line change
Expand Up @@ -110,8 +110,7 @@ SPDX-License-Identifier: GPL-3.0-only
Title="Server"
Description="The user mode server application, installed as a service."
>
<ComponentGroupRef Id="Usbipd" />
<ComponentRef Id="usbipd.exe" />
<ComponentGroupRef Id="usbipd" />
<Feature
Id="Drivers"
Level="1"
Expand All @@ -122,6 +121,16 @@ SPDX-License-Identifier: GPL-3.0-only
>
<ComponentGroupRef Id="Drivers" />
</Feature>
<Feature
Id="WSL"
Level="1"
AllowAdvertise="no"
AllowAbsent="yes"
Title="WSL Support"
Description="Support files to attach devices to WSL."
>
<ComponentGroupRef Id="WSL" />
</Feature>
<Feature
Id="PowerShell"
Level="1"
Expand All @@ -140,9 +149,7 @@ SPDX-License-Identifier: GPL-3.0-only

<Fragment>
<StandardDirectory Id="ProgramFiles64Folder">
<Directory Id="APPLICATIONFOLDER" Name="usbipd-win" FileSource="$(var.PublishDir)">
<Directory Id="PowerShell" Name="PowerShell" FileSource="$(var.PowerShellDir)" />
</Directory>
<Directory Id="APPLICATIONFOLDER" Name="usbipd-win" FileSource="$(var.PublishDir)" />
</StandardDirectory>
</Fragment>
</Wix>
10 changes: 10 additions & 0 deletions Installer/Server.wxs
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,10 @@ SPDX-License-Identifier: GPL-3.0-only
Value="[APPLICATIONFOLDER]"
/>
</Component>

<Component Id="COPYING.md">
<File Name="COPYING.md" />
</Component>
</DirectoryRef>

<!-- This will restore the original Windows drivers for devices that were forced bound. -->
Expand All @@ -94,4 +98,10 @@ SPDX-License-Identifier: GPL-3.0-only
<Custom Action="TryStartService" Before="InstallFinalize" Condition="$usbipd.exe=3" />
</InstallExecuteSequence>
</Fragment>
<Fragment>
<ComponentGroup Id="usbipd">
<ComponentRef Id="COPYING.md" />
<ComponentRef Id="usbipd.exe" />
</ComponentGroup>
</Fragment>
</Wix>
2 changes: 1 addition & 1 deletion Installer/UserInterface.wxs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ SPDX-License-Identifier: GPL-3.0-only
<?define WizardH="270" ?>

<?define WizardLineY="234" ?>
<?define WizardLineW="372" ?>
<?define WizardLineW="370" ?>
<?define WizardButtonX1="159" ?>
<?define WizardButtonX2="224" ?>
<?define WizardButtonX3="297" ?>
Expand Down
60 changes: 60 additions & 0 deletions Installer/WSL.wxs
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
SPDX-FileCopyrightText: 2024 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">
<!-- Windows uses uppercase spelling for folders related to WSL (and lowercase for files). -->
<Directory Id="WSL" Name="WSL" />
</DirectoryRef>
</Fragment>
<Fragment>
<DirectoryRef Id="WSL" FileSource="$(var.PublishDir)\WSL">
<Component Id="WSL_README.md">
<File Name="README.md" />
</Component>
<Component Id="usbip">
<File Name="usbip" />
</Component>
<Component Id="auto_attach.sh">
<File Name="auto-attach.sh" />
</Component>
</DirectoryRef>

<!--
This directory gets mounted within WSL, and Linux should not treat ordinary files as executable.
We want to inherit all rights + add a deny for execution of non-executable files.
WiX does not have tooling to add a "deny permission".
NOTE: Add the following for any non-executable files.
-->
<!--
<SetProperty Id="FixExecutionRights_file.id" Value="&quot;[System64Folder]\icacls.exe&quot; &quot;[#file.id]&quot; /deny &quot;*S-1-1-0:(X)&quot;" Sequence="execute" Before="FixExecutionRights_file.id" />
<CustomAction Id="FixExecutionRights_file.id" BinaryRef="Wix4UtilCA_X64" DllEntry="WixQuietExec64" Return="ignore" Impersonate="no" Execute="deferred" />
<InstallExecuteSequence>
<Custom Action="FixExecutionRights_file.id" Before="InstallFinalize" Condition="$file.id=3" />
</InstallExecuteSequence>
-->

<SetProperty Id="FixExecutionRights_WSL_README.md" Value="&quot;[System64Folder]\icacls.exe&quot; &quot;[#WSL_README.md]&quot; /deny &quot;*S-1-1-0:(X)&quot;" Sequence="execute" Before="FixExecutionRights_WSL_README.md" />
<CustomAction Id="FixExecutionRights_WSL_README.md" BinaryRef="Wix4UtilCA_X64" DllEntry="WixQuietExec64" Return="ignore" Impersonate="no" Execute="deferred" />

<InstallExecuteSequence>
<Custom Action="FixExecutionRights_WSL_README.md" After="InstallFiles" Condition="$WSL_README.md=3" />
</InstallExecuteSequence>
</Fragment>
<Fragment>
<ComponentGroup Id="WSL">
<ComponentRef Id="WSL_README.md" />
<ComponentRef Id="usbip" />
<ComponentRef Id="auto_attach.sh" />
</ComponentGroup>
</Fragment>
</Wix>
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
18 changes: 12 additions & 6 deletions Usbipd/Wsl.cs
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,18 @@ async Task OnLine(StreamReader streamReader, bool isStandardError)
/// </summary>
public static async Task<ExitCode> Attach(BusId busId, bool autoAttach, string? distribution, IConsole console, CancellationToken cancellationToken)
{
var wslWindowsPath = Path.Combine(Path.GetDirectoryName(Environment.ProcessPath)!, "WSL");
if (!Path.Exists(wslWindowsPath))
{
console.ReportError($"WSL support was not installed; reinstall this application with the WSL feature enabled.");
return ExitCode.Failure;
}
if ((Path.GetPathRoot(wslWindowsPath) is not string wslWindowsPathRoot) || (!LocalDriveRegex().IsMatch(wslWindowsPathRoot)))
{
console.ReportError($"Option '--wsl' requires that this software is installed on a local drive.");
return ExitCode.Failure;
}

// Figure out which distribution to use. WSL can be in many states:
// (a) not installed at all
// (b) if the user specified one:
Expand Down Expand Up @@ -279,12 +291,6 @@ public static async Task<ExitCode> Attach(BusId busId, bool autoAttach, string?
// NOTE: We don't know the shell type (for example, docker-desktop does not even have bash),
// so be as portable as possible: single line, use 'test', quote all paths, etc.
{
var wslWindowsPath = Path.Combine(Path.GetDirectoryName(Environment.ProcessPath)!, "wsl");
if ((Path.GetPathRoot(wslWindowsPath) is not string wslWindowsPathRoot) || (!LocalDriveRegex().IsMatch(wslWindowsPathRoot)))
{
console.ReportError($"Option '--wsl' requires that this software is installed on a local drive.");
return ExitCode.Failure;
}
var wslResult = await RunWslAsync((distribution, "/"), null, cancellationToken, "/bin/sh", "-c", $$"""
if ! test -d "{{WslMountPoint}}"; then
mkdir -m 0000 "{{WslMountPoint}}";
Expand Down

0 comments on commit a52ac33

Please sign in to comment.