diff --git a/.github/workflows/nightly.yml b/.github/workflows/nightly.yml index 57861230..f0689f35 100644 --- a/.github/workflows/nightly.yml +++ b/.github/workflows/nightly.yml @@ -210,6 +210,18 @@ jobs: esac ls -la out + # The .deb is an update payload too: a .deb install updates from the + # app (the updater runs pkexec dpkg -i on it), so it needs a signature. + - name: Sign the .deb + if: matrix.name == 'linux' + shell: bash + env: + TAURI_SIGNING_PRIVATE_KEY: ${{ secrets.TAURI_SIGNING_PRIVATE_KEY }} + TAURI_SIGNING_PRIVATE_KEY_PASSWORD: ${{ secrets.TAURI_SIGNING_PRIVATE_KEY_PASSWORD }} + run: | + npx tauri signer sign out/stroke-nightly_amd64.deb + test -s out/stroke-nightly_amd64.deb.sig + - uses: actions/upload-artifact@v4 with: name: nightly-${{ matrix.name }} @@ -217,11 +229,69 @@ jobs: if-no-files-found: error retention-days: 3 + # ── 2b. The Arch package ──────────────────────────────────────────────────── + # The same package the AUR builds (stroke-nightly-bin, from the .deb), + # built here so an Arch install can update from the app: it downloads + # this and runs `pkexec pacman -U` on it. Same name and version as the + # AUR's, so yay sees the result as up to date. + build-pacman: + needs: [check, build] + runs-on: ubuntu-latest + container: archlinux:latest + steps: + - name: Tools + run: pacman -Syu --noconfirm --needed base-devel nodejs npm git sudo + + - uses: actions/checkout@v5 + with: + ref: ${{ needs.check.outputs.sha }} + + - uses: actions/download-artifact@v4 + with: + name: nightly-linux + path: linux + + - name: Build the package + env: + VERSION: ${{ needs.check.outputs.version }} + COMMIT: ${{ needs.check.outputs.sha }} + run: | + set -euo pipefail + PKGVER="${VERSION//-/.}" + useradd -m builder + mkdir -p /tmp/pkg + # Named the way the PKGBUILD's source names it, so makepkg uses this + # file instead of downloading a release that isn't published yet. + cp linux/stroke-nightly_amd64.deb "/tmp/pkg/stroke-nightly-${PKGVER}.deb" + SHA=$(sha256sum "/tmp/pkg/stroke-nightly-${PKGVER}.deb" | cut -d' ' -f1) + sed -e "s/@PKGVER@/${PKGVER}/" -e "s/@SHA256@/${SHA}/" -e "s/@COMMIT@/${COMMIT}/" \ + packaging/aur/stroke-nightly-bin/PKGBUILD.in > /tmp/pkg/PKGBUILD + chown -R builder /tmp/pkg + sudo -u builder bash -c 'cd /tmp/pkg && makepkg --nodeps --noconfirm' + mkdir -p out + cp /tmp/pkg/stroke-nightly-bin-*.pkg.tar.zst out/stroke-nightly_x86_64.pkg.tar.zst + ls -la out + + - name: Sign + env: + TAURI_SIGNING_PRIVATE_KEY: ${{ secrets.TAURI_SIGNING_PRIVATE_KEY }} + TAURI_SIGNING_PRIVATE_KEY_PASSWORD: ${{ secrets.TAURI_SIGNING_PRIVATE_KEY_PASSWORD }} + run: | + npx -y @tauri-apps/cli@2 signer sign out/stroke-nightly_x86_64.pkg.tar.zst + test -s out/stroke-nightly_x86_64.pkg.tar.zst.sig + + - uses: actions/upload-artifact@v4 + with: + name: nightly-pacman + path: out/* + if-no-files-found: error + retention-days: 3 + # ── 3. Replace the `nightly` pre-release ─────────────────────────────────── # Only after every platform built: a failed night keeps the previous # nightly up instead of publishing a partial one. publish: - needs: [check, build] + needs: [check, build, build-pacman] runs-on: ubuntu-latest steps: - uses: actions/checkout@v5 @@ -252,6 +322,10 @@ jobs: 'darwin-aarch64': { url: BASE + '/stroke-nightly_aarch64.app.tar.gz', signature: sig('stroke-nightly_aarch64.app.tar.gz.sig') }, 'darwin-x86_64': { url: BASE + '/stroke-nightly_x64.app.tar.gz', signature: sig('stroke-nightly_x64.app.tar.gz.sig') }, 'linux-x86_64': { url: BASE + '/stroke-nightly_amd64.AppImage', signature: sig('stroke-nightly_amd64.AppImage.sig') }, + // Linux packages update from the app too, each from its own entry: + // a .deb through pkexec dpkg, an Arch install through pkexec pacman. + 'linux-x86_64-deb': { url: BASE + '/stroke-nightly_amd64.deb', signature: sig('stroke-nightly_amd64.deb.sig') }, + 'linux-x86_64-pacman': { url: BASE + '/stroke-nightly_x86_64.pkg.tar.zst', signature: sig('stroke-nightly_x86_64.pkg.tar.zst.sig') }, 'windows-x86_64': { url: BASE + '/stroke-nightly_x64-setup.exe', signature: sig('stroke-nightly_x64-setup.exe.sig') }, } // The changelog since the last stable release, in CHANGELOG.md's own @@ -284,7 +358,7 @@ jobs: echo "| macOS (Apple Silicon) | \`stroke-nightly_aarch64.dmg\` |" echo "| macOS (Intel) | \`stroke-nightly_x64.dmg\` |" echo "| Windows | \`stroke-nightly_x64-setup.exe\` |" - echo "| Linux | \`stroke-nightly_amd64.AppImage\` · \`stroke-nightly_amd64.deb\` |" + echo "| Linux | \`stroke-nightly_amd64.AppImage\` · \`stroke-nightly_amd64.deb\` · \`stroke-nightly_x86_64.pkg.tar.zst\` (Arch) |" echo echo "### Changes since the last nightly" if [ -n "$PREV" ]; then diff --git a/src-tauri/src/updates.rs b/src-tauri/src/updates.rs index e9ab478d..730832c1 100644 --- a/src-tauri/src/updates.rs +++ b/src-tauri/src/updates.rs @@ -63,6 +63,9 @@ pub struct UpdateInfo { pub manual: bool, /// The command that updates it, where there is one (`yay -Syu ...`). pub manual_command: Option, + /// Installing asks for the system password (a Linux .deb, .rpm or Arch + /// package goes through pkexec, which writes to /usr). + pub needs_password: bool, } #[derive(Clone, Serialize)] @@ -91,6 +94,9 @@ pub struct UpdateState { /// Set when the exit under way is a restart. A Windows install then keeps /// the installer's own relaunch instead of suppressing it. restarting: AtomicBool, + /// The feed has no package for this kind of install yet (an older + /// release): the update is offered as a command, not installed. + manual_fallback: AtomicBool, } /// A poisoned lock only means another command panicked mid-update; the Option @@ -99,7 +105,7 @@ fn lock(m: &Mutex) -> MutexGuard<'_, T> { m.lock().unwrap_or_else(|e| e.into_inner()) } -fn info(update: &Update, staged: bool) -> UpdateInfo { +fn info(update: &Update, staged: bool, manual: bool) -> UpdateInfo { UpdateInfo { version: update.version.clone(), current_version: update.current_version.clone(), @@ -107,18 +113,23 @@ fn info(update: &Update, staged: bool) -> UpdateInfo { date: update.date.map(|d| d.unix_timestamp()), staged, apply_on_quit: can_apply_on_quit(), - manual: package_managed(), - manual_command: manual_command(), + manual, + manual_command: if manual { manual_command() } else { None }, + needs_password: !manual && installs_with_password(), } } +fn is_manual(state: &UpdateState) -> bool { + package_managed() || state.manual_fallback.load(Ordering::Relaxed) +} + fn staged_info(state: &UpdateState) -> Option { - // Nothing is ever staged for a package-managed install; never offer a - // restart that can only fail. - if package_managed() { + // Nothing is ever staged for an install that can't update itself; never + // offer a restart that can only fail. + if is_manual(state) { return None; } - lock(&state.staged).as_ref().map(|s| info(&s.update, true)) + lock(&state.staged).as_ref().map(|s| info(&s.update, true, false)) } fn updates_dir(app: &AppHandle) -> Result { @@ -140,16 +151,29 @@ pub async fn update_check( if let Some(staged) = staged_info(&state) { return Ok(Some(staged)); } - let update = app - .updater_builder() - .timeout(CHECK_TIMEOUT) - .build() - .map_err(|e| e.to_string())? - .check() - .await - .map_err(|e| e.to_string())?; - let found = update.as_ref().map(|u| info(u, false)); - *lock(&state.pending) = update; + let check = |target: Option<&'static str>| { + let mut builder = app.updater_builder().timeout(CHECK_TIMEOUT); + if let Some(t) = target { + builder = builder.target(t); + } + async move { builder.build().map_err(|e| e.to_string())?.check().await.map_err(|e| e.to_string()) } + }; + // A Linux package (Arch, .deb, .rpm) takes its own entry in the feed. A + // feed without one (an older release) still says a version is out, from + // the AppImage's entry, and the update is offered as a command instead. + let target = update_target(); + let (update, fallback) = match check(target).await { + Ok(update) => (update, false), + Err(e) if target.is_some() => { + log::warn!("[updater] no {} entry in the feed ({e}); offering the update as a command", target.unwrap_or("")); + (check(None).await?, true) + } + Err(e) => return Err(e), + }; + state.manual_fallback.store(fallback, Ordering::Relaxed); + let manual = is_manual(&state); + let found = update.as_ref().map(|u| info(u, false, manual)); + *lock(&state.pending) = if manual { None } else { update }; Ok(found) } @@ -163,7 +187,7 @@ pub async fn update_download( if let Some(staged) = staged_info(&state) { return Ok(staged); } - if package_managed() { + if is_manual(&state) { return Err(MANAGED_MESSAGE.into()); } let update = lock(&state.pending) @@ -206,7 +230,7 @@ pub async fn update_download( .map_err(|e| e.to_string())? .map_err(|e| format!("Could not save the update: {e}"))?; - let staged = info(&update, true); + let staged = info(&update, true, false); *lock(&state.staged) = Some(Staged { update, path }); *lock(&state.pending) = None; Ok(staged) @@ -224,7 +248,7 @@ pub fn update_status(state: State<'_, UpdateState>) -> Option { /// thread, and `restart()` from another thread goes through the normal exit. #[tauri::command] pub async fn update_restart(app: AppHandle, state: State<'_, UpdateState>) -> Result<(), String> { - if package_managed() { + if is_manual(&state) { return Err(MANAGED_MESSAGE.into()); } let staged = lock(&state.staged) @@ -235,9 +259,15 @@ pub async fn update_restart(app: AppHandle, state: State<'_, UpdateState>) -> Re Err(e) => return Err(format!("The downloaded update is missing: {e}")), }; // On Windows this hands over to the installer and exits; the installer - // relaunches the app when it is done (`/R`). - if let Err(e) = staged.update.install(&bytes) { - let msg = e.to_string(); + // relaunches the app when it is done (`/R`). A Linux .deb or .rpm goes + // through the plugin too (pkexec dpkg / rpm); an Arch package through + // pacman, below. + let installed = if update_target() == Some(PACMAN_TARGET) { + install_pacman(&bytes) + } else { + staged.update.install(&bytes).map_err(|e| e.to_string()) + }; + if let Err(msg) = installed { *lock(&state.staged) = Some(staged); return Err(msg); } @@ -311,16 +341,127 @@ pub fn apply_on_quit(app: &AppHandle) { const MANAGED_MESSAGE: &str = "This copy of Stroke was installed by your package manager, so it updates there."; -/// Linux installs that are not the AppImage: the AUR packages (which unpack -/// the .deb, so the binary reads as a .deb install), a .deb or an .rpm. The -/// release feed ships only the AppImage for Linux, so the plugin tried to -/// install an AppImage as a .deb and failed with "invalid updater binary -/// format". Files under /usr belong to the package manager anyway. +/// How this Linux copy of Stroke was installed, which decides how it updates. #[cfg(target_os = "linux")] -pub fn package_managed() -> bool { +#[derive(Clone, Copy, PartialEq, Eq)] +enum LinuxInstall { + /// A running AppImage: replaced in place, no password. + AppImage, + /// The AUR package (built from the .deb, so the binary reads as a .deb): + /// updated with `pacman -U` on the Arch package from the feed. + Pacman, + /// A .deb (dpkg) or .rpm: the plugin installs the matching package from + /// the feed through pkexec. + Deb, + Rpm, + /// Anything else (a .deb unpacked on a system without dpkg, an AppImage + /// that was extracted): offered as a download. + Other, +} + +#[cfg(target_os = "linux")] +fn linux_install() -> LinuxInstall { use tauri::utils::config::BundleType; - !matches!(tauri::utils::platform::bundle_type(), Some(BundleType::AppImage)) - || std::env::var_os("APPIMAGE").is_none() + let bundle = tauri::utils::platform::bundle_type(); + if matches!(bundle, Some(BundleType::AppImage)) && std::env::var_os("APPIMAGE").is_some() { + return LinuxInstall::AppImage; + } + if aur_package().is_some() { + return LinuxInstall::Pacman; + } + let has = |bin: &str| ["/usr/bin", "/bin", "/usr/sbin"].iter().any(|d| std::path::Path::new(d).join(bin).exists()); + match bundle { + Some(BundleType::Deb) if has("dpkg") => LinuxInstall::Deb, + Some(BundleType::Rpm) if has("rpm") => LinuxInstall::Rpm, + _ => LinuxInstall::Other, + } +} + +/// The AUR package this copy came from, read from pacman's local database. +#[cfg(target_os = "linux")] +fn aur_package() -> Option<&'static str> { + let local = std::path::Path::new("/var/lib/pacman/local"); + let installed = |name: &str| { + std::fs::read_dir(local).ok().is_some_and(|dir| { + dir.flatten().any(|e| { + e.file_name().to_string_lossy().strip_prefix(name).is_some_and(|rest| { + rest.starts_with('-') && rest[1..].starts_with(|c: char| c.is_ascii_digit()) + }) + }) + }) + }; + // Nightly and Stable install side by side: match the running build. + let nightly = tauri::utils::platform::current_exe() + .is_ok_and(|exe| exe.to_string_lossy().contains("nightly")); + let name = if nightly { "stroke-nightly-bin" } else { "stroke-bin" }; + installed(name).then_some(name) +} + +const PACMAN_TARGET: &str = "linux-x86_64-pacman"; + +/// The feed entry this install updates from, when it isn't the default one. +#[cfg(target_os = "linux")] +fn update_target() -> Option<&'static str> { + if !cfg!(target_arch = "x86_64") { + return None; + } + match linux_install() { + LinuxInstall::Pacman => Some(PACMAN_TARGET), + LinuxInstall::Deb => Some("linux-x86_64-deb"), + LinuxInstall::Rpm => Some("linux-x86_64-rpm"), + LinuxInstall::AppImage | LinuxInstall::Other => None, + } +} + +#[cfg(not(target_os = "linux"))] +fn update_target() -> Option<&'static str> { + None +} + +/// Only copies that can't install the feed's package at all. Arch, .deb and +/// .rpm installs update from the app now, through the system password prompt. +#[cfg(target_os = "linux")] +pub fn package_managed() -> bool { + linux_install() == LinuxInstall::Other || (update_target().is_none() && linux_install() != LinuxInstall::AppImage) +} + +#[cfg(target_os = "linux")] +fn installs_with_password() -> bool { + matches!(linux_install(), LinuxInstall::Pacman | LinuxInstall::Deb | LinuxInstall::Rpm) +} + +#[cfg(not(target_os = "linux"))] +fn installs_with_password() -> bool { + false +} + +/// Install the Arch package from the feed with `pacman -U`, through pkexec +/// (the system's password prompt). pacman then records the new version, so +/// the AUR helper sees it as up to date instead of reinstalling the old one. +#[cfg(target_os = "linux")] +fn install_pacman(bytes: &[u8]) -> Result<(), String> { + let dir = std::env::temp_dir().join(format!("stroke-update-{}", std::process::id())); + std::fs::create_dir_all(&dir).map_err(|e| format!("Could not prepare the update: {e}"))?; + let pkg = dir.join("stroke-update.pkg.tar.zst"); + std::fs::write(&pkg, bytes).map_err(|e| format!("Could not prepare the update: {e}"))?; + let status = std::process::Command::new("pkexec") + .args(["pacman", "-U", "--noconfirm"]) + .arg(&pkg) + .status(); + let _ = std::fs::remove_dir_all(&dir); + let fallback = aur_package().map(|p| format!(" You can also run: yay -Syu {p}")).unwrap_or_default(); + match status { + Ok(s) if s.success() => Ok(()), + // pkexec: 126 = the prompt was dismissed, 127 = not authorized. + Ok(s) if matches!(s.code(), Some(126 | 127)) => Err(format!("The password prompt was closed, so nothing was installed.{fallback}")), + Ok(s) => Err(format!("pacman could not install the update (exit {}).{fallback}", s.code().unwrap_or(-1))), + Err(e) => Err(format!("Could not ask for the password (pkexec: {e}).{fallback}")), + } +} + +#[cfg(not(target_os = "linux"))] +fn install_pacman(_bytes: &[u8]) -> Result<(), String> { + Err("Not an Arch install.".into()) } /// A Scoop install. Scoop unpacks the NSIS setup into its own folder, so the @@ -354,28 +495,12 @@ pub fn package_managed() -> bool { false } -/// The update command for an Arch install from the AUR. A .deb or .rpm from -/// the website has no repository to update from: the app links to the -/// download page instead. +/// What to run when the app can't install the update itself: the AUR +/// helper for an Arch install (when the feed has no Arch package), nothing +/// for anything else (the dialog links to the download page). #[cfg(target_os = "linux")] fn manual_command() -> Option { - if !package_managed() { - return None; - } - let local = std::path::Path::new("/var/lib/pacman/local"); - let installed = |name: &str| { - std::fs::read_dir(local).ok().is_some_and(|dir| { - dir.flatten().any(|e| { - e.file_name().to_string_lossy().strip_prefix(name).is_some_and(|rest| { - rest.starts_with('-') && rest[1..].starts_with(|c: char| c.is_ascii_digit()) - }) - }) - }) - }; - ["stroke-nightly-bin", "stroke-bin"] - .into_iter() - .find(|p| installed(p)) - .map(|p| format!("yay -Syu {p}")) + aur_package().map(|p| format!("yay -Syu {p}")) } #[cfg(target_os = "windows")] diff --git a/src/lib/api.js b/src/lib/api.js index 6982b2d4..300667df 100644 --- a/src/lib/api.js +++ b/src/lib/api.js @@ -2238,7 +2238,7 @@ async function blobToBase64(blob) { // install can finish on its own (src-tauri/src/updates.rs). /** - * @typedef {{ version: string, currentVersion: string, notes: string, date: number | null, staged: boolean, applyOnQuit: boolean, manual: boolean, manualCommand: string | null }} UpdateInfo + * @typedef {{ version: string, currentVersion: string, notes: string, date: number | null, staged: boolean, applyOnQuit: boolean, manual: boolean, manualCommand: string | null, needsPassword: boolean }} UpdateInfo * @typedef {{ event: 'started', data: { contentLength: number | null } } | { event: 'progress', data: { downloaded: number } } | { event: 'finished' }} UpdateDownloadEvent */ diff --git a/src/lib/components/UpdateDialog.svelte b/src/lib/components/UpdateDialog.svelte index bdbe474e..0690caab 100644 --- a/src/lib/components/UpdateDialog.svelte +++ b/src/lib/components/UpdateDialog.svelte @@ -40,6 +40,8 @@ let manual = $state(false) /** The command that updates it, when there is one (`yay -Syu stroke-bin`). */ let manualCommand = $state(/** @type {string | null} */ (null)) + /** Installing asks for the system password (a Linux .deb, .rpm or Arch package). */ + let needsPassword = $state(false) let copied = $state(false) /** The running build, for "You have v…". */ let appVersion = $state('') @@ -333,6 +335,7 @@ applyOnQuit = info.applyOnQuit manual = !!info.manual manualCommand = info.manualCommand ?? null + needsPassword = !!info.needsPassword } async function copyCommand() { @@ -569,7 +572,7 @@

{#if status === 'ready'} - {applyOnQuit ? 'It installs when you quit, so the next start is the new version. Restart now to use it straight away.' : 'Restart Stroke to finish installing it.'} + {applyOnQuit ? 'It installs when you quit, so the next start is the new version. Restart now to use it straight away.' : needsPassword ? 'Restart Stroke to install it. Your system asks for your password first.' : 'Restart Stroke to finish installing it.'} {:else if status === 'downloading'} {totalBytes > 0 ? `${fmt(downloadedBytes)} of ${fmt(totalBytes)}` : 'Starting'}. It keeps going if you close this. {:else if manual}