Share some code
MODIFY
WalletWasabi.Packager/Program.cs
WalletWasabi.Packager/Program.cs
@@ -388,34 +388,22 @@ public static class Program
}
Console.WriteLine("Create Linux .tar.gz");
+
if (!Directory.Exists(publishedFolder))
{
throw new Exception($"{publishedFolder} does not exist.");
}
+
var newFolderName = $"Wasabi-{VersionPrefix}";
var newFolderPath = Path.Combine(BinDistDirectory, newFolderName);
Directory.Move(publishedFolder, newFolderPath);
publishedFolder = newFolderPath;
- var driveLetterUpper = BinDistDirectory[0];
- var driveLetterLower = char.ToLower(driveLetterUpper);
-
- var linuxPath = $"/mnt/{driveLetterLower}/{Tools.LinuxPath(BinDistDirectory[3..])}";
-
var chmodExecutablesArgs = "-type f \\( -name 'wassabee' -o -name 'hwi' -o -name 'bitcoind' -o -name 'tor' \\) -exec chmod +x {} \\;";
-
- var commands = new[]
- {
- $"cd /",
- $"sudo umount -l /mnt/{driveLetterLower}",
- $"sudo mount -t drvfs {driveLetterUpper}: /mnt/{driveLetterLower} -o metadata",
- $"cd {linuxPath}",
+ string arguments = BuildWslCommand(BinDistDirectory,
$"sudo find ./{newFolderName} -type f -exec chmod 644 {{}} \\;",
$"sudo find ./{newFolderName} {chmodExecutablesArgs}",
- $"tar -pczvf {newFolderName}.tar.gz {newFolderName}"
- };
-
- string arguments = string.Join(" && ", commands);
+ $"tar -pczvf {newFolderName}.tar.gz {newFolderName}");
StartProcessAndWaitForExit("wsl", BinDistDirectory, arguments: arguments);
@@ -498,20 +486,12 @@ public static class Program
string debExeLinuxPath = Tools.LinuxPathCombine(newFolderRelativePath, ExecutableName);
string debDestopFileLinuxPath = Tools.LinuxPathCombine(debUsrAppFolderRelativePath, $"{ExecutableName}.desktop");
- commands = new[]
- {
- $"cd /",
- $"sudo umount -l /mnt/c",
- $"sudo mount -t drvfs C: /mnt/c -o metadata",
- $"cd {linuxPath}",
+ arguments = BuildWslCommand(BinDistDirectory,
$"sudo find {Tools.LinuxPath(newFolderRelativePath)} -type f -exec chmod 644 {{}} \\;",
$"sudo find {Tools.LinuxPath(newFolderRelativePath)} {chmodExecutablesArgs}",
$"sudo chmod -R 0775 {Tools.LinuxPath(debianFolderRelativePath)}",
$"sudo chmod -R 0644 {debDestopFileLinuxPath}",
- $"dpkg --build {Tools.LinuxPath(debFolderRelativePath)} $(pwd)"
- };
-
- arguments = string.Join(" && ", commands);
+ $"dpkg --build {Tools.LinuxPath(debFolderRelativePath)} $(pwd)");
StartProcessAndWaitForExit("wsl", BinDistDirectory, arguments: arguments);
@@ -527,6 +507,22 @@ public static class Program
}
}
+ private static string BuildWslCommand(string windowsPath, params string[] commands)
+ {
+ string wslPath = Tools.Win2WslPath(windowsPath, out char driveLetterUpper);
+ char driveLetterLower = char.ToLower(driveLetterUpper);
+
+ string[] allCommands = new string[]
+ {
+ $"cd /",
+ $"sudo umount -l /mnt/{driveLetterLower}",
+ $"sudo mount -t drvfs {driveLetterUpper}: /mnt/{driveLetterLower} -o metadata",
+ $"cd {wslPath}",
+ }.Concat(commands).ToArray();
+
+ return string.Join(" && ", allCommands);
+ }
+
/// <summary>Checks whether there are uncommitted changes.</summary>
/// <remarks>This is important to really release a build that corresponds with a git hash.</remarks>
private static void CheckUncommittedGitChanges()

MODIFY
WalletWasabi.Packager/Tools.cs
WalletWasabi.Packager/Tools.cs
@@ -52,6 +52,17 @@ public static class Tools
return path.Replace(@"\", @"/");
}
+ /// <summary>Converts a Windows path to a WSL path.</summary>
+ /// <param name="windowsPath">Full Windows path (e.g. <c>C:\something\something</c>).</param>
+ /// <param name="driveLetterUpper">Output parameter with capital drive letter of <paramref name="windowsPath"/>.</param>
+ /// <returns>WSL path corresponding with <paramref name="windowsPath"/> (e.g. <c>/mnt/c/something/something</c>).</returns>
+ /// <remarks>Supports both WSL 1 and WSL 2.</remarks>
+ public static string Win2WslPath(string windowsPath, out char driveLetterUpper)
+ {
+ driveLetterUpper = char.ToUpper(windowsPath[0]);
+ return $"/mnt/{char.ToLower(driveLetterUpper)}/{LinuxPath(windowsPath[3..])}";
+ }
+
public static long DirSize(DirectoryInfo d)
{
long size = 0;

Share some code