Add dosh update command
ci / test (push) Has been cancelled
ci / remote-bench (push) Has been cancelled

This commit is contained in:
Codex
2026-06-11 09:49:53 -04:00
parent da60b71984
commit 3ad8f95833
6 changed files with 62 additions and 1 deletions
+44 -1
View File
@@ -17,7 +17,7 @@ use serde::{Deserialize, Serialize};
use std::fs;
use std::io::{Read, Write};
use std::net::{SocketAddr, ToSocketAddrs};
use std::process::Command;
use std::process::{Command, Stdio};
use std::time::{Duration, Instant, SystemTime, UNIX_EPOCH};
use tokio::net::UdpSocket;
use tokio::sync::mpsc;
@@ -76,6 +76,9 @@ struct CachedCredential {
async fn main() -> Result<()> {
let args = Args::parse();
let config = load_client_config(None).unwrap_or_default();
if args.server.as_deref() == Some("update") {
return run_update(&config);
}
let server = args.server.unwrap_or(config.server);
let session = select_session(args.session.as_deref(), args.new, &config.default_session);
let mode = if args.view_only || config.view_only {
@@ -208,6 +211,46 @@ async fn main() -> Result<()> {
run_terminal(socket, cred, Some(first)).await
}
fn run_update(config: &dosh::config::ClientConfig) -> Result<()> {
let repo = config
.update_repo
.clone()
.unwrap_or_else(|| "https://git.palav.dev/Palav/dosh.git".to_string());
let raw_base = raw_base_from_repo(&repo);
let installer = format!("{raw_base}/raw/branch/main/install.sh");
let mut script = format!(
"curl -fsSL {} | DOSH_REPO={} DOSH_PORT={} sh -s -- client",
shell_word(&installer),
shell_word(&repo),
config.update_port.unwrap_or(config.dosh_port)
);
if config.server != "user@example.com" {
script.push_str(&format!(" --server {}", shell_word(&config.server)));
}
if let Some(host) = &config.dosh_host {
script.push_str(&format!(" --dosh-host {}", shell_word(host)));
}
script.push_str(" --force-config");
let status = Command::new("sh")
.arg("-lc")
.arg(script)
.stdin(Stdio::null())
.status()
.context("run dosh update installer")?;
if !status.success() {
return Err(anyhow!("dosh update failed with status {status}"));
}
Ok(())
}
fn raw_base_from_repo(repo: &str) -> String {
repo.trim_end_matches(".git").to_string()
}
fn shell_word(value: &str) -> String {
format!("'{}'", value.replace('\'', "'\\''"))
}
fn local_bootstrap(
session: &str,
mode: &str,
+4
View File
@@ -44,6 +44,8 @@ impl Default for ServerConfig {
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct ClientConfig {
pub update_repo: Option<String>,
pub update_port: Option<u16>,
pub server: String,
pub dosh_host: Option<String>,
pub ssh_auth_command: Option<String>,
@@ -59,6 +61,8 @@ pub struct ClientConfig {
impl Default for ClientConfig {
fn default() -> Self {
Self {
update_repo: None,
update_port: None,
server: "user@example.com".to_string(),
dosh_host: None,
ssh_auth_command: Some("~/.local/bin/dosh-auth".to_string()),