Skip to content
Open
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
2 changes: 1 addition & 1 deletion RELEASES.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ maker's own build machines.
(the VM's guest, the signed app, the disk image; all in `xtask/`), then
Apple's notarization (`xcrun notarytool`)
- Windows: `cargo xtask msi` (the installer, from `installer/windows`)
- Linux: `scripts/ci/linux-build.sh` (all `.deb` and `.rpm` packages),
- Linux: `scripts/ci/linux-build.sh` (all `.deb` and `.rpm` packages, and the AppImage),
then `packaging/linux/test-host.sh`, which installs them on Ubuntu and
Fedora and runs containers through them. A build that doesn't install
and run isn't released.
Expand Down
28 changes: 27 additions & 1 deletion crates/kiri/src/hostaccess.rs
Original file line number Diff line number Diff line change
Expand Up @@ -158,12 +158,38 @@ pub fn run(args: &[String]) -> io::Result<u8> {
must_output(tool_cmd(&groupadd).args(["--system", group]), "groupadd")
},
|member, group| add_member_with(member, group, find_tool("usermod").as_deref(), find_tool("gpasswd").as_deref()),
|| engine(restart),
|| install_from_appimage().and_then(|()| engine(restart)),
|group| crate::daemon::access::grant(Path::new(SOCKET), group),
|line| println!("{line}"),
)
}

fn install_from_appimage() -> io::Result<()> {
let Some(appdir) = appdir() else { return Ok(()) };
if ["/lib/systemd/system/kiri.service", "/usr/lib/systemd/system/kiri.service"].iter().any(|p| Path::new(p).exists()) {
return Ok(());
}
let bin = Path::new("/usr/local/bin");
std::fs::create_dir_all(bin)?;
for name in ["kiri", "kiri-init"] {
let to = bin.join(name);
// Copy, then rename over the old file: a running engine keeps its own binary.
let part = to.with_extension("part");
std::fs::copy(appdir.join("usr/bin").join(name), &part).and_then(|_| std::fs::rename(&part, &to)).map_err(|e| io::Error::other(format!("{}: {e}", to.display())))?;
}
let unit = include_str!("../../../packaging/linux/kiri.service").replace("/usr/bin/kiri", "/usr/local/bin/kiri");
std::fs::write("/etc/systemd/system/kiri.service", unit)?;
println!("Kiri's engine is installed in /usr/local/bin");
let systemctl = find_tool("systemctl").ok_or_else(|| io::Error::other("systemctl not found in system directories"))?;
must(tool_cmd(&systemctl).arg("daemon-reload"), "systemctl daemon-reload")
}

/// APPDIR, only when this program is inside it: programs started from another AppImage inherit APPDIR too.
pub fn appdir() -> Option<std::path::PathBuf> {
let dir = std::path::PathBuf::from(std::env::var_os("APPDIR")?);
std::env::current_exe().ok()?.starts_with(&dir).then_some(dir)
}

