Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ jobs:
fi
# The key the app is built with, so a secret that does not match it
# fails here instead of in every installed app.
PUBLIC_KEY="$(sed -n 's/^const RELEASE_PUBLIC_KEY: &str = "\(.*\)";$/\1/p' src/update/macos.rs)"
PUBLIC_KEY="$(sed -n 's/^const RELEASE_PUBLIC_KEY: &str = "\(.*\)";$/\1/p' src/update/download.rs)"
if ! grep -qxF "PUBLIC_KEY=\"$PUBLIC_KEY\"" install.sh; then
echo "install.sh does not check downloads against the app's release key" >&2
exit 1
Expand All @@ -194,6 +194,13 @@ jobs:
echo "$ASSET.minisig is not a prehashed signature" >&2
exit 1
fi
# The app requires the trusted comment, which the signature covers,
# to name the asset it downloaded: minisign's default
# `file:<basename>` is what binds a signature to one release.
if [[ "$(sed -n 3p "$ASSET.minisig")"$'\t' != *$'\t'"file:${ASSET##*/}"$'\t'* ]]; then
echo "$ASSET.minisig does not name ${ASSET##*/} in its trusted comment" >&2
exit 1
fi
minisign -V -q -P "$PUBLIC_KEY" -m "$ASSET" -x "$ASSET.minisig"
done
env:
Expand Down
2 changes: 2 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

