PluginPacker: Shell fallback for macOS/Linux

This commit is contained in:
Dennis Reimann
2022-05-30 11:36:25 +02:00
committed by Andrew Camilleri
parent b1f62f74cd
commit ff66e66f21

View File

@@ -66,31 +66,45 @@ namespace BTCPayServer.PluginPacker
File.Delete(sha256dirs); File.Delete(sha256dirs);
} }
await File.WriteAllTextAsync(sha256dirs, sha256sums.ToString()); await File.WriteAllTextAsync(sha256dirs, sha256sums.ToString());
// try Windows executable first, fall back to macOS/Linux PowerShell
try try
{ {
Process cmd = new(); await CreateShasums("powershell.exe", sha256dirs, outputDir);
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());
} }
catch (Exception e) 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}"); 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) private static Type[] GetAllExtensionTypesFromAssembly(Assembly assembly)
{ {
return assembly.GetTypes().Where(type => return assembly.GetTypes().Where(type =>