Compare commits
15 Commits
5a09db7423
...
88c6d7c284
Author | SHA1 | Date | |
---|---|---|---|
88c6d7c284 | |||
|
7bbeaedf48 | ||
|
332ed62ca3 | ||
|
205ef71dcd | ||
a61c3fbfd9 | |||
3d512f25ab | |||
4f474591da | |||
81fc8f1883 | |||
89e79b1025 | |||
35c6c5c8d9 | |||
9ad8012052 | |||
10ba654b09 | |||
888df20cc9 | |||
04048c4cb9 | |||
20599a03ba |
4
.gitignore
vendored
4
.gitignore
vendored
@ -1,3 +1,3 @@
|
||||
.vscode/
|
||||
obj/
|
||||
bin/
|
||||
[Oo]bj/
|
||||
[Bb]in/
|
||||
|
16
Program.cs
16
Program.cs
@ -1,16 +0,0 @@
|
||||
public class Program {
|
||||
static void Main(string[] args) {
|
||||
if (args.Length == 0) {
|
||||
Console.ForegroundColor = ConsoleColor.Red;
|
||||
Console.WriteLine("Please specify an option.");
|
||||
Console.ResetColor();
|
||||
} else {
|
||||
switch (args[0]) {
|
||||
case "":
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
31
justfile
Normal file
31
justfile
Normal file
@ -0,0 +1,31 @@
|
||||
default:
|
||||
@just --list
|
||||
|
||||
project_name := `printf '%s\n' "${PWD##*/}"`
|
||||
uppercase_project_name := capitalize(project_name)
|
||||
|
||||
setup:
|
||||
@dotnet new sln --name {{project_name}}
|
||||
@mkdir src
|
||||
@dotnet new classlib -o src/{{uppercase_project_name}}
|
||||
@dotnet new xunit -o src/{{uppercase_project_name}}.Tests
|
||||
@dotnet sln add src/{{uppercase_project_name}}/{{uppercase_project_name}}.csproj
|
||||
@dotnet sln add src/{{uppercase_project_name}}.Tests/{{uppercase_project_name}}.Tests.csproj
|
||||
@dotnet add src/{{uppercase_project_name}}/{{uppercase_project_name}}.csproj reference src/{{uppercase_project_name}}.Tests/{{uppercase_project_name}}.Tests.csproj
|
||||
|
||||
run:
|
||||
@dotnet run
|
||||
|
||||
build:
|
||||
@dotnet build src/Pacserver/pacserver.csproj
|
||||
@dotnet build src/Pacserver.Tests/Pacserver.Tests.csproj
|
||||
|
||||
publish: format
|
||||
@dotnet publish --configuration Release src/Pacserver/pacserver.csproj
|
||||
|
||||
format:
|
||||
@dotnet format src/Pacserver
|
||||
@dotnet format src/Pacserver.Tests
|
||||
|
||||
test: build
|
||||
@dotnet test src/Pacserver.Tests
|
23
pacserver.cs
23
pacserver.cs
@ -1,23 +0,0 @@
|
||||
public class Pacserver {
|
||||
public static string pacmanCacheDirectory { get; set; } = string.Empty;
|
||||
public static string determinePacmanCacheDirectory() {
|
||||
return pacmanCacheDirectory;
|
||||
}
|
||||
|
||||
public static string pacmanDatabaseDirectory { get; set; } = string.Empty;
|
||||
public static string determinePacmanDatabaseDirectory() {
|
||||
return pacmanDatabaseDirectory;
|
||||
}
|
||||
|
||||
public static void checkForNewerPackagesAndDatabases() {
|
||||
|
||||
}
|
||||
|
||||
public static void transferPacmanCache() {
|
||||
|
||||
}
|
||||
|
||||
public static void transferPacmanDatabases() {
|
||||
|
||||
}
|
||||
}
|
28
src/Pacserver.Tests/Pacserver.Tests.csproj
Normal file
28
src/Pacserver.Tests/Pacserver.Tests.csproj
Normal file
@ -0,0 +1,28 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net7.0</TargetFramework>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<Nullable>enable</Nullable>
|
||||
<RuntimeIdentifier>linux-x64</RuntimeIdentifier>
|
||||
<IsPackable>false</IsPackable>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.3.2" />
|
||||
<PackageReference Include="xunit" Version="2.4.2" />
|
||||
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.5">
|
||||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
||||
<PrivateAssets>all</PrivateAssets>
|
||||
</PackageReference>
|
||||
<PackageReference Include="coverlet.collector" Version="3.1.2">
|
||||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
||||
<PrivateAssets>all</PrivateAssets>
|
||||
</PackageReference>
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\Pacserver\pacserver.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
13
src/Pacserver.Tests/TransferFilesTest.cs
Normal file
13
src/Pacserver.Tests/TransferFilesTest.cs
Normal file
@ -0,0 +1,13 @@
|
||||
using Pacserver.Utils;
|
||||
|
||||
namespace Pacserver.Tests;
|
||||
|
||||
public class TranserFilesTest {
|
||||
[Fact]
|
||||
public void TransferPacmanCacheTest() {
|
||||
string result = PacserverUtils.determinePacmanCacheDirectory();
|
||||
PacserverUtils.TransferPacmanCache();
|
||||
|
||||
//Assert.NotEmpty(Directory.GetFiles("/home/rene/test/"));
|
||||
}
|
||||
}
|
1
src/Pacserver.Tests/Usings.cs
Normal file
1
src/Pacserver.Tests/Usings.cs
Normal file
@ -0,0 +1 @@
|
||||
global using Xunit;
|
13
src/Pacserver.Tests/pacmanCache_Test.cs
Normal file
13
src/Pacserver.Tests/pacmanCache_Test.cs
Normal file
@ -0,0 +1,13 @@
|
||||
using Pacserver.Utils;
|
||||
|
||||
namespace Pacserver.Tests;
|
||||
|
||||
public class pacmanCache_Test {
|
||||
[Fact]
|
||||
public void doesPacmanCacheExist() {
|
||||
string result = PacserverUtils.determinePacmanCacheDirectory();
|
||||
|
||||
Assert.Equivalent(result, "/var/cache/pacman/pkg/");
|
||||
}
|
||||
}
|
||||
|
12
src/Pacserver.Tests/pacmanDatabase_Test.cs
Normal file
12
src/Pacserver.Tests/pacmanDatabase_Test.cs
Normal file
@ -0,0 +1,12 @@
|
||||
using Pacserver.Utils;
|
||||
|
||||
namespace Pacserver.Tests;
|
||||
|
||||
public class pacmanDatabase_Test {
|
||||
[Fact]
|
||||
public void doesPacmanDatabaseExist() {
|
||||
string result = PacserverUtils.determinePacmanDatabaseDirectory();
|
||||
|
||||
Assert.Equivalent(result, "/var/lib/pacman/");
|
||||
}
|
||||
}
|
71
src/Pacserver/Pacserver.cs
Normal file
71
src/Pacserver/Pacserver.cs
Normal file
@ -0,0 +1,71 @@
|
||||
using System.Net.Http.Headers;
|
||||
using System.Text.RegularExpressions;
|
||||
|
||||
namespace Pacserver.Utils;
|
||||
public class PacserverUtils {
|
||||
public static string pacmanCacheDirectory { get; set; } = string.Empty;
|
||||
public static string determinePacmanCacheDirectory() {
|
||||
string defaultPacmanCacheDirectory = "/var/cache/pacman/pkg/";
|
||||
|
||||
Regex regex = new Regex(@"\/(?:[\w.-]+\/)*[\w.-]+(?:\.\w+)*\/?$"); // https://regex101.com/r/GwWeui/2
|
||||
string? line;
|
||||
StreamReader file = new StreamReader("/etc/pacman.conf");
|
||||
while ((line = file.ReadLine()) is not null) {
|
||||
if (line.Contains("CacheDir")) {
|
||||
Match match = regex.Match(line);
|
||||
if (match.Success) {
|
||||
pacmanCacheDirectory = match.ToString();
|
||||
} else {
|
||||
throw new Exception("Could not determine where pacman cache is! Would normally be found here " + defaultPacmanCacheDirectory);
|
||||
}
|
||||
}
|
||||
}
|
||||
file.Close();
|
||||
|
||||
return pacmanCacheDirectory;
|
||||
}
|
||||
|
||||
public static string pacmanDatabaseDirectory { get; set; } = string.Empty;
|
||||
public static string determinePacmanDatabaseDirectory() {
|
||||
string defaultPacmanDatabaseDirectory = "/var/lib/pacman/";
|
||||
|
||||
Regex regex = new Regex(@"\/(?:[\w.-]+\/)*[\w.-]+(?:\.\w+)*\/?$"); // https://regex101.com/r/GwWeui/2
|
||||
string? line;
|
||||
StreamReader file = new StreamReader("/etc/pacman.conf");
|
||||
while ((line = file.ReadLine()) is not null) {
|
||||
if (line.Contains("DBPath")) {
|
||||
Match match = regex.Match(line);
|
||||
if (match.Success) {
|
||||
pacmanDatabaseDirectory = match.ToString();
|
||||
} else {
|
||||
throw new Exception("Could not determine where pacman database is! Would normally be found here " + defaultPacmanDatabaseDirectory);
|
||||
}
|
||||
}
|
||||
}
|
||||
file.Close();
|
||||
|
||||
return pacmanDatabaseDirectory;
|
||||
}
|
||||
|
||||
public static void checkForNewerPackagesAndDatabases() {
|
||||
|
||||
}
|
||||
|
||||
private static List<String> NewerPackagesAndDatabases = new List<String>();
|
||||
public static async void TransferPacmanCache() {
|
||||
HttpClient client = new HttpClient();
|
||||
HttpRequestMessage request = new HttpRequestMessage(HttpMethod.Post, "http://192.168.0.69:12000/upload?path=/");
|
||||
MultipartFormDataContent content = new MultipartFormDataContent();
|
||||
|
||||
foreach (String PkgOrDb in NewerPackagesAndDatabases) {
|
||||
content.Add(new ByteArrayContent(File.ReadAllBytes(pacmanCacheDirectory + PkgOrDb)), "path", Path.GetFileName(pacmanCacheDirectory + PkgOrDb));
|
||||
}
|
||||
request.Content = content;
|
||||
|
||||
await client.SendAsync(request);
|
||||
}
|
||||
|
||||
public static void transferPacmanDatabases() {
|
||||
|
||||
}
|
||||
}
|
25
src/Pacserver/Program.cs
Normal file
25
src/Pacserver/Program.cs
Normal file
@ -0,0 +1,25 @@
|
||||
using Pacserver.Utils;
|
||||
|
||||
public class Program {
|
||||
static void Main(string[] args) {
|
||||
if (args.Length == 0) {
|
||||
Console.ForegroundColor = ConsoleColor.Red;
|
||||
Console.WriteLine("Please specify an option.");
|
||||
Console.ResetColor();
|
||||
Console.WriteLine("Possible options are: determinePacmanCacheDirectory");
|
||||
return;
|
||||
}
|
||||
|
||||
switch (args[0]) {
|
||||
case "determinePacmanCacheDirectory":
|
||||
Console.WriteLine(PacserverUtils.determinePacmanCacheDirectory());
|
||||
break;
|
||||
default:
|
||||
Console.ForegroundColor = ConsoleColor.Red;
|
||||
Console.WriteLine(args[0] + " is not a recognized option.");
|
||||
Console.ResetColor();
|
||||
Console.WriteLine("Possible options are: determinePacmanCacheDirectory");
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
32
src/pacserver.sln
Normal file
32
src/pacserver.sln
Normal file
@ -0,0 +1,32 @@
|
||||
|
||||
Microsoft Visual Studio Solution File, Format Version 12.00
|
||||
# Visual Studio Version 17
|
||||
VisualStudioVersion = 17.0.31903.59
|
||||
MinimumVisualStudioVersion = 10.0.40219.1
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "pacserver", "Pacserver\pacserver.csproj", "{2B605458-AFBE-4A78-B4EA-9562C82BC932}"
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Pacserver.Tests", "Pacserver.Tests\Pacserver.Tests.csproj", "{0B504958-E66D-4E32-AB22-19F94713AFCD}"
|
||||
EndProject
|
||||
Global
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
Debug|Any CPU = Debug|Any CPU
|
||||
Release|Any CPU = Release|Any CPU
|
||||
EndGlobalSection
|
||||
GlobalSection(SolutionProperties) = preSolution
|
||||
HideSolutionNode = FALSE
|
||||
EndGlobalSection
|
||||
GlobalSection(ProjectConfigurationPlatforms) = postSolution
|
||||
{6FCF1241-CE3C-4A4A-8625-866A4E8E7623}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{6FCF1241-CE3C-4A4A-8625-866A4E8E7623}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{6FCF1241-CE3C-4A4A-8625-866A4E8E7623}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{6FCF1241-CE3C-4A4A-8625-866A4E8E7623}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{2B605458-AFBE-4A78-B4EA-9562C82BC932}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{2B605458-AFBE-4A78-B4EA-9562C82BC932}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{2B605458-AFBE-4A78-B4EA-9562C82BC932}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{2B605458-AFBE-4A78-B4EA-9562C82BC932}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{0B504958-E66D-4E32-AB22-19F94713AFCD}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{0B504958-E66D-4E32-AB22-19F94713AFCD}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{0B504958-E66D-4E32-AB22-19F94713AFCD}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{0B504958-E66D-4E32-AB22-19F94713AFCD}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
EndGlobalSection
|
||||
EndGlobal
|
Loading…
x
Reference in New Issue
Block a user