Repository navigation
Publish installed engine CLIs on the user's PATH #113
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
ckelseynv
wants to merge
4
commits into
develop
Choose a base branch
from
feat/engine-install-path-gh
base: develop
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
a1b3de5
feat(engine-manager): publish installed engine CLIs on the user's PATH
ckelseynv ab7a88f
feat: ask before adding or removing engines on the user's PATH
ckelseynv 5353719
fix: keep PATH claims on unasked uninstalls and keep path_managed cur…
ckelseynv cb132b9
fix(desktop): shorten the Add to PATH question
ckelseynv File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,47 @@ | ||
| #!/bin/bash | ||
| # SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved. | ||
| # SPDX-License-Identifier: Apache-2.0 | ||
|
|
||
| # Personal AI Router Debian pre-remove. Keeps a copy of nvpair-engine-manager so | ||
| # that after-remove can release the user's PATH entries on `purge`. No `set -e`, | ||
| # and a trailing `exit 0`, so a best-effort step never fails the removal. | ||
| # | ||
| # Unlike after-install.sh and after-remove.sh, this one reaches fpm through the | ||
| # raw passthrough in electron-builder.config.ts, so ${macro} is NOT expanded | ||
| # here. It finds its own paths at runtime instead. | ||
| # | ||
| # WHY A COPY. Engine-manager records what it added to PATH under the user's data | ||
| # root (engine-bin/engine-path/), while the entries themselves live in the login | ||
| # shell's profiles, which no maintainer script touches. Only a purge deletes the | ||
| # data root, and only postrm can tell a purge from a plain remove -- prerm sees | ||
| # "remove" either way. But dpkg deletes the package's files before postrm runs, | ||
| # and a purge can come long after the remove, so the binary that understands the | ||
| # records has to outlive the package. It is kept under /var/lib/<package>, which | ||
| # after-remove deletes on purge. | ||
| # | ||
| # Releasing here instead would give up the entries on a plain `apt remove`, which | ||
| # keeps the engines: a reinstalled app would then have nothing that republishes | ||
| # them short of reinstalling each engine. | ||
| # | ||
| # dpkg calls prerm with "upgrade" during an update, and "failed-upgrade" when | ||
| # recovering from one. Those keep the installation, so there is nothing to keep. | ||
| case "${1:-}" in | ||
| upgrade|failed-upgrade) | ||
| exit 0 | ||
| ;; | ||
| esac | ||
|
|
||
| # Ask dpkg where it put the binary rather than rebuilding /opt/<product>/... | ||
| # from a name this script cannot be told at build time. | ||
| package="${DPKG_MAINTSCRIPT_PACKAGE:-}" | ||
| [ -n "$package" ] || exit 0 | ||
| command -v dpkg-query >/dev/null 2>&1 || exit 0 | ||
| engine_manager="$(dpkg-query -L "$package" 2>/dev/null \ | ||
| | grep -E '/cli-bin/nvpair-engine-manager$' | head -n 1)" | ||
| [ -n "$engine_manager" ] && [ -x "$engine_manager" ] || exit 0 | ||
|
|
||
| mkdir -p "/var/lib/$package" 2>/dev/null \ | ||
| && install -m 0755 "$engine_manager" "/var/lib/$package/nvpair-engine-manager" 2>/dev/null \ | ||
| || true | ||
|
|
||
| exit 0 | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -98,6 +98,45 @@ if [ -x "$CTL" ]; then | |
| fi | ||
| fi | ||
|
|
||
| # Release the PATH entries this user's engines own, while the binary that owns | ||
| # the ownership records still exists. | ||
| # | ||
| # Engine-manager records what it added under the data root | ||
| # (engine-bin/engine-path/), while the entries themselves live in the login | ||
| # shell's profiles — which the purge below never touches. Removing the records | ||
| # first would strand those entries with no way left to identify them, pointing | ||
| # at engine directories this script is about to delete. Only needed when data is | ||
| # going away: keeping it keeps the engines, the records, and a reinstall's | ||
| # ability to clean up later. | ||
| # | ||
| # Runs as the invoking user for the same reason as the helper above: the | ||
| # profiles and the records are theirs, not root's. | ||
| # | ||
| # Unlike every other step here, a failure is not shrugged off. The binary | ||
| # removes what it can and reports the rest, and the records that could still | ||
| # identify whatever it left are inside the data root the purge is about to | ||
| # delete — so a failed release cancels the purge rather than making those | ||
| # entries unidentifiable. The app bundle still goes; a reinstall retries. | ||
| if [ "$PURGE_DATA" = "1" ]; then | ||
| EM="$APP_PATH/Contents/Resources/cli-bin/nvpair-engine-manager" | ||
| if [ -x "$EM" ]; then | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should we set PURGE_DATA back to 1 if this is false? |
||
| echo "Releasing engine PATH entries..." | ||
| # `|| released=$?` rather than a bare call: set -e is on, so a failure would | ||
| # otherwise abort before the check below could keep the data. | ||
| released=0 | ||
| if [ -n "$real_user" ] && [ "$real_user" != "root" ]; then | ||
| sudo -u "$real_user" "$EM" --remove-user-path >/dev/null 2>&1 || released=$? | ||
| else | ||
| "$EM" --remove-user-path >/dev/null 2>&1 || released=$? | ||
| fi | ||
| if [ "$released" -ne 0 ]; then | ||
| echo "Warning: could not release every engine PATH entry." >&2 | ||
| echo "Keeping user data so a reinstall can finish the cleanup; re-run with --purge afterwards." >&2 | ||
| PURGE_DATA=0 | ||
| fi | ||
| fi | ||
| fi | ||
|
|
||
| echo "Removing $APP_PATH ..." | ||
| rm -rf "$APP_PATH" 2>/dev/null || true | ||
|
|
||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Codex pointed this out:
before-remove.sh (line 43) ignores failure to save the executable. In after-remove.sh (line 69, keep_data starts at zero and changes only when an attempted cleanup returns an error. If the saved executable is absent, cleanup is skipped and the data directory is deleted anyway. PATH entries survive without their ownership records. This matters because dpkg removes package files before calling postrm.