Implement auto-update routine
This commit is contained in:
+60
-7
@@ -15,7 +15,7 @@
|
||||
// lazily from a `RwLock<String>` whenever any path is computed (config dir,
|
||||
// log dir, named-pipe namespace, …), so setting it before any of those
|
||||
// initializers fire is enough to redirect all hbb_common state under
|
||||
// `%APPDATA%\HelloAgent\` and the matching LocalService path. Identical
|
||||
// `%APPDATA%\hello-agent\` and the matching LocalService path. Identical
|
||||
// to the `read_custom_client` write path the upstream Flutter build uses
|
||||
// for OEM rebrands.
|
||||
|
||||
@@ -39,17 +39,28 @@ use cli::{Action, ParsedArgs};
|
||||
/// Product name used to namespace all on-disk state and the IPC pipe path.
|
||||
/// Written into `hbb_common::config::APP_NAME` at the top of `main` so
|
||||
/// every subsequent path computation (config dir, log dir, named pipe)
|
||||
/// targets `%APPDATA%\HelloAgent\` rather than the upstream default of
|
||||
/// targets `%APPDATA%\hello-agent\` rather than the upstream default of
|
||||
/// `%APPDATA%\RustDesk\`. Must be set before any code touches a path —
|
||||
/// `hbb_common` initializes path globals lazily on first read.
|
||||
pub const APP_NAME: &str = "HelloAgent";
|
||||
///
|
||||
/// Important: this value also drives upstream's installer lookup paths.
|
||||
/// `librustdesk::platform::get_install_info` computes the expected install
|
||||
/// dir as `%ProgramFiles%\<APP_NAME>` and the expected exe filename as
|
||||
/// `<APP_NAME>.exe`. Keeping `APP_NAME` aligned with the lowercase-hyphenated
|
||||
/// install path (`%ProgramFiles%\hello-agent\hello-agent.exe`) is what
|
||||
/// makes `--update` (which delegates to `librustdesk::platform::update_me`)
|
||||
/// find the binary it needs to replace, kill the right process by image
|
||||
/// name, and rename the staged exe to `hello-agent.exe` after the copy.
|
||||
/// Renaming this constant without renaming the install dir / exe will
|
||||
/// silently break self-update.
|
||||
pub const APP_NAME: &str = "hello-agent";
|
||||
|
||||
/// Set up logging. We delegate to `hbb_common::init_log`, which:
|
||||
/// * In **debug** builds: installs `env_logger` writing to stderr.
|
||||
/// * In **release** builds: installs `flexi_logger` writing to a rolling
|
||||
/// file under `<config_dir>/log/<mode>/` — the SYSTEM service log ends
|
||||
/// up at `%SystemRoot%\ServiceProfiles\LocalService\AppData\Roaming\HelloAgent\log\<mode>\`
|
||||
/// and the user-mode log at `%APPDATA%\HelloAgent\log\<mode>\`.
|
||||
/// up at `%SystemRoot%\ServiceProfiles\LocalService\AppData\Roaming\hello-agent\log\<mode>\`
|
||||
/// and the user-mode log at `%APPDATA%\hello-agent\log\<mode>\`.
|
||||
///
|
||||
/// The `mode` label segregates per-run-mode log files so service worker
|
||||
/// chatter doesn't tangle with --install diagnostics. `init_log` is
|
||||
@@ -65,7 +76,7 @@ fn main() {
|
||||
// we'd never recover.
|
||||
*hbb_common::config::APP_NAME.write().unwrap() = APP_NAME.to_owned();
|
||||
// Identify ourselves to the rustdesk-server's /api/sysinfo endpoint
|
||||
// so the admin Devices page can show "HelloAgent 0.1.0" instead of
|
||||
// so the admin Devices page can show "hello-agent 0.1.0" instead of
|
||||
// the embedded rustdesk core version. These RwLocks are read once
|
||||
// per sysinfo upload by hbbs_http::sync; setting them here (before
|
||||
// start_server) ensures the very first upload carries the identity.
|
||||
@@ -90,10 +101,40 @@ fn main() {
|
||||
Action::Service => "service",
|
||||
Action::Server => "server",
|
||||
Action::Cm => "cm",
|
||||
Action::Update => "update",
|
||||
Action::ConfigOnly | Action::None => "hello-agent",
|
||||
};
|
||||
init_logging(mode);
|
||||
|
||||
// --update is the self-replacement re-entry: the running service's
|
||||
// updater downloads a new hello-agent.exe to %TEMP%, verifies its
|
||||
// SHA256, then launches `<temp>\hello-agent.exe --update` as an
|
||||
// elevated child. We are that child — `current_exe()` is the staged
|
||||
// new binary, and our only job is to copy ourselves over the
|
||||
// installed location and restart the service. Do it before the
|
||||
// config-import dance below so a corrupt-on-disk config can't block
|
||||
// an update from going through.
|
||||
if parsed.action == Action::Update {
|
||||
#[cfg(target_os = "windows")]
|
||||
{
|
||||
match librustdesk::platform::update_me(false) {
|
||||
Ok(()) => {
|
||||
log::info!("hello-agent: --update completed");
|
||||
}
|
||||
Err(e) => {
|
||||
log::error!("hello-agent: --update failed: {e:#}");
|
||||
std::process::exit(1);
|
||||
}
|
||||
}
|
||||
}
|
||||
#[cfg(not(target_os = "windows"))]
|
||||
{
|
||||
eprintln!("hello-agent: --update is Windows-only.");
|
||||
std::process::exit(1);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
// --config is allowed to combine with --install (one-line MDM deploy)
|
||||
// but on its own is a separate operation. Apply it first so --install
|
||||
// sees the populated config.
|
||||
@@ -108,7 +149,14 @@ fn main() {
|
||||
// (or a prior install) already set custom-rendezvous-server, this is a
|
||||
// no-op. Without this, a bare `hello-agent.exe --install` would land
|
||||
// at an unconfigured agent that can't reach any server.
|
||||
config_import::apply_defaults_if_empty();
|
||||
//
|
||||
// Skipped for `--uninstall`: an uninstall flow has no business mutating
|
||||
// the calling user's config, and otherwise we'd write defaults into
|
||||
// %APPDATA% right before tearing the agent down. (`--update` is
|
||||
// dispatched in the early-return block above and never reaches here.)
|
||||
if parsed.action != Action::Uninstall {
|
||||
config_import::apply_defaults_if_empty();
|
||||
}
|
||||
|
||||
match parsed.action {
|
||||
Action::Install => {
|
||||
@@ -172,6 +220,11 @@ fn main() {
|
||||
// can watch logs. Production deployments use --install + --service.
|
||||
run_server();
|
||||
}
|
||||
Action::Update => {
|
||||
// Handled in the early-return block above (before config-import).
|
||||
// The match has to cover this variant for exhaustiveness.
|
||||
unreachable!("Action::Update is dispatched before this match");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user