From 8e3db472fa9ff1ee3bfbafe60a6661142d933a24 Mon Sep 17 00:00:00 2001 From: Stephen Waits Date: Sat, 21 Nov 2026 15:41:22 -0700 Subject: [PATCH] feat(packaging): a per-user Windows installer, a universal macOS app and dmg, desktop entries with the icon (P15 C1) Windows: a hand-written NSIS script (per user, no administrator prompt, installs under the profile's Programs folder; one program file; a Start Menu entry named Wanderbooks with the icon; an uninstaller listed in Settings > Apps that removes only what the installer put in its own folder and never names the data folder). The installer asks the person to quit the app fully before it replaces or removes the program. An optional Authenticode signing step runs only when its secrets exist. macOS: the .app is assembled by a script (Info.plist with the bundle identifier, version, name, Documents-folder purpose string; the one program at Contents/MacOS/wanderbooks; the licences), signed with the hardened runtime and an empty entitlements file that says why, put in a dmg with an Applications shortcut, notarized and stapled when the owner's Apple identity is given and skipped with a notice when not. The program is one universal binary (lipo of the two release builds). Linux: both desktop entries name the window's app id and the icon; the rpm now installs the icon; the deb, the pacman tarball and the rpm all carry LICENSE-MIT and LICENSE-APACHE beside the notices. One version: deploy/packaging/version.sh reads crates/ledger-cli's Cargo.toml; every script takes it from there. Tests read the scripts and build a bundle with a stand-in program. Co-Authored-By: Claude Fable 5.2 --- crates/ledger-cli/Cargo.toml | 3 + crates/ledger-cli/tests/packaging.rs | 570 +++++++++++++++++++ deploy/packaging/Info.plist | 12 - deploy/packaging/build-linux.sh | 4 + deploy/packaging/build-macos.sh | 33 -- deploy/packaging/icons/wanderbooks.ico | Bin 0 -> 370070 bytes deploy/packaging/macos/Info.plist.in | 48 ++ deploy/packaging/macos/build-macos.sh | 143 +++++ deploy/packaging/macos/entitlements.plist | 29 + deploy/packaging/macos/import-certificate.sh | 24 + deploy/packaging/packager-macos.toml | 36 -- deploy/packaging/packager.toml | 4 + deploy/packaging/version.sh | 21 + deploy/packaging/wanderbooks-static.desktop | 8 +- deploy/packaging/wanderbooks.desktop | 1 + deploy/packaging/windows/build-windows.sh | 63 ++ deploy/packaging/windows/sign-windows.ps1 | 36 ++ deploy/packaging/windows/wanderbooks.nsi | 144 +++++ justfile | 17 +- 19 files changed, 1110 insertions(+), 86 deletions(-) create mode 100644 crates/ledger-cli/tests/packaging.rs delete mode 100644 deploy/packaging/Info.plist delete mode 100755 deploy/packaging/build-macos.sh create mode 100644 deploy/packaging/icons/wanderbooks.ico create mode 100644 deploy/packaging/macos/Info.plist.in create mode 100755 deploy/packaging/macos/build-macos.sh create mode 100644 deploy/packaging/macos/entitlements.plist create mode 100755 deploy/packaging/macos/import-certificate.sh delete mode 100644 deploy/packaging/packager-macos.toml create mode 100755 deploy/packaging/version.sh create mode 100755 deploy/packaging/windows/build-windows.sh create mode 100644 deploy/packaging/windows/sign-windows.ps1 create mode 100644 deploy/packaging/windows/wanderbooks.nsi diff --git a/crates/ledger-cli/Cargo.toml b/crates/ledger-cli/Cargo.toml index 7d8e19cd..ff19b180 100644 --- a/crates/ledger-cli/Cargo.toml +++ b/crates/ledger-cli/Cargo.toml @@ -82,5 +82,8 @@ assets = [ { source = "target/release/wanderbooks", dest = "/usr/bin/wanderbooks", mode = "0755" }, { source = "deploy/packaging/install-method-rpm", dest = "/usr/share/wanderbooks/install-method", mode = "0644" }, { source = "deploy/packaging/wanderbooks-static.desktop", dest = "/usr/share/applications/wanderbooks.desktop", mode = "0644" }, + { source = "deploy/packaging/icons/512x512.png", dest = "/usr/share/icons/hicolor/512x512/apps/wanderbooks.png", mode = "0644" }, + { source = "LICENSE-MIT", dest = "/usr/share/doc/wanderbooks/LICENSE-MIT", mode = "0644" }, + { source = "LICENSE-APACHE", dest = "/usr/share/doc/wanderbooks/LICENSE-APACHE", mode = "0644" }, { source = "THIRD-PARTY-NOTICES.txt", dest = "/usr/share/doc/wanderbooks/THIRD-PARTY-NOTICES.txt", mode = "0644" }, ] diff --git a/crates/ledger-cli/tests/packaging.rs b/crates/ledger-cli/tests/packaging.rs new file mode 100644 index 00000000..ad61926e --- /dev/null +++ b/crates/ledger-cli/tests/packaging.rs @@ -0,0 +1,570 @@ +//! The packages (plan P15 unit C1; WB-pkg-1 to WB-pkg-7): what can be checked +//! on Linux about the Windows installer, the macOS app, the Linux entries and +//! the one source of the version. For Windows and macOS the release workflow +//! is the real test (each packaging step fails loudly); these tests keep the +//! files it builds from true to the rules. +//! +//! ```text +//! GOAL: an installed Wanderbooks is one executable at a stable path, named +//! Wanderbooks everywhere a person sees it, with the licences beside +//! it; installing a newer one over it, or uninstalling it, never +//! touches the person's books. +//! SOURCE: WB-pkg-1 (installs like a normal program), WB-pkg-2 (one +//! executable, a stable bridge path), WB-pkg-6 (one version, one +//! name), WB-pkg-7 (the release carries the licences); D-77. +//! INVARIANTS: +//! 1. The version is written once (ledger-cli's Cargo.toml); the packaging +//! scripts read it through deploy/packaging/version.sh. +//! 2. The Windows installer is per user (no administrator), installs one +//! program, and its uninstaller names nothing but what the installer +//! put in its own folder: no recursive removal, no wildcard, no data +//! folder. +//! 3. The macOS bundle holds one program at Contents/MacOS/wanderbooks, an +//! Info.plist whose identifier, name, version and executable agree with +//! the scripts, and the licences. +//! 4. The Linux desktop entries launch plain `wanderbooks` (an AppImage's +//! launcher appends what it is given) with the icon, the name, and the +//! window's app id. +//! 5. Every package carries LICENSE-MIT, LICENSE-APACHE and +//! THIRD-PARTY-NOTICES.txt. +//! SCENARIOS: +//! 1. The bundle script run on Linux with a stand-in program makes a +//! bundle whose plist and files match the rules above. +//! ``` + +use std::path::{Path, PathBuf}; +use std::process::Command; + +fn root() -> PathBuf { + Path::new(env!("CARGO_MANIFEST_DIR")).join("../..") +} + +fn read(path: &str) -> String { + std::fs::read_to_string(root().join(path)).unwrap_or_else(|e| panic!("{path}: {e}")) +} + +/// The lines of `text` that are not comments (`;` for NSIS, `#` for shell +/// and TOML). +fn code(text: &str) -> Vec<&str> { + text.lines() + .map(str::trim) + .filter(|l| !l.is_empty() && !l.starts_with(';') && !l.starts_with('#')) + .collect() +} + +const LICENCE_FILES: [&str; 3] = ["LICENSE-MIT", "LICENSE-APACHE", "THIRD-PARTY-NOTICES.txt"]; + +// ---- the version, written once --------------------------------------------------- + +#[cfg(unix)] +#[test] +fn the_version_is_written_once_and_every_script_reads_it_from_there() { + let out = Command::new("sh") + .arg(root().join("deploy/packaging/version.sh")) + .output() + .unwrap(); + assert!(out.status.success(), "{out:?}"); + let said = String::from_utf8(out.stdout).unwrap(); + assert_eq!(said.trim(), env!("CARGO_PKG_VERSION")); + + // The Linux packager's own file carries a version the build script + // overwrites; it must not drift from the source. + let packager = read("deploy/packaging/packager.toml"); + let line = code(&packager) + .into_iter() + .find(|l| l.starts_with("version = ")) + .unwrap(); + assert_eq!(line, format!("version = \"{}\"", env!("CARGO_PKG_VERSION"))); + + // No packaging script or workflow assigns a literal version. + for file in [ + "deploy/packaging/windows/build-windows.sh", + "deploy/packaging/macos/build-macos.sh", + ".github/workflows/release.yml", + ] { + for line in code(&read(file)) { + let assigns = line.starts_with("version=") || line.starts_with("version:"); + let literal = line.split(['=', ':']).nth(1).is_some_and(|v| { + v.trim() + .trim_matches('"') + .chars() + .next() + .is_some_and(|c| c.is_ascii_digit()) + }); + assert!(!(assigns && literal), "{file}: a literal version: {line}"); + } + } + for file in [ + "deploy/packaging/windows/build-windows.sh", + "deploy/packaging/macos/build-macos.sh", + "deploy/packaging/build-linux.sh", + ] { + let text = read(file); + assert!( + text.contains("version.sh") || text.contains("ledger-cli/Cargo.toml"), + "{file} does not read the version from its one source" + ); + } +} + +#[cfg(unix)] +#[test] +fn a_version_that_is_not_three_numbers_is_refused() { + let dir = tempfile::tempdir().unwrap(); + std::fs::create_dir_all(dir.path().join("deploy/packaging")).unwrap(); + std::fs::create_dir_all(dir.path().join("crates/ledger-cli")).unwrap(); + std::fs::copy( + root().join("deploy/packaging/version.sh"), + dir.path().join("deploy/packaging/version.sh"), + ) + .unwrap(); + for (toml, ok) in [ + ("version = \"0.2.0\"\n", true), + ("version = \"0.2.0-rc1\"\n", false), + ("version = \"two\"\n", false), + ("", false), + ] { + std::fs::write(dir.path().join("crates/ledger-cli/Cargo.toml"), toml).unwrap(); + let out = Command::new("sh") + .arg(dir.path().join("deploy/packaging/version.sh")) + .output() + .unwrap(); + assert_eq!(out.status.success(), ok, "{toml:?}: {out:?}"); + } +} + +// ---- Windows -------------------------------------------------------------------- + +#[test] +fn the_windows_installer_is_per_user_and_installs_one_program() { + let nsi = read("deploy/packaging/windows/wanderbooks.nsi"); + let lines = code(&nsi); + let has = |needle: &str| lines.iter().any(|l| l.contains(needle)); + // No administrator prompt; everything in the person's own profile. + assert!(has("RequestExecutionLevel user")); + assert!(has(r#"InstallDir "$LOCALAPPDATA\Programs\Wanderbooks""#)); + assert!( + !lines.iter().any(|l| l.contains("HKLM")), + "per-machine registry" + ); + assert!(!has("SetShellVarContext all"), "all users' Start Menu"); + // A Start Menu entry named Wanderbooks, with the icon. + assert!(has( + r#"CreateShortCut "$SMPROGRAMS\${NAME}.lnk" "$INSTDIR\wanderbooks.exe""# + )); + assert!(has(r#"!define NAME "Wanderbooks""#)); + assert!(has("wanderbooks.ico")); + // An uninstaller, listed in Settings > Apps, whose name is the product's. + assert!(has("WriteUninstaller")); + assert!(has(r#""DisplayName" "${NAME}""#)); + assert!(has("UninstallString")); + // One program: the only .exe installed besides the uninstaller. + let programs: Vec<&&str> = lines + .iter() + .filter(|l| l.starts_with("File ") && l.contains(".exe")) + .collect(); + assert_eq!(programs.len(), 1, "{programs:?}"); + assert!(programs[0].contains("/oname=wanderbooks.exe")); + // The licences travel with it. + for file in LICENCE_FILES { + assert!(has(&format!("/oname={file}")), "{file} is not installed"); + } +} + +/// WB-pkg-1: the uninstaller removes what the installer put in its own +/// folder and nothing else; the books are in the data folder, which it never +/// names. +#[test] +fn the_uninstaller_never_removes_the_books() { + let nsi = read("deploy/packaging/windows/wanderbooks.nsi"); + let lines = code(&nsi); + let start = lines + .iter() + .position(|l| l.starts_with(r#"Section "Uninstall""#)) + .expect("an uninstall section"); + let section = &lines[start..]; + let mut removals = 0; + for line in section { + let word = line.split_whitespace().next().unwrap_or(""); + if matches!(word, "Delete" | "RMDir" | "DeleteRegKey" | "DeleteRegValue") { + removals += 1; + assert!(!line.contains("/r"), "a recursive removal: {line}"); + assert!( + !line.contains('*') && !line.contains('?'), + "a wildcard: {line}" + ); + let ok = line.contains("$INSTDIR") + || line.contains("$SMPROGRAMS") + || line.contains("${UNINSTALL_KEY}") + || line.contains("${APP_KEY}"); + assert!( + ok, + "removes something that is not the program's own: {line}" + ); + } + } + assert!(removals >= 6, "the uninstaller removes the installed files"); + // The data folder, the roaming settings and the keys are named nowhere + // in the script's code (the comments say where the books are). + for line in &lines { + for data in [ + "$LOCALAPPDATA\\wanderbooks", + "$APPDATA", + "\\link", + "legacy", + "books\\", + ] { + assert!(!line.contains(data), "{data} named: {line}"); + } + } + // Only the registry keys of its own. + let keys: Vec<&&str> = lines + .iter() + .filter(|l| l.starts_with("!define") && l.contains("_KEY")) + .collect(); + assert_eq!(keys.len(), 2, "{keys:?}"); + assert!(keys[0].contains(r"Software\Microsoft\Windows\CurrentVersion\Uninstall\Wanderbooks")); + assert!(keys[1].contains(r"Software\Wanderbooks")); +} + +/// If NSIS is installed here, the script compiles with stand-in files +/// (the release workflow compiles it for real on Windows). +#[test] +fn the_installer_script_compiles_when_nsis_is_here() { + let Some(makensis) = std::env::var_os("PATH").and_then(|p| { + std::env::split_paths(&p) + .map(|d| d.join("makensis")) + .find(|f| f.is_file()) + }) else { + eprintln!( + "makensis is not installed here: the Windows job of the release workflow compiles the installer" + ); + return; + }; + let dir = tempfile::tempdir().unwrap(); + let p = dir.path(); + std::fs::write(p.join("wanderbooks.exe"), b"MZ").unwrap(); + for f in LICENCE_FILES { + std::fs::write(p.join(f), b"x").unwrap(); + } + std::fs::copy( + root().join("deploy/packaging/icons/wanderbooks.ico"), + p.join("wanderbooks.ico"), + ) + .unwrap(); + let out = Command::new(makensis) + .arg("-V2") + .arg(format!("-DVERSION={}", env!("CARGO_PKG_VERSION"))) + .arg(format!("-DPROGRAM={}", p.join("wanderbooks.exe").display())) + .arg(format!("-DICON={}", p.join("wanderbooks.ico").display())) + .arg(format!("-DLICENSES={}", p.display())) + .arg(format!("-DOUTFILE={}", p.join("setup.exe").display())) + .arg(root().join("deploy/packaging/windows/wanderbooks.nsi")) + .output() + .unwrap(); + assert!( + out.status.success(), + "{}", + String::from_utf8_lossy(&out.stdout) + ); + assert!(p.join("setup.exe").metadata().unwrap().len() > 0); +} + +/// WB-pkg-2: on Windows the one executable is built for the GUI subsystem +/// (no console window for the app), and gives a terminal its words back. +#[test] +fn the_windows_program_opens_no_console_window_and_still_speaks_in_a_terminal() { + let main = read("crates/ledger-cli/src/main.rs"); + assert!( + main.contains( + r#"#![cfg_attr(all(windows, feature = "gui"), windows_subsystem = "windows")]"# + ) + ); + assert!(main.contains("console::attach_parent_console()")); + let console = read("crates/ledger-cli/src/console.rs"); + assert!(console.contains("AttachConsole(ATTACH_PARENT_PROCESS)")); + // The server child the app starts has no console window of its own. + assert!(read("crates/ledger-host/src/app_server.rs").contains("NO_WINDOW")); +} + +// ---- macOS ---------------------------------------------------------------------- + +/// The ``/value pairs of a plist's top-level dict, as text. Good enough +/// for the plain plists here (no nesting). +fn plist(text: &str) -> Vec<(String, String)> { + let mut pairs = Vec::new(); + let mut key: Option = None; + for line in text.lines().map(str::trim) { + if let Some(k) = line + .strip_prefix("") + .and_then(|l| l.strip_suffix("")) + { + assert!(key.is_none(), "a key with no value: {k}"); + key = Some(k.to_string()); + } else if let Some(k) = key.take_if(|_| line.starts_with('<') && !line.starts_with(" - - - LSMultipleInstancesProhibited - - NSSupportsAutomaticGraphicsSwitching - - - diff --git a/deploy/packaging/build-linux.sh b/deploy/packaging/build-linux.sh index ea84b556..88bad803 100755 --- a/deploy/packaging/build-linux.sh +++ b/deploy/packaging/build-linux.sh @@ -37,6 +37,7 @@ sed "s/^version = \".*\"/version = \"$version\"/ s#\"target/release\"#\"$PWD/$stage\"# s#\"deploy/packaging/#\"$PWD/deploy/packaging/# s#\"LICENSE-MIT\"#\"$PWD/LICENSE-MIT\"# + s#^\"LICENSE-APACHE\"#\"$PWD/LICENSE-APACHE\"# s#^\"THIRD-PARTY-NOTICES.txt\"#\"$PWD/THIRD-PARTY-NOTICES.txt\"#" \ deploy/packaging/packager.toml >"$config" # The AppImage tools are themselves AppImages; run them without FUSE. @@ -46,6 +47,9 @@ assets='assets = [ { source = "'$PWD/$stage'/wanderbooks", dest = "/usr/bin/wanderbooks", mode = "0755" }, { source = "deploy/packaging/install-method-rpm", dest = "/usr/share/wanderbooks/install-method", mode = "0644" }, { source = "deploy/packaging/wanderbooks-static.desktop", dest = "/usr/share/applications/wanderbooks.desktop", mode = "0644" }, + { source = "deploy/packaging/icons/512x512.png", dest = "/usr/share/icons/hicolor/512x512/apps/wanderbooks.png", mode = "0644" }, + { source = "LICENSE-MIT", dest = "/usr/share/doc/wanderbooks/LICENSE-MIT", mode = "0644" }, + { source = "LICENSE-APACHE", dest = "/usr/share/doc/wanderbooks/LICENSE-APACHE", mode = "0644" }, { source = "THIRD-PARTY-NOTICES.txt", dest = "/usr/share/doc/wanderbooks/THIRD-PARTY-NOTICES.txt", mode = "0644" }, ]' cargo generate-rpm -p crates/ledger-cli --set-metadata "version=\"$version\"" --set-metadata "$assets" -o "$out/" diff --git a/deploy/packaging/build-macos.sh b/deploy/packaging/build-macos.sh deleted file mode 100755 index f9e809f3..00000000 --- a/deploy/packaging/build-macos.sh +++ /dev/null @@ -1,33 +0,0 @@ -#!/usr/bin/env bash -# The macOS bundle (P11a step 6), UNSIGNED, from the release program -# already built at target/release/wanderbooks (`cargo build --release -p -# ledger-cli`). Run on a Mac from the repository root: -# -# build-macos.sh [VERSION] -# -# Puts Wanderbooks_VERSION_.dmg into target/packages/VERSION/. It -# is not signed or notarized (step 5): Gatekeeper refuses it on a Mac -# that downloaded it, and the owner opens it with right-click > Open. -# Portable shell: macOS has BSD sed and no GNU mktemp options. -set -euo pipefail -own=$(sed -n 's/^version = "\(.*\)"/\1/p' crates/ledger-cli/Cargo.toml | head -n1) -version=${1:-$own} -out="target/packages/$version" -program=${WB_PROGRAM:-target/release/wanderbooks} -test -x "$program" || { echo "build the release program first: cargo build --release -p ledger-cli" >&2; exit 1; } -rm -rf "$out"; mkdir -p "$out" -stage="target/packages/.stage-$version" -rm -rf "$stage"; mkdir -p "$stage" -cp "$program" "$stage/wanderbooks" -config="$stage/packager.toml" -# cargo-packager reads paths relative to the config file, which is in the -# stage folder here, so they are made absolute. -sed -e "s/^version = \".*\"/version = \"$version\"/" \ - -e "s#^out-dir = .*#out-dir = \"$PWD/$out\"#" \ - -e "s#\"target/release\"#\"$PWD/$stage\"#" \ - -e "s#\"deploy/packaging/#\"$PWD/deploy/packaging/#" \ - -e "s#\"LICENSE-MIT\"#\"$PWD/LICENSE-MIT\"#" \ - deploy/packaging/packager-macos.toml >"$config" -cargo packager --config "$config" --formats dmg --release -rm -rf "$stage" -ls -l "$out" diff --git a/deploy/packaging/icons/wanderbooks.ico b/deploy/packaging/icons/wanderbooks.ico new file mode 100644 index 0000000000000000000000000000000000000000..a2c72ed54f43cdd285a7cf6717c282051ae0b9a9 GIT binary patch literal 370070 zcmeHQX|xs9mA=H#wmb6?$hx8}OHrtd8_ zRduTB410gy-lyuEI=56BQ2Lt^{sxo=mrfk~&eEl_-`w1L{I>&2(9^89;OsVvv83Rkl$QJos_Rdo2V{-B<(nnNg`847K&^W=@xlgggmDXihu!N9he99!2xgqoB%g6?+a?Q z!EpY1Ik#ElkVp~i%r?@_elY+}fE(aQOu+yziaM@^0dNl-Y={rAmLvP07TGOQt6of_UWkFl zU;rEh7whT+Ecs(Bzggr}5!#qKAO@1h0JsQFf}7e81b(P@xxwTq+hau*h|uQL0Wpw1 z41k;9Xly>ffNhvR z>;1Bi_X~X9Pp7TPLE6QR0dO_aJ3$NoF}|={#9juEsS{!#y%+#zD`SH}`T!R0V}1e0 z_tR@*@{hK0!vMHjnIq)K2Uxg&lBay!3@+>U0bV}9Tqj%1G42te zeW?RtAiEd&$g|}Roc&v0dU%}4`AUxV?VKD#}1G4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Wanderbooks + CFBundleDisplayName + Wanderbooks + CFBundleIdentifier + @BUNDLE_ID@ + CFBundleExecutable + wanderbooks + CFBundleIconFile + wanderbooks + CFBundlePackageType + APPL + CFBundleInfoDictionaryVersion + 6.0 + CFBundleShortVersionString + @VERSION@ + CFBundleVersion + @VERSION@ + LSMinimumSystemVersion + 11.0 + LSApplicationCategoryType + public.app-category.finance + NSHighResolutionCapable + + + LSMultipleInstancesProhibited + + + NSSupportsAutomaticGraphicsSwitching + + NSHumanReadableCopyright + MIT OR Apache-2.0 + + NSDocumentsFolderUsageDescription + Wanderbooks keeps a small folder in Documents for each company, where an assistant such as Claude Code works, and the extension file for the Claude app. + + diff --git a/deploy/packaging/macos/build-macos.sh b/deploy/packaging/macos/build-macos.sh new file mode 100755 index 00000000..fc7e7f0b --- /dev/null +++ b/deploy/packaging/macos/build-macos.sh @@ -0,0 +1,143 @@ +#!/usr/bin/env bash +# The macOS app and its .dmg (plan P15 unit C1; WB-pkg-1). Run on a Mac from +# the repository root (CI: the `macos` job of .github/workflows/release.yml): +# +# build-macos.sh [VERSION] +# +# Puts Wanderbooks-VERSION-macos-universal.dmg into target/packages/VERSION/. +# +# One UNIVERSAL program (Apple silicon and Intel in one file, `lipo`ed from +# the two release builds): one download for everyone. The program is +# WB_PROGRAM if set (any program file), else the lipo of +# target/aarch64-apple-darwin/release/wanderbooks and +# target/x86_64-apple-darwin/release/wanderbooks. +# +# Signing and notarization need the owner's Apple Developer identity and run +# only when it is given, in the environment (the release workflow sets these +# from secrets; nothing here is a secret and nothing prints one): +# WB_SIGN_IDENTITY the signing identity, e.g. +# "Developer ID Application: Name (TEAMID)", already in +# the keychain (import-certificate.sh does that in CI) +# WB_NOTARY_APPLE_ID, WB_NOTARY_TEAM_ID, WB_NOTARY_PASSWORD +# for `xcrun notarytool` (an app-specific password) +# Without WB_SIGN_IDENTITY the app is signed ad hoc ("-"): Apple silicon +# will not start an unsigned program at all, so it runs, but Gatekeeper +# still refuses a download of it (right-click > Open once, docs/install.md). +# Without the notarization variables the .dmg is signed but not notarized. +# +# WB_NO_ICNS=1 skips the icon (no `iconutil` off a Mac): the structure +# tests build the bundle that way on Linux; a release never does. +# WB_BUNDLE_ONLY=1 stops after the .app (the structure tests). +set -euo pipefail + +here=$(CDPATH='' cd -- "$(dirname -- "$0")" && pwd) +root=$(CDPATH='' cd -- "$here/../../.." && pwd) +cd "$root" +fail() { echo "build-macos: $*" >&2; exit 1; } +notice() { echo "::notice title=$1::$2"; echo "build-macos: $2"; } + +own=$(sh deploy/packaging/version.sh) +version=${1:-$own} +case "$version" in + [0-9]*.[0-9]*.[0-9]*) ;; + *) fail "'$version' is not an x.y.z version" ;; +esac +bundle_id=${WB_BUNDLE_ID:-ai.wanderbooks.app} +out="target/packages/$version" +stage="target/packages/.stage-macos-$version" +app="$stage/Wanderbooks.app" +dmg="Wanderbooks-$version-macos-universal.dmg" + +for f in LICENSE-MIT LICENSE-APACHE THIRD-PARTY-NOTICES.txt deploy/packaging/icons/512x512.png \ + deploy/packaging/macos/Info.plist.in deploy/packaging/macos/entitlements.plist; do + test -f "$f" || fail "$f is missing from the repository" +done + +# 1. The program: universal, or the one given. +rm -rf "${stage:?}" +mkdir -p "$stage" "$out" +program=${WB_PROGRAM:-} +if [ -z "$program" ]; then + arm=target/aarch64-apple-darwin/release/wanderbooks + intel=target/x86_64-apple-darwin/release/wanderbooks + test -f "$arm" || fail "$arm is missing: cargo build --release -p ledger-cli --target aarch64-apple-darwin" + test -f "$intel" || fail "$intel is missing: cargo build --release -p ledger-cli --target x86_64-apple-darwin" + lipo -create -output "$stage/wanderbooks-universal" "$arm" "$intel" + archs=$(lipo -archs "$stage/wanderbooks-universal") + case "$archs" in + *arm64*x86_64*|*x86_64*arm64*) ;; + *) fail "the universal program holds '$archs', not both arm64 and x86_64" ;; + esac + program="$stage/wanderbooks-universal" +fi +test -f "$program" || fail "the program is not at $program" + +# 2. The bundle. The program's path inside it, +# /Applications/Wanderbooks.app/Contents/MacOS/wanderbooks, is the one an +# assistant is registered with: it does not change when the app is +# replaced by a newer one dragged over it. +mkdir -p "$app/Contents/MacOS" "$app/Contents/Resources" +cp "$program" "$app/Contents/MacOS/wanderbooks" +chmod 755 "$app/Contents/MacOS/wanderbooks" +sed -e "s/@VERSION@/$version/g" -e "s/@BUNDLE_ID@/$bundle_id/g" \ + deploy/packaging/macos/Info.plist.in > "$app/Contents/Info.plist" +printf 'APPL????' > "$app/Contents/PkgInfo" +cp LICENSE-MIT LICENSE-APACHE THIRD-PARTY-NOTICES.txt "$app/Contents/Resources/" +if [ "${WB_NO_ICNS:-}" = 1 ]; then + notice "no icon" "WB_NO_ICNS=1: the bundle has no icon (a test build, never a release)" +else + command -v iconutil >/dev/null || fail "iconutil is not here: build the icon on a Mac, or set WB_NO_ICNS=1 for a test bundle" + iconset="$stage/wanderbooks.iconset" + mkdir -p "$iconset" + src=deploy/packaging/icons/512x512.png + for size in 16 32 128 256 512; do + sips -z "$size" "$size" "$src" --out "$iconset/icon_${size}x${size}.png" >/dev/null + done + for size in 16 32 128 256; do + double=$((size * 2)) + sips -z "$double" "$double" "$src" --out "$iconset/icon_${size}x${size}@2x.png" >/dev/null + done + iconutil -c icns "$iconset" -o "$app/Contents/Resources/wanderbooks.icns" +fi +if [ "${WB_BUNDLE_ONLY:-}" = 1 ]; then + echo "build-macos: bundle at $app (WB_BUNDLE_ONLY=1)" + exit 0 +fi + +# 3. Sign: hardened runtime, the entitlements, a secure timestamp. +identity=${WB_SIGN_IDENTITY:-} +if [ -z "$identity" ]; then + notice "macOS signing skipped" "no WB_SIGN_IDENTITY: the app is signed ad hoc, so it runs here, but macOS Gatekeeper will refuse a download of it until it is signed with a Developer ID and notarized" + identity=- + timestamp=--timestamp=none +else + timestamp=--timestamp +fi +codesign --force --options runtime "$timestamp" \ + --entitlements deploy/packaging/macos/entitlements.plist \ + --sign "$identity" "$app" +codesign --verify --deep --strict --verbose=2 "$app" + +# 4. The .dmg: the app and a shortcut to Applications (drag to install). +mkdir -p "$stage/dmg" +cp -R "$app" "$stage/dmg/" +ln -s /Applications "$stage/dmg/Applications" +rm -f "${out:?}/${dmg:?}" +hdiutil create -volname "Wanderbooks" -srcfolder "$stage/dmg" -ov -format UDZO "$out/$dmg" +if [ "$identity" != "-" ]; then + codesign --force --timestamp --sign "$identity" "$out/$dmg" +fi + +# 5. Notarize and staple (the Developer ID signature and Apple's ticket). +if [ "$identity" != "-" ] && [ -n "${WB_NOTARY_APPLE_ID:-}" ] && [ -n "${WB_NOTARY_TEAM_ID:-}" ] && [ -n "${WB_NOTARY_PASSWORD:-}" ]; then + xcrun notarytool submit "$out/$dmg" \ + --apple-id "$WB_NOTARY_APPLE_ID" --team-id "$WB_NOTARY_TEAM_ID" \ + --password "$WB_NOTARY_PASSWORD" --wait + xcrun stapler staple "$out/$dmg" + xcrun stapler validate "$out/$dmg" + spctl --assess --type open --context context:primary-signature --verbose=2 "$out/$dmg" +else + notice "macOS notarization skipped" "no signing identity or no WB_NOTARY_APPLE_ID / WB_NOTARY_TEAM_ID / WB_NOTARY_PASSWORD: the .dmg is not notarized, and macOS will warn on the first open" +fi +rm -rf "${stage:?}" +ls -l "$out" diff --git a/deploy/packaging/macos/entitlements.plist b/deploy/packaging/macos/entitlements.plist new file mode 100644 index 00000000..30dd36ee --- /dev/null +++ b/deploy/packaging/macos/entitlements.plist @@ -0,0 +1,29 @@ + + + + + + diff --git a/deploy/packaging/macos/import-certificate.sh b/deploy/packaging/macos/import-certificate.sh new file mode 100755 index 00000000..25bcecf0 --- /dev/null +++ b/deploy/packaging/macos/import-certificate.sh @@ -0,0 +1,24 @@ +#!/usr/bin/env bash +# Put the owner's Developer ID certificate into a temporary keychain on a CI +# macOS runner, so `codesign` can use it (plan P15 unit C1). Run by the +# release workflow only when the secrets exist. Takes the certificate (a .p12, +# base64) and its password from the environment, never the command line: +# APPLE_CERTIFICATE_P12_BASE64, APPLE_CERTIFICATE_PASSWORD +# Prints no secret. The keychain lives in RUNNER_TEMP and goes with the +# runner. +set -euo pipefail +: "${APPLE_CERTIFICATE_P12_BASE64:?the certificate secret is empty}" +: "${APPLE_CERTIFICATE_PASSWORD:?the certificate password secret is empty}" +: "${RUNNER_TEMP:?not on a GitHub runner}" +keychain="$RUNNER_TEMP/wanderbooks-signing.keychain-db" +password=$(uuidgen) +p12="$RUNNER_TEMP/wanderbooks-signing.p12" +printf '%s' "$APPLE_CERTIFICATE_P12_BASE64" | base64 --decode > "$p12" +security create-keychain -p "$password" "$keychain" +security set-keychain-settings -lut 21600 "$keychain" +security unlock-keychain -p "$password" "$keychain" +security import "$p12" -k "$keychain" -P "$APPLE_CERTIFICATE_PASSWORD" -T /usr/bin/codesign +security set-key-partition-list -S apple-tool:,apple: -s -k "$password" "$keychain" >/dev/null +security list-keychains -d user -s "$keychain" login.keychain +rm -f "$p12" +security find-identity -v -p codesigning "$keychain" diff --git a/deploy/packaging/packager-macos.toml b/deploy/packaging/packager-macos.toml deleted file mode 100644 index 64ef6c00..00000000 --- a/deploy/packaging/packager-macos.toml +++ /dev/null @@ -1,36 +0,0 @@ -# cargo-packager's description of the macOS bundle (P11a step 6; D-24, -# D-25): the .app and its .dmg, UNSIGNED. `deploy/packaging/build-macos.sh` -# runs it on a Mac (CI: the `macos` job of .github/workflows/release.yml). -# Developer ID signing and notarization are step 5 (the owner's Apple -# certificate, Q-4): they add `signing-identity` under [macos] and the -# certificate and notarization credentials as CI secrets. -# Paths are relative to this file's copy that build-macos.sh writes. -name = "wanderbooks" -product-name = "Wanderbooks" -version = "0.1.0" -identifier = "ai.wanderbooks.app" -description = "Double-entry bookkeeping your agent keeps and you can read." -homepage = "https://wanderbooks.ai" -authors = ["Stephen Waits"] -license-file = "LICENSE-MIT" -category = "Finance" -binaries-dir = "target/release" -out-dir = "target/packages" -# A png is made into the .icns (cargo-packager does it); the 512 px -# placeholder is the owner's to replace. -icons = ["deploy/packaging/icons/512x512.png"] -formats = ["dmg"] -binaries = [{ path = "wanderbooks", main = true }] - -[macos] -# The oldest macOS Rust's tier-1 aarch64-apple-darwin and x86-64 targets -# run on; eframe's wgpu/Metal path needs 10.15 at least. -minimum-system-version = "11.0" -# Keys merged into the generated Info.plist: one viewer at a time, and the -# discrete GPU is not woken for a ledger. -info-plist-path = "deploy/packaging/Info.plist" - -[dmg] -window-size = { width = 540, height = 380 } -app-position = { x = 140, y = 180 } -application-folder-position = { x = 400, y = 180 } diff --git a/deploy/packaging/packager.toml b/deploy/packaging/packager.toml index 0974f661..b0307d5a 100644 --- a/deploy/packaging/packager.toml +++ b/deploy/packaging/packager.toml @@ -31,6 +31,8 @@ depends = ["libc6", "libgcc-s1"] # The notices the third-party licences ask to travel with the program # (`just notices`); `wanderbooks licenses` prints the same text. "THIRD-PARTY-NOTICES.txt" = "usr/share/doc/wanderbooks/THIRD-PARTY-NOTICES.txt" +"LICENSE-MIT" = "usr/share/doc/wanderbooks/LICENSE-MIT" +"LICENSE-APACHE" = "usr/share/doc/wanderbooks/LICENSE-APACHE" [pacman] depends = ["gcc-libs", "glibc"] @@ -38,3 +40,5 @@ depends = ["gcc-libs", "glibc"] [pacman.files] "deploy/packaging/install-method-aur" = "usr/share/wanderbooks/install-method" "THIRD-PARTY-NOTICES.txt" = "usr/share/doc/wanderbooks/THIRD-PARTY-NOTICES.txt" +"LICENSE-MIT" = "usr/share/doc/wanderbooks/LICENSE-MIT" +"LICENSE-APACHE" = "usr/share/doc/wanderbooks/LICENSE-APACHE" diff --git a/deploy/packaging/version.sh b/deploy/packaging/version.sh new file mode 100755 index 00000000..99304cd3 --- /dev/null +++ b/deploy/packaging/version.sh @@ -0,0 +1,21 @@ +#!/bin/sh +# The program's version: the one place it is written is `version = "..."` +# in crates/ledger-cli/Cargo.toml (plan P15 C1, WB-pkg-6). Every package, the +# release workflow and the installer take it from here; the program itself +# reports the same file's version through `CARGO_PKG_VERSION`. +# +# deploy/packaging/version.sh prints 0.1.0 +# +# A version that is not three plain numbers is refused: the Windows +# installer's file-version fields and the macOS bundle's both need them. +set -eu +here=$(CDPATH='' cd -- "$(dirname -- "$0")" && pwd) +version=$(sed -n 's/^version = "\(.*\)"/\1/p' "$here/../../crates/ledger-cli/Cargo.toml" | head -n1) +case "$version" in + [0-9]*.[0-9]*.[0-9]*) ;; + *) echo "version.sh: no x.y.z version in crates/ledger-cli/Cargo.toml (found: '$version')" >&2; exit 1 ;; +esac +case "$version" in + *[!0-9.]*) echo "version.sh: '$version' is not three plain numbers" >&2; exit 1 ;; +esac +printf '%s\n' "$version" diff --git a/deploy/packaging/wanderbooks-static.desktop b/deploy/packaging/wanderbooks-static.desktop index ffa4bbe2..c6a9391a 100644 --- a/deploy/packaging/wanderbooks-static.desktop +++ b/deploy/packaging/wanderbooks-static.desktop @@ -1,7 +1,9 @@ [Desktop Entry] -Categories=Office;Finance; +Type=Application +Name=Wanderbooks Comment=Double-entry bookkeeping your agent keeps and you can read. Exec=wanderbooks -Name=Wanderbooks +Icon=wanderbooks Terminal=false -Type=Application +Categories=Office;Finance; +StartupWMClass=wanderbooks diff --git a/deploy/packaging/wanderbooks.desktop b/deploy/packaging/wanderbooks.desktop index 574cd598..5e3f2a8a 100644 --- a/deploy/packaging/wanderbooks.desktop +++ b/deploy/packaging/wanderbooks.desktop @@ -8,3 +8,4 @@ Icon={{icon}} Name={{name}} Terminal=false Type=Application +StartupWMClass=wanderbooks diff --git a/deploy/packaging/windows/build-windows.sh b/deploy/packaging/windows/build-windows.sh new file mode 100755 index 00000000..68ea948f --- /dev/null +++ b/deploy/packaging/windows/build-windows.sh @@ -0,0 +1,63 @@ +#!/usr/bin/env bash +# The Windows installer (plan P15 unit C1), from the release program already +# built at target/release/wanderbooks.exe (`cargo build --release -p +# ledger-cli`). Run from the repository root, in Git Bash on Windows (CI: +# the `windows` job of .github/workflows/release.yml) or anywhere makensis +# is: +# +# build-windows.sh [VERSION] +# +# Puts Wanderbooks-VERSION-windows-x64-setup.exe into target/packages/VERSION/. +# VERSION defaults to the program's own (deploy/packaging/version.sh). +# WB_PROGRAM names another program file; WB_MAKENSIS another makensis. +# +# Unsigned: signing is a separate, optional step (sign-windows.ps1) that +# runs when the release workflow has the certificate's secrets. +set -euo pipefail + +here=$(CDPATH='' cd -- "$(dirname -- "$0")" && pwd) +root=$(CDPATH='' cd -- "$here/../../.." && pwd) +cd "$root" +own=$(sh deploy/packaging/version.sh) +version=${1:-$own} +case "$version" in + [0-9]*.[0-9]*.[0-9]*) ;; + *) echo "build-windows: '$version' is not an x.y.z version" >&2; exit 1 ;; +esac +program=${WB_PROGRAM:-target/release/wanderbooks.exe} +out="target/packages/$version" +installer="Wanderbooks-$version-windows-x64-setup.exe" + +fail() { echo "build-windows: $*" >&2; exit 1; } +test -f "$program" || fail "the release program is not at $program: run cargo build --release -p ledger-cli first" +for f in LICENSE-MIT LICENSE-APACHE THIRD-PARTY-NOTICES.txt deploy/packaging/icons/wanderbooks.ico deploy/packaging/windows/wanderbooks.nsi; do + test -f "$f" || fail "$f is missing from the repository" +done + +makensis=${WB_MAKENSIS:-} +if [ -z "$makensis" ]; then + if command -v makensis >/dev/null 2>&1; then + makensis=makensis + elif [ -x "/c/Program Files (x86)/NSIS/makensis.exe" ]; then + makensis="/c/Program Files (x86)/NSIS/makensis.exe" + else + fail "makensis (NSIS) is not installed: choco install nsis, or apt install nsis" + fi +fi + +# NSIS is a Windows program; Git Bash must neither rewrite its options +# (-D...) nor hand it a Unix path, so paths are made native here. +export MSYS2_ARG_CONV_EXCL='*' +native() { if command -v cygpath >/dev/null 2>&1; then cygpath -w "$1"; else printf '%s\n' "$1"; fi; } + +rm -rf "${out:?}" +mkdir -p "$out" +"$makensis" -V2 \ + "-DVERSION=$version" \ + "-DPROGRAM=$(native "$program")" \ + "-DICON=$(native deploy/packaging/icons/wanderbooks.ico)" \ + "-DLICENSES=$(native "$root")" \ + "-DOUTFILE=$(native "$out/$installer")" \ + "$(native deploy/packaging/windows/wanderbooks.nsi)" +test -s "$out/$installer" || fail "makensis finished but $out/$installer is missing or empty" +ls -l "$out" diff --git a/deploy/packaging/windows/sign-windows.ps1 b/deploy/packaging/windows/sign-windows.ps1 new file mode 100644 index 00000000..6fce5ba0 --- /dev/null +++ b/deploy/packaging/windows/sign-windows.ps1 @@ -0,0 +1,36 @@ +# Sign Windows files with an Authenticode code-signing certificate (plan P15 +# unit C1). The release workflow runs this only when its secrets exist +# (WINDOWS_CERTIFICATE_PFX_BASE64 and WINDOWS_CERTIFICATE_PASSWORD); with none +# it prints a notice and the installer stays unsigned (SmartScreen warns). +# +# sign-windows.ps1 FILE [FILE...] +# +# The certificate is written to a temporary file for the signing and +# removed. Nothing here prints a secret. A failure is loud: a signature that +# was asked for and did not happen stops the release. +param([Parameter(Mandatory = $true, ValueFromRemainingArguments = $true)][string[]]$Files) +$ErrorActionPreference = 'Stop' + +if (-not $env:WINDOWS_CERTIFICATE_PFX_BASE64 -or -not $env:WINDOWS_CERTIFICATE_PASSWORD) { + Write-Host "::notice title=Windows signing skipped::no WINDOWS_CERTIFICATE_PFX_BASE64 / WINDOWS_CERTIFICATE_PASSWORD secret: the installer is unsigned and Windows SmartScreen will warn on the first run." + exit 0 +} + +$signtool = Get-ChildItem "${env:ProgramFiles(x86)}\Windows Kits\10\bin" -Recurse -Filter signtool.exe -ErrorAction SilentlyContinue | + Where-Object { $_.FullName -match '\\x64\\' } | + Sort-Object FullName -Descending | Select-Object -First 1 +if (-not $signtool) { throw "signtool.exe was not found in the Windows SDK on this runner" } + +$pfx = Join-Path $env:RUNNER_TEMP 'wanderbooks-codesign.pfx' +[IO.File]::WriteAllBytes($pfx, [Convert]::FromBase64String($env:WINDOWS_CERTIFICATE_PFX_BASE64)) +try { + foreach ($file in $Files) { + & $signtool.FullName sign /fd sha256 /f $pfx /p $env:WINDOWS_CERTIFICATE_PASSWORD /tr http://timestamp.digicert.com /td sha256 $file + if ($LASTEXITCODE -ne 0) { throw "signtool failed on $file" } + & $signtool.FullName verify /pa $file + if ($LASTEXITCODE -ne 0) { throw "the signature on $file does not verify" } + Write-Host "signed $file" + } +} finally { + Remove-Item $pfx -Force -ErrorAction SilentlyContinue +} diff --git a/deploy/packaging/windows/wanderbooks.nsi b/deploy/packaging/windows/wanderbooks.nsi new file mode 100644 index 00000000..9d332144 --- /dev/null +++ b/deploy/packaging/windows/wanderbooks.nsi @@ -0,0 +1,144 @@ +; The Wanderbooks installer for Windows (plan P15 unit C1; WB-pkg-1, WB-pkg-2, +; WB-pkg-7). Built by deploy/packaging/windows/build-windows.sh with NSIS +; (https://nsis.sourceforge.io, free software, zlib licence). +; +; makensis -DVERSION=0.1.0 -DPROGRAM=...\wanderbooks.exe -DICON=...\wanderbooks.ico ^ +; -DLICENSES= -DOUTFILE=...\Wanderbooks-0.1.0-windows-x64-setup.exe wanderbooks.nsi +; +; What it does, and the rules it keeps: +; * Per user: RequestExecutionLevel user, so double-clicking it shows no +; administrator prompt. Everything goes under the person's own profile +; and HKEY_CURRENT_USER. +; * One program file, wanderbooks.exe. It is the window, the books +; server's child and the assistants' bridge; an assistant is registered +; with this installed path, which an update keeps (the same folder, the +; same file name, replaced in place). +; * A Start Menu entry named Wanderbooks, with the icon, and an entry in +; Settings > Apps (the uninstaller). +; * The uninstaller removes the files this installer put in the install +; folder, the Start Menu entry and its two registry keys. It NEVER +; removes the person's books, keys, backups or settings: they live in +; the data folder (%LOCALAPPDATA%\wanderbooks), which this script +; names nowhere, and no command below deletes a folder's contents or +; uses a wildcard (a test, crates/ledger-cli/tests/packaging.rs, reads +; this file and fails if one appears). +; * It asks the person to quit Wanderbooks fully before it replaces or +; removes the program (a running program cannot be replaced). +; * Unsigned until the owner has a code-signing certificate: Windows +; SmartScreen says so on the first run (docs/install.md). + +Unicode true +SetCompressor /SOLID lzma +!include "MUI2.nsh" +!include "LogicLib.nsh" + +!ifndef VERSION + !error "pass -DVERSION=x.y.z (deploy/packaging/version.sh)" +!endif +!ifndef PROGRAM + !error "pass -DPROGRAM=" +!endif +!ifndef ICON + !error "pass -DICON=" +!endif +!ifndef LICENSES + !error "pass -DLICENSES=" +!endif +!ifndef OUTFILE + !error "pass -DOUTFILE=" +!endif + +!define NAME "Wanderbooks" +!define PUBLISHER "Wanderbooks" +!define UNINSTALL_KEY "Software\Microsoft\Windows\CurrentVersion\Uninstall\Wanderbooks" +!define APP_KEY "Software\Wanderbooks" + +Name "${NAME}" +OutFile "${OUTFILE}" +RequestExecutionLevel user +InstallDir "$LOCALAPPDATA\Programs\Wanderbooks" +InstallDirRegKey HKCU "${APP_KEY}" "InstallDir" +BrandingText "${NAME} ${VERSION}" +ShowInstDetails nevershow +ShowUninstDetails nevershow + +VIProductVersion "${VERSION}.0" +VIAddVersionKey "ProductName" "${NAME}" +VIAddVersionKey "FileDescription" "${NAME} installer" +VIAddVersionKey "FileVersion" "${VERSION}" +VIAddVersionKey "ProductVersion" "${VERSION}" +VIAddVersionKey "LegalCopyright" "MIT OR Apache-2.0" + +!define MUI_ICON "${ICON}" +!define MUI_UNICON "${ICON}" +!define MUI_ABORTWARNING +!define MUI_FINISHPAGE_RUN "$INSTDIR\wanderbooks.exe" +!define MUI_FINISHPAGE_RUN_TEXT "Start ${NAME}" + +!insertmacro MUI_PAGE_INSTFILES +!insertmacro MUI_PAGE_FINISH +!insertmacro MUI_UNPAGE_CONFIRM +!insertmacro MUI_UNPAGE_INSTFILES +!insertmacro MUI_LANGUAGE "English" + +; A program that is running cannot be replaced or removed. Try to open the +; installed file for writing; if it is in use, ask the person to quit +; Wanderbooks (its window, which closes the books and the server) and retry. +!macro WaitUntilNotRunning + ${Do} + ClearErrors + ${If} ${FileExists} "$INSTDIR\wanderbooks.exe" + FileOpen $0 "$INSTDIR\wanderbooks.exe" a + ${IfNot} ${Errors} + FileClose $0 + ${Break} + ${EndIf} + MessageBox MB_RETRYCANCEL|MB_ICONEXCLAMATION "${NAME} is open. Quit it fully (close its window), then choose Retry." IDRETRY +2 + Abort "${NAME} is still open." + ${Else} + ${Break} + ${EndIf} + ${Loop} +!macroend + +Section "Install" + SetOutPath "$INSTDIR" + !insertmacro WaitUntilNotRunning + File "/oname=wanderbooks.exe" "${PROGRAM}" + File "/oname=wanderbooks.ico" "${ICON}" + File "/oname=LICENSE-MIT" "${LICENSES}\LICENSE-MIT" + File "/oname=LICENSE-APACHE" "${LICENSES}\LICENSE-APACHE" + File "/oname=THIRD-PARTY-NOTICES.txt" "${LICENSES}\THIRD-PARTY-NOTICES.txt" + WriteUninstaller "$INSTDIR\Uninstall Wanderbooks.exe" + + CreateShortCut "$SMPROGRAMS\${NAME}.lnk" "$INSTDIR\wanderbooks.exe" "" "$INSTDIR\wanderbooks.ico" 0 + + WriteRegStr HKCU "${APP_KEY}" "InstallDir" "$INSTDIR" + WriteRegStr HKCU "${UNINSTALL_KEY}" "DisplayName" "${NAME}" + WriteRegStr HKCU "${UNINSTALL_KEY}" "DisplayVersion" "${VERSION}" + WriteRegStr HKCU "${UNINSTALL_KEY}" "Publisher" "${PUBLISHER}" + WriteRegStr HKCU "${UNINSTALL_KEY}" "DisplayIcon" "$INSTDIR\wanderbooks.ico" + WriteRegStr HKCU "${UNINSTALL_KEY}" "InstallLocation" "$INSTDIR" + WriteRegStr HKCU "${UNINSTALL_KEY}" "URLInfoAbout" "https://wanderbooks.ai" + WriteRegStr HKCU "${UNINSTALL_KEY}" "UninstallString" '"$INSTDIR\Uninstall Wanderbooks.exe"' + WriteRegStr HKCU "${UNINSTALL_KEY}" "QuietUninstallString" '"$INSTDIR\Uninstall Wanderbooks.exe" /S' + WriteRegDWORD HKCU "${UNINSTALL_KEY}" "NoModify" 1 + WriteRegDWORD HKCU "${UNINSTALL_KEY}" "NoRepair" 1 +SectionEnd + +Section "Uninstall" + !insertmacro WaitUntilNotRunning + Delete "$INSTDIR\wanderbooks.exe" + Delete "$INSTDIR\wanderbooks.ico" + Delete "$INSTDIR\LICENSE-MIT" + Delete "$INSTDIR\LICENSE-APACHE" + Delete "$INSTDIR\THIRD-PARTY-NOTICES.txt" + Delete "$INSTDIR\Uninstall Wanderbooks.exe" + ; Only if empty: a folder the person put something in stays. + RMDir "$INSTDIR" + Delete "$SMPROGRAMS\${NAME}.lnk" + DeleteRegKey HKCU "${UNINSTALL_KEY}" + DeleteRegKey HKCU "${APP_KEY}" + ; The person's books, keys, backups and settings are not here: they are + ; in the data folder, which an uninstall leaves exactly as it is. +SectionEnd diff --git a/justfile b/justfile index 8db57ebf..e524faad 100644 --- a/justfile +++ b/justfile @@ -591,10 +591,23 @@ package-linux version="" formats="deb,appimage,pacman": cargo build --release -p ledger-cli deploy/packaging/build-linux.sh {{version}} {{formats}} -# Build the unsigned macOS .dmg (on a Mac; CI does it on a tag or dispatch) +# The macOS app and its universal .dmg (on a Mac; CI does it on a tag or +# dispatch). Signs and notarizes only with WB_SIGN_IDENTITY and WB_NOTARY_* +# in the environment (deploy/packaging/macos/build-macos.sh says which). +# Build the universal macOS .dmg package-macos version="": + rustup target add aarch64-apple-darwin x86_64-apple-darwin + cargo build --release -p ledger-cli --target aarch64-apple-darwin + cargo build --release -p ledger-cli --target x86_64-apple-darwin + deploy/packaging/macos/build-macos.sh {{version}} + +# The per-user Windows installer (in Git Bash on Windows, with NSIS: choco +# install nsis; CI does it on a tag or dispatch). Unsigned unless the +# release workflow signs it. +# Build the Windows installer +package-windows version="": cargo build --release -p ledger-cli - deploy/packaging/build-macos.sh {{version}} + deploy/packaging/windows/build-windows.sh {{version}} # A release folder on this machine signed with a throwaway key; then # `wanderbooks update --feed file://DIR/manifest.json --trusted-key DIR/release.pub`