Skip to content

Commit

Permalink
Get installed packages from dpkg.log
Browse files Browse the repository at this point in the history
  • Loading branch information
impactaky committed Jan 13, 2024
1 parent b451f48 commit b2bd30d
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 1 deletion.
19 changes: 18 additions & 1 deletion mimic-cross.deno/apt/apt.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { deployPackages } from "./apt.ts";
import { deployPackages, getIntalledPackagesFromLog } from "./apt.ts";
import { checkNeeded, getElfArch } from "../src/util.ts";
import $ from "dax/mod.ts";
import { assert, assertEquals } from "std/assert/mod.ts";
Expand All @@ -8,3 +8,20 @@ Deno.test("deployPackages coreutils", async () => {
assert(await checkNeeded($.path("/bin/cat"), "libmimic-cross.so"));
assertEquals(await getElfArch($.path("/bin/cat")), "x86_64");
});

Deno.test("getIntalledPackagesFromLog", async () => {
const packages = await getIntalledPackagesFromLog(
"2024-01-13 15:26:44",
$.path("test/dpkg.log"),
);
assertEquals(packages, ["libtime-duration-perl", "moreutils", "man-db"]);
});

Deno.test("getIntalledPackagesFromLog not found", async () => {
const packages = await getIntalledPackagesFromLog(
"2024-01-13 15:26:48",
$.path("test/dpkg.log"),
);
assertEquals(packages, []);
assert(!packages);
});
12 changes: 12 additions & 0 deletions mimic-cross.deno/apt/apt.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import $ from "daxex/mod.ts";
import { PathRefLike } from "daxex/mod.ts";
import { prepareChroot, runOnHost } from "../src/chroot.ts";
import { config } from "../config/config.ts";
import { deployAllCommands } from "./helper.ts";
Expand Down Expand Up @@ -81,3 +82,14 @@ export async function deployInstalledPackages() {
}).lines();
await deployPackages(installedPackages);
}

export function getIntalledPackagesFromLog(
ts: string,
logFile: PathRefLike = "/var/log/dpkg.log",
) {
return $.cat(logFile).apply((l) => {
if (l < ts) return;
const m = l.match(/status installed (.*):/);
return m?.[1];
}).lines();
}
26 changes: 26 additions & 0 deletions mimic-cross.deno/test/dpkg.log
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
2024-01-11 12:45:02 trigproc man-db:amd64 2.9.1-1 <なし>
2024-01-11 12:45:02 status half-configured man-db:amd64 2.9.1-1
2024-01-11 12:45:02 status installed man-db:amd64 2.9.1-1
2024-01-11 12:45:02 trigproc systemd:amd64 245.4-4ubuntu3.22 <なし>
2024-01-11 12:45:02 status half-configured systemd:amd64 245.4-4ubuntu3.22
2024-01-11 12:45:02 status installed systemd:amd64 245.4-4ubuntu3.22
2024-01-13 15:26:44 startup archives unpack
2024-01-13 15:26:45 install libtime-duration-perl:all <なし> 1.21-1
2024-01-13 15:26:45 status half-installed libtime-duration-perl:all 1.21-1
2024-01-13 15:26:45 status triggers-pending man-db:amd64 2.9.1-1
2024-01-13 15:26:45 status unpacked libtime-duration-perl:all 1.21-1
2024-01-13 15:26:45 install moreutils:amd64 <なし> 0.63-1
2024-01-13 15:26:45 status half-installed moreutils:amd64 0.63-1
2024-01-13 15:26:45 status unpacked moreutils:amd64 0.63-1
2024-01-13 15:26:45 startup packages configure
2024-01-13 15:26:45 configure libtime-duration-perl:all 1.21-1 <なし>
2024-01-13 15:26:45 status unpacked libtime-duration-perl:all 1.21-1
2024-01-13 15:26:45 status half-configured libtime-duration-perl:all 1.21-1
2024-01-13 15:26:45 status installed libtime-duration-perl:all 1.21-1
2024-01-13 15:26:45 configure moreutils:amd64 0.63-1 <なし>
2024-01-13 15:26:45 status unpacked moreutils:amd64 0.63-1
2024-01-13 15:26:45 status half-configured moreutils:amd64 0.63-1
2024-01-13 15:26:45 status installed moreutils:amd64 0.63-1
2024-01-13 15:26:45 trigproc man-db:amd64 2.9.1-1 <なし>
2024-01-13 15:26:45 status half-configured man-db:amd64 2.9.1-1
2024-01-13 15:26:47 status installed man-db:amd64 2.9.1-1

0 comments on commit b2bd30d

Please sign in to comment.