Skip to content

Open-source Grok Bot alternative with a virtual machine that bots can use

fix(updater): the rpm hand-off resolves dependencies with dnf, not bare rpm

koeria95d0ff77cbf9
diff --git a/electron/package-install-command.mjs b/electron/package-install-command.mjs
index bfbd36eb56..7476dcff7a 100644
--- a/electron/package-install-command.mjs
+++ b/electron/package-install-command.mjs
@@ -25,7 +25,14 @@ export function linuxPackageType({
const BUILDERS = {
// apt-get, never `dpkg -i`: only apt-get resolves dependencies, and Ubuntu satisfies ours through virtual Provides.
deb: (file) => `sudo apt-get install -y ${file}`,
- rpm: (file) => `sudo rpm -Uvh ${file}`,
+ // dnf (then yum, zypper), never bare `rpm -Uvh`: rpm installs nothing when a dependency is missing and leaves
+ // the package out of the package manager's own database, so the next update conflicts. Same pick order as
+ // electron-updater's RpmUpdater; the file rides as $0 so the quoted path survives the inner shell too.
+ rpm: (file) =>
+ `sudo sh -c 'if command -v dnf >/dev/null 2>&1; then exec dnf install --nogpgcheck -y "$0"; ` +
+ `elif command -v yum >/dev/null 2>&1; then exec yum install --nogpgcheck -y "$0"; ` +
+ `elif command -v zypper >/dev/null 2>&1; then exec zypper --non-interactive --no-refresh install --allow-unsigned-rpm -f "$0"; ` +
+ `else exec rpm -Uvh --replacepkgs --replacefiles "$0"; fi' ${file}`,
pacman: (file) => `sudo pacman -U ${file}`,
};
diff --git a/electron/package-install-command.node-test.mjs b/electron/package-install-command.node-test.mjs
index 13935804a1..789ec80c10 100644
--- a/electron/package-install-command.node-test.mjs
+++ b/electron/package-install-command.node-test.mjs
@@ -100,6 +100,47 @@ test("the whole command parses into the arguments apt-get would receive", { skip
assert.deepEqual(printed.split("\n").filter(Boolean), ["install", "-y", file]);
});
+test("the rpm command picks a dependency-resolving package manager and passes only the file", { skip: posixShell }, () => {
+ const file = "/home/o'brien/.cache/openmausbot-updater/pending/OpenMausBot-0.1.44-x86_64.rpm";
+ const command = packageInstallCommand("rpm", file);
+
+ // Fake package managers on PATH announce themselves and print their arguments; a bare rpm would resolve
+ // nothing, so the fallback branch must never run here.
+ const fakeBin = (present) => {
+ const bin = mkdtempSync(join(tmpdir(), "omb-rpm-pm-"));
+ for (const name of present) {
+ writeFileSync(
+ join(bin, name),
+ `#!/bin/sh\necho "PM-\${0##*/}"\nfor a in "$@"; do printf '%s\\n' "$a"; done\n`,
+ { mode: 0o755 },
+ );
+ }
+ // sudo becomes a pass-through printer of what it would run as root.
+ writeFileSync(join(bin, "sudo"), "#!/bin/sh\nprintf '%s\\n' sudo\nfor a in \"$@\"; do printf '%s\\n' \"$a\"; done\nexec \"$@\"\n", { mode: 0o755 });
+ return bin;
+ };
+
+ const run = (bin) =>
+ execFileSync("/bin/sh", ["-c", command], {
+ encoding: "utf8",
+ env: { ...process.env, PATH: `${bin}:${process.env.PATH}` },
+ }).split("\n").filter(Boolean);
+
+ try {
+ // Fedora: dnf first, resolving dependencies, with the file as its only operand.
+ let out = run(fakeBin(["dnf", "rpm"]));
+ assert.deepEqual(out.slice(0, 3), ["sudo", "sh", "-c"]);
+ assert.deepEqual(out.slice(-5), ["PM-dnf", "install", "--nogpgcheck", "-y", file]);
+
+ // openSUSE: no dnf, no yum, so zypper is picked, again with dependency resolution.
+ out = run(fakeBin(["zypper", "rpm"]));
+ assert.deepEqual(out.slice(-7), ["PM-zypper", "--non-interactive", "--no-refresh", "install", "--allow-unsigned-rpm", "-f", file]);
+ } finally {
+ rmSync(join(tmpdir(), "omb-rpm-pm-"), { recursive: true, force: true });
+ }
+});
+
+
test("the package marker decides the install path", () => {
const marker = (declared) => (file) => (file.endsWith("package-type") ? declared : null);