diff --git a/Pages/Index.cshtml b/Pages/Index.cshtml
index 6bfe442..64c369b 100644
--- a/Pages/Index.cshtml
+++ b/Pages/Index.cshtml
@@ -1,4 +1,5 @@
@page
+@using System.Web
@model IndexModel
@{
ViewData["Title"] = "Builds";
@@ -40,7 +41,7 @@
}
@if (System.IO.File.Exists(System.IO.Path.Combine(Program.Repo._pkgpath, p.Name, "buildlog.txt")))
{
-
View Build log |
+ View Build log |
}
else
{
diff --git a/Program.cs b/Program.cs
index d0de94d..3d5311f 100644
--- a/Program.cs
+++ b/Program.cs
@@ -6,148 +6,130 @@ using System.Threading.Tasks;
using Microsoft.AspNetCore;
using Microsoft.AspNetCore.Hosting;
using Microsoft.Extensions.Configuration;
+using Microsoft.Extensions.Hosting;
using Microsoft.Extensions.Logging;
-namespace repomgr
-{
- public static class Program
- {
- public static RepoMgr Repo;
+namespace repomgr {
+ public static class Program {
+ public static RepoMgr Repo;
- public static void Main(string[] args)
- {
- if (File.Exists("/tmp/repomgr.lock") && args[1] != "daemon")
- {
- Console.WriteLine("/tmp/repomgr.lock exists, delete it if you are sure no other process is running");
- Environment.Exit(1);
- }
- else if (args[1] != "daemon")
- {
- File.Create("/tmp/repomgr.lock");
- }
+ public static void Main(string[] args) {
+ if (File.Exists("/tmp/repomgr.lock") && args[1] != "daemon") {
+ Console.WriteLine("/tmp/repomgr.lock exists, delete it if you are sure no other process is running");
+ Environment.Exit(1);
+ }
+ else if (args[1] != "daemon") {
+ File.Create("/tmp/repomgr.lock");
+ }
- if (args.Length < 2 || args[1].Equals("help"))
- PrintHelp();
- Repo = new RepoMgr(args[0]);
- if (File.Exists(Path.Combine(args[0], "repomgr.index.json")))
- Repo.ReadIndex();
- switch (args[1])
- {
- case "daemon":
- CreateWebHostBuilder(args).Build().Run();
- break;
- case "init":
- if (args.Length != 4)
- PrintHelp();
- try
- {
- Repo.Init(args[2], args[3]);
- }
- catch (Exception e)
- {
- Console.WriteLine("Init failed with error: " + e);
- }
+ if (args.Length < 2 || args[1].Equals("help"))
+ PrintHelp();
- break;
- case "add":
- if (args.Length != 3)
- PrintHelp();
- try
- {
- Repo.Add(args[2]);
- }
- catch (Exception e)
- {
- Console.WriteLine("Add failed with error: " + e);
- }
+ Repo = new RepoMgr(args[0]);
+ if (File.Exists(Path.Combine(args[0], "repomgr.index.json")))
+ Repo.ReadIndex();
+ switch (args[1]) {
+ case "daemon":
+ CreateHostBuilder(args).Build().Run();
+ break;
+ case "init":
+ if (args.Length != 4)
+ PrintHelp();
+ try {
+ Repo.Init(args[2], args[3]);
+ }
+ catch (Exception e) {
+ Console.WriteLine("Init failed with error: " + e);
+ }
- break;
- case "update":
- if (args.Length < 3 || args.Length > 4)
- PrintHelp();
- try
- {
- switch (args.Length)
- {
- case 3:
- Repo.Build(args[2]);
- break;
- case 4 when args[3] == "-f":
- Repo.Build(args[2], true);
- break;
- default:
- PrintHelp();
- break;
- }
- }
- catch (Exception e)
- {
- Console.WriteLine("Build failed with error: " + e);
- }
+ break;
+ case "add":
+ if (args.Length != 3)
+ PrintHelp();
+ try {
+ Repo.Add(args[2]);
+ }
+ catch (Exception e) {
+ Console.WriteLine("Add failed with error: " + e);
+ }
- break;
- case "update-all":
- if (args.Length != 2)
- PrintHelp();
- try
- {
- Repo.BuildAll();
- }
- catch (Exception e)
- {
- Console.WriteLine("BuildAll failed with error: " + e);
- }
+ break;
+ case "update":
+ if (args.Length < 3 || args.Length > 4)
+ PrintHelp();
+ try {
+ switch (args.Length) {
+ case 3:
+ Repo.Build(args[2]);
+ break;
+ case 4 when args[3] == "-f":
+ Repo.Build(args[2], true);
+ break;
+ default:
+ PrintHelp();
+ break;
+ }
+ }
+ catch (Exception e) {
+ Console.WriteLine("Build failed with error: " + e);
+ }
- break;
- case "remove":
- if (args.Length != 3)
- PrintHelp();
- try
- {
- Repo.Remove(args[2]);
- }
- catch (Exception e)
- {
- Console.WriteLine("Remove failed with error: " + e);
- }
+ break;
+ case "update-all":
+ if (args.Length != 2)
+ PrintHelp();
+ try {
+ Repo.BuildAll();
+ }
+ catch (Exception e) {
+ Console.WriteLine("BuildAll failed with error: " + e);
+ }
- break;
- case "list":
- if (args.Length != 2)
- PrintHelp();
- try
- {
- Repo.List();
- }
- catch (Exception e)
- {
- Console.WriteLine("List failed with error " + e);
- }
+ break;
+ case "remove":
+ if (args.Length != 3)
+ PrintHelp();
+ try {
+ Repo.Remove(args[2]);
+ }
+ catch (Exception e) {
+ Console.WriteLine("Remove failed with error: " + e);
+ }
- break;
- default:
- PrintHelp();
- break;
- }
- if (File.Exists("/tmp/repomgr.lock"))
- File.Delete("/tmp/repomgr.lock");
- }
+ break;
+ case "list":
+ if (args.Length != 2)
+ PrintHelp();
+ try {
+ Repo.List();
+ }
+ catch (Exception e) {
+ Console.WriteLine("List failed with error " + e);
+ }
- private static void PrintHelp()
- {
- //TODO: add/remove [...]
- Console.WriteLine("Usage:");
- Console.WriteLine("repomgr init ");
- Console.WriteLine("repomgr list");
- Console.WriteLine("repomgr add ");
- Console.WriteLine("repomgr remove ");
- Console.WriteLine("repomgr update [-f]");
- Console.WriteLine("repomgr update-all");
- Console.WriteLine("repomgr daemon");
- }
+ break;
+ default:
+ PrintHelp();
+ break;
+ }
- private static IWebHostBuilder CreateWebHostBuilder(string[] args) =>
- WebHost.CreateDefaultBuilder(args)
- .UseStartup();
- }
+ if (File.Exists("/tmp/repomgr.lock"))
+ File.Delete("/tmp/repomgr.lock");
+ }
+
+ private static void PrintHelp() {
+ //TODO: add/remove [...]
+ Console.WriteLine("Usage:");
+ Console.WriteLine("repomgr init ");
+ Console.WriteLine("repomgr list");
+ Console.WriteLine("repomgr add ");
+ Console.WriteLine("repomgr remove ");
+ Console.WriteLine("repomgr update [-f]");
+ Console.WriteLine("repomgr update-all");
+ Console.WriteLine("repomgr daemon");
+ }
+
+ public static IHostBuilder CreateHostBuilder(string[] args) =>
+ Host.CreateDefaultBuilder(args).ConfigureWebHostDefaults(webBuilder => { webBuilder.UseStartup(); });
+ }
}
\ No newline at end of file
diff --git a/RepoMgr.cs b/RepoMgr.cs
index 556e1de..3e482a2 100644
--- a/RepoMgr.cs
+++ b/RepoMgr.cs
@@ -6,343 +6,309 @@ using System.Linq;
using LibGit2Sharp;
using System.Diagnostics;
-namespace repomgr
-{
- public class RepoMgr
- {
- public RepoMgr(string buildpath)
- {
- _buildpath = Path.GetFullPath(buildpath);
- _pkgpath = Path.Combine(_buildpath, "pkg");
- }
+namespace repomgr {
+ public class RepoMgr {
+ public RepoMgr(string buildpath) {
+ _buildpath = Path.GetFullPath(buildpath);
+ _pkgpath = Path.Combine(_buildpath, "pkg");
+ }
- public readonly string _buildpath;
- public readonly string _pkgpath;
- public Repository _repo;
- public void Init(string repopath, string reponame)
- {
- _repo = new Repository(repopath, reponame);
- if (!Directory.Exists(repopath))
- Directory.CreateDirectory(repopath);
- WriteIndex();
- Console.WriteLine("Initialized.");
- }
- public void Add(string package)
- {
- Package pkg;
- if (Directory.Exists(Path.Combine(_pkgpath, package)))
- {
- if (_repo.Packages.Find(p => p.Name.Equals(package)) != null)
- {
- Console.WriteLine("Package already exists.");
- return;
- }
-
- if (!CheckPackage(package))
- {
- throw new Exception("Package directory exists but is invalid (PKGBUILD or .git missing)");
- }
- pkg = new Package(package);
- }
- else
- {
- if (_repo.Packages.Find(p => p.Name.Equals(package)) != null)
- _repo.Packages.RemoveAll(p => p.Name.Equals(package));
- try
- {
- var refcount = LibGit2Sharp.Repository.ListRemoteReferences($"https://aur.archlinux.org/{package}.git").Count();
- if (refcount < 1)
- {
- throw new Exception("git clone failed: Package doesn't exist in remote");
- }
+ public readonly string _buildpath;
+ public readonly string _pkgpath;
+ public Repository _repo;
- LibGit2Sharp.Repository.Clone($"https://aur.archlinux.org/{package}.git",
- Path.Combine(_pkgpath, package));
- }
- catch (Exception e)
- {
- throw new Exception($"Error during clone: {e}");
- }
-
- pkg = new Package(package);
- }
-
- Console.WriteLine($"Adding package {package}...");
- _repo.Packages.Add(pkg);
- WriteIndex();
- }
- private void Build(Package package, bool force = false)
- {
- if (UpdateAvailable(package))
- 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 = Shell.ExecR("source PKGBUILD; echo \"$pkgver-$pkgrel\"", Path.Combine(_pkgpath, package.Name));
- WriteIndex();
- 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;
+ public void Init(string repopath, string reponame) {
+ _repo = new Repository(repopath, reponame);
+ if (!Directory.Exists(repopath))
+ Directory.CreateDirectory(repopath);
+ WriteIndex();
+ Console.WriteLine("Initialized.");
+ }
- var resultingPackages = Directory
- .GetFiles(Path.Combine(_pkgpath, package.Name), "*.pkg.tar*");
- if (resultingPackages.Length < 1)
- {
- package.LastBuildSucceeded = false;
- throw new Exception("makepkg didn't build any package");
- }
+ public void Add(string package) {
+ Package pkg;
+ if (Directory.Exists(Path.Combine(_pkgpath, package))) {
+ if (_repo.Packages.Find(p => p.Name.Equals(package)) != null) {
+ Console.WriteLine("Package already exists.");
+ return;
+ }
- 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)}", _repo.Path);
- }
- package.RepoVersion = package.CurrentVersion;
- WriteIndex();
- }
- private void Remove(Package package)
- {
- var packageDir = Path.Combine(_pkgpath, package.Name);
- if (Directory.Exists(packageDir))
- Directory.Delete(packageDir, true);
- Shell.Exec($"repo-remove --sign {_repo.Name}.db.tar.gz {package.Name}", _repo.Path);
- 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.OrderBy(p => p.Name))
- {
- var line = $"{Shell.Bold(package.Name)}";
- if (package.RepoVersion != package.CurrentVersion)
- line += $" ({Shell.Red(package.RepoVersion)} {Shell.Gray("->")} {Shell.Yellow(package.CurrentVersion)})";
- else
- line += $" ({Shell.Green(package.RepoVersion)})";
- if (package.LastBuildSucceeded)
- line += $" [{Shell.Green(Shell.Bold("BUILD PASSING"))}]";
- else
- line += $" [{Shell.Red(Shell.Bold("BUILD FAILING"))}]";
- Console.WriteLine(line);
- }
- }
-
- // util stuff
- private Package GetPackage(string package)
- {
- var pkg = _repo.Packages.FirstOrDefault(p => p.Name.Equals(package));
- if (pkg != null) return pkg;
- throw new Exception("Package not found.");
- }
- // git fetch, returns true if differences between origin/master and master found
- private bool UpdateAvailable(Package package)
- {
- var repo = new LibGit2Sharp.Repository(Path.Combine(_pkgpath, package.Name));
- var remote = repo.Network.Remotes["origin"];
- var refSpecs = remote.FetchRefSpecs.Select(x => x.Specification);
- Commands.Fetch(repo, remote.Name, refSpecs, null, null);
-
- return repo.Diff.Compare(repo.Branches["origin/master"].Tip.Tree,
- DiffTargets.Index | DiffTargets.WorkingDirectory).Any();
- }
- // resets master to origin/master
- private void UpdatePackage(Package package)
- {
- var repo = new LibGit2Sharp.Repository(Path.Combine(_pkgpath, package.Name));
- var originMaster = repo.Branches["origin/master"];
- repo.Reset(ResetMode.Hard, originMaster.Tip);
- }
- public void ReadIndex()
- {
- try
- {
- _repo = JsonConvert.DeserializeObject(
- File.ReadAllText(Path.Combine(_buildpath, "repomgr.index.json")));
- }
- catch (IOException)
- {
- throw new Exception("configuration file not found or wrong permissions. Did you run repomgr init?");
- }
- catch (JsonException)
- {
- throw new Exception("configuration corrupt. Please check manually or re-init repo.");
- }
- }
- private void WriteIndex()
- {
- try
- {
- var json = JsonConvert.SerializeObject(_repo);
- if (!Directory.Exists(_buildpath))
- Directory.CreateDirectory(_buildpath);
- File.WriteAllText(Path.Combine(_buildpath, "repomgr.index.json"), json);
- }
- catch (IOException)
- {
- throw new Exception("Unable to write configuration. Check permissions.");
- }
- }
- private bool CheckPackage(string package)
- {
- return Directory.Exists(Path.Combine(_pkgpath, package, ".git")) &&
- File.Exists(Path.Combine(_pkgpath, package, "PKGBUILD"));
- }
- public void Build(string package, bool force = false)
- {
- if (!CheckPackage(package)) return;
- var iPackage = GetPackage(package);
- try
- {
- Build(iPackage, force);
- }
- catch (Exception)
- {
- iPackage.LastBuildSucceeded = false;
- throw;
- }
- }
- public void BuildAll()
- {
- foreach (var package in _repo.Packages)
- {
- if (!CheckPackage(package.Name)) return;
- try
- {
- Build(package);
- }
- catch (Exception)
- {
- package.LastBuildSucceeded = false;
- }
- }
- }
- public void Remove(string package)
- {
- if (CheckPackage(package))
- Remove(GetPackage(package));
- }
- }
+ if (!CheckPackage(package)) {
+ throw new Exception("Package directory exists but is invalid (PKGBUILD or .git missing)");
+ }
- public class Repository
- {
- public Repository(string path, string name)
- {
- Path = path;
- Name = name;
- Packages = new List();
- }
+ pkg = new Package(package);
+ }
+ else {
+ if (_repo.Packages.Find(p => p.Name.Equals(package)) != null)
+ _repo.Packages.RemoveAll(p => p.Name.Equals(package));
+ try {
+ var refcount = LibGit2Sharp.Repository.ListRemoteReferences($"https://aur.archlinux.org/{package}.git").Count();
+ if (refcount < 1) {
+ throw new Exception("git clone failed: Package doesn't exist in remote");
+ }
- public readonly string Path;
- public readonly string Name;
- public readonly List Packages;
- }
+ LibGit2Sharp.Repository.Clone($"https://aur.archlinux.org/{package}.git", Path.Combine(_pkgpath, package));
+ }
+ catch (Exception e) {
+ throw new Exception($"Error during clone: {e}");
+ }
- public class Package
- {
- public Package(string name)
- {
- Name = name;
- }
+ pkg = new Package(package);
+ }
- public readonly string Name;
- public string CurrentVersion = "never-updated";
- public string RepoVersion = "nA";
- public bool LastBuildSucceeded = true;
- public readonly List PkgFiles = new List();
- }
+ Console.WriteLine($"Adding package {package}...");
+ _repo.Packages.Add(pkg);
+ WriteIndex();
+ }
- internal static class Shell
- {
- public static void Exec(string cmd, string workingDirectory)
- {
- var escapedArgs = cmd.Replace("\"", "\\\"");
-
- var process = new Process()
- {
- StartInfo = new ProcessStartInfo
- {
- FileName = "/bin/bash",
- Arguments = $"-c \"{escapedArgs}\"",
- WorkingDirectory = workingDirectory,
- RedirectStandardOutput = false,
- RedirectStandardError = false,
- UseShellExecute = false,
- CreateNoWindow = true,
- }
- };
- 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();
- }
+ private void Build(Package package, bool force = false) {
+ if (UpdateAvailable(package))
+ 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 = Shell.ExecR("source PKGBUILD; echo \"$pkgver-$pkgrel\"", Path.Combine(_pkgpath, package.Name));
+ WriteIndex();
+ 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;
- public static string Bold(string s)
- {
- return $"\x1B[1m{s}\x1B[21m";
- }
+ var resultingPackages = Directory.GetFiles(Path.Combine(_pkgpath, package.Name), "*.pkg.tar*");
+ if (resultingPackages.Length < 1) {
+ package.LastBuildSucceeded = false;
+ throw new Exception("makepkg didn't build any package");
+ }
- public static string Red(string s)
- {
- return $"\x1b[31m{s}\x1b[39m";
- }
- public static string Yellow(string s)
- {
- return $"\x1b[33m{s}\x1b[39m";
- }
- public static string Green(string s)
- {
- return $"\x1b[32m{s}\x1b[39m";
- }
- public static string Gray(string s)
- {
- return $"\x1b[90m{s}\x1b[39m";
- }
- }
+ 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)}", _repo.Path);
+ }
+
+ package.RepoVersion = package.CurrentVersion;
+ WriteIndex();
+ }
+
+ private void Remove(Package package) {
+ var packageDir = Path.Combine(_pkgpath, package.Name);
+ if (Directory.Exists(packageDir))
+ Directory.Delete(packageDir, true);
+ Shell.Exec($"repo-remove --sign {_repo.Name}.db.tar.gz {package.Name}", _repo.Path);
+ 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.OrderBy(p => p.Name)) {
+ var line = $"{Shell.Bold(package.Name)}";
+ if (package.RepoVersion != package.CurrentVersion)
+ line += $" ({Shell.Red(package.RepoVersion)} {Shell.Gray("->")} {Shell.Yellow(package.CurrentVersion)})";
+ else
+ line += $" ({Shell.Green(package.RepoVersion)})";
+ if (package.LastBuildSucceeded)
+ line += $" [{Shell.Green(Shell.Bold("BUILD PASSING"))}]";
+ else
+ line += $" [{Shell.Red(Shell.Bold("BUILD FAILING"))}]";
+ Console.WriteLine(line);
+ }
+ }
+
+ // util stuff
+ private Package GetPackage(string package) {
+ var pkg = _repo.Packages.FirstOrDefault(p => p.Name.Equals(package));
+ if (pkg != null)
+ return pkg;
+
+ throw new Exception("Package not found.");
+ }
+
+ // git fetch, returns true if differences between origin/master and master found
+ private bool UpdateAvailable(Package package) {
+ var repo = new LibGit2Sharp.Repository(Path.Combine(_pkgpath, package.Name));
+ var remote = repo.Network.Remotes["origin"];
+ var refSpecs = remote.FetchRefSpecs.Select(x => x.Specification);
+ Commands.Fetch(repo, remote.Name, refSpecs, null, null);
+
+ return repo.Diff.Compare(repo.Branches["origin/master"].Tip.Tree, DiffTargets.Index | DiffTargets.WorkingDirectory).Any();
+ }
+
+ // resets master to origin/master
+ private void UpdatePackage(Package package) {
+ var repo = new LibGit2Sharp.Repository(Path.Combine(_pkgpath, package.Name));
+ var originMaster = repo.Branches["origin/master"];
+ repo.Reset(ResetMode.Hard, originMaster.Tip);
+ repo.RemoveUntrackedFiles();
+ }
+
+ public void ReadIndex() {
+ try {
+ _repo = JsonConvert.DeserializeObject(File.ReadAllText(Path.Combine(_buildpath, "repomgr.index.json")));
+ }
+ catch (IOException) {
+ throw new Exception("configuration file not found or wrong permissions. Did you run repomgr init?");
+ }
+ catch (JsonException) {
+ throw new Exception("configuration corrupt. Please check manually or re-init repo.");
+ }
+ }
+
+ private void WriteIndex() {
+ try {
+ var json = JsonConvert.SerializeObject(_repo);
+ if (!Directory.Exists(_buildpath))
+ Directory.CreateDirectory(_buildpath);
+ File.WriteAllText(Path.Combine(_buildpath, "repomgr.index.json"), json);
+ }
+ catch (IOException) {
+ throw new Exception("Unable to write configuration. Check permissions.");
+ }
+ }
+
+ private bool CheckPackage(string package) {
+ return Directory.Exists(Path.Combine(_pkgpath, package, ".git")) && File.Exists(Path.Combine(_pkgpath, package, "PKGBUILD"));
+ }
+
+ public void Build(string package, bool force = false) {
+ if (!CheckPackage(package))
+ return;
+
+ var iPackage = GetPackage(package);
+ try {
+ Build(iPackage, force);
+ }
+ catch (Exception) {
+ iPackage.LastBuildSucceeded = false;
+ throw;
+ }
+ }
+
+ public void BuildAll() {
+ foreach (var package in _repo.Packages) {
+ if (!CheckPackage(package.Name))
+ return;
+
+ try {
+ Build(package);
+ }
+ catch (Exception) {
+ package.LastBuildSucceeded = false;
+ }
+ }
+ }
+
+ public void Remove(string package) {
+ if (CheckPackage(package))
+ Remove(GetPackage(package));
+ }
+ }
+
+ public class Repository {
+ public Repository(string path, string name) {
+ Path = path;
+ Name = name;
+ Packages = new List();
+ }
+
+ public readonly string Path;
+ public readonly string Name;
+ public readonly List Packages;
+ }
+
+ public class Package {
+ public Package(string name) {
+ Name = name;
+ }
+
+ public readonly string Name;
+ public string CurrentVersion = "never-updated";
+ public string RepoVersion = "nA";
+ public bool LastBuildSucceeded = true;
+ public readonly List PkgFiles = new List();
+ }
+
+ internal static class Shell {
+ public static void Exec(string cmd, string workingDirectory) {
+ var escapedArgs = cmd.Replace("\"", "\\\"");
+
+ var process = new Process() {
+ StartInfo = new ProcessStartInfo {
+ FileName = "/bin/bash",
+ Arguments = $"-c \"{escapedArgs}\"",
+ WorkingDirectory = workingDirectory,
+ RedirectStandardOutput = false,
+ RedirectStandardError = false,
+ UseShellExecute = false,
+ CreateNoWindow = true,
+ }
+ };
+ 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) {
+ return $"\x1B[1m{s}\x1B[0m";
+ }
+
+ public static string Red(string s) {
+ return $"\x1b[31m{s}\x1b[39m";
+ }
+
+ public static string Yellow(string s) {
+ return $"\x1b[33m{s}\x1b[39m";
+ }
+
+ public static string Green(string s) {
+ return $"\x1b[32m{s}\x1b[39m";
+ }
+
+ public static string Gray(string s) {
+ return $"\x1b[90m{s}\x1b[39m";
+ }
+ }
}
\ No newline at end of file
diff --git a/Startup.cs b/Startup.cs
index bb847d4..5d4c47d 100644
--- a/Startup.cs
+++ b/Startup.cs
@@ -9,51 +9,48 @@ using Microsoft.AspNetCore.HttpsPolicy;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
+using Microsoft.Extensions.Hosting;
namespace repomgr
{
- public class Startup
- {
- public Startup(IConfiguration configuration)
- {
- Configuration = configuration;
- }
+ public class Startup {
+ public Startup(IConfiguration configuration) => Configuration = configuration;
public IConfiguration Configuration { get; }
// This method gets called by the runtime. Use this method to add services to the container.
- public void ConfigureServices(IServiceCollection services)
- {
- services.Configure(options =>
- {
- // This lambda determines whether user consent for non-essential cookies is needed for a given request.
- options.CheckConsentNeeded = context => true;
- options.MinimumSameSitePolicy = SameSiteMode.None;
- });
-
-
- services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_2);
+ public void ConfigureServices(IServiceCollection services) {
+ services.AddRazorPages();
+ #if (DEBUG)
+ services.AddControllers().AddRazorRuntimeCompilation();
+ #else
+ services.AddControllers();
+ #endif
}
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
- public void Configure(IApplicationBuilder app, IHostingEnvironment env)
- {
- if (env.IsDevelopment())
- {
+ public void Configure(IApplicationBuilder app, IWebHostEnvironment env) {
+ if (env.IsDevelopment()) {
app.UseDeveloperExceptionPage();
}
- else
- {
+ else {
app.UseExceptionHandler("/Error");
// The default HSTS value is 30 days. You may want to change this for production scenarios, see https://aka.ms/aspnetcore-hsts.
app.UseHsts();
}
app.UseHttpsRedirection();
- app.UseStaticFiles();
- app.UseCookiePolicy();
- app.UseMvc();
+ app.UseStaticFiles();
+
+ app.UseRouting();
+
+ app.UseAuthorization();
+
+ app.UseEndpoints(endpoints => {
+ endpoints.MapRazorPages();
+ endpoints.MapControllers();
+ });
}
}
}
\ No newline at end of file
diff --git a/repomgr.csproj b/repomgr.csproj
index 4d6878e..eaee4be 100644
--- a/repomgr.csproj
+++ b/repomgr.csproj
@@ -1,21 +1,21 @@
-
+
- netcoreapp2.2
+ netcoreapp3.1
full
Debug;Release
AnyCPU
linux-x64
+ true
+ Exe
-
-
-
-
-
-
+
+
+
+
diff --git a/tests/tests.csproj b/tests/tests.csproj
index 9115d94..3c4a3be 100644
--- a/tests/tests.csproj
+++ b/tests/tests.csproj
@@ -1,15 +1,16 @@
- netcoreapp2.2
+ netcoreapp3.1
false
-
+
+
-
+