diff --git a/.gitignore b/.gitignore index 2c2075f..9c9168e 100644 --- a/.gitignore +++ b/.gitignore @@ -349,3 +349,5 @@ healthchecksdb MigrationBackup/ .idea/ + +repomgr diff --git a/RepoMgr.cs b/RepoMgr.cs index 4e87308..54855c0 100644 --- a/RepoMgr.cs +++ b/RepoMgr.cs @@ -76,23 +76,16 @@ namespace repomgr UpdatePackage(package); if (File.ReadAllText(Path.Combine(_pkgpath, package.Name, "PKGBUILD")).Contains("pkgver()")) Shell.Exec("makepkg -os --noconfirm", Path.Combine(_pkgpath, package.Name)); - package.CurrentVersion = - File.ReadAllText(Path.Combine(_pkgpath, package.Name, "PKGBUILD")) - .Split("\n") - .First(p => p.StartsWith("pkgver=")) - .Split("pkgver=")[1]; - package.CurrentVersion += "-" + - File.ReadAllText(Path.Combine(_pkgpath, package.Name, "PKGBUILD")) - .Split("\n") - .First(p => p.StartsWith("pkgrel=")) - .Split("pkgrel=")[1]; + package.CurrentVersion = Shell.ExecR("source PKGBUILD; echo \"$pkgver-$pkgrel\"", Path.Combine(_pkgpath, package.Name)); WriteIndex(); - if (package.CurrentVersion != package.RepoVersion || force) - Shell.Exec("makepkg -csf --sign --noconfirm 2>&1| tee buildlog.txt", Path.Combine(_pkgpath, package.Name)); + if (force) + Shell.Exec("makepkg -Ccsf --sign --noconfirm 2>&1| tee buildlog.txt", Path.Combine(_pkgpath, package.Name)); + else if (package.CurrentVersion != package.RepoVersion) + Shell.Exec("makepkg -Ccs --sign --noconfirm 2>&1| tee buildlog.txt", Path.Combine(_pkgpath, package.Name)); else return; var resultingPackages = Directory - .GetFiles(Path.Combine(_pkgpath, package.Name), $"{package.Name}*{package.CurrentVersion}*.tar*"); + .GetFiles(Path.Combine(_pkgpath, package.Name), "*.pkg.tar*"); if (resultingPackages.Length < 1) { package.LastBuildSucceeded = false; @@ -100,16 +93,26 @@ namespace repomgr } package.LastBuildSucceeded = true; + if (package.PkgFiles.Any()) + { + foreach (var pkgFile in package.PkgFiles) + if (File.Exists(Path.Combine(_repo.Path, pkgFile))) + File.Delete(Path.Combine(_repo.Path, pkgFile)); + package.PkgFiles.Clear(); + } + foreach (var resultingPackage in resultingPackages.Where(p => p.EndsWith(".sig"))) { File.Copy(resultingPackage, Path.Combine(_repo.Path, Path.GetFileName(resultingPackage)), true); File.Delete(resultingPackage); + package.PkgFiles.Add(Path.GetFileName(resultingPackage)); } foreach (var resultingPackage in resultingPackages.Where(p => !p.EndsWith(".sig"))) { File.Copy(resultingPackage, Path.Combine(_repo.Path, Path.GetFileName(resultingPackage)), true); File.Delete(resultingPackage); + package.PkgFiles.Add(Path.GetFileName(resultingPackage)); Shell.Exec($"repo-add --remove --sign {_repo.Name}.db.tar.gz {Path.GetFileName(resultingPackage)} 2>&1| tee -a {Path.Combine(_buildpath, "repolog.txt")}", _repo.Path); } package.RepoVersion = package.CurrentVersion; @@ -121,15 +124,20 @@ namespace repomgr if (Directory.Exists(packageDir)) Directory.Delete(packageDir, true); Shell.Exec($"repo-remove --sign {_repo.Name}.db.tar.gz {package.Name} 2>&1| tee -a {Path.Combine(_buildpath, "repolog.txt")}", _repo.Path); - foreach (var file in Directory.GetFiles(_repo.Path, $"{package.Name}*.tar*")) - File.Delete(file); + if (package.PkgFiles.Any()) + { + foreach (var pkgFile in package.PkgFiles) + if (File.Exists(Path.Combine(_repo.Path, pkgFile))) + File.Delete(Path.Combine(_repo.Path, pkgFile)); + package.PkgFiles.Clear(); + } _repo.Packages.Remove(package); WriteIndex(); } public void List() { Console.WriteLine(Shell.Yellow($"{Shell.Bold(_repo.Name)} ({_repo.Packages.Count} packages):")); - foreach (var package in _repo.Packages) + foreach (var package in _repo.Packages.OrderBy(p => p.Name)) { var line = $"{Shell.Bold(package.Name)}"; if (package.RepoVersion != package.CurrentVersion) @@ -265,6 +273,7 @@ namespace repomgr public string CurrentVersion = "never-updated"; public string RepoVersion = "nA"; public bool LastBuildSucceeded = true; + public readonly List PkgFiles = new List(); } internal static class Shell @@ -289,6 +298,29 @@ namespace repomgr process.Start(); process.WaitForExit(); } + + public static string ExecR(string cmd, string workingDirectory) + { + var escapedArgs = cmd.Replace("\"", "\\\""); + + var process = new Process() + { + StartInfo = new ProcessStartInfo + { + FileName = "/bin/bash", + Arguments = $"-c \"{escapedArgs}\"", + WorkingDirectory = workingDirectory, + RedirectStandardOutput = true, + RedirectStandardError = true, + UseShellExecute = false, + CreateNoWindow = true, + } + }; + process.Start(); + var stdout = process.StandardOutput.ReadToEnd(); + process.WaitForExit(); + return stdout.Trim(); + } public static string Bold(string s) { diff --git a/repomgr.csproj b/repomgr.csproj index 2f84e1e..cb248c7 100644 --- a/repomgr.csproj +++ b/repomgr.csproj @@ -3,6 +3,9 @@ netcoreapp2.2 full + Debug;Release + AnyCPU + linux-x64 diff --git a/repomgr.sln b/repomgr.sln index 4546565..4380556 100644 --- a/repomgr.sln +++ b/repomgr.sln @@ -8,9 +8,9 @@ Global Release|Any CPU = Release|Any CPU EndGlobalSection GlobalSection(ProjectConfigurationPlatforms) = postSolution - {86A2FA88-E7F3-44AD-9279-CBE5318F792F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {86A2FA88-E7F3-44AD-9279-CBE5318F792F}.Debug|Any CPU.Build.0 = Debug|Any CPU {86A2FA88-E7F3-44AD-9279-CBE5318F792F}.Release|Any CPU.ActiveCfg = Release|Any CPU {86A2FA88-E7F3-44AD-9279-CBE5318F792F}.Release|Any CPU.Build.0 = Release|Any CPU + {86A2FA88-E7F3-44AD-9279-CBE5318F792F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {86A2FA88-E7F3-44AD-9279-CBE5318F792F}.Debug|Any CPU.Build.0 = Debug|Any CPU EndGlobalSection EndGlobal