From da601be07e49f3035e571b49149c9d6aff26b190 Mon Sep 17 00:00:00 2001 From: Ben Olden-Cooligan Date: Sun, 31 Mar 2024 23:17:19 -0700 Subject: [PATCH] Tools: Sign RPMs #335 --- .../Project/Packaging/PackageCommand.cs | 2 +- NAPS2.Tools/Project/Packaging/RpmPackager.cs | 23 +++++++++++++------ 2 files changed, 17 insertions(+), 8 deletions(-) diff --git a/NAPS2.Tools/Project/Packaging/PackageCommand.cs b/NAPS2.Tools/Project/Packaging/PackageCommand.cs index f89f8fe686..fbe378da70 100644 --- a/NAPS2.Tools/Project/Packaging/PackageCommand.cs +++ b/NAPS2.Tools/Project/Packaging/PackageCommand.cs @@ -42,7 +42,7 @@ public int Run(PackageOptions opts) DebPackager.PackageDeb(GetPackageInfoForConfig()); break; case PackageType.Rpm: - RpmPackager.PackageRpm(GetPackageInfoForConfig()); + RpmPackager.PackageRpm(GetPackageInfoForConfig(), opts.NoSign); break; case PackageType.Flatpak: FlatpakPackager.Package(GetPackageInfoForConfig(), opts.NoPre); diff --git a/NAPS2.Tools/Project/Packaging/RpmPackager.cs b/NAPS2.Tools/Project/Packaging/RpmPackager.cs index a1d889badb..b930b6feda 100644 --- a/NAPS2.Tools/Project/Packaging/RpmPackager.cs +++ b/NAPS2.Tools/Project/Packaging/RpmPackager.cs @@ -4,7 +4,7 @@ namespace NAPS2.Tools.Project.Packaging; public static class RpmPackager { - public static void PackageRpm(PackageInfo pkgInfo) + public static void PackageRpm(PackageInfo pkgInfo, bool noSign) { var rpmPath = pkgInfo.GetPath("rpm"); Output.Info($"Packaging rpm: {rpmPath}"); @@ -12,7 +12,8 @@ public static void PackageRpm(PackageInfo pkgInfo) Output.Verbose("Building binaries"); var runtimeId = pkgInfo.Platform == Platform.LinuxArm ? "linux-arm64" : "linux-x64"; Cli.Run("dotnet", $"clean NAPS2.App.Gtk -c Release -r {runtimeId}"); - Cli.Run("dotnet", $"publish NAPS2.App.Gtk -c Release -r {runtimeId} --self-contained /p:DebugType=None /p:DebugSymbols=false"); + Cli.Run("dotnet", + $"publish NAPS2.App.Gtk -c Release -r {runtimeId} --self-contained /p:DebugType=None /p:DebugSymbols=false"); Output.Verbose("Creating package"); @@ -61,21 +62,29 @@ public static void PackageRpm(PackageInfo pkgInfo) File.Copy( Path.Combine(Paths.SolutionRoot, "LICENSE"), Path.Combine(targetDir, "LICENSE.txt")); - + // Create symlinks var binDir = Path.Combine(filesDir, "usr/bin"); Directory.CreateDirectory(binDir); Cli.Run("ln", $"-s /usr/lib/naps2/naps2 {Path.Combine(binDir, "naps2")}"); - + // Compress files - Cli.Run("tar", $"-zcvf {workingDir}/SOURCES/naps2-{pkgInfo.VersionNumber}.tar.gz {Path.GetFileName(filesDir)}", workingDir: workingDir); - + Cli.Run("tar", $"-zcvf {workingDir}/SOURCES/naps2-{pkgInfo.VersionNumber}.tar.gz {Path.GetFileName(filesDir)}", + workingDir: workingDir); + // Build RPM var arch = pkgInfo.Platform == Platform.LinuxArm ? "aarch64" : "x86_64"; Cli.Run("rpmbuild", $"{dirArg} -ba --target {arch} {workingDir}/SPECS/naps2.spec"); + var sourceRpmPath = Path.Combine(workingDir, $"RPMS/{arch}/naps2-{pkgInfo.VersionNumber}-1.{arch}.rpm"); + + // Sign + if (!noSign) + { + Cli.Run("rpmsign", $"--addsign {sourceRpmPath}"); + } // Copy to output - File.Copy(Path.Combine(workingDir, $"RPMS/{arch}/naps2-{pkgInfo.VersionNumber}-1.{arch}.rpm"), rpmPath, true); + File.Copy(sourceRpmPath, rpmPath, true); Output.OperationEnd($"Packaged rpm: {rpmPath}"); }