Skip to content

Beautiful, AI-native markdown IDE and LLM wiki

Name Linux packages after their executables (PRD-9402) (#6396)

Andrew Mikofalvy0ace2f105627
diff --git a/.changeset/linux-package-names.md b/.changeset/linux-package-names.md
new file mode 100644
index 000000000..7ccc067a5
--- /dev/null
+++ b/.changeset/linux-package-names.md
@@ -0,0 +1,5 @@
+---
+"@inkeep/open-knowledge": patch
+---
+
+The Linux packages are now named after the app they install: `openknowledge` for Stable on deb and rpm, and `openknowledge-beta` for Beta. Existing installs update in place and keep their terminal commands.
diff --git a/docs/content/reference/cli.mdx b/docs/content/reference/cli.mdx
index 1b80d6d3c..5f689c9ae 100644
--- a/docs/content/reference/cli.mdx
+++ b/docs/content/reference/cli.mdx
@@ -198,4 +198,4 @@ Both commands print their plan and ask before acting; `--dry-run` previews witho
On the macOS desktop app, **App menu → Uninstall OpenKnowledge…** lets you choose projects to deinitialize, confirm removal, and answer or skip the optional "why are you leaving?" screen. The progress window stays visible while the original app quits and cleanup runs, so shutdown cannot recreate its settings. The same window then reports the result: successful cleanup guides you through dragging the app to the Trash; incomplete cleanup points to a retained log so you can repair the problem and retry.
-To remove the desktop app on the other platforms: on **Windows**, uninstall OpenKnowledge from **Settings → Apps → Installed apps**; on **Linux**, remove the package with your package manager (`sudo apt remove openknowledge` on Debian/Ubuntu, `sudo dnf remove OpenKnowledge` on Fedora/RHEL). Run `ok uninstall` first if you also want the rest of the footprint cleaned up — it works the same on every platform.
+To remove the desktop app on the other platforms: on **Windows**, uninstall OpenKnowledge from **Settings → Apps → Installed apps**; on **Linux**, remove the package with your package manager. `ok uninstall` prints the command for the package that is actually installed. Both the deb and the rpm are named `openknowledge` for Stable and `openknowledge-beta` for Beta: `sudo apt remove openknowledge` on Debian/Ubuntu, `sudo dnf remove openknowledge` on Fedora/RHEL, `sudo zypper remove openknowledge` on openSUSE. An install that has not yet updated to the renamed package keeps its earlier name: `OpenKnowledge` for the Stable rpm and `openknowledge-beta-desktop` for the Beta deb and rpm (the Stable deb was always `openknowledge`). Run `ok uninstall` first if you also want the rest of the footprint cleaned up — it works the same on every platform.
diff --git a/packages/cli/src/commands/uninstall.test.ts b/packages/cli/src/commands/uninstall.test.ts
index b95215a50..cdaabec77 100644
--- a/packages/cli/src/commands/uninstall.test.ts
+++ b/packages/cli/src/commands/uninstall.test.ts
@@ -135,11 +135,12 @@ describe('detectInstallMethods', () => {
undefined,
() => null,
(p) => p === '/opt/OpenKnowledge/openknowledge',
- { platform: 'linux' },
+ { platform: 'linux', queryPackageDatabase: () => null },
);
expect(methods.map((m) => m.method)).toEqual(['app']);
- expect(methods[0]?.instruction).toContain('apt remove openknowledge');
- expect(methods[0]?.instruction).toContain('dnf remove OpenKnowledge');
+ expect(methods[0]?.instruction).toBe(
+ 'Remove with your package manager: sudo apt remove openknowledge (Debian/Ubuntu), sudo dnf remove openknowledge (Fedora/RHEL) or sudo zypper remove openknowledge (openSUSE)',
+ );
});
test('reports the Beta Linux install by product name', () => {
@@ -148,15 +149,70 @@ describe('detectInstallMethods', () => {
undefined,
() => null,
(path) => path === '/opt/OpenKnowledge Beta/openknowledge-beta',
- { platform: 'linux' },
+ { platform: 'linux', queryPackageDatabase: () => null },
);
expect(methods).toEqual([
{
method: 'app',
label: 'OpenKnowledge Beta (/opt/OpenKnowledge Beta)',
instruction:
- 'Remove with your package manager: sudo apt remove openknowledge-beta-desktop (Debian/Ubuntu) or sudo dnf remove openknowledge-beta-desktop (Fedora/RHEL)',
+ 'Remove with your package manager: sudo apt remove openknowledge-beta (Debian/Ubuntu), sudo dnf remove openknowledge-beta (Fedora/RHEL) or sudo zypper remove openknowledge-beta (openSUSE)',
+ },
+ ]);
+ });
+
+ test.each([
+ {
+ installed: 'a Beta deb from before the rename',
+ executable: '/opt/OpenKnowledge Beta/openknowledge-beta',
+ dpkg: 'openknowledge-beta-desktop: /opt/OpenKnowledge Beta/openknowledge-beta\n',
+ rpm: null,
+ instruction: 'sudo apt remove openknowledge-beta-desktop',
+ },
+ {
+ installed: 'a renamed Beta deb',
+ executable: '/opt/OpenKnowledge Beta/openknowledge-beta',
+ dpkg: 'openknowledge-beta: /opt/OpenKnowledge Beta/openknowledge-beta\n',
+ rpm: null,
+ instruction: 'sudo apt remove openknowledge-beta',
+ },
+ {
+ installed: 'a Stable rpm from before the rename',
+ executable: '/opt/OpenKnowledge/openknowledge',
+ dpkg: null,
+ rpm: 'OpenKnowledge\n',
+ instruction:
+ 'sudo dnf remove OpenKnowledge (Fedora/RHEL) or sudo zypper remove OpenKnowledge (openSUSE)',
+ },
+ {
+ installed: 'a renamed Stable rpm',
+ executable: '/opt/OpenKnowledge/openknowledge',
+ dpkg: null,
+ rpm: 'openknowledge\n',
+ instruction:
+ 'sudo dnf remove openknowledge (Fedora/RHEL) or sudo zypper remove openknowledge (openSUSE)',
+ },
+ ])('names the package that owns $installed', ({ executable, dpkg, rpm, instruction }) => {
+ const queries: string[][] = [];
+ const methods = detectInstallMethods(
+ '/home/jane',
+ undefined,
+ () => null,
+ (p) => p === executable,
+ {
+ platform: 'linux',
+ queryPackageDatabase: (command, args) => {
+ queries.push([command, ...args]);
+ return command === 'dpkg-query' ? dpkg : rpm;
+ },
},
+ );
+ expect(methods.map((m) => m.instruction)).toEqual([
+ `Remove with your package manager: ${instruction}`,
+ ]);
+ expect(queries).toEqual([
+ ['dpkg-query', '-S', executable],
+ ...(dpkg === null ? [['rpm', '-qf', '--queryformat', '%{NAME}\n', executable]] : []),
]);
});
diff --git a/packages/cli/src/commands/uninstall.ts b/packages/cli/src/commands/uninstall.ts
index 50801cc5c..09efaffa6 100644
--- a/packages/cli/src/commands/uninstall.ts
+++ b/packages/cli/src/commands/uninstall.ts
@@ -44,7 +44,12 @@ export function detectInstallMethods(
argv1: string | undefined,
runNpmLs: (args: string[]) => string | null = defaultNpmLs,
exists: (path: string) => boolean = existsSync,
- opts: { platform?: NodeJS.Platform; env?: NodeJS.ProcessEnv; execPath?: string } = {},
+ opts: {
+ platform?: NodeJS.Platform;
+ env?: NodeJS.ProcessEnv;
+ execPath?: string;
+ queryPackageDatabase?: (command: string, args: string[]) => string | null;
+ } = {},
): InstallMethod[] {
const methods: InstallMethod[] = [];
const platform = opts.platform ?? process.platform;
@@ -89,14 +94,23 @@ export function detectInstallMethods(
}
}
} else if (platform === 'linux') {
+ const query = opts.queryPackageDatabase ?? defaultRunCommand;
for (const product of desktopProducts) {
const installDir = `/opt/${product.productName}`;
- if (exists(join(installDir, product.linuxExecutableName))) {
+ const executable = join(installDir, product.linuxExecutableName);
+ if (exists(executable)) {
const { deb: debPackageName, rpm: rpmPackageName } = product.linuxPackageNames;
+ const owner = linuxPackageOwner(executable, query);
methods.push({
method: 'app',
label: `${product.productName} (${installDir})`,
- instruction: `Remove with your package manager: sudo apt remove ${debPackageName} (Debian/Ubuntu) or sudo dnf remove ${rpmPackageName} (Fedora/RHEL)`,
+ instruction: `Remove with your package manager: ${
+ owner === null
+ ? `sudo apt remove ${debPackageName} (Debian/Ubuntu), ${rpmRemoveCommands(rpmPackageName)}`
+ : owner.format === 'deb'
+ ? `sudo apt remove ${owner.name}`
+ : rpmRemoveCommands(owner.name)
+ }`,
});
}
}
@@ -123,10 +137,10 @@ export function detectInstallMethods(
return methods;
}
-function defaultNpmLs(args: string[]): string | null {
+function defaultRunCommand(command: string, args: string[]): string | null {
try {
return execFileSync(
- 'npm',
+ command,
args,
withHiddenWindowsConsole({
encoding: 'utf-8',
@@ -139,6 +153,29 @@ function defaultNpmLs(args: string[]): string | null {
}
}
+function rpmRemoveCommands(name: string): string {
+ return `sudo dnf remove ${name} (Fedora/RHEL) or sudo zypper remove ${name} (openSUSE)`;
+}
+
+function linuxPackageOwner(
+ path: string,
+ query: (command: string, args: string[]) => string | null,
+): { format: 'deb' | 'rpm'; name: string } | null {
+ const debName = query('dpkg-query', ['-S', path])
+ ?.split('\n')[0]
+ ?.split(':')[0]
+ ?.split(',')[0]
+ ?.trim();
+ if (debName && /^[a-z0-9][a-z0-9.+-]*$/.test(debName)) return { format: 'deb', name: debName };
+ const rpmName = query('rpm', ['-qf', '--queryformat', '%{NAME}\n', path])?.split('\n')[0]?.trim();
+ if (rpmName && /^[A-Za-z0-9._+-]+$/.test(rpmName)) return { format: 'rpm', name: rpmName };
+ return null;
+}
+
+function defaultNpmLs(args: string[]): string | null {
+ return defaultRunCommand('npm', args);
+}
+
const CALLOUT_RULE = '━'.repeat(64);
function formatInstallInstructions(
diff --git a/packages/core/src/constants/product.test.ts b/packages/core/src/constants/product.test.ts
index 5bedc6979..6b9ccb632 100644
--- a/packages/core/src/constants/product.test.ts
+++ b/packages/core/src/constants/product.test.ts
@@ -57,6 +57,45 @@ describe('resolveDesktopProductName', () => {
expect(DESKTOP_PRODUCTS.stable.keyringService).toBe('open-knowledge');
});
+ it('names each channel’s deb and rpm after its Linux executable', () => {
+ expect(
+ Object.fromEntries(
+ Object.entries(DESKTOP_PRODUCTS).map(([name, p]) => [name, p.linuxPackageNames]),
+ ),
+ ).toEqual({
+ stable: { deb: 'openknowledge', rpm: 'openknowledge' },
+ beta: { deb: 'openknowledge-beta', rpm: 'openknowledge-beta' },
+ });
+ for (const product of Object.values(DESKTOP_PRODUCTS)) {
+ expect(product.linuxPackageNames.deb).toBe(product.linuxExecutableName);
+ expect(product.linuxPackageNames.rpm).toBe(product.linuxExecutableName);
+ }
+ });
+
+ it('retires the package names each channel shipped before, and only its own', () => {
+ expect(DESKTOP_PRODUCTS.stable.retiredLinuxPackageNames).toEqual({
+ deb: [],
+ rpm: ['OpenKnowledge'],
+ });
+ expect(DESKTOP_PRODUCTS.beta.retiredLinuxPackageNames).toEqual({
+ deb: ['openknowledge-beta-desktop'],
+ rpm: ['openknowledge-beta-desktop'],
+ });
+ const current = Object.values(DESKTOP_PRODUCTS).flatMap((p) => [
+ p.linuxPackageNames.deb,
+ p.linuxPackageNames.rpm,
+ ]);
+ const retired = Object.values(DESKTOP_PRODUCTS).flatMap((p) => [
+ ...p.retiredLinuxPackageNames.deb,
+ ...p.retiredLinuxPackageNames.rpm,
+ ]);
+ for (const name of retired) expect(current).not.toContain(name);
+ for (const product of Object.values(DESKTOP_PRODUCTS)) {
+ for (const name of product.retiredLinuxPackageNames.deb)
+ expect(name).toMatch(/^[a-z0-9.+-]+$/);
+ }
+ });
+
it('gives every channel its own deep-link scheme, keeping Stable on openknowledge', () => {
expect(
Object.fromEntries(
diff --git a/packages/core/src/constants/product.ts b/packages/core/src/constants/product.ts
index 99390bf83..3974a2b6a 100644
--- a/packages/core/src/constants/product.ts
+++ b/packages/core/src/constants/product.ts
@@ -7,7 +7,11 @@ export const DESKTOP_PRODUCTS = {
protocolScheme: 'openknowledge',
linuxPackageNames: {
deb: 'openknowledge',
- rpm: 'OpenKnowledge',
+ rpm: 'openknowledge',
+ },
+ retiredLinuxPackageNames: {
+ deb: [],
+ rpm: ['OpenKnowledge'],
},
cliCommandNames: ['ok', 'open-knowledge'],
mcpServerName: 'open-knowledge',
@@ -23,8 +27,12 @@ export const DESKTOP_PRODUCTS = {
linuxExecutableName: 'openknowledge-beta',
protocolScheme: 'openknowledge-beta',
linuxPackageNames: {
- deb: 'openknowledge-beta-desktop',
- rpm: 'openknowledge-beta-desktop',
+ deb: 'openknowledge-beta',
+ rpm: 'openknowledge-beta',
+ },
+ retiredLinuxPackageNames: {
+ deb: ['openknowledge-beta-desktop'],
+ rpm: ['openknowledge-beta-desktop'],
},
cliCommandNames: ['ok-beta', 'open-knowledge-beta'],
mcpServerName: 'open-knowledge-beta',
diff --git a/packages/desktop/build/deb-postinst.sh b/packages/desktop/build/deb-postinst.sh
index 6176b0f93..45c36d763 100644
--- a/packages/desktop/build/deb-postinst.sh
+++ b/packages/desktop/build/deb-postinst.sh
@@ -27,9 +27,11 @@ if hash update-desktop-database 2>/dev/null; then
update-desktop-database /usr/share/applications || true
fi
+rm -f '/etc/apparmor.d/${executable}'
+
if apparmor_status --enabled > /dev/null 2>&1; then
APPARMOR_PROFILE_SOURCE='/opt/${sanitizedProductName}/resources/apparmor-profile'
- APPARMOR_PROFILE_TARGET='/etc/apparmor.d/${executable}'
+ APPARMOR_PROFILE_TARGET='/etc/apparmor.d/${executable}-userns'
if apparmor_parser --skip-kernel-load --debug "$APPARMOR_PROFILE_SOURCE" > /dev/null 2>&1; then
cp -f "$APPARMOR_PROFILE_SOURCE" "$APPARMOR_PROFILE_TARGET"
if ! { [ -x '/usr/bin/ischroot' ] && /usr/bin/ischroot; } && hash apparmor_parser 2>/dev/null; then
diff --git a/packages/desktop/build/deb-postrm.sh b/packages/desktop/build/deb-postrm.sh
index 665bc7b45..f37de042a 100644
--- a/packages/desktop/build/deb-postrm.sh
+++ b/packages/desktop/build/deb-postrm.sh
@@ -13,11 +13,7 @@ else
rm -f '/usr/bin/${executable}'
fi
-APPARMOR_PROFILE_DEST='/etc/apparmor.d/${executable}'
-
-if [ -f "$APPARMOR_PROFILE_DEST" ]; then
- rm -f "$APPARMOR_PROFILE_DEST"
-fi
+rm -f '/etc/apparmor.d/${executable}-userns' '/etc/apparmor.d/${executable}'
for link in /usr/bin/ok /usr/bin/open-knowledge; do
if [ -L "$link" ]; then
diff --git a/packages/desktop/scripts/desktop-variant-config.ts b/packages/desktop/scripts/desktop-variant-config.ts
index 443ae42cc..b2b9ae5b4 100644
--- a/packages/desktop/scripts/desktop-variant-config.ts
+++ b/packages/desktop/scripts/desktop-variant-config.ts
@@ -12,6 +12,7 @@ interface LinuxPackageTargetConfig {
afterRemove: string;
packageName?: string;
depends?: string[];
+ fpm?: string[];
}
interface BuilderConfig {
@@ -53,6 +54,7 @@ export interface VariantConfigPaths {
readonly includePath: string;
readonly postInstallPath: string;
readonly postRemovePath: string;
+ readonly postTransactionPath: string;
readonly localEntitlementsPath: string;
readonly helperInfoPath: string;
readonly profileAvailable: boolean;
@@ -117,6 +119,28 @@ export function createVariantBuilderConfig(
config.linux.executableName = variant.linuxExecutableName;
config.deb.packageName = variant.linuxPackageNames.deb;
config.rpm.packageName = variant.linuxPackageNames.rpm;
+ config.deb.fpm = [
+ ...(config.deb.fpm ?? []),
+ ...variant.retiredLinuxPackageNames.deb.flatMap((name) => [
+ '--replaces',
+ name,
+ '--conflicts',
+ name,
+ '--provides',
+ name,
+ ]),
+ ];
+ config.rpm.fpm = [
+ ...(config.rpm.fpm ?? []),
+ ...variant.retiredLinuxPackageNames.rpm.flatMap((name) => [
+ '--replaces',
+ name,
+ '--provides',
+ name,
+ ]),
+ '--rpm-posttrans',
+ paths.postTransactionPath,
+ ];
config.nsis.include = paths.includePath;
config.deb.afterInstall = paths.postInstallPath;
config.deb.afterRemove = paths.postRemovePath;
@@ -212,6 +236,29 @@ export function createVariantPostRemove(source: string, variantName: DesktopVari
);
}
+export function createVariantPostTransaction(
+ postInstallSource: string,
+ variantName: DesktopVariantName,
+): string {
+ const variant = DESKTOP_VARIANTS[variantName];
+ const macros = new Map([
+ ['executable', variant.linuxExecutableName],
+ ['sanitizedProductName', variant.productName],
+ ]);
+ return createVariantPostInstall(postInstallSource, variantName).replace(
+ /\$\{([^}]*)\}/g,
+ (macro, name: string) => {
+ const value = macros.get(name);
+ if (value === undefined) {
+ throw new Error(
+ `Desktop packaging template build/deb-postinst.sh uses ${macro}, which the rpm post-transaction script cannot expand.`,
+ );
+ }
+ return value;
+ },
+ );
+}
+
export function createLocalEntitlements(source: string): string {
return replaceRequired(
source,
diff --git a/packages/desktop/scripts/run-electron-builder.mjs b/packages/desktop/scripts/run-electron-builder.mjs
index 45829549a..6c9f4a299 100644
--- a/packages/desktop/scripts/run-electron-builder.mjs
+++ b/packages/desktop/scripts/run-electron-builder.mjs
@@ -12,6 +12,7 @@ import {
createVariantNsisInclude,
createVariantPostInstall,
createVariantPostRemove,
+ createVariantPostTransaction,
parseBuilderConfig,
} from './desktop-variant-config.ts';
import {
@@ -41,6 +42,7 @@ mkdirSync(buildDir, { recursive: true });
const includePath = '.variant-build/installer.nsh';
const postInstallPath = '.variant-build/deb-postinst.sh';
const postRemovePath = '.variant-build/deb-postrm.sh';
+const postTransactionPath = '.variant-build/rpm-posttrans.sh';
const localEntitlementsPath = '.variant-build/entitlements.mac.local.plist';
const helperInfoPath = '.variant-build/helper-Info.plist';
@@ -53,6 +55,7 @@ const config = createVariantBuilderConfig(
includePath,
postInstallPath,
postRemovePath,
+ postTransactionPath,
localEntitlementsPath,
helperInfoPath,
profileAvailable,
@@ -73,6 +76,10 @@ writeFileSync(
postRemovePath,
createVariantPostRemove(readFileSync('build/deb-postrm.sh', 'utf8'), variantName),
);
+writeFileSync(
+ postTransactionPath,
+ createVariantPostTransaction(readFileSync('build/deb-postinst.sh', 'utf8'), variantName),
+);
writeFileSync(
localEntitlementsPath,
createLocalEntitlements(readFileSync('build/entitlements.mac.plist', 'utf8')),
diff --git a/packages/desktop/src/shared/desktop-variant.ts b/packages/desktop/src/shared/desktop-variant.ts
index 7405a7552..21fa91d29 100644
--- a/packages/desktop/src/shared/desktop-variant.ts
+++ b/packages/desktop/src/shared/desktop-variant.ts
@@ -21,6 +21,10 @@ interface DesktopVariantIdentity {
readonly deb: string;
readonly rpm: string;
};
+ readonly retiredLinuxPackageNames: {
+ readonly deb: readonly string[];
+ readonly rpm: readonly string[];
+ };
readonly cliCommandNames: readonly [string, string];
readonly cliHomeSegment: string | null;
}
@@ -40,6 +44,7 @@ const DESKTOP_PRODUCT_VARIANTS = {
windowsIconPath: 'build/icon.ico',
linuxExecutableName: DESKTOP_PRODUCTS.stable.linuxExecutableName,
linuxPackageNames: DESKTOP_PRODUCTS.stable.linuxPackageNames,
+ retiredLinuxPackageNames: DESKTOP_PRODUCTS.stable.retiredLinuxPackageNames,
cliCommandNames: DESKTOP_PRODUCTS.stable.cliCommandNames,
cliHomeSegment: null,
},
@@ -57,6 +62,7 @@ const DESKTOP_PRODUCT_VARIANTS = {
windowsIconPath: 'build/icon-beta.ico',
linuxExecutableName: DESKTOP_PRODUCTS.beta.linuxExecutableName,
linuxPackageNames: DESKTOP_PRODUCTS.beta.linuxPackageNames,
+ retiredLinuxPackageNames: DESKTOP_PRODUCTS.beta.retiredLinuxPackageNames,
cliCommandNames: DESKTOP_PRODUCTS.beta.cliCommandNames,
cliHomeSegment: 'beta',
},
diff --git a/packages/desktop/tests/support/retired-beta-deb-postrm.sh b/packages/desktop/tests/support/retired-beta-deb-postrm.sh
new file mode 100644
index 000000000..a9d1fc79d
--- /dev/null
+++ b/packages/desktop/tests/support/retired-beta-deb-postrm.sh
@@ -0,0 +1,26 @@
+#!/bin/bash
+
+case "$1" in
+ upgrade | failed-upgrade | abort-upgrade | [1-9]*) exit 0 ;;
+esac
+
+if type update-alternatives >/dev/null 2>&1; then
+ update-alternatives --remove 'openknowledge-beta' '/usr/bin/openknowledge-beta'
+else
+ rm -f '/usr/bin/openknowledge-beta'
+fi
+
+APPARMOR_PROFILE_DEST='/etc/apparmor.d/openknowledge-beta'
+
+if [ -f "$APPARMOR_PROFILE_DEST" ]; then
+ rm -f "$APPARMOR_PROFILE_DEST"
+fi
+
+for link in /usr/bin/ok-beta /usr/bin/open-knowledge-beta; do
+ if [ -L "$link" ]; then
+ target=$(readlink "$link")
+ case "$target" in
+ '/opt/OpenKnowledge Beta/'*) rm -f "$link" ;;
+ esac
+ fi
+done
diff --git a/packages/desktop/tests/unit/desktop-variant-config.test.ts b/packages/desktop/tests/unit/desktop-variant-config.test.ts
index 10198d8d9..92202044b 100644
--- a/packages/desktop/tests/unit/desktop-variant-config.test.ts
+++ b/packages/desktop/tests/unit/desktop-variant-config.test.ts
@@ -22,6 +22,7 @@ import {
createVariantNsisInclude,
createVariantPostInstall,
createVariantPostRemove,
+ createVariantPostTransaction,
parseBuilderConfig,
} from '../../scripts/desktop-variant-config.ts';
import { MAC_UPDATE_MINIMUM_DARWIN_VERSION } from '../../scripts/mac-update-manifest.ts';
@@ -214,6 +215,7 @@ const paths = {
includePath: '.variant-build/installer.nsh',
postInstallPath: '.variant-build/deb-postinst.sh',
postRemovePath: '.variant-build/deb-postrm.sh',
+ postTransactionPath: '.variant-build/rpm-posttrans.sh',
localEntitlementsPath: '.variant-build/entitlements.mac.local.plist',
helperInfoPath: '.variant-build/helper-Info.plist',
profileAvailable: false,
@@ -277,12 +279,21 @@ describe('desktop variant builder config', () => {
afterInstall: paths.postInstallPath,
afterRemove: paths.postRemovePath,
packageName: 'openknowledge',
+ fpm: [],
},
rpm: {
afterInstall: paths.postInstallPath,
afterRemove: paths.postRemovePath,
- packageName: 'OpenKnowledge',
+ packageName: 'openknowledge',
depends: ['libsecret'],
+ fpm: [
+ '--replaces',
+ 'OpenKnowledge',
+ '--provides',
+ 'OpenKnowledge',
+ '--rpm-posttrans',
+ paths.postTransactionPath,
+ ],
},
});
expect(config.win.extraResources).toEqual([
@@ -322,13 +333,29 @@ describe('desktop variant builder config', () => {
deb: {
afterInstall: paths.postInstallPath,
afterRemove: paths.postRemovePath,
- packageName: 'openknowledge-beta-desktop',
+ packageName: 'openknowledge-beta',
+ fpm: [
+ '--replaces',
+ 'openknowledge-beta-desktop',
+ '--conflicts',
+ 'openknowledge-beta-desktop',
+ '--provides',
+ 'openknowledge-beta-desktop',
+ ],
},
rpm: {
afterInstall: paths.postInstallPath,
afterRemove: paths.postRemovePath,
- packageName: 'openknowledge-beta-desktop',
+ packageName: 'openknowledge-beta',
depends: ['libsecret'],
+ fpm: [
+ '--replaces',
+ 'openknowledge-beta-desktop',
+ '--provides',
+ 'openknowledge-beta-desktop',
+ '--rpm-posttrans',
+ paths.postTransactionPath,
+ ],
},
});
expect(beta.mac.provisioningProfile).toBeUndefined();
@@ -396,6 +423,37 @@ describe('desktop variant builder config', () => {
).toContain('/usr/bin/ok-beta /usr/bin/open-knowledge-beta');
});
+ test.each([
+ {
+ variant: 'stable',
+ links: ['/usr/bin/ok', '/usr/bin/open-knowledge'],
+ exe: "'/opt/OpenKnowledge/openknowledge'",
+ },
+ {
+ variant: 'beta',
+ links: ['/usr/bin/ok-beta', '/usr/bin/open-knowledge-beta'],
+ exe: "'/opt/OpenKnowledge Beta/openknowledge-beta'",
+ },
+ ] as const)(
+ 'rebuilds the $variant postinst as an rpm post-transaction script with every macro expanded',
+ ({ variant, links, exe }) => {
+ const postInstall = readFileSync(resolve(desktopRoot, 'build/deb-postinst.sh'), 'utf8');
+ const script = createVariantPostTransaction(postInstall, variant);
+ expect(script).not.toMatch(/\$\{/);
+ expect(script).toContain(exe);
+ for (const link of links) expect(script).toContain(`ln -sf "$OK_WRAPPER" ${link}`);
+ },
+ );
+
+ test('refuses a post-transaction template with a macro it cannot expand', () => {
+ expect(() =>
+ createVariantPostTransaction(
+ `ln -sf "$OK_WRAPPER" /usr/bin/ok\nln -sf "$OK_WRAPPER" /usr/bin/open-knowledge\n${token('version')}`,
+ 'beta',
+ ),
+ ).toThrow(/\$\{version\}/);
+ });
+
test('drops the restricted entitlement for unsigned local variant builds', () => {
expect(
createLocalEntitlements(
@@ -426,6 +484,7 @@ describe('desktop variant builder config', () => {
expect(() => createVariantNsisInclude(installer, variant)).not.toThrow();
expect(() => createVariantPostInstall(postInstall, variant)).not.toThrow();
expect(() => createVariantPostRemove(postRemove, variant)).not.toThrow();
+ expect(() => createVariantPostTransaction(postInstall, variant)).not.toThrow();
expect(() => createVariantHelperInfo(helperInfo, variant)).not.toThrow();
}
expect(() => createLocalEntitlements(entitlements)).not.toThrow();
@@ -492,6 +551,13 @@ describe('electron-builder wrapper execution', () => {
);
expect(generated.npmRebuild).toBe(target === '--linux' ? false : baseRebuild);
expect(generated.mac.notarize).toBe(false);
+ expect(generated.rpm.fpm.slice(-2)).toEqual([
+ '--rpm-posttrans',
+ '.variant-build/rpm-posttrans.sh',
+ ]);
+ expect(readFileSync(join(fixture, '.variant-build/rpm-posttrans.sh'), 'utf8')).toContain(
+ `/opt/${DESKTOP_VARIANTS[variant as keyof typeof DESKTOP_VARIANTS].productName}/`,
+ );
if (target === '--mac') {
const manifest = parseYaml(
readFileSync(join(fixture, 'dist-desktop/latest-mac.yml'), 'utf8'),
diff --git a/packages/desktop/tests/unit/helper-bundle-name-agreement.test.ts b/packages/desktop/tests/unit/helper-bundle-name-agreement.test.ts
index 698ec13f4..7cb0853f5 100644
--- a/packages/desktop/tests/unit/helper-bundle-name-agreement.test.ts
+++ b/packages/desktop/tests/unit/helper-bundle-name-agreement.test.ts
@@ -69,6 +69,7 @@ describe('helper-bundle name agreement across spawn site / Info.plist / afterPac
includePath: 'installer.nsh',
postInstallPath: 'deb-postinst.sh',
postRemovePath: 'deb-postrm.sh',
+ postTransactionPath: 'rpm-posttrans.sh',
localEntitlementsPath: 'entitlements.mac.local.plist',
helperInfoPath: 'helper-Info.plist',
profileAvailable: false,
diff --git a/packages/desktop/tests/unit/linux-package-scripts.test.ts b/packages/desktop/tests/unit/linux-package-scripts.test.ts
new file mode 100644
index 000000000..a097e1172
--- /dev/null
+++ b/packages/desktop/tests/unit/linux-package-scripts.test.ts
@@ -0,0 +1,141 @@
+import { spawnSync } from 'node:child_process';
+import {
+ chmodSync,
+ existsSync,
+ mkdirSync,
+ mkdtempSync,
+ readdirSync,
+ readFileSync,
+ writeFileSync,
+} from 'node:fs';
+import { tmpdir } from 'node:os';
+import { dirname, join, resolve } from 'node:path';
+import { fileURLToPath } from 'node:url';
+import { afterEach, describe, expect, test } from 'vitest';
+import {
+ createVariantPostRemove,
+ createVariantPostTransaction,
+} from '../../scripts/desktop-variant-config.ts';
+import { DESKTOP_VARIANTS } from '../../src/shared/desktop-variant.ts';
+import { removeTempDirBestEffort } from '../support/temp-dir-cleanup.test-helper';
+
+const desktopRoot = resolve(dirname(fileURLToPath(import.meta.url)), '../..');
+const PROFILE = 'profile openknowledge-beta flags=(unconfined) { userns, }\n';
+const roots: string[] = [];
+
+afterEach(() => {
+ for (const root of roots.splice(0)) removeTempDirBestEffort(root);
+});
+
+function installRoot() {
+ const root = mkdtempSync(join(tmpdir(), 'ok-linux-scripts-'));
+ roots.push(root);
+ const app = join(root, 'opt/OpenKnowledge Beta');
+ mkdirSync(join(app, 'resources/cli/bin'), { recursive: true });
+ for (const dir of ['etc/apparmor.d', 'usr/bin', 'usr/share/mime', 'usr/share/applications']) {
+ mkdirSync(join(root, dir), { recursive: true });
+ }
+ writeFileSync(join(app, 'openknowledge-beta'), '');
+ writeFileSync(join(app, 'chrome-sandbox'), '');
+ writeFileSync(join(app, 'resources/apparmor-profile'), PROFILE);
+ writeFileSync(join(app, 'resources/cli/bin/ok.sh'), '');
+ const stubs = join(root, 'stubs');
+ mkdirSync(stubs);
+ for (const [name, status] of [
+ ['apparmor_status', 0],
+ ['apparmor_parser', 0],
+ ['update-alternatives', 1],
+ ['update-mime-database', 0],
+ ['update-desktop-database', 0],
+ ] as const) {
+ writeFileSync(join(stubs, name), `#!/bin/sh\nexit ${status}\n`);
+ chmodSync(join(stubs, name), 0o755);
+ }
+ return root;
+}
+
+function run(root: string, script: string, action: string) {
+ const rooted = script.replace(/(?<=['" =])\/(opt|usr|etc)\//g, `${root}/$1/`);
+ const result = spawnSync('bash', ['-s', action], {
+ input: rooted,
+ encoding: 'utf8',
+ env: { PATH: `${join(root, 'stubs')}:/usr/bin:/bin` },
+ });
+ expect(result.status, result.stderr).toBe(0);
+}
+
+function expandMacros(script: string) {
+ const variant = DESKTOP_VARIANTS.beta;
+ const macros = new Map([
+ ['executable', variant.linuxExecutableName],
+ ['sanitizedProductName', variant.productName],
+ ]);
+ return script.replace(/\$\{([^}]*)\}/g, (macro, name: string) => macros.get(name) ?? macro);
+}
+
+const postInstall = () =>
+ createVariantPostTransaction(
+ readFileSync(resolve(desktopRoot, 'build/deb-postinst.sh'), 'utf8'),
+ 'beta',
+ );
+const postRemove = () =>
+ expandMacros(
+ createVariantPostRemove(
+ readFileSync(resolve(desktopRoot, 'build/deb-postrm.sh'), 'utf8'),
+ 'beta',
+ ),
+ );
+const retiredPostRemove = () =>
+ readFileSync(resolve(desktopRoot, 'tests/support/retired-beta-deb-postrm.sh'), 'utf8');
+
+function installedProfiles(root: string) {
+ const dir = join(root, 'etc/apparmor.d');
+ return readdirSync(dir).filter((name) => readFileSync(join(dir, name), 'utf8') === PROFILE);
+}
+
+describe.skipIf(process.platform === 'win32')('Beta deb maintainer scripts', () => {
+ test('keeps the AppArmor profile when the retired package’s leftover record is purged', () => {
+ const root = installRoot();
+ run(root, postInstall(), 'configure');
+ expect(installedProfiles(root)).toHaveLength(1);
+
+ run(root, retiredPostRemove(), 'purge');
+
+ expect(installedProfiles(root)).toHaveLength(1);
+ });
+
+ test('a reinstall restores the CLI links that purge deletes', () => {
+ const root = installRoot();
+ run(root, postInstall(), 'configure');
+ run(root, retiredPostRemove(), 'purge');
+ expect(existsSync(join(root, 'usr/bin/ok-beta'))).toBe(false);
+
+ run(root, postInstall(), 'configure');
+
+ for (const link of ['ok-beta', 'open-knowledge-beta']) {
+ expect(existsSync(join(root, 'usr/bin', link))).toBe(true);
+ }
+ expect(installedProfiles(root)).toHaveLength(1);
+ });
+
+ test('moves a profile an earlier package installed so only one copy loads', () => {
+ const root = installRoot();
+ writeFileSync(join(root, 'etc/apparmor.d/openknowledge-beta'), PROFILE);
+
+ run(root, postInstall(), 'configure');
+
+ expect(installedProfiles(root)).toHaveLength(1);
+ });
+
+ test('removing the package removes its profile and links', () => {
+ const root = installRoot();
+ run(root, postInstall(), 'configure');
+
+ run(root, postRemove(), 'remove');
+
+ expect(installedProfiles(root)).toEqual([]);
+ for (const link of ['ok-beta', 'open-knowledge-beta']) {
+ expect(existsSync(join(root, 'usr/bin', link))).toBe(false);
+ }
+ });
+});