@uppercut-labs/desktop-installed-check 0.0.0-stage → 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +85 -2
- package/dist/index.d.ts +55 -0
- package/dist/index.js +54 -0
- package/package.json +50 -4
- package/scripts/installed-check.sh +275 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Uppercut Labs
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,3 +1,86 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @uppercut-labs/desktop-installed-check
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Checks an installed desktop app on macOS and Linux through files and the app's own control channel, never through input events, so it takes no focus and types nothing. It is one POSIX shell script with seven steps, plus a small Node wrapper that runs a step and reads the verdict.
|
|
4
|
+
|
|
5
|
+
```sh
|
|
6
|
+
npm install --save-dev @uppercut-labs/desktop-installed-check
|
|
7
|
+
```
|
|
8
|
+
|
|
9
|
+
## What the script checks
|
|
10
|
+
|
|
11
|
+
| Step | What it does |
|
|
12
|
+
| --- | --- |
|
|
13
|
+
| `list` | What is installed: files, bundled helpers, notices. On macOS the code signature and hardened-runtime flag of the bundle and of every helper, entitlements, Gatekeeper and quarantine. On Linux the package, the sandbox helper's owner and mode, the desktop entry, icons, shared libraries and the AppArmor profile |
|
|
14
|
+
| `helpers` | Runs every bundled helper from its installed location, started by the installed app's own executable acting as Node (`ELECTRON_RUN_AS_NODE=1`) with `PATH` emptied |
|
|
15
|
+
| `launch` | Starts the app from its real launcher: `open` on the bundle (macOS) or the command line in the installed desktop entry (Linux) |
|
|
16
|
+
| `collect` | Asks the running app, through its control channel and never through a second launch, for its diagnostics and a picture of its window |
|
|
17
|
+
| `memory` | Private memory over the app's processes, by each system's definition: `footprint` on macOS, `Anonymous` plus `Swap` from `smaps_rollup` on Linux |
|
|
18
|
+
| `quit` | Asks the running app to close |
|
|
19
|
+
| `uninstall` | Removes the installed copy and never the data folder |
|
|
20
|
+
|
|
21
|
+
Every line goes to the terminal and to `<EVIDENCE>/installed-<step>.txt`. The script exits 1 when any line starts with `FAILED:`, and 0 otherwise. An unknown step is a failure.
|
|
22
|
+
|
|
23
|
+
## Use
|
|
24
|
+
|
|
25
|
+
The script reads the names of the app from a file, which your packaging step writes:
|
|
26
|
+
|
|
27
|
+
```sh
|
|
28
|
+
# out/package.env
|
|
29
|
+
PRODUCT_NAME="Example App"
|
|
30
|
+
EXE_NAME=example
|
|
31
|
+
LINUX_NAME=example
|
|
32
|
+
APP_ID=com.example.app
|
|
33
|
+
VERSION=1.2.3
|
|
34
|
+
HELPERS="ffmpeg ffprobe"
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
```sh
|
|
38
|
+
PACKAGE_ENV=out/package.env EVIDENCE=qa/evidence DATA_DIR=/tmp/app-data NO_ACTIVATE=1 \
|
|
39
|
+
sh node_modules/@uppercut-labs/desktop-installed-check/scripts/installed-check.sh list
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
| Variable | Meaning |
|
|
43
|
+
| --- | --- |
|
|
44
|
+
| `PACKAGE_ENV` | The names file above (default `out/package.env`). `HELPERS` is the bundled helper programs separated by spaces, and may be empty |
|
|
45
|
+
| `EVIDENCE` | Where result files go (default `qa/evidence`). On macOS keep it and `DATA_DIR` on the internal disk: an app started by `open` that touches a removable or network volume waits for a privacy prompt that nobody answers |
|
|
46
|
+
| `DATA_DIR` | The app's data folder. `collect` and `quit` find the running app's control channel through `control.json` there, so they require it |
|
|
47
|
+
| `APP_SCRIPTS` | The folder holding the app's own `control.cjs`, `installed-helpers.cjs` and `installed-diagnostics.cjs` (default: the folder of the script) |
|
|
48
|
+
| `INSTALL_TO` | macOS: the Applications folder (default `~/Applications`). Linux portable: the folder it was unpacked into (default `~/.local/opt`) |
|
|
49
|
+
| `KIND` | Linux: `deb` (default) or `portable` |
|
|
50
|
+
| `NO_ACTIVATE=1` | `launch` without taking focus, so the app serves its control channel |
|
|
51
|
+
| `EMPTY_PATH=1` | `launch` with `PATH` emptied, to prove nothing is looked up there |
|
|
52
|
+
| `LAUNCH_EXTRA` | `launch` only: more arguments, separated by spaces, such as `--remote-debugging-port=9333 --mute-audio` |
|
|
53
|
+
| `BUDGET_MB`, `CEILING_MB` | The `memory` step's limits, `300` and `680` by default. Over the budget is a note; over the ceiling is a failure |
|
|
54
|
+
|
|
55
|
+
The `collect`, `helpers` and `quit` steps call scripts that belong to the app: `control.cjs` (a client of [`@uppercut-labs/electron-control-channel`](../electron-control-channel)), `installed-helpers.cjs` and `installed-diagnostics.cjs`, found in `APP_SCRIPTS`. `list`, `launch`, `memory` and `uninstall` need none of them.
|
|
56
|
+
|
|
57
|
+
## From Node
|
|
58
|
+
|
|
59
|
+
```ts
|
|
60
|
+
import { runInstalledCheck } from '@uppercut-labs/desktop-installed-check';
|
|
61
|
+
|
|
62
|
+
const run = await runInstalledCheck('list', { packageEnv: 'out/package.env', evidenceDir: 'qa/evidence' });
|
|
63
|
+
if (!run.report.passed) console.error(run.report.failed);
|
|
64
|
+
```
|
|
65
|
+
|
|
66
|
+
| Export | Meaning |
|
|
67
|
+
| --- | --- |
|
|
68
|
+
| `installedCheckScript` | Absolute path of the script. `require.resolve('@uppercut-labs/desktop-installed-check/installed-check.sh')` gives the same file |
|
|
69
|
+
| `runInstalledCheck(step, options)` | Runs one step with `sh` and returns `{ step, exitCode, output, report }`. Options map to the variables above: `packageEnv`, `evidenceDir`, `appScripts`, `dataDir`, `installTo`, `kind`, `noActivate`, `emptyPath`, `launchExtra`, `budgetMb`, `ceilingMb`, `env`, `timeoutMs`, `shell` |
|
|
70
|
+
| `parseInstalledCheckOutput(text)` | Reads a step's text into `{ failed, finished, passed, overBudget, memory? }`. `finished` is true only when the script reached its last line, so a killed script does not pass |
|
|
71
|
+
| `installedCheckEnvironment(options)` | The environment `runInstalledCheck` builds |
|
|
72
|
+
| `INSTALLED_CHECK_STEPS` | The step names |
|
|
73
|
+
|
|
74
|
+
## What runs where
|
|
75
|
+
|
|
76
|
+
| Part | Language | Runs on |
|
|
77
|
+
| --- | --- | --- |
|
|
78
|
+
| `scripts/installed-check.sh` | POSIX `sh`, not Bash-specific (it runs under `dash` and `bash`) | macOS and Linux |
|
|
79
|
+
| The Node wrapper (`runInstalledCheck` and the rest) | TypeScript on Node 18 or later; it starts `sh` | macOS and Linux |
|
|
80
|
+
| The parser and environment helpers (`parseInstalledCheckOutput`, `installedCheckEnvironment`) | TypeScript on Node 18 or later | any system, Windows included |
|
|
81
|
+
|
|
82
|
+
There is no PowerShell part and no Windows version of the check. On Windows, write the same steps as a PowerShell script in your own project, using the same step names and the same `FAILED:` convention, so `parseInstalledCheckOutput` reads its output too. Under Windows the package's script tests are skipped.
|
|
83
|
+
|
|
84
|
+
## License
|
|
85
|
+
|
|
86
|
+
MIT
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
/** Absolute path of the canonical `installed-check.sh` shipped in this package. */
|
|
2
|
+
export declare const installedCheckScript: string;
|
|
3
|
+
export declare const INSTALLED_CHECK_STEPS: readonly ["list", "helpers", "launch", "collect", "memory", "quit", "uninstall"];
|
|
4
|
+
export type InstalledCheckStep = (typeof INSTALLED_CHECK_STEPS)[number];
|
|
5
|
+
export interface InstalledCheckMemory {
|
|
6
|
+
mb: number;
|
|
7
|
+
budgetMb: number;
|
|
8
|
+
ceilingMb: number;
|
|
9
|
+
}
|
|
10
|
+
export interface InstalledCheckReport {
|
|
11
|
+
/** Every line that starts with `FAILED:`, without the prefix. */
|
|
12
|
+
failed: string[];
|
|
13
|
+
/** The script reached its last line. A script that was killed or crashed did not. */
|
|
14
|
+
finished: boolean;
|
|
15
|
+
/** Present for the memory step. */
|
|
16
|
+
memory?: InstalledCheckMemory;
|
|
17
|
+
/** The memory step said the app is over budget and the reason must be recorded. */
|
|
18
|
+
overBudget: boolean;
|
|
19
|
+
/** `finished` and no failures. */
|
|
20
|
+
passed: boolean;
|
|
21
|
+
}
|
|
22
|
+
/** Reads the text an `installed-check.sh` step wrote (its stdout, or `installed-<step>.txt`). */
|
|
23
|
+
export declare function parseInstalledCheckOutput(text: string): InstalledCheckReport;
|
|
24
|
+
export interface InstalledCheckOptions {
|
|
25
|
+
/** The names file the packaging step wrote (`PACKAGE_ENV`). */
|
|
26
|
+
packageEnv: string;
|
|
27
|
+
/** Where `installed-<step>.txt` and the other result files go (`EVIDENCE`). */
|
|
28
|
+
evidenceDir: string;
|
|
29
|
+
/** The folder with the app's own control.cjs, installed-helpers.cjs and installed-diagnostics.cjs (`APP_SCRIPTS`). */
|
|
30
|
+
appScripts?: string;
|
|
31
|
+
dataDir?: string;
|
|
32
|
+
installTo?: string;
|
|
33
|
+
kind?: 'deb' | 'portable';
|
|
34
|
+
noActivate?: boolean;
|
|
35
|
+
emptyPath?: boolean;
|
|
36
|
+
launchExtra?: string;
|
|
37
|
+
budgetMb?: number;
|
|
38
|
+
ceilingMb?: number;
|
|
39
|
+
/** Extra environment variables. The current environment is passed through. */
|
|
40
|
+
env?: NodeJS.ProcessEnv;
|
|
41
|
+
/** Default 120000. */
|
|
42
|
+
timeoutMs?: number;
|
|
43
|
+
/** Shell to run the script with. Default `sh`. */
|
|
44
|
+
shell?: string;
|
|
45
|
+
}
|
|
46
|
+
export interface InstalledCheckRun {
|
|
47
|
+
step: InstalledCheckStep;
|
|
48
|
+
exitCode: number;
|
|
49
|
+
output: string;
|
|
50
|
+
report: InstalledCheckReport;
|
|
51
|
+
}
|
|
52
|
+
/** The environment variables the script reads, built from the options. */
|
|
53
|
+
export declare function installedCheckEnvironment(options: InstalledCheckOptions): NodeJS.ProcessEnv;
|
|
54
|
+
/** Runs one step of the installed-app check on macOS or Linux and returns its output and verdict. */
|
|
55
|
+
export declare function runInstalledCheck(step: InstalledCheckStep, options: InstalledCheckOptions): Promise<InstalledCheckRun>;
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import { execFile } from 'node:child_process';
|
|
2
|
+
import { fileURLToPath } from 'node:url';
|
|
3
|
+
/** Absolute path of the canonical `installed-check.sh` shipped in this package. */
|
|
4
|
+
export const installedCheckScript = fileURLToPath(new URL('../scripts/installed-check.sh', import.meta.url));
|
|
5
|
+
export const INSTALLED_CHECK_STEPS = ['list', 'helpers', 'launch', 'collect', 'memory', 'quit', 'uninstall'];
|
|
6
|
+
/** Reads the text an `installed-check.sh` step wrote (its stdout, or `installed-<step>.txt`). */
|
|
7
|
+
export function parseInstalledCheckOutput(text) {
|
|
8
|
+
const lines = text.split(/\r?\n/).map((line) => line.trimEnd());
|
|
9
|
+
const failed = lines.filter((line) => line.startsWith('FAILED:')).map((line) => line.slice('FAILED:'.length).trim());
|
|
10
|
+
const finished = lines.filter((line) => line !== '').at(-1) === 'done';
|
|
11
|
+
const overBudget = lines.some((line) => line.startsWith('over budget:'));
|
|
12
|
+
const report = { failed, finished, overBudget, passed: finished && failed.length === 0 };
|
|
13
|
+
for (const line of lines) {
|
|
14
|
+
const match = /^memory: ([\d.]+) MB \(.*\); budget ([\d.]+) MB, ceiling ([\d.]+) MB$/.exec(line);
|
|
15
|
+
if (match)
|
|
16
|
+
report.memory = { mb: Number(match[1]), budgetMb: Number(match[2]), ceilingMb: Number(match[3]) };
|
|
17
|
+
}
|
|
18
|
+
return report;
|
|
19
|
+
}
|
|
20
|
+
/** The environment variables the script reads, built from the options. */
|
|
21
|
+
export function installedCheckEnvironment(options) {
|
|
22
|
+
const env = { ...process.env, ...options.env, PACKAGE_ENV: options.packageEnv, EVIDENCE: options.evidenceDir };
|
|
23
|
+
const optional = [
|
|
24
|
+
['APP_SCRIPTS', options.appScripts],
|
|
25
|
+
['DATA_DIR', options.dataDir],
|
|
26
|
+
['INSTALL_TO', options.installTo],
|
|
27
|
+
['KIND', options.kind],
|
|
28
|
+
['LAUNCH_EXTRA', options.launchExtra],
|
|
29
|
+
['BUDGET_MB', options.budgetMb],
|
|
30
|
+
['CEILING_MB', options.ceilingMb],
|
|
31
|
+
];
|
|
32
|
+
for (const [name, value] of optional)
|
|
33
|
+
if (value !== undefined)
|
|
34
|
+
env[name] = String(value);
|
|
35
|
+
if (options.noActivate)
|
|
36
|
+
env.NO_ACTIVATE = '1';
|
|
37
|
+
if (options.emptyPath)
|
|
38
|
+
env.EMPTY_PATH = '1';
|
|
39
|
+
return env;
|
|
40
|
+
}
|
|
41
|
+
/** Runs one step of the installed-app check on macOS or Linux and returns its output and verdict. */
|
|
42
|
+
export function runInstalledCheck(step, options) {
|
|
43
|
+
if (!INSTALLED_CHECK_STEPS.includes(step))
|
|
44
|
+
return Promise.reject(new RangeError(`Unknown step '${String(step)}'`));
|
|
45
|
+
return new Promise((resolve, reject) => {
|
|
46
|
+
execFile(options.shell ?? 'sh', [installedCheckScript, step], { env: installedCheckEnvironment(options), timeout: options.timeoutMs ?? 120_000, maxBuffer: 8 * 1024 * 1024 }, (error, stdout, stderr) => {
|
|
47
|
+
const output = String(stdout) + String(stderr);
|
|
48
|
+
const code = error && typeof error.code === 'number' ? (error.code) : error ? -1 : 0;
|
|
49
|
+
if (error && code === -1)
|
|
50
|
+
return reject(error);
|
|
51
|
+
resolve({ step, exitCode: code, output, report: parseInstalledCheckOutput(output) });
|
|
52
|
+
});
|
|
53
|
+
});
|
|
54
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,52 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@uppercut-labs/desktop-installed-check",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "Check an installed desktop app on macOS and Linux through files and its control channel, never through input events: one POSIX shell script with seven steps, and a Node wrapper that runs a step and reads its verdict.",
|
|
5
|
+
"license": "MIT",
|
|
6
|
+
"author": "Uppercut Labs <packages@uppercut-labs.com>",
|
|
7
|
+
"type": "module",
|
|
8
|
+
"exports": {
|
|
9
|
+
".": {
|
|
10
|
+
"types": "./dist/index.d.ts",
|
|
11
|
+
"default": "./dist/index.js"
|
|
12
|
+
},
|
|
13
|
+
"./installed-check.sh": "./scripts/installed-check.sh"
|
|
14
|
+
},
|
|
15
|
+
"main": "./dist/index.js",
|
|
16
|
+
"types": "./dist/index.d.ts",
|
|
17
|
+
"files": [
|
|
18
|
+
"dist",
|
|
19
|
+
"scripts",
|
|
20
|
+
"README.md",
|
|
21
|
+
"LICENSE"
|
|
22
|
+
],
|
|
23
|
+
"sideEffects": false,
|
|
24
|
+
"scripts": {
|
|
25
|
+
"build": "tsc -p tsconfig.json",
|
|
26
|
+
"prepack": "node -e \"require('fs').copyFileSync('../../LICENSE','LICENSE')\""
|
|
27
|
+
},
|
|
28
|
+
"keywords": [
|
|
29
|
+
"electron",
|
|
30
|
+
"desktop",
|
|
31
|
+
"qa",
|
|
32
|
+
"installed-app",
|
|
33
|
+
"macos",
|
|
34
|
+
"linux",
|
|
35
|
+
"shell"
|
|
36
|
+
],
|
|
37
|
+
"repository": {
|
|
38
|
+
"type": "git",
|
|
39
|
+
"url": "git+https://github.com/uppercut-labs/js-kit.git",
|
|
40
|
+
"directory": "packages/desktop-installed-check"
|
|
41
|
+
},
|
|
42
|
+
"bugs": {
|
|
43
|
+
"url": "https://github.com/uppercut-labs/js-kit/issues"
|
|
44
|
+
},
|
|
45
|
+
"homepage": "https://github.com/uppercut-labs/js-kit/tree/main/packages/desktop-installed-check#readme",
|
|
46
|
+
"engines": {
|
|
47
|
+
"node": ">=18"
|
|
48
|
+
},
|
|
49
|
+
"publishConfig": {
|
|
50
|
+
"access": "public"
|
|
51
|
+
}
|
|
52
|
+
}
|
|
@@ -0,0 +1,275 @@
|
|
|
1
|
+
#!/bin/sh
|
|
2
|
+
# Checks the installed app on macOS or Linux through files, never through input
|
|
3
|
+
# events. It covers macOS and Linux; a Windows check needs its own script.
|
|
4
|
+
#
|
|
5
|
+
# scripts/installed-check.sh <step>
|
|
6
|
+
#
|
|
7
|
+
# list what is installed: files, helpers, notices, and on macOS the signature of the
|
|
8
|
+
# bundle and of every helper; on Linux the package, sandbox helper, desktop entry, icons
|
|
9
|
+
# helpers run every bundled helper from its installed location, started by the installed
|
|
10
|
+
# app's own executable with PATH emptied (installed-helpers.cjs)
|
|
11
|
+
# launch start the app from its real launcher: `open` on the bundle (macOS), the command
|
|
12
|
+
# line in the installed desktop entry (Linux)
|
|
13
|
+
# collect ask the running app (through its control channel, never a second launch) for its
|
|
14
|
+
# diagnostics and a picture of its window, and report
|
|
15
|
+
# where it runs from and what it says about its tool
|
|
16
|
+
# memory memory over the running app's processes, by this system's definition of private
|
|
17
|
+
# memory: `footprint` on macOS, Anonymous + Swap from smaps_rollup on Linux
|
|
18
|
+
# quit ask the running app to close
|
|
19
|
+
# uninstall remove the installed copy (never the data folder)
|
|
20
|
+
#
|
|
21
|
+
# Environment:
|
|
22
|
+
# INSTALL_TO macOS: the Applications folder used by install.sh (default ~/Applications)
|
|
23
|
+
# Linux portable: the folder it was unpacked into (default ~/.local/opt)
|
|
24
|
+
# KIND Linux: deb (default) or portable
|
|
25
|
+
# DATA_DIR keep the app's data here; required by collect and quit, which find the running
|
|
26
|
+
# app's control channel through control.json there
|
|
27
|
+
# NO_ACTIVATE=1 launch without taking focus (the app then serves its control channel)
|
|
28
|
+
# EMPTY_PATH=1 launch with PATH emptied, to prove nothing is looked up there
|
|
29
|
+
# LAUNCH_EXTRA launch only: more arguments, separated by spaces, for example
|
|
30
|
+
# "--remote-debugging-port=9333 --mute-audio" so a script can drive the
|
|
31
|
+
# page with input events through the DevTools protocol, silently;
|
|
32
|
+
# --control makes an app launched without NO_ACTIVATE serve its control channel
|
|
33
|
+
# EVIDENCE where installed-<step>.txt and the other result files go (default qa/evidence)
|
|
34
|
+
#
|
|
35
|
+
# On macOS keep DATA_DIR and EVIDENCE on the internal disk. An app started by
|
|
36
|
+
# `open` that touches a removable or network volume waits for a privacy prompt
|
|
37
|
+
# that nobody is there to answer, and stops at its first file call.
|
|
38
|
+
# PACKAGE_ENV the names file package.mjs wrote (default out/package.env). It sets
|
|
39
|
+
# PRODUCT_NAME, EXE_NAME, LINUX_NAME, APP_ID, VERSION and HELPERS (the bundled
|
|
40
|
+
# helper programs, separated by spaces; may be empty)
|
|
41
|
+
# APP_SCRIPTS the folder holding the app's own control.cjs, installed-helpers.cjs and
|
|
42
|
+
# installed-diagnostics.cjs (default: the folder of this script)
|
|
43
|
+
#
|
|
44
|
+
# The exit status is 1 when any line starting with FAILED: was written, otherwise 0.
|
|
45
|
+
set -u
|
|
46
|
+
STEP=${1:-list}
|
|
47
|
+
HERE=$(cd "$(dirname "$0")" && pwd)
|
|
48
|
+
ROOT=$(cd "$HERE/.." && pwd)
|
|
49
|
+
EVIDENCE=${EVIDENCE:-$ROOT/qa/evidence}
|
|
50
|
+
PACKAGE_ENV=${PACKAGE_ENV:-$ROOT/out/package.env}
|
|
51
|
+
APP_SCRIPTS=${APP_SCRIPTS:-$HERE}
|
|
52
|
+
mkdir -p "$EVIDENCE"
|
|
53
|
+
if [ ! -f "$PACKAGE_ENV" ]; then echo "FAILED: the names file $PACKAGE_ENV does not exist. Set PACKAGE_ENV." >&2; exit 1; fi
|
|
54
|
+
# shellcheck disable=SC1090
|
|
55
|
+
. "$PACKAGE_ENV"
|
|
56
|
+
HELPERS=${HELPERS-}
|
|
57
|
+
OUT="$EVIDENCE/installed-$STEP.txt"
|
|
58
|
+
: > "$OUT"
|
|
59
|
+
FAILED_ANY=0
|
|
60
|
+
say() {
|
|
61
|
+
case "$*" in FAILED:*) FAILED_ANY=1 ;; esac
|
|
62
|
+
echo "$*" | tee -a "$OUT"
|
|
63
|
+
}
|
|
64
|
+
OS=$(uname -s)
|
|
65
|
+
ARCH=$(uname -m | sed -e 's/x86_64/x64/' -e 's/aarch64/arm64/')
|
|
66
|
+
KIND=${KIND:-deb}
|
|
67
|
+
say "step $STEP at $(date +%Y-%m-%dT%H:%M:%S%z) on $OS $ARCH"
|
|
68
|
+
|
|
69
|
+
if [ "$OS" = Darwin ]; then
|
|
70
|
+
APP="${INSTALL_TO:-$HOME/Applications}/$PRODUCT_NAME.app"
|
|
71
|
+
APPROOT="$APP"
|
|
72
|
+
BIN="$APP/Contents/MacOS/$EXE_NAME"
|
|
73
|
+
RES="$APP/Contents/Resources"
|
|
74
|
+
TARGET="darwin-$ARCH"
|
|
75
|
+
else
|
|
76
|
+
if [ "$KIND" = portable ]; then APPROOT="${INSTALL_TO:-$HOME/.local/opt}/$LINUX_NAME-$VERSION-linux-$ARCH"; else APPROOT="/opt/$LINUX_NAME"; fi
|
|
77
|
+
BIN="$APPROOT/$LINUX_NAME"
|
|
78
|
+
RES="$APPROOT/resources"
|
|
79
|
+
TARGET="linux-$ARCH"
|
|
80
|
+
fi
|
|
81
|
+
|
|
82
|
+
# The arguments every call to the installed app carries.
|
|
83
|
+
common() {
|
|
84
|
+
if [ -n "${DATA_DIR:-}" ]; then printf '%s\n' "--data-dir=$DATA_DIR"; fi
|
|
85
|
+
if [ "${NO_ACTIVATE:-}" = 1 ]; then printf '%s\n' "--no-activate"; fi
|
|
86
|
+
}
|
|
87
|
+
# Process ids of the app: every process whose program file is inside the installed app.
|
|
88
|
+
pids() {
|
|
89
|
+
if [ "$OS" = Darwin ]; then
|
|
90
|
+
ps -axwwo pid=,comm= | while read -r p c; do case "$c" in "$APPROOT"/*) echo "$p" ;; esac; done
|
|
91
|
+
else
|
|
92
|
+
for d in /proc/[0-9]*; do
|
|
93
|
+
e=$(readlink "$d/exe" 2>/dev/null) || continue
|
|
94
|
+
case "$e" in "$APPROOT"/*) echo "${d#/proc/}" ;; esac
|
|
95
|
+
done
|
|
96
|
+
fi
|
|
97
|
+
}
|
|
98
|
+
count() { pids | wc -l | tr -d ' '; }
|
|
99
|
+
# The installed app acting as Node, for the checks written in JavaScript. No window opens.
|
|
100
|
+
as_node() { ELECTRON_RUN_AS_NODE=1 "$BIN" "$@"; }
|
|
101
|
+
# Hands a command to the running app through its control channel (control.cjs, a small client of @uppercut-labs/electron-control-channel),
|
|
102
|
+
# sent by control.cjs (in APP_SCRIPTS) run by the installed app acting as Node: no window, and no
|
|
103
|
+
# second instance of the app, which on Windows could hand the app the foreground. The app
|
|
104
|
+
# serves the channel because the launch step started it with --no-activate (or --control),
|
|
105
|
+
# and it is found through control.json in DATA_DIR, which is therefore required here.
|
|
106
|
+
ask() {
|
|
107
|
+
if [ -z "${DATA_DIR:-}" ]; then say "FAILED: set DATA_DIR to the data folder the launch step used"; return 1; fi
|
|
108
|
+
if as_node "$APP_SCRIPTS/control.cjs" --data-dir "$DATA_DIR" --wait 20 -- "$@" >>"$OUT" 2>&1; then return 0; fi
|
|
109
|
+
say "FAILED: the running app did not carry out $* (see the reply above)"
|
|
110
|
+
return 1
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
case "$STEP" in
|
|
114
|
+
list)
|
|
115
|
+
[ -e "$BIN" ] || { say "FAILED: nothing installed at $APPROOT"; exit 1; }
|
|
116
|
+
say "installed at: $APPROOT ($(du -sk "$APPROOT" | cut -f1) kB)"
|
|
117
|
+
say "executable: $(ls -l "$BIN")"
|
|
118
|
+
for f in $HELPERS manifest.json; do say "helper: $(ls -l "$RES/bin/$TARGET/$f" 2>&1)"; done
|
|
119
|
+
say "notices: $(ls -l "$RES/THIRD-PARTY-NOTICES.txt" 2>&1)"
|
|
120
|
+
if [ "$OS" = Darwin ]; then
|
|
121
|
+
say "bundle id: $(/usr/libexec/PlistBuddy -c 'Print :CFBundleIdentifier' "$APP/Contents/Info.plist"), version $(/usr/libexec/PlistBuddy -c 'Print :CFBundleShortVersionString' "$APP/Contents/Info.plist"), minimum macOS $(/usr/libexec/PlistBuddy -c 'Print :LSMinimumSystemVersion' "$APP/Contents/Info.plist")"
|
|
122
|
+
if codesign --verify --deep --strict "$APP" >>"$OUT" 2>&1; then say "codesign --verify --deep --strict: passes"; else say "FAILED: codesign --verify --deep --strict"; fi
|
|
123
|
+
# One argument per program, so a product name with a space ("Example App.app") stays whole.
|
|
124
|
+
set -- "$APP"
|
|
125
|
+
for h in $HELPERS; do set -- "$@" "$RES/bin/$TARGET/$h"; done
|
|
126
|
+
for f in "$@"; do
|
|
127
|
+
info=$(codesign -dv "$f" 2>&1)
|
|
128
|
+
say "signature of ${f#"$APP"/}: $(echo "$info" | grep -E '^(Signature|TeamIdentifier)=' | tr '\n' ' ')$(echo "$info" | grep -o 'flags=[^ ]*')"
|
|
129
|
+
case "$info" in *runtime*) ;; *) say "FAILED: ${f#"$APP"/} lacks the hardened runtime flag" ;; esac
|
|
130
|
+
done
|
|
131
|
+
say "entitlements of the app: $(codesign -d --entitlements - "$APP" 2>/dev/null | grep -o 'com\.apple[a-z.-]*' | tr '\n' ' ')"
|
|
132
|
+
for h in $HELPERS; do say "entitlements of $h: $(codesign -d --entitlements - "$RES/bin/$TARGET/$h" 2>/dev/null | grep -o 'com\.apple[a-z.-]*' | tr '\n' ' ')(none expected)"; done
|
|
133
|
+
say "Gatekeeper (spctl --assess --type execute): $(spctl --assess --type execute -v "$APP" 2>&1 | tr '\n' ' ')"
|
|
134
|
+
say "quarantine mark: $(xattr -p com.apple.quarantine "$APP" 2>/dev/null || echo none)"
|
|
135
|
+
else
|
|
136
|
+
if [ "$KIND" = deb ]; then
|
|
137
|
+
say "package: $(dpkg -s "$LINUX_NAME" 2>&1 | grep -E '^(Status|Version|Architecture):' | tr '\n' ' ')"
|
|
138
|
+
say "command: $(ls -l "/usr/bin/$LINUX_NAME" 2>&1)"
|
|
139
|
+
ENTRY="/usr/share/applications/$APP_ID.desktop"
|
|
140
|
+
ICONS=/usr/share/icons/hicolor
|
|
141
|
+
say "AppArmor profile carried: $(ls -l "$RES/apparmor-profile" 2>&1)"
|
|
142
|
+
say "AppArmor profile installed: $( [ -f "/etc/apparmor.d/$LINUX_NAME" ] && echo yes || echo "no (AppArmor is not active here, or its parser does not accept the profile)")"
|
|
143
|
+
else
|
|
144
|
+
ENTRY="${XDG_DATA_HOME:-$HOME/.local/share}/applications/$APP_ID.desktop"
|
|
145
|
+
ICONS="${XDG_DATA_HOME:-$HOME/.local/share}/icons/hicolor"
|
|
146
|
+
fi
|
|
147
|
+
S=$(ls -ln "$APPROOT/chrome-sandbox" 2>&1)
|
|
148
|
+
say "sandbox helper: $S"
|
|
149
|
+
if [ "$KIND" = deb ]; then case "$S" in "-rwsr-xr-x"*" 0 0 "*) say "sandbox helper is root-owned with mode 4755" ;; *) say "FAILED: the sandbox helper must be root-owned with mode 4755" ;; esac; fi
|
|
150
|
+
say "desktop entry: $ENTRY"
|
|
151
|
+
sed 's/^/ /' "$ENTRY" 2>&1 | tee -a "$OUT"
|
|
152
|
+
if command -v desktop-file-validate >/dev/null 2>&1; then if desktop-file-validate "$ENTRY" >>"$OUT" 2>&1; then say "desktop-file-validate: passes"; else say "FAILED: desktop-file-validate"; fi; fi
|
|
153
|
+
say "icons: $(ls "$ICONS"/*/apps/"$APP_ID".png 2>/dev/null | wc -l | tr -d ' ') sizes of $APP_ID.png under $ICONS"
|
|
154
|
+
MISSING=$(ldd "$BIN" 2>/dev/null | grep 'not found' || true)
|
|
155
|
+
if [ -z "$MISSING" ]; then say "shared libraries: all found"; else say "FAILED: missing shared libraries: $MISSING"; fi
|
|
156
|
+
say "desktop name in the packaged app: $(grep -a -o '"desktopName": *"[^"]*"' "$RES/app.asar" | head -1)"
|
|
157
|
+
fi
|
|
158
|
+
;;
|
|
159
|
+
helpers)
|
|
160
|
+
rm -f "$EVIDENCE/installed-helpers.json"
|
|
161
|
+
as_node "$APP_SCRIPTS/installed-helpers.cjs" --out "$EVIDENCE/installed-helpers.json" 2>&1 | tee -a "$OUT"
|
|
162
|
+
[ -f "$EVIDENCE/installed-helpers.json" ] || say "FAILED: the installed app did not run the check. If its RunAsNode fuse is off: node scripts/installed-helpers.cjs --resources \"$RES\""
|
|
163
|
+
;;
|
|
164
|
+
launch)
|
|
165
|
+
if [ "$(count)" != 0 ]; then say "FAILED: the app is already running from $APPROOT"; exit 1; fi
|
|
166
|
+
if [ "$OS" = Darwin ]; then
|
|
167
|
+
set -- -g "$APP"
|
|
168
|
+
if [ "${EMPTY_PATH:-}" = 1 ]; then set -- "$@" --env PATH=; fi
|
|
169
|
+
IFS='
|
|
170
|
+
'
|
|
171
|
+
# shellcheck disable=SC2046
|
|
172
|
+
set -- "$@" --args $(common)
|
|
173
|
+
unset IFS
|
|
174
|
+
# shellcheck disable=SC2086
|
|
175
|
+
set -- "$@" ${LAUNCH_EXTRA:-}
|
|
176
|
+
say "open $*"
|
|
177
|
+
open "$@" 2>&1 | tee -a "$OUT"
|
|
178
|
+
else
|
|
179
|
+
if [ "$KIND" = deb ]; then ENTRY="/usr/share/applications/$APP_ID.desktop"; else ENTRY="${XDG_DATA_HOME:-$HOME/.local/share}/applications/$APP_ID.desktop"; fi
|
|
180
|
+
# What a launcher does with a desktop entry: take Exec and drop the field codes.
|
|
181
|
+
EXEC=$(sed -n 's/^Exec=//p' "$ENTRY" | head -1 | sed 's/ *%[fFuUdDnNickvm]//g')
|
|
182
|
+
say "desktop entry $ENTRY: Exec=$EXEC"
|
|
183
|
+
if [ "${EMPTY_PATH:-}" = 1 ]; then LAUNCH_PATH=; else LAUNCH_PATH=$PATH; fi
|
|
184
|
+
IFS='
|
|
185
|
+
'
|
|
186
|
+
# shellcheck disable=SC2046
|
|
187
|
+
set -- $(common)
|
|
188
|
+
unset IFS
|
|
189
|
+
# shellcheck disable=SC2086
|
|
190
|
+
set -- "$@" ${LAUNCH_EXTRA:-}
|
|
191
|
+
# A launcher starts the program with the session's environment; this is the
|
|
192
|
+
# same with everything unrelated removed. Absolute paths throughout.
|
|
193
|
+
# shellcheck disable=SC2086
|
|
194
|
+
/usr/bin/env -i HOME="$HOME" USER="${USER:-}" DISPLAY="${DISPLAY:-}" WAYLAND_DISPLAY="${WAYLAND_DISPLAY:-}" \
|
|
195
|
+
XDG_SESSION_TYPE="${XDG_SESSION_TYPE:-}" XDG_RUNTIME_DIR="${XDG_RUNTIME_DIR:-}" DBUS_SESSION_BUS_ADDRESS="${DBUS_SESSION_BUS_ADDRESS:-}" \
|
|
196
|
+
PATH="$LAUNCH_PATH" /usr/bin/setsid $EXEC "$@" >"$EVIDENCE/app.log" 2>&1 &
|
|
197
|
+
fi
|
|
198
|
+
n=0
|
|
199
|
+
while [ "$(count)" = 0 ] && [ $n -lt 30 ]; do sleep 0.5; n=$((n + 1)); done
|
|
200
|
+
sleep 5
|
|
201
|
+
say "processes running from $APPROOT: $(count)"
|
|
202
|
+
if [ "$(count)" = 0 ]; then say "FAILED: the app is not running"; [ -f "$EVIDENCE/app.log" ] && tail -5 "$EVIDENCE/app.log" | tee -a "$OUT"; exit 1; fi
|
|
203
|
+
if [ "$OS" = Linux ]; then
|
|
204
|
+
MAIN=$(pids | sort -n | head -1)
|
|
205
|
+
say "PATH of the app's main process: '$(tr '\0' '\n' < "/proc/$MAIN/environ" | sed -n 's/^PATH=//p')'"
|
|
206
|
+
# The renderer is sandboxed when it runs under seccomp filter mode (2).
|
|
207
|
+
for p in $(pids); do
|
|
208
|
+
if tr '\0' ' ' < "/proc/$p/cmdline" | grep -q -- '--type=renderer'; then say "renderer $p: Seccomp $(sed -n 's/^Seccomp:[[:space:]]*//p' "/proc/$p/status"), $(tr '\0' ' ' < "/proc/$p/cmdline" | grep -o -- '--no-sandbox' || echo 'no --no-sandbox switch')"; fi
|
|
209
|
+
done
|
|
210
|
+
else
|
|
211
|
+
MAIN=$(pids | sort -n | head -1)
|
|
212
|
+
say "PATH of the app's main process: '$(ps eww -o command= -p "$MAIN" | tr ' ' '\n' | sed -n 's/^PATH=//p' | head -1)'"
|
|
213
|
+
say "frontmost app: $(lsappinfo info -only name "$(lsappinfo front)" 2>/dev/null | tr -d '\n')"
|
|
214
|
+
fi
|
|
215
|
+
;;
|
|
216
|
+
collect)
|
|
217
|
+
if [ "$(count)" = 0 ]; then say "FAILED: the app is not running from $APPROOT. Run the launch step first."; exit 1; fi
|
|
218
|
+
rm -f "$EVIDENCE/installed-diagnostics.json" "$EVIDENCE/installed-window.png"
|
|
219
|
+
ask "--diagnostics=$EVIDENCE/installed-diagnostics.json" "--capture=$EVIDENCE/installed-window.png"
|
|
220
|
+
sleep 1
|
|
221
|
+
if [ -f "$EVIDENCE/installed-diagnostics.json" ]; then
|
|
222
|
+
as_node "$APP_SCRIPTS/installed-diagnostics.cjs" "$EVIDENCE/installed-diagnostics.json" "$APPROOT" 2>&1 | tee -a "$OUT"
|
|
223
|
+
else
|
|
224
|
+
say "FAILED: the running app wrote no diagnostics. Is it running with the same data folder?"
|
|
225
|
+
fi
|
|
226
|
+
say "window picture: $(ls -l "$EVIDENCE/installed-window.png" 2>&1)"
|
|
227
|
+
;;
|
|
228
|
+
memory)
|
|
229
|
+
P=$(pids | tr '\n' ' ')
|
|
230
|
+
[ -n "$P" ] || { say "FAILED: the app is not running from $APPROOT"; exit 1; }
|
|
231
|
+
if [ "$OS" = Darwin ]; then
|
|
232
|
+
# shellcheck disable=SC2086
|
|
233
|
+
footprint $P > "$EVIDENCE/installed-footprint.txt" 2>&1
|
|
234
|
+
grep -E '^(Summary Footprint|[A-Za-z].*\[[0-9]+\].*Footprint)' "$EVIDENCE/installed-footprint.txt" | tee -a "$OUT"
|
|
235
|
+
MB=$(sed -n 's/^Summary Footprint:[[:space:]]*\([0-9.]*\) \([KMG]\)B.*/\1 \2/p' "$EVIDENCE/installed-footprint.txt" | awk '{ if ($2=="G") print $1*1024; else if ($2=="K") print $1/1024; else print $1 }')
|
|
236
|
+
[ -n "$MB" ] || MB=$(grep -E 'Footprint: *[0-9.]+ [KMG]B' "$EVIDENCE/installed-footprint.txt" | sed 's/.*Footprint: *\([0-9.]*\) \([KMG]\)B.*/\1 \2/' | awk '{ if ($2=="G") s+=$1*1024; else if ($2=="K") s+=$1/1024; else s+=$1 } END { print s }')
|
|
237
|
+
HOW="footprint, summed over"
|
|
238
|
+
else
|
|
239
|
+
KB=0
|
|
240
|
+
for p in $P; do
|
|
241
|
+
k=$(awk '/^(Anonymous|Swap):/ { s += $2 } END { print s + 0 }' "/proc/$p/smaps_rollup" 2>/dev/null || echo 0)
|
|
242
|
+
say " pid $p: $k kB ($(tr '\0' ' ' < "/proc/$p/cmdline" | grep -o -- '--type=[a-z-]*' || echo main))"
|
|
243
|
+
KB=$((KB + k))
|
|
244
|
+
done
|
|
245
|
+
MB=$((KB / 1024))
|
|
246
|
+
HOW="Anonymous + Swap from smaps_rollup, summed over"
|
|
247
|
+
fi
|
|
248
|
+
say "memory: $MB MB ($HOW $(echo "$P" | wc -w | tr -d ' ') processes); budget ${BUDGET_MB:-300} MB, ceiling ${CEILING_MB:-680} MB"
|
|
249
|
+
VERDICT=$(awk -v m="$MB" -v b="${BUDGET_MB:-300}" -v c="${CEILING_MB:-680}" 'BEGIN { if (m > c) print "FAILED: over the ceiling"; else if (m > b) print "over budget: record the reason or bring it down"; else print "within budget" }')
|
|
250
|
+
say "$VERDICT"
|
|
251
|
+
;;
|
|
252
|
+
quit)
|
|
253
|
+
if [ "$(count)" = 0 ]; then say "the app is not running; nothing to close"; else
|
|
254
|
+
ask --quit
|
|
255
|
+
n=0
|
|
256
|
+
while [ "$(count)" != 0 ] && [ $n -lt 30 ]; do sleep 0.5; n=$((n + 1)); done
|
|
257
|
+
say "processes still running from $APPROOT: $(count)"
|
|
258
|
+
fi
|
|
259
|
+
;;
|
|
260
|
+
uninstall)
|
|
261
|
+
if [ "$(count)" != 0 ]; then say "FAILED: the app is running. Run the quit step first."; exit 1; fi
|
|
262
|
+
if [ "$OS" = Darwin ]; then
|
|
263
|
+
case "$APP" in */"$PRODUCT_NAME".app) rm -rf "$APP"; say "removed $APP" ;; *) say "FAILED: refusing to remove $APP" ;; esac
|
|
264
|
+
elif [ "$KIND" = deb ]; then
|
|
265
|
+
DEBIAN_FRONTEND=noninteractive apt-get remove -y "$LINUX_NAME" >>"$OUT" 2>&1 && say "removed the package $LINUX_NAME"
|
|
266
|
+
say "left behind under /opt/$LINUX_NAME: $(ls "/opt/$LINUX_NAME" 2>/dev/null | wc -l | tr -d ' ') entries; profile: $( [ -f "/etc/apparmor.d/$LINUX_NAME" ] && echo still there || echo gone)"
|
|
267
|
+
else
|
|
268
|
+
"$APPROOT/install-for-user.sh" --remove | tee -a "$OUT"
|
|
269
|
+
case "$APPROOT" in */"$LINUX_NAME-$VERSION-linux-$ARCH") rm -rf "$APPROOT"; say "removed $APPROOT" ;; *) say "FAILED: refusing to remove $APPROOT" ;; esac
|
|
270
|
+
fi
|
|
271
|
+
;;
|
|
272
|
+
*) say "FAILED: unknown step '$STEP' (steps: list helpers launch collect memory quit uninstall)" ;;
|
|
273
|
+
esac
|
|
274
|
+
say done
|
|
275
|
+
[ "$FAILED_ANY" = 0 ] || exit 1
|