Package-based updates: sf-update, signed shell and app packages
- sf-update (root): lists sf-shell / sf-app-* in the Gitea generic registry, downloads, checks the Ed25519 signature and unpacks to /var/lib/sf-pkg, switches via current/previous/staged symlinks; the factory copies on the read-only root stay as fallback. A new shell is on trial and rolls back after 3 failed starts. - Launcher: apps from factory + installed packages (newer version wins), Settings > System > Updates (check, install now), shell trial confirm. - Image: sf-update units (boot apply, 6-hourly download, launcher requests), sf-shell-exec wrapper for sf-remote, factory versions, registry token. - CI: .gitea/workflows/packages.yml builds, signs and uploads packages whose version isn't published yet (tools/pkg/packages.sh). - docs/updates.md: protocol and layout. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -31,26 +31,31 @@ slint::include_modules!();
|
||||
const CROSSFADE: f32 = 0.35;
|
||||
|
||||
struct Options {
|
||||
apps_dir: PathBuf,
|
||||
/// Factory apps, then installed app packages (`--apps` may repeat).
|
||||
apps_dirs: Vec<PathBuf>,
|
||||
settings_path: PathBuf,
|
||||
fullscreen: bool,
|
||||
}
|
||||
|
||||
fn parse_args() -> Options {
|
||||
let mut apps_dir = None;
|
||||
let mut apps_dirs = Vec::new();
|
||||
let mut settings_path = None;
|
||||
let mut fullscreen = false;
|
||||
let mut args = std::env::args().skip(1);
|
||||
while let Some(a) = args.next() {
|
||||
match a.as_str() {
|
||||
"--apps" => apps_dir = args.next().map(PathBuf::from),
|
||||
"--apps" => apps_dirs.extend(args.next().map(PathBuf::from)),
|
||||
"--settings" => settings_path = args.next().map(PathBuf::from),
|
||||
"--fullscreen" | "-f" => fullscreen = true,
|
||||
other => log::warn!("unknown argument {other}"),
|
||||
}
|
||||
}
|
||||
Options {
|
||||
apps_dir: apps_dir.or_else(find_apps_dir).unwrap_or_else(|| PathBuf::from("/usr/share/smartfox/apps")),
|
||||
apps_dirs: if apps_dirs.is_empty() {
|
||||
vec![find_apps_dir().unwrap_or_else(|| PathBuf::from("/usr/share/smartfox/apps"))]
|
||||
} else {
|
||||
apps_dirs
|
||||
},
|
||||
settings_path: settings_path.unwrap_or_else(default_settings_path),
|
||||
fullscreen,
|
||||
}
|
||||
@@ -311,8 +316,9 @@ fn main() -> Result<()> {
|
||||
}
|
||||
let data_dir = opts.settings_path.parent().map(Path::to_path_buf).unwrap_or_else(|| PathBuf::from("."));
|
||||
|
||||
let apps = sf_ipc::load_apps(&opts.apps_dir).with_context(|| format!("loading apps from {}", opts.apps_dir.display()))?;
|
||||
log::info!("{} apps from {}", apps.len(), opts.apps_dir.display());
|
||||
let apps = sf_ipc::manifest::load_apps_from(&opts.apps_dirs).with_context(|| format!("loading apps from {:?}", opts.apps_dirs))?;
|
||||
log::info!("{} apps from {:?}", apps.len(), opts.apps_dirs);
|
||||
system::confirm_shell_trial();
|
||||
|
||||
let ui = App::new()?;
|
||||
let entries: Vec<AppEntry> = apps.iter().map(|a| entry_of(a, &settings)).collect();
|
||||
|
||||
@@ -10,7 +10,7 @@ use std::time::{Duration, Instant};
|
||||
|
||||
use slint::{ComponentHandle, ModelRc, SharedString, VecModel};
|
||||
|
||||
use crate::system::{self, BtDevice, DeviceInfo, Display, Mode, NetInfo, RemoteDebug, Security, Wifi, WifiNetwork};
|
||||
use crate::system::{self, BtDevice, DeviceInfo, Display, Mode, NetInfo, RemoteDebug, Security, UpdateStatus, Wifi, WifiNetwork};
|
||||
use crate::power;
|
||||
use crate::{App, SettingRow, keyboard};
|
||||
|
||||
@@ -21,6 +21,7 @@ const DISPLAY: i32 = 0;
|
||||
const DEVICES: i32 = 1;
|
||||
const NETWORK: i32 = 2;
|
||||
const ENERGY: i32 = 3;
|
||||
const SYSTEM: i32 = 4;
|
||||
|
||||
#[derive(Clone, PartialEq)]
|
||||
enum Action {
|
||||
@@ -50,6 +51,9 @@ enum Action {
|
||||
SuspendAfter,
|
||||
PickSuspendAfter(u32),
|
||||
StandbyNow,
|
||||
Updates,
|
||||
UpdateCheck,
|
||||
UpdateInstall,
|
||||
}
|
||||
|
||||
#[derive(Clone, PartialEq)]
|
||||
@@ -64,6 +68,7 @@ enum Sub {
|
||||
RemoteDebug,
|
||||
PowerMode,
|
||||
SuspendAfter,
|
||||
Updates,
|
||||
}
|
||||
|
||||
struct Pending {
|
||||
@@ -88,6 +93,9 @@ enum Loaded {
|
||||
Removed { name: String, result: Result<(), String>, then_pair: bool },
|
||||
RemoteDebug(RemoteDebug),
|
||||
RemoteDebugSet { on: bool, result: Result<(), String> },
|
||||
/// sf-update's status.json (None: it never ran).
|
||||
Updates(Option<UpdateStatus>),
|
||||
UpdateRequested { install: bool, result: Result<(), String> },
|
||||
}
|
||||
|
||||
struct State {
|
||||
@@ -105,6 +113,8 @@ struct State {
|
||||
info: Option<DeviceInfo>,
|
||||
/// Whether sshd runs (remote debugging); None until queried.
|
||||
remote_debug: Option<RemoteDebug>,
|
||||
/// Package updates; None until read, Some(None) if sf-update never ran.
|
||||
updates: Option<Option<UpdateStatus>>,
|
||||
remote_status: String,
|
||||
/// One-line feedback shown under the page title (e.g. "AirPods eltávolítva").
|
||||
notice: String,
|
||||
@@ -182,6 +192,7 @@ impl Screen {
|
||||
wifi_pending: None,
|
||||
info: None,
|
||||
remote_debug: None,
|
||||
updates: None,
|
||||
remote_status: String::new(),
|
||||
notice: String::new(),
|
||||
actions: Vec::new(),
|
||||
@@ -253,6 +264,7 @@ impl Screen {
|
||||
post(|| Loaded::Net(system::network()));
|
||||
post(|| Loaded::Wifi(wifi_result(system::wifi())));
|
||||
post(|| Loaded::RemoteDebug(system::remote_debug()));
|
||||
post(|| Loaded::Updates(system::update_status()));
|
||||
if self.state.borrow().info.is_none() {
|
||||
post(|| Loaded::Info(system::device_info()));
|
||||
}
|
||||
@@ -271,6 +283,10 @@ impl Screen {
|
||||
if sub == Sub::KeepMode {
|
||||
self.rebuild(None);
|
||||
}
|
||||
// The updater reports progress through a file: cheap to poll.
|
||||
if self.is_open() && category == SYSTEM && matches!(sub, Sub::None | Sub::Updates) && ticks % 2 == 0 {
|
||||
post(|| Loaded::Updates(system::update_status()));
|
||||
}
|
||||
if !self.is_open() || sub != Sub::None || ticks % 4 != 0 {
|
||||
return;
|
||||
}
|
||||
@@ -401,6 +417,21 @@ impl Screen {
|
||||
}
|
||||
}
|
||||
Loaded::Info(i) => self.state.borrow_mut().info = Some(i),
|
||||
Loaded::Updates(u) => self.state.borrow_mut().updates = Some(u),
|
||||
Loaded::UpdateRequested { install, result } => {
|
||||
self.state.borrow_mut().notice = match result {
|
||||
Ok(()) if install => "Telepítés folyamatban. Utána a felület magától újraindul.".into(),
|
||||
Ok(()) => "Frissítések keresése…".into(),
|
||||
Err(e) => {
|
||||
log::warn!("update request: {e}");
|
||||
format!("Nem sikerült: {}", short_err(&e))
|
||||
}
|
||||
};
|
||||
post(|| {
|
||||
std::thread::sleep(Duration::from_millis(700));
|
||||
Loaded::Updates(system::update_status())
|
||||
});
|
||||
}
|
||||
Loaded::RemoteDebug(on) => self.state.borrow_mut().remote_debug = Some(on),
|
||||
Loaded::RemoteDebugSet { on, result } => {
|
||||
{
|
||||
@@ -687,6 +718,18 @@ impl Screen {
|
||||
Some(true) => self.run(Action::SetRemoteDebug(false)),
|
||||
None => {}
|
||||
},
|
||||
Action::Updates => {
|
||||
self.state.borrow_mut().notice.clear();
|
||||
self.enter(Sub::Updates, 0);
|
||||
}
|
||||
Action::UpdateCheck | Action::UpdateInstall => {
|
||||
let install = action == Action::UpdateInstall;
|
||||
log::info!("updates: {}", if install { "install" } else { "check" });
|
||||
post(move || Loaded::UpdateRequested {
|
||||
install,
|
||||
result: system::request_update(if install { "install" } else { "check" }).map_err(|e| format!("{e:#}")),
|
||||
});
|
||||
}
|
||||
Action::SetRemoteDebug(on) => {
|
||||
log::info!("remote debug: turning {}", if on { "on" } else { "off" });
|
||||
self.state.borrow_mut().busy = true;
|
||||
@@ -855,6 +898,31 @@ impl Screen {
|
||||
push(row("Mégse", "", "", "action"), Action::Back);
|
||||
("Felület újraindítása".to_string(), "A futó alkalmazás bezárul, a kezdőképernyő újraindul.".to_string())
|
||||
}
|
||||
(Sub::Updates, _) => {
|
||||
let status = st.updates.clone().flatten();
|
||||
let busy = status.as_ref().is_some_and(UpdateStatus::busy);
|
||||
let updates: Vec<_> = status.as_ref().map(|s| s.updates().into_iter().cloned().collect()).unwrap_or_default();
|
||||
if !updates.is_empty() {
|
||||
let label = if busy { "Folyamatban…" } else { "Telepítés most" };
|
||||
push(row(label, "", "A felület utána újraindul", "danger"), Action::UpdateInstall);
|
||||
}
|
||||
let label = if busy { "Folyamatban…" } else { "Frissítések keresése" };
|
||||
push(row(label, "", "", "action"), Action::UpdateCheck);
|
||||
for p in status.iter().flat_map(|s| s.packages.iter()) {
|
||||
let (value, detail) = match p.update() {
|
||||
Some(v) if p.ready() => (format!("{} → {v}", p.installed), "Letöltve, újraindításkor települ".to_string()),
|
||||
Some(v) => (format!("{} → {v}", p.installed), "Új verzió".to_string()),
|
||||
None => (p.installed.clone(), String::new()),
|
||||
};
|
||||
push(row(p.title.clone(), value, detail, "info"), Action::None);
|
||||
}
|
||||
push(row("Vissza", "", "", "action"), Action::Back);
|
||||
let subtitle = match &status {
|
||||
None => "A frissítő még nem futott ezen a gépen.".to_string(),
|
||||
Some(s) => update_summary(s).1,
|
||||
};
|
||||
("Frissítések".to_string(), notice_or(&subtitle))
|
||||
}
|
||||
(Sub::RemoteDebug, _) => {
|
||||
let label = if st.busy { "Bekapcsolás…" } else { "Bekapcsolás" };
|
||||
push(row(label, "", "", "danger"), Action::SetRemoteDebug(true));
|
||||
@@ -1012,6 +1080,12 @@ impl Screen {
|
||||
(false, Some(_)) => ("Ki".to_string(), "SSH a helyi hálózatról".to_string()),
|
||||
};
|
||||
push(row("Távoli hibakeresés", value, detail, "action"), Action::RemoteDebug);
|
||||
let (value, detail) = match &st.updates {
|
||||
None => ("…".to_string(), String::new()),
|
||||
Some(None) => ("Nem elérhető".to_string(), "A frissítő még nem futott".to_string()),
|
||||
Some(Some(u)) => update_summary(u),
|
||||
};
|
||||
push(row("Frissítések", value, detail, "action"), Action::Updates);
|
||||
push(row("Felület újraindítása", "", "", "action"), Action::Restart);
|
||||
("Rendszer".to_string(), notice_or("Az eszköz adatai."))
|
||||
}
|
||||
@@ -1089,3 +1163,29 @@ pub fn glass(ui: &App, scale: f32) -> Vec<crate::glass::Panel> {
|
||||
}
|
||||
out
|
||||
}
|
||||
|
||||
/// Value and detail for the Updates row: "2 frissítés" / "SmartFox felület 0.2.0 · YouTube 1.1.0".
|
||||
fn update_summary(u: &UpdateStatus) -> (String, String) {
|
||||
let checked = || {
|
||||
use chrono::TimeZone;
|
||||
match chrono::Local.timestamp_opt(u.checked_at, 0).single() {
|
||||
Some(t) if u.checked_at > 0 => format!("Utoljára ellenőrizve: {}", t.format("%m. %d. %H:%M")),
|
||||
_ => "Még nem kereste".to_string(),
|
||||
}
|
||||
};
|
||||
match u.state.as_str() {
|
||||
"checking" => return ("Keresés…".into(), String::new()),
|
||||
"downloading" => return ("Letöltés…".into(), u.message.clone()),
|
||||
"installing" => return ("Telepítés…".into(), String::new()),
|
||||
"error" => return ("Hiba".into(), short_err(&u.message)),
|
||||
_ => {}
|
||||
}
|
||||
let updates = u.updates();
|
||||
if updates.is_empty() {
|
||||
return ("Naprakész".into(), checked());
|
||||
}
|
||||
let list = updates.iter().map(|p| format!("{} {}", p.title, p.update().unwrap_or_default())).collect::<Vec<_>>().join(" · ");
|
||||
let value = if updates.len() == 1 { "1 frissítés".to_string() } else { format!("{} frissítés", updates.len()) };
|
||||
let detail = if updates.iter().all(|p| p.ready()) { format!("{list} · újraindításkor települ") } else { list };
|
||||
(value, detail)
|
||||
}
|
||||
|
||||
@@ -5,6 +5,7 @@
|
||||
//! backend with in-memory state keeps the settings screen usable.
|
||||
//! All calls can block for a moment, so run them off the UI thread.
|
||||
|
||||
use std::path::{Path, PathBuf};
|
||||
use std::process::{Command, Stdio};
|
||||
use std::sync::Mutex;
|
||||
use std::time::{Duration, Instant};
|
||||
@@ -855,6 +856,139 @@ pub fn set_remote_debug(on: bool) -> Result<()> {
|
||||
bail!("ssh.service is still {}", if on { "stopped" } else { "running" })
|
||||
}
|
||||
|
||||
// ---- updates (sf-update, docs/updates.md) --------------------------------
|
||||
|
||||
/// Written by sf-update (root), readable by everyone.
|
||||
const UPDATE_STATUS: &str = "/var/lib/sf-pkg/status.json";
|
||||
/// The launcher asks sf-update for things by dropping empty files here.
|
||||
const UPDATE_REQUESTS: &str = "/var/lib/smartfox/update-requests";
|
||||
|
||||
static DEMO_UPDATE: Mutex<u8> = Mutex::new(0);
|
||||
|
||||
#[derive(Debug, Clone, Default)]
|
||||
pub struct UpdateStatus {
|
||||
/// idle | checking | downloading | installing | error
|
||||
pub state: String,
|
||||
pub message: String,
|
||||
/// Unix time of the last check, 0 if never.
|
||||
pub checked_at: i64,
|
||||
pub packages: Vec<UpdatePackage>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Default)]
|
||||
pub struct UpdatePackage {
|
||||
/// Display name ("SmartFox felület", "YouTube").
|
||||
pub title: String,
|
||||
pub installed: String,
|
||||
pub available: Option<String>,
|
||||
pub staged: Option<String>,
|
||||
}
|
||||
|
||||
impl UpdatePackage {
|
||||
/// The newer version on the server, if there is one.
|
||||
pub fn update(&self) -> Option<&str> {
|
||||
self.available.as_deref().filter(|a| sf_ipc::manifest::version_cmp(a, &self.installed).is_gt())
|
||||
}
|
||||
|
||||
/// Downloaded already, goes live at the next start.
|
||||
pub fn ready(&self) -> bool {
|
||||
self.update().is_some() && self.staged.as_deref() == self.update()
|
||||
}
|
||||
}
|
||||
|
||||
impl UpdateStatus {
|
||||
pub fn busy(&self) -> bool {
|
||||
matches!(self.state.as_str(), "checking" | "downloading" | "installing")
|
||||
}
|
||||
|
||||
pub fn updates(&self) -> Vec<&UpdatePackage> {
|
||||
self.packages.iter().filter(|p| p.update().is_some()).collect()
|
||||
}
|
||||
}
|
||||
|
||||
/// "sf-shell" -> "SmartFox felület", "sf-app-youtube" -> the app's name.
|
||||
fn package_title(name: &str) -> String {
|
||||
if name == "sf-shell" {
|
||||
return "SmartFox felület".into();
|
||||
}
|
||||
let id = name.strip_prefix("sf-app-").unwrap_or(name);
|
||||
let dirs = [PathBuf::from("/usr/share/smartfox/apps"), PathBuf::from("/var/lib/sf-pkg/apps")];
|
||||
sf_ipc::manifest::load_apps_from(&dirs)
|
||||
.ok()
|
||||
.and_then(|apps| apps.into_iter().find(|a| a.id == id).map(|a| a.name))
|
||||
.unwrap_or_else(|| id.to_string())
|
||||
}
|
||||
|
||||
/// What sf-update last reported; None if it never ran.
|
||||
pub fn update_status() -> Option<UpdateStatus> {
|
||||
if demo() {
|
||||
let step = *DEMO_UPDATE.lock().unwrap();
|
||||
let pkg = |title: &str, installed: &str, available: &str| UpdatePackage {
|
||||
title: title.into(),
|
||||
installed: installed.into(),
|
||||
available: Some(available.into()),
|
||||
staged: None,
|
||||
};
|
||||
let packages = match step {
|
||||
0 => vec![pkg("SmartFox felület", "0.1.0", "0.2.0"), pkg("YouTube", "1.0.0", "1.1.0"), pkg("Netflex", "1.0.0", "1.0.0")],
|
||||
_ => vec![pkg("SmartFox felület", "0.2.0", "0.2.0"), pkg("YouTube", "1.1.0", "1.1.0")],
|
||||
};
|
||||
return Some(UpdateStatus { state: "idle".into(), message: String::new(), checked_at: 1_792_800_000, packages });
|
||||
}
|
||||
let text = std::fs::read_to_string(UPDATE_STATUS).ok()?;
|
||||
let v: serde_json::Value = serde_json::from_str(&text).ok()?;
|
||||
let s = |v: &serde_json::Value, k: &str| v.get(k).and_then(|x| x.as_str()).map(str::to_string);
|
||||
let packages = v
|
||||
.get("packages")
|
||||
.and_then(|p| p.as_array())
|
||||
.map(|list| {
|
||||
list.iter()
|
||||
.map(|p| UpdatePackage {
|
||||
title: package_title(&s(p, "name").unwrap_or_default()),
|
||||
installed: s(p, "installed").unwrap_or_default(),
|
||||
available: s(p, "available"),
|
||||
staged: s(p, "staged"),
|
||||
})
|
||||
.collect()
|
||||
})
|
||||
.unwrap_or_default();
|
||||
Some(UpdateStatus {
|
||||
state: s(&v, "state").unwrap_or_else(|| "idle".into()),
|
||||
message: s(&v, "message").unwrap_or_default(),
|
||||
checked_at: v.get("checked_at").and_then(|x| x.as_i64()).unwrap_or(0),
|
||||
packages,
|
||||
})
|
||||
}
|
||||
|
||||
/// Asks sf-update (root) to `check` or `install`; it runs from
|
||||
/// sf-update-requests.path and reports through status.json.
|
||||
pub fn request_update(what: &str) -> Result<()> {
|
||||
if demo() {
|
||||
if what == "install" {
|
||||
*DEMO_UPDATE.lock().unwrap() = 1;
|
||||
}
|
||||
return Ok(());
|
||||
}
|
||||
let path = Path::new(UPDATE_REQUESTS).join(what);
|
||||
std::fs::write(&path, b"").with_context(|| format!("writing {}", path.display()))
|
||||
}
|
||||
|
||||
/// A freshly installed shell is on trial (sf-launcher-start sets
|
||||
/// SMARTFOX_SHELL_TRIAL); once it has run for a while it tells sf-update to
|
||||
/// keep it. If it never gets here, sf-update rolls it back.
|
||||
pub fn confirm_shell_trial() {
|
||||
if std::env::var_os("SMARTFOX_SHELL_TRIAL").is_none() {
|
||||
return;
|
||||
}
|
||||
std::thread::spawn(|| {
|
||||
std::thread::sleep(Duration::from_secs(30));
|
||||
match request_update("confirm") {
|
||||
Ok(()) => log::info!("new shell confirmed"),
|
||||
Err(e) => log::warn!("confirming the new shell: {e:#}"),
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
||||
Reference in New Issue
Block a user