/// The engine running and answering on its socket; with `restart`, a
/// running one restarted (on the binary the package installed).
fn engine(restart: bool) -> io::Result<()> {
Expand Down
21 changes: 17 additions & 4 deletions crates/kiri/src/ui/linux.rs
Original file line number Diff line number Diff line change
Expand Up @@ -229,8 +229,6 @@ pub mod onboarding {
use std::process::{Command, Stdio};

const SOCKET: &str = crate::client::SERVICE_SOCKET;
/// The package's command; pkexec wants a full path.
const KIRI: &str = "/usr/bin/kiri";

/// Each check's state for the page: "ok", "no" (fix it), "bad" (broken:
/// fix it), "off" (can't tell until an earlier one passes) or "restart"
Expand All @@ -240,7 +238,9 @@ pub mod onboarding {
pub fn checks() -> serde_json::Value {
let installed = ["/lib/systemd/system/kiri.service", "/usr/lib/systemd/system/kiri.service", "/etc/systemd/system/kiri.service"]
.iter()
.any(|p| Path::new(p).exists());
.any(|p| Path::new(p).exists())
// The AppImage carries the engine; "Start engine" installs it.
|| crate::hostaccess::appdir().is_some();
let (running, access) = match std::os::unix::net::UnixStream::connect(SOCKET) {
Ok(_) => ("ok", "ok"),
// The engine is there; this session may not use it. In the group
Expand Down Expand Up @@ -323,7 +323,20 @@ pub mod onboarding {
if which("pkexec").is_none() {
return Err(io::Error::other(format!("this system has no pkexec to ask for your password: in a terminal, run sudo kiri host-access {}{user}", flags.iter().map(|f| format!("{f} ")).collect::<String>())));
}
let out = Command::new("pkexec").arg(KIRI).arg("host-access").args(flags).arg(&user).stdin(Stdio::null()).output()?;
// Root can't read the AppImage's mount, so pkexec runs the AppImage file itself.
let mut cmd = Command::new("pkexec");
match std::env::var_os("APPIMAGE").filter(|_| crate::hostaccess::appdir().is_some()) {
Some(appimage) => {
cmd.arg(appimage);
if std::env::var_os("APPIMAGE_EXTRACT_AND_RUN").is_some() {
cmd.arg("--appimage-extract-and-run");
}
}
None => {
cmd.arg("/usr/bin/kiri");
}
}
let out = cmd.arg("host-access").args(flags).arg(&user).stdin(Stdio::null()).output()?;
match out.status.code() {
Some(0) | Some(10) => Ok(()),
// pkexec: 126 the dialog was dismissed or the password refused, 127 not allowed.
Expand Down
1 change: 1 addition & 0 deletions packaging/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ directory (and `installer/windows`) does.
| Linux (Debian, Ubuntu) | `kiri_<v>_amd64.deb`, `_arm64.deb` | `packaging/linux/build.sh` | engine + docker CLI, Compose, buildx; the window on x86-64 |
| Linux (Debian, Ubuntu) | `kiri-lite_<v>_amd64.deb`, `_arm64.deb` | `packaging/linux/build.sh` | engine only |
| Linux (Fedora, RHEL, openSUSE) | `kiri-<v>-1.x86_64.rpm`, `.aarch64.rpm`, `kiri-lite-…rpm` | `packaging/linux/build.sh` | same two flavours |
| Linux (any distro with GTK 3 and WebKitGTK 4.1) | `Kiri-<v>-x86_64.AppImage`, `-aarch64.AppImage` | `packaging/linux/appimage.sh` | the window and the engine, and a `.zsync` file per AppImage, which goes on the GitHub release next to it so AppImageUpdate and similar tools can update Kiri; the window's setup installs the engine as `/usr/local/bin/kiri` with `/etc/systemd/system/kiri.service` (remove both to uninstall) |
| Windows | `Kiri-<v>-x86_64.msi` | `cargo xtask msi` | engine for WSL2, `kiri-win.exe`, docker CLI, Compose, buildx |
| Windows on Arm | `Kiri-<v>-arm64.msi` | `cargo xtask msi --arch arm64` | the same, arm64 throughout (docker CLI built from source) |
| macOS | `Kiri.app` in `Kiri-<v>-arm64.dmg` (`-x86_64` for Intel), Kiri Lite | `cargo xtask release` | app + CLI tools; Lite downloads the tools |
Expand Down
6 changes: 6 additions & 0 deletions packaging/linux/AppRun
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#!/bin/sh
# No arguments, or `ui`: the window. Anything else goes to the static kiri.
here=$(dirname "$(readlink -f "$0")")
[ $# -eq 0 ] && set -- ui
[ "$1" = ui ] && exec "$here/usr/bin/kiri-window" "$@"
exec "$here/usr/bin/kiri" "$@"
54 changes: 54 additions & 0 deletions packaging/linux/appimage.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
#!/bin/bash
set -euo pipefail
umask 022
bindir=$1 window=$2 outdir=$3 cache=${4:-${XDG_CACHE_HOME:-$HOME/.cache}/kiri-appimage}
here=$(cd "$(dirname "$0")" && pwd)
root=$(cd "$here/../.." && pwd)
version=$(sed -n 's/^version = "\(.*\)"/\1/p' "$root/Cargo.toml" | head -1 | tr -d '\r')
for b in "$bindir/kiri" "$bindir/kiri-init" "$window"; do
[ -x "$b" ] || { echo "no $b" >&2; exit 1; }
done
mkdir -p "$outdir" "$cache"
outdir=$(cd "$outdir" && pwd) cache=$(cd "$cache" && pwd)
get() { # url file sum
local f=$cache/$2
if [ ! -f "$f" ]; then
curl -fsSL --proto '=https' --proto-redir '=https' --retry 3 -o "$f.$$.part" "$1" || { rm -f "$f.$$.part"; echo "could not download $1" >&2; exit 1; }
mv "$f.$$.part" "$f"
fi
echo "$3 $f" | sha256sum -c --quiet - || { echo "$2 does not match the pinned SHA-256; delete $f and retry" >&2; exit 1; }
}
arch=$(uname -m)
case $arch in
x86_64) tool_sum=ed4ce84f0d9caff66f50bcca6ff6f35aae54ce8135408b3fa33abfc3cb384eb0 runtime_sum=2fca8b443c92510f1483a883f60061ad09b46b978b2631c807cd873a47ec260d ;;
aarch64) tool_sum=f0837e7448a0c1e4e650a93bb3e85802546e60654ef287576f46c71c126a9158 runtime_sum=00cbdfcf917cc6c0ff6d3347d59e0ca1f7f45a6df1a428a0d6d8a78664d87444 ;;
*) echo "no AppImage for $arch" >&2; exit 1 ;;
esac
get "https://github.com/AppImage/appimagetool/releases/download/1.9.1/appimagetool-$arch.AppImage" "appimagetool-1.9.1-$arch.AppImage" "$tool_sum"
get "https://github.com/AppImage/type2-runtime/releases/download/20251108/runtime-$arch" "runtime-20251108-$arch" "$runtime_sum"
work=$(mktemp -d)
trap 'rm -rf "$work"' EXIT
app=$work/Kiri.AppDir
install -D -m 755 "$bindir/kiri" "$app/usr/bin/kiri"
install -m 755 "$bindir/kiri-init" "$app/usr/bin/kiri-init"
install -m 755 "$window" "$app/usr/bin/kiri-window"
install -m 755 "$here/AppRun" "$app/AppRun"
# The launcher runs the AppImage itself; the icon is the AppDir's kiri.svg.
sed -e 's|^Exec=.*|Exec=kiri|' -e 's|^Icon=.*|Icon=kiri|' "$root/contrib/linux/kiri.desktop" > "$app/kiri.desktop"
# AppImageUpdate and other update tools read this, and the .zsync file next to each release's AppImage.
update="gh-releases-zsync|libracoder|kiri|latest|Kiri-*-$arch.AppImage.zsync"
printf 'X-AppImage-Name=Kiri\nX-AppImage-Version=%s\nX-AppImage-Arch=%s\nX-AppImage-UpdateInformation=%s\n' "$version" "$arch" "$update" >> "$app/kiri.desktop"
install -m 644 "$root/brand/icon/kiri-app-icon.svg" "$app/kiri.svg"
mkdir -p "$app/usr/share/metainfo"
sed -e "s/@VERSION@/$version/" -e "s/@DATE@/$(date -u +%Y-%m-%d)/" "$root/contrib/linux/dev.kiri.Kiri.metainfo.xml" > "$app/usr/share/metainfo/dev.kiri.Kiri.metainfo.xml"
install -D -m 644 "$root/LICENSE" "$app/usr/share/doc/kiri/LICENSE"
install -m 644 "$root/NOTICE" "$app/usr/share/doc/kiri/NOTICE"
tool=$work/appimagetool
install -m 755 "$cache/appimagetool-1.9.1-$arch.AppImage" "$tool"
out=$outdir/Kiri-$version-$arch.AppImage
# Extract-and-run: build machines and containers often have no FUSE.
# appimagetool writes the .zsync file in OWD when that is set, else in the current directory.
cd "$outdir"
ARCH=$arch OWD=$outdir APPIMAGE_EXTRACT_AND_RUN=1 "$tool" --no-appstream --updateinformation "$update" --runtime-file "$cache/runtime-20251108-$arch" "$app" "$out" >&2
[ -f "$out.zsync" ] || { echo "appimagetool made no $out.zsync" >&2; exit 1; }
echo "$out"
7 changes: 6 additions & 1 deletion scripts/ci/linux-build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
# and WebKitGTK) for this machine's own architecture, when
# libwebkit2gtk-4.1-dev is installed; it goes in the full kiri package
# - kiri and kiri-lite as .deb and .rpm for each (packaging/linux/build.sh)
# - Kiri as an AppImage, when the GTK/WebKitGTK window binary was built (packaging/linux/appimage.sh)
#
# scripts/ci/linux-build.sh
#
Expand Down Expand Up @@ -46,6 +47,10 @@ for arch in x86_64 aarch64; do
w=; [ "$arch" = "$(uname -m)" ] && w=$window
bash packaging/linux/build.sh "$bins/$arch" target/packages "$arch" "target/linux-cli-$arch" $w
done
if [ -n "$window" ]; then
bash packaging/linux/appimage.sh "$bins/$(uname -m)" "$window" target/packages
fi
cd target/packages
sha256sum *.deb *.rpm > SHA256SUMS-linux
appimages=$(ls *.AppImage 2>/dev/null || true)
sha256sum *.deb *.rpm $appimages > SHA256SUMS-linux
cat SHA256SUMS-linux