From ff66e66f214f22d5631a65af52b07750997e2c0b Mon Sep 17 00:00:00 2001 From: Dennis Reimann Date: Mon, 30 May 2022 11:36:25 +0200 Subject: [PATCH] PluginPacker: Shell fallback for macOS/Linux --- BTCPayServer.PluginPacker/Program.cs | 44 ++++++++++++++++++---------- 1 file changed, 29 insertions(+), 15 deletions(-) diff --git a/BTCPayServer.PluginPacker/Program.cs b/BTCPayServer.PluginPacker/Program.cs index 5c3778260..0987d6bba 100644 --- a/BTCPayServer.PluginPacker/Program.cs +++ b/BTCPayServer.PluginPacker/Program.cs @@ -66,31 +66,45 @@ namespace BTCPayServer.PluginPacker File.Delete(sha256dirs); } await File.WriteAllTextAsync(sha256dirs, sha256sums.ToString()); + + // try Windows executable first, fall back to macOS/Linux PowerShell try { - Process cmd = new(); - cmd.StartInfo.FileName = "powershell.exe"; - cmd.StartInfo.RedirectStandardInput = true; - cmd.StartInfo.RedirectStandardOutput = true; - cmd.StartInfo.CreateNoWindow = false; - cmd.StartInfo.UseShellExecute = false; - cmd.Start(); - - await cmd.StandardInput.WriteLineAsync($"cat {sha256dirs} | gpg -s > {Path.Combine(outputDir, "SHA256SUMS.asc")}"); - await cmd.StandardInput.FlushAsync(); - cmd.StandardInput.Close(); - await cmd.WaitForExitAsync(); - Console.WriteLine(await cmd.StandardOutput.ReadToEndAsync()); - + await CreateShasums("powershell.exe", sha256dirs, outputDir); } catch (Exception e) { - Console.WriteLine($"Attempted to sign hashes with gpg but maybe powershell is not installed?\n{e.Message}"); + try + { + await CreateShasums("bash", sha256dirs, outputDir); + } + catch (Exception ex) + { + Console.WriteLine( + $"Attempted to sign hashes with gpg but maybe powershell is not installed?\n{ex.Message}"); + } } Console.WriteLine($"Created {outputFile}.btcpay at {directory}"); } + private static async Task CreateShasums(string exec, string sha256dirs, string outputDir) + { + Process cmd = new(); + cmd.StartInfo.FileName = exec; + cmd.StartInfo.RedirectStandardInput = true; + cmd.StartInfo.RedirectStandardOutput = true; + cmd.StartInfo.CreateNoWindow = false; + cmd.StartInfo.UseShellExecute = false; + cmd.Start(); + + await cmd.StandardInput.WriteLineAsync($"cat {sha256dirs} | gpg -s > {Path.Combine(outputDir, "SHA256SUMS.asc")}"); + await cmd.StandardInput.FlushAsync(); + cmd.StandardInput.Close(); + await cmd.WaitForExitAsync(); + Console.WriteLine(await cmd.StandardOutput.ReadToEndAsync()); + } + private static Type[] GetAllExtensionTypesFromAssembly(Assembly assembly) { return assembly.GetTypes().Where(type =>