Skip to content

Commit 9609536

Browse files
committed
Implement Linux rpm installer
1 parent f252546 commit 9609536

File tree

2 files changed

+80
-0
lines changed

2 files changed

+80
-0
lines changed

packages/compass-smoke-tests/src/installers/index.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import { installWindowsMSI } from './windows-msi';
66
import { installWindowsSetup } from './windows-setup';
77
import { installLinuxTar } from './linux-tar';
88
import { installLinuxDeb } from './linux-deb';
9+
import { installLinuxRpm } from './linux-rpm';
910

1011
export function getInstaller(kind: PackageKind) {
1112
if (kind === 'osx_dmg') {
@@ -22,6 +23,8 @@ export function getInstaller(kind: PackageKind) {
2223
return installLinuxTar;
2324
} else if (kind === 'linux_deb') {
2425
return installLinuxDeb;
26+
} else if (kind === 'linux_rpm') {
27+
return installLinuxRpm;
2528
} else {
2629
throw new Error(`Installer for '${kind}' is not yet implemented`);
2730
}
Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
import assert from 'node:assert/strict';
2+
import cp from 'node:child_process';
3+
import path from 'node:path';
4+
import fs from 'node:fs';
5+
6+
import type { InstalledAppInfo, InstallablePackage } from './types';
7+
import { execute } from '../execute';
8+
/**
9+
* Call dnf to get the package name
10+
*/
11+
function getPackageName(filepath: string) {
12+
const result = cp.spawnSync(
13+
'dnf',
14+
['repoquery', '--queryformat', '%{NAME}', filepath],
15+
{ encoding: 'utf8' }
16+
);
17+
assert.equal(
18+
result.status,
19+
0,
20+
`Expected a clean exit, got status ${result.status || 'null'}`
21+
);
22+
return result.stdout.trim();
23+
}
24+
25+
/**
26+
* Check if a package is installed (by name)
27+
*/
28+
export function isInstalled(packageName: string) {
29+
const result = cp.spawnSync('dnf', ['list', 'installed', packageName], {
30+
stdio: 'inherit',
31+
});
32+
return result.status === 0;
33+
}
34+
35+
export function installLinuxRpm({
36+
appName,
37+
filepath,
38+
}: InstallablePackage): InstalledAppInfo {
39+
const packageName = getPackageName(filepath);
40+
const installPath = `/usr/lib/${packageName}`;
41+
const appPath = path.resolve(installPath, appName);
42+
43+
function uninstall() {
44+
execute('dnf', ['dnf', 'remove', '-y', packageName]);
45+
}
46+
47+
if (isInstalled(packageName)) {
48+
console.warn(
49+
'Found an existing install directory (likely from a previous run): Uninstalling first'
50+
);
51+
uninstall();
52+
}
53+
54+
console.warn(
55+
"Installing globally, since we haven't discovered a way to specify an install path"
56+
);
57+
assert(!isInstalled(packageName), 'Expected the package to not be installed');
58+
assert(
59+
!fs.existsSync(installPath),
60+
`Expected no install directory to exist: ${installPath}`
61+
);
62+
execute('dnf', ['install', '-y', filepath]);
63+
64+
assert(isInstalled(packageName), 'Expected the package to be installed');
65+
assert(
66+
fs.existsSync(installPath),
67+
`Expected an install directory to exist: ${installPath}`
68+
);
69+
70+
// Check that the executable will run without being quarantined or similar
71+
execute('xvfb-run', [appPath, '--version', '--no-sandbox']); // Remove '--no-sandbox' if we don't plan on running this as root
72+
73+
return {
74+
appPath: installPath,
75+
uninstall,
76+
};
77+
}

0 commit comments

Comments
 (0)