From 7ead5eabb04f122b5352e5d072c025e289cb975b Mon Sep 17 00:00:00 2001 From: Booklordofthedings Date: Mon, 14 Apr 2025 19:23:21 +0200 Subject: [PATCH] Moving things, and allowing for retrieving installed packages --- package.list | 36 ++++++++++++++++++----- src/Helper.cs | 28 +++++++++++++++++- src/Program.cs | 4 ++- src/Tasks/GetInstalledPackages.cs | 45 +++++++++++++++++++++++++++++ src/{ => Tasks}/PackageInstaller.cs | 2 +- 5 files changed, 104 insertions(+), 11 deletions(-) create mode 100644 src/Tasks/GetInstalledPackages.cs rename src/{ => Tasks}/PackageInstaller.cs (93%) diff --git a/package.list b/package.list index 6bb9c4c..651f700 100644 --- a/package.list +++ b/package.list @@ -1,15 +1,35 @@ -nano +audacity +clang-18 +clangd-18 +cmake +containerd.io +dconf-editor +dotnet-sdk-8.0 +git +kdenlive +kopia-ui +krita +lmms +micro +npm +obs-studio +pcscd +php +python3-pip +qdirstat +qemu-block-extra +remmina +steam-installer +vagrant +veracrypt +virt-manager +virtualbox wine wine64 +xppenlinux build-essential -git -remmina mesa-vulkan-drivers libglx-mesa0:i386 mesa-vulkan-drivers:i386 libgl1-mesa-dri:i386 -dconf-editor -beefbuild -audacity -npm -neofetch \ No newline at end of file +neofetch diff --git a/src/Helper.cs b/src/Helper.cs index a5e8ac3..5add291 100644 --- a/src/Helper.cs +++ b/src/Helper.cs @@ -5,8 +5,14 @@ using System.Diagnostics; public class Helper { - public static void RunCommand(String verb, String? arguments = null) + public static void RunCommand(string verb, string? arguments = null) { + /* + #if DEBUG + Console.WriteLine($"Run Command: {verb} {arguments}"); + return; + #endif*/ + ProcessStartInfo info = new ProcessStartInfo(); info.FileName = verb; if(arguments != null) @@ -20,4 +26,24 @@ public class Helper while (process.HasExited == false) continue; } + + public static string RunCommandAndGetOutput(string verb, string? arguments = null) + { + ProcessStartInfo info = new ProcessStartInfo(); + info.FileName = verb; + if(arguments != null) + info.Arguments = arguments; + info.UseShellExecute = false; + info.RedirectStandardOutput = true; + info.CreateNoWindow = true; + + Process process = new Process(); + process.StartInfo = info; + process.Start(); + + while (process.HasExited == false) + continue; + + return process.StandardOutput.ReadToEnd(); + } } \ No newline at end of file diff --git a/src/Program.cs b/src/Program.cs index 75f3d5e..d91ee2a 100644 --- a/src/Program.cs +++ b/src/Program.cs @@ -1,4 +1,5 @@ using Setup_Workspace; +using Setup_Workspace.Tasks; Console.WriteLine(""" WSS - Workspace Setup Script version 1.0 @@ -16,7 +17,8 @@ switch (input) { case "full-install": new Runner().Then( - new PackageInstaller() + new GetInstalledPackages()//, + //new PackageInstaller() ).Run(); break; diff --git a/src/Tasks/GetInstalledPackages.cs b/src/Tasks/GetInstalledPackages.cs new file mode 100644 index 0000000..6b93fee --- /dev/null +++ b/src/Tasks/GetInstalledPackages.cs @@ -0,0 +1,45 @@ +namespace Setup_Workspace.Tasks; + +public class GetInstalledPackages : Doable +{ + + /* + The goal here is to retrieve all of the packages, + that have been installed after the initial install + + - Get the initially installed programs + /var/log/installer/initial-status.gz //For linux mint + Check wether a line has "Package: " and remove it + + - Get the currently installed programs + apt-mark showmanual + */ + public override bool Do() + { + Helper.RunCommand("gzip", "/var/log/installer/initial-status.gz -d -k -f"); + + var dPackages = File.ReadAllText("/var/log/installer/initial-status"); + HashSet dPackageList = new HashSet(); + foreach (var line in dPackages.Split('\n')) + if(line.StartsWith("Package: ")) + dPackageList.Add(line.Replace("Package: ", "")); + + var installPackages = Helper.RunCommandAndGetOutput("apt-mark", "showmanual"); + HashSet installedManualPackages = new HashSet(); + foreach (var line in installPackages.Split('\n')) + if(line != "") + installedManualPackages.Add(line); + + List toInstall = new List(); + foreach (var item in installedManualPackages) + if(!dPackageList.Contains(item)) + toInstall.Add(item); + + String toWrite = ""; + foreach(var item in toInstall) + toWrite += item + "\n"; + File.WriteAllText("package.list.export", toWrite); + + return true; + } +} \ No newline at end of file diff --git a/src/PackageInstaller.cs b/src/Tasks/PackageInstaller.cs similarity index 93% rename from src/PackageInstaller.cs rename to src/Tasks/PackageInstaller.cs index 105de86..da3112f 100644 --- a/src/PackageInstaller.cs +++ b/src/Tasks/PackageInstaller.cs @@ -1,4 +1,4 @@ -namespace Setup_Workspace; +namespace Setup_Workspace.Tasks; public class PackageInstaller : Doable {