Skip to content

Commit 22f655c

Browse files
committed
Implement Linux deb installer
1 parent a223f25 commit 22f655c

File tree

3 files changed

+77
-0
lines changed

3 files changed

+77
-0
lines changed
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
import assert from 'node:assert/strict';
2+
import cp from 'node:child_process';
3+
4+
/**
5+
* Call apt to get the package name
6+
*/
7+
export function getPackageName(filepath: string) {
8+
const result = cp.spawnSync('apt', ['show', filepath], { encoding: 'utf8' });
9+
assert.equal(
10+
result.status,
11+
0,
12+
`Expected a clean exit, got status ${result.status || 'null'}`
13+
);
14+
const packageMatch = result.stdout.match(/Package: (?<name>.+)/);
15+
assert(packageMatch, 'Expected a line in the output with the package name');
16+
assert(packageMatch.groups);
17+
const { name } = packageMatch.groups;
18+
assert(typeof name === 'string');
19+
return name;
20+
}

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import { installWindowsZIP } from './windows-zip';
55
import { installWindowsMSI } from './windows-msi';
66
import { installWindowsSetup } from './windows-setup';
77
import { installLinuxTar } from './linux-tar';
8+
import { installLinuxDeb } from './linux-deb';
89

910
export function getInstaller(kind: PackageKind) {
1011
if (kind === 'osx_dmg') {
@@ -19,6 +20,8 @@ export function getInstaller(kind: PackageKind) {
1920
return installWindowsSetup;
2021
} else if (kind === 'linux_tar') {
2122
return installLinuxTar;
23+
} else if (kind === 'linux_deb') {
24+
return installLinuxDeb;
2225
} else {
2326
throw new Error(`Installer for '${kind}' is not yet implemented`);
2427
}
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
import assert from 'node:assert/strict';
2+
import fs from 'node:fs';
3+
import path from 'node:path';
4+
5+
import type { InstalledAppInfo, InstallablePackage } from './types';
6+
import { execute } from '../execute';
7+
import * as apt from './apt';
8+
9+
export function installLinuxDeb({
10+
appName,
11+
filepath,
12+
destinationPath,
13+
}: InstallablePackage): InstalledAppInfo {
14+
const packageName = apt.getPackageName(filepath);
15+
const installPath = `/usr/lib/${packageName}`;
16+
const appPath = path.resolve(installPath, appName);
17+
18+
function uninstall() {
19+
execute('sudo', ['apt', 'remove', '--yes', '--purge', packageName]);
20+
}
21+
22+
console.warn(
23+
"Installing globally, since we haven't discovered a way to specify an install path"
24+
);
25+
26+
if (fs.existsSync(installPath)) {
27+
console.warn(
28+
'Found an existing install directory (likely from a previous run): Uninstalling first'
29+
);
30+
uninstall();
31+
}
32+
33+
assert(
34+
!fs.existsSync(installPath),
35+
`Expected no install directory to exist: ${installPath}`
36+
);
37+
console.warn(
38+
"Installing globally, since we haven't discovered a way to specify an install path"
39+
);
40+
execute('sudo', ['apt', 'install', filepath]);
41+
42+
assert(
43+
fs.existsSync(installPath),
44+
`Expected an install directory to exist: ${installPath}`
45+
);
46+
47+
// Check that the executable will run without being quarantined or similar
48+
execute('xvfb-run', [appPath, '--version']);
49+
50+
return {
51+
appPath: installPath,
52+
uninstall,
53+
};
54+
}

0 commit comments

Comments
 (0)