19 changes: 16 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -414,15 +414,28 @@ windows-sys = { version = "=0.61.2", features = [
libc = "=0.2.189"

# Checking a downloaded update against the key releases are signed with. Zero
# dependencies. macOS alone for now, as the one platform that updates itself.
[target.'cfg(target_os = "macos")'.dependencies]
# dependencies. macOS and Linux, the platforms that update themselves.
[target.'cfg(any(target_os = "macos", target_os = "linux"))'.dependencies]
minisign-verify = "=0.3.0"

# Unpacking a Linux update tarball. Both already in the graph (tar through
# libduckdb-sys's build, flate2 through mysql and zip) and pinned to the
# versions locked there, so naming them adds no crate. No default features:
# tar's only one restores extended attributes, which a release never carries.
[target.'cfg(target_os = "linux")'.dependencies]
tar = { version = "=0.4.46", default-features = false }
flate2 = "=1.1.9"

# Signing the updater's test files the way the release pipeline's minisign
# does, so no tool has to be installed to run them.
[target.'cfg(target_os = "macos")'.dev-dependencies]
[target.'cfg(any(target_os = "macos", target_os = "linux"))'.dev-dependencies]
minisign = "=0.10.0"

# The Linux updater's tests also run on macOS, the platform it is written on.
[target.'cfg(target_os = "macos")'.dev-dependencies]
tar = { version = "=0.4.46", default-features = false }
flate2 = "=1.1.9"

[features]
# Lets an end-to-end test point the updater at its own feed and key, and lets a
# DBDELVE_VARIANT build update itself. Never on in a shipped build, so no
Expand Down
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,9 @@ otherwise refuse it over. Without Homebrew:
curl -fsSL https://raw.githubusercontent.com/ShayanAbbas1/dbdelve/main/install.sh | sh
```

**Linux** (x86_64 or aarch64): `yay -S dbdelve-bin` from the AUR, or the
tarball or AppImage from [the latest release][releases].
**Linux** (x86_64 or aarch64): the same one-liner installs it under `~/.local`
with no root, or `yay -S dbdelve-bin` from the AUR, or the tarball or AppImage
from [the latest release][releases].

**Windows** (x86_64): run the installer from [the latest release][releases],
or unzip the zip and run `dbdelve.exe`. The installer asks for AppData (just
Expand Down
83 changes: 73 additions & 10 deletions assets/linux/install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,29 @@ HERE="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
BIN="$HOME/.local/bin"
ICONS="$HOME/.local/share/icons/hicolor"
APPS="$HOME/.local/share/applications"
# The binary lands alone in ~/.local/bin, so its bridge goes to the per-user
# plugin directory db::plugin::discover() also reads, not beside the binary.
DATA="${XDG_DATA_HOME:-$HOME/.local/share}/dbdelve"
PLUGINS="$DATA/plugins"
# The bridge's staged and backup copies: beside plugins/ rather than in it,
# where another DBDelve would load them, and on its filesystem, so moving one
# into place is a rename.
STAGED="$DATA/.odbc.new"
BACKUP="$DATA/.odbc.old"
SIZES=(16 32 64 128 256 512)

# One install or uninstall at a time: two would share the staged and backup
# names above and undo each other's work. A lock file of this script's own --
# the app's updater, which runs this, already holds one on ~/.local/bin.
mkdir -p "$DATA"
if command -v flock >/dev/null; then
exec 9>"$DATA/.install.lock"
flock -n 9 || {
echo "another dbdelve install is running" >&2
exit 1
}
fi

refresh() {
# Both are optional: a desktop without them still reads the directories on
# its own schedule, and a headless box has neither installed.
Expand All @@ -26,8 +47,8 @@ refresh() {
}

if [[ "${1:-}" == --uninstall ]]; then
rm -f "$BIN/dbdelve" "$APPS/dbdelve.desktop"
rm -rf "${XDG_DATA_HOME:-$HOME/.local/share}/dbdelve/plugins/odbc"
rm -f "$BIN/dbdelve" "$BIN/.dbdelve.new" "$APPS/dbdelve.desktop"
rm -rf "$PLUGINS/odbc" "$STAGED" "$BACKUP"
for size in "${SIZES[@]}"; do
rm -f "$ICONS/${size}x${size}/apps/dbdelve.png"
done
Expand All @@ -38,14 +59,56 @@ if [[ "${1:-}" == --uninstall ]]; then
exit 0
fi

mkdir -p "$BIN" "$APPS"
install -m 755 "$HERE/dbdelve" "$BIN/dbdelve"
# The binary lands alone in ~/.local/bin, so its bridge goes to the per-user
# plugin directory db::plugin::discover() also reads, not beside the binary.
PLUGINS="${XDG_DATA_HOME:-$HOME/.local/share}/dbdelve/plugins"
rm -rf "$PLUGINS/odbc"
mkdir -p "$PLUGINS"
cp -R "$HERE/plugins/odbc" "$PLUGINS/odbc"
mkdir -p "$BIN" "$APPS" "$PLUGINS"

# A run killed during its commit, below, left the backup. With the new binary
# still staged, or no bridge in place, the commit had not finished and the
# backup is the installed bridge; otherwise it had, and the backup is spare.
if [[ -d "$BACKUP" ]]; then
if [[ -e "$BIN/.dbdelve.new" || ! -e "$PLUGINS/odbc" ]]; then
rm -rf "$PLUGINS/odbc"
mv "$BACKUP" "$PLUGINS/odbc"
else
rm -rf "$BACKUP"
fi
fi

# The binary and its bridge are copied beside where they go, then renamed into
# place only once both copies are whole, and a failure part way through the
# renames puts the old bridge back. A running DBDelve -- the one updating
# itself, say -- keeps the files it started from.
moved_aside=
swapped=
committed=
roll_back() {
if [[ -z "$committed" ]]; then
if [[ -n "$swapped" ]]; then
rm -rf "$PLUGINS/odbc"
fi
if [[ -n "$moved_aside" && ! -e "$PLUGINS/odbc" ]]; then
mv "$BACKUP" "$PLUGINS/odbc"
fi
fi
rm -rf "$BIN/.dbdelve.new" "$STAGED"
}
trap roll_back EXIT
trap 'exit 1' HUP INT TERM
rm -rf "$BIN/.dbdelve.new" "$STAGED"
Comment thread
ShayanAbbas1 marked this conversation as resolved.
Resolved
install -m 755 "$HERE/dbdelve" "$BIN/.dbdelve.new"
cp -R "$HERE/plugins/odbc" "$STAGED"
# Ignored while only renames run, so a signal cannot land between a rename and
# the flag that records it and leave roll_back undoing the wrong step.
trap '' HUP INT TERM
if [[ -e "$PLUGINS/odbc" || -L "$PLUGINS/odbc" ]]; then
mv "$PLUGINS/odbc" "$BACKUP"
moved_aside=1
fi
mv "$STAGED" "$PLUGINS/odbc"
swapped=1
Comment thread
coderabbitai[bot] marked this conversation as resolved.
Resolved
mv -f "$BIN/.dbdelve.new" "$BIN/dbdelve"
committed=1
rm -rf "$BACKUP"
trap 'exit 1' HUP INT TERM
# Exec gets the absolute path rather than the bare name the entry ships with:
# a desktop launches its entries with the session's PATH, and ~/.local/bin only
# joins that at login -- and only when it already existed. Bare `dbdelve` would
Expand Down
9 changes: 9 additions & 0 deletions dev/package-appimage.sh
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,15 @@ cat > "$APPDIR/AppRun" <<'APPRUN'
# for the names we ship and the host supplies every other name, which is the
# split package-appimage.sh made.
HERE="$(dirname "$(readlink -f "$0")")"
# A DBDelve started by another -- relaunching into its update, say -- inherits
# that one's LD_LIBRARY_PATH, which points into the old mount, so what the
# earlier AppRun saved is the original.
if [ -n "${DBDELVE_ORIGINAL_LD_LIBRARY_PATH+x}" ]; then
export LD_LIBRARY_PATH="$DBDELVE_ORIGINAL_LD_LIBRARY_PATH"
elif [ -n "${DBDELVE_ORIGINAL_LD_LIBRARY_PATH_UNSET+x}" ]; then
unset LD_LIBRARY_PATH
fi
unset DBDELVE_ORIGINAL_LD_LIBRARY_PATH DBDELVE_ORIGINAL_LD_LIBRARY_PATH_UNSET
# Saved for the ODBC bridge, whose vendor drivers must not see the bundled libraries.
if [ -n "${LD_LIBRARY_PATH+x}" ]; then
export DBDELVE_ORIGINAL_LD_LIBRARY_PATH="$LD_LIBRARY_PATH"
Expand Down
102 changes: 84 additions & 18 deletions docs/agents/shipping.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,32 +48,98 @@ Four things in the script are load-bearing:
- **The font licences ship inside the bundle**, because the fonts are compiled
into the binary and the OFL asks the licence to travel with them.

## Self-update (macOS)
## Self-update (macOS and Linux)

`src/update.rs` checks GitHub's `releases/latest` at launch and every six
hours. On macOS (`src/update/macos.rs`) an install that can replace itself
gets **Update and restart**: it downloads `DBDelve-<version>.dmg`, verifies
`DBDelve-<version>.dmg.minisig` against `RELEASE_PUBLIC_KEY`, copies the app
out of the image to a hidden sibling, checks it (`codesign --verify --deep
--strict`, same `CFBundleIdentifier`, `CFBundleShortVersionString` equal to the
release and newer than both the running build and the installed bundle),
exchanges the two in one `renamex_np(RENAME_SWAP)` and relaunches through
`App::restart`, which quits the way Quit does. A volume without the atomic
exchange fails the update and keeps the release link: moving the app aside
first would leave nothing installed if the process died in between. A lock on
the bundle's folder keeps two processes from clearing each other's hidden
sibling, and an install clears the one an interrupted install left.
hours. An install that can replace itself gets **Update and restart**; every
other one gets the link to the release page. What both platforms share --
the release key, the download, the minisign check, the folder lock and the
scratch directory -- is in `src/update/download.rs`. Both fetch the
`.minisig` before the asset, so a release without one fails before the large
download, and verify once the download is complete. The pill and its menu sit
at the right end of the titlebar on the home screen as well as in a
connection, and the palette lists the update on both.

On macOS (`src/update/macos.rs`) the update downloads
`DBDelve-<version>.dmg`, verifies `DBDelve-<version>.dmg.minisig` against
`RELEASE_PUBLIC_KEY`, copies the app out of the image to a hidden sibling,
checks it (`codesign --verify --deep --strict`, same `CFBundleIdentifier`,
`CFBundleShortVersionString` equal to the release and newer than both the
running build and the installed bundle), exchanges the two in one
`renamex_np(RENAME_SWAP)` and relaunches through `App::restart`, which quits
the way Quit does. A volume without the atomic exchange fails the update and
keeps the release link: moving the app aside first would leave nothing
installed if the process died in between.

On Linux (`src/update/linux.rs`) two kinds of install update themselves:

- **An AppImage** downloads `dbdelve-<version>-<arch>.AppImage`, copies it to
a hidden sibling of the AppImage (same filesystem), checks it is an ELF and
`rename(2)`s it over the old one under the old one's name. The running
image keeps its inode until it exits. It counts as an AppImage only when
`APPIMAGE` names a regular file *and* the executable lies inside `APPDIR`:
the runtime exports both to everything an AppImage starts, so a terminal
opened from one hands them to an unrelated DBDelve. The relaunch inherits
the old mount's `LD_LIBRARY_PATH`; AppRun restores the original from the
`DBDELVE_ORIGINAL_LD_LIBRARY_PATH` pair the earlier AppRun saved before
saving it again, so the new process sees the same as a fresh start.
Before the relaunch every descriptor past stdio is made close-on-exec: the
runtime keeps its FUSE mount alive while any process holds a pipe it hands
the app, and the relaunch would otherwise keep the old mount, and the
replaced file under it, alive until the new app exits. An AppImage run with
`--appimage-extract-and-run` (its `APPDIR` is not a mount point) keeps the
link, since the plain relaunch would need the FUSE it ran without; with
`APPIMAGE_EXTRACT_AND_RUN` set it updates, as the relaunch inherits that.
- **The tarball's `install.sh` install**, recognised only when the executable
is exactly `~/.local/bin/dbdelve` (a regular file, not a link), downloads
`dbdelve-<version>-linux-<arch>.tar.gz`, unpacks it with the `tar` crate
(no entry may land outside the scratch directory), requires the one
directory `dbdelve-<version>-linux-<arch>` holding `dbdelve` and
`install.sh`, and runs that `install.sh`: the new release knows its own
layout. `install.sh` copies the binary beside where it goes and the ODBC
bridge beside `plugins/` (never in it, where discovery would load it), and
renames both into place only once both copies are whole, so a failed copy
changes nothing and a running copy keeps its file. The commit is renames
only, with HUP, INT and TERM ignored while it runs; a failed rename puts
the old bridge back, and a run killed hard part way through leaves a backup
the next run restores before doing anything else. A lock file of its own,
`.install.lock` in the data directory (taken when `flock` exists; never the
`~/.local/bin` lock the updater holds), keeps two runs from sharing the
staged and backup names. Plugin discovery skips hidden folders, so neither
copy is ever loaded.

Everything else on Linux -- a tarball run where it was unpacked, a distro or
Snap package, a binary anywhere else -- keeps the link.

Both platforms take a lock on the folder of what they replace, which keeps two
processes from clearing each other's hidden sibling, and clear the one an
interrupted install left. Under that lock both refuse an install that another
process has updated since this one started, so a stale offer never puts an
older release over a newer one: macOS by the installed bundle's version, Linux
by the file itself (the AppImage as recorded at startup, before any update
check, or `/proc/self/exe` for `~/.local/bin/dbdelve`, by device and inode). On
Linux a replaced install also stops offering the update, and when the refusal
comes at install time the menu offers **Restart DBDelve**, which relaunches
the install on disk, rather than a retry that could never succeed.

- **Only the release build in a writable place updates itself.** A dev or
other `DBDELVE_VARIANT` build, a binary outside a `.app`, a bundle on a
read-only volume (run from the DMG), App-Translocated, or in a folder the
user cannot write, keeps the link to the release page. So does a release
missing either asset, and a build whose key is still the placeholder.
user cannot write, keeps the link to the release page; so does an AppImage
in a folder the user cannot write. So does a release missing the asset or
its `.minisig`, and a build whose key is still the placeholder.
- **A signature binds the asset's name.** minisign's default trusted comment
is `timestamp:<n>\tfile:<name>\thashed`, and the signature covers it. The
app refuses a signature whose `file:` is not the exact asset it asked for,
which carries the version, so an older release's genuine file and signature
served under the new name do not verify. The release must keep signing
with the default comment (no `-t`); the workflow checks it does.
- **The release workflow signs every asset** with the `UPDATE_SIGNING_KEY`
secret (an unencrypted minisign secret key) and checks each signature is
prehashed and verifies against the key in `src/update/macos.rs`; it refuses
to publish otherwise. Changing the key strands every installed app on the
old one, which then never verifies another release.
prehashed, names its asset and verifies against the key in
`src/update/download.rs`; it refuses to publish otherwise. Changing the key
strands every installed app on the old one, which then never verifies
another release.
- **The cask says `auto_updates true`**, so `brew upgrade` does not fight the
app over which copy is current.
- **`update-test-hooks` is the only way to point an app elsewhere.** Off by
Expand Down
Loading
Loading