Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 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
30 changes: 20 additions & 10 deletions assets/linux/install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@ 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.
PLUGINS="${XDG_DATA_HOME:-$HOME/.local/share}/dbdelve/plugins"
SIZES=(16 32 64 128 256 512)

refresh() {
Expand All @@ -26,8 +29,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" "$PLUGINS/.odbc.new" "$PLUGINS/.odbc.old"
for size in "${SIZES[@]}"; do
rm -f "$ICONS/${size}x${size}/apps/dbdelve.png"
done
Expand All @@ -38,14 +41,21 @@ 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"
# The binary and its bridge are copied beside where they go, and only renamed
# into place once both copies are whole: a failed copy leaves the installed
# pair as it was, never a new binary beside a missing bridge. A running
# DBDelve -- the one updating itself, say -- keeps the files it started from.
trap 'rm -rf "$BIN/.dbdelve.new" "$PLUGINS/.odbc.new"' EXIT
rm -rf "$BIN/.dbdelve.new" "$PLUGINS/.odbc.new" "$PLUGINS/.odbc.old"
install -m 755 "$HERE/dbdelve" "$BIN/.dbdelve.new"
cp -R "$HERE/plugins/odbc" "$PLUGINS/.odbc.new"
if [[ -e "$PLUGINS/odbc" || -L "$PLUGINS/odbc" ]]; then
mv "$PLUGINS/odbc" "$PLUGINS/.odbc.old"
fi
mv "$PLUGINS/.odbc.new" "$PLUGINS/odbc"
mv -f "$BIN/.dbdelve.new" "$BIN/dbdelve"
rm -rf "$PLUGINS/.odbc.old"
# 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
82 changes: 64 additions & 18 deletions docs/agents/shipping.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,32 +48,78 @@ 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`.

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.
- **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 and the ODBC bridge beside where
they go and renames both into place only once both copies are whole, so a
failed copy leaves the old pair installed and a running copy keeps its
file.

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 first seen, or `/proc/self/exe` for
`~/.local/bin/dbdelve`, by device and inode). On Linux a replaced install also
stops offering the update.

- **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
49 changes: 36 additions & 13 deletions docs/install.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,19 @@ Applications; the quarantine step doesn't apply here.

## Linux

Install from the AUR:
One line installs the latest release for your architecture under `~/.local`,
with no root:

```sh
curl -fsSL https://raw.githubusercontent.com/ShayanAbbas1/dbdelve/main/install.sh | sh
```

It downloads the tarball described below and runs the `install.sh` inside it.
If `minisign` is installed it also checks the release's signature, and installs
nothing that fails the check. It needs `curl`, `tar` and `bash`. An install made
this way updates itself, see [Updating](#updating).

Or install from the AUR:

```sh
yay -S dbdelve-bin
Expand Down Expand Up @@ -82,9 +94,10 @@ cd dbdelve-*-linux-*/
Everything goes under `~/.local`, so no root: the binary to `~/.local/bin`, the
icons and the desktop entry where your desktop looks for them, which is what
puts DBDelve in the app menu. Make sure `~/.local/bin` is on your PATH —
`install.sh` says so if it isn't. Updating means unpacking the next release and
running it again; `./install.sh --uninstall` reverses it and leaves your
connections and query history alone.
`install.sh` says so if it isn't. The installed app updates itself, and
running the next release's `install.sh` over it works too;
`./install.sh --uninstall` reverses it and leaves your connections and query
history alone.

Or take `dbdelve-<version>-<arch>.AppImage` from the same release, which is one
file that runs where it lands:
Expand All @@ -106,7 +119,8 @@ What it does not do is put DBDelve in the app menu: an AppImage on its own is
just a file you run, so there is no desktop entry and no icon until you
integrate it — Gear Lever and AppImageLauncher both do that, or you copy the
entry out by hand. The tarball does it for you, which is still the reason to
prefer it. Updating either way is downloading the next one.
prefer it. An AppImage in a folder you can write to updates itself in place,
see [Updating](#updating).
Comment thread
coderabbitai[bot] marked this conversation as resolved.
Resolved

To build it yourself instead, on Debian or Ubuntu the build needs:

Expand Down Expand Up @@ -171,21 +185,30 @@ DBDelve doesn't bundle any.

## Updating

On macOS, **Update and restart** in the titlebar's update menu (or
"Update to dbdelve … and restart" in the command palette) does it in one click,
as described [above](#macos). Homebrew leaves a self-updating app to update
On macOS and Linux, **Update and restart** in the titlebar's update menu (or
"Update to dbdelve … and restart" in the command palette) does it in one click.
It downloads the release from GitHub, checks its signature against the key built
into the app, replaces the app and opens the new one. On macOS that is
described [above](#macos). Homebrew leaves a self-updating app to update
itself, so `brew upgrade` skips DBDelve unless you add `--greedy`.

Elsewhere it doesn't update itself yet. If you used the Windows installer, run
On Linux it works for an install at `~/.local/bin/dbdelve`, which is what the
tarball's `install.sh` and the one-liner make, and for a running AppImage whose
folder you can write to. Installs from the AUR or another package manager, a
tarball run from where it was unpacked, and builds from source don't update
themselves; the titlebar links to [the latest release][releases] instead, and
your package manager is the way to update.

Windows doesn't update itself yet. If you used the Windows installer, run
the next one over it; it upgrades in place. The zip has no upgrade: each
version unzips to its own folder, so delete the old one. Connections and any
plugins you added live in `%APPDATA%\dbdelve`, not there. Otherwise the
titlebar links to [the latest release][releases] once there is a newer one.
plugins you added live in `%APPDATA%\dbdelve`, not there. The titlebar links
to [the latest release][releases] once there is a newer one.

There is no telemetry. The only requests DBDelve makes on its own are to
GitHub, to check for a newer release at startup and every six hours after,
which you can turn off in Settings, and on macOS to download the release you
asked to update to.
which you can turn off in Settings, and to download the release you asked to
update to, on macOS and Linux.

[releases]: https://github.com/ShayanAbbas1/dbdelve/releases/latest
[Inno Setup]: https://jrsoftware.org/isinfo.php
Loading
Loading