From 3ad8f958330e97fa5c625d25855139c078edb861 Mon Sep 17 00:00:00 2001 From: Codex Date: Thu, 11 Jun 2026 09:49:53 -0400 Subject: [PATCH] Add dosh update command --- README.md | 6 ++++++ SPEC.md | 2 ++ install.ps1 | 3 +++ install.sh | 3 +++ src/bin/dosh-client.rs | 45 +++++++++++++++++++++++++++++++++++++++++- src/config.rs | 4 ++++ 6 files changed, 62 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 33f2acf..9b1058d 100644 --- a/README.md +++ b/README.md @@ -106,6 +106,12 @@ curl -fsSL https://git.palav.dev/Palav/dosh/raw/branch/main/install.sh \ | DOSH_REPO=https://git.palav.dev/Palav/dosh.git DOSH_SERVER=palav DOSH_HOST=git.palav.dev DOSH_PORT=50000 sh -s -- client ``` +Update an installed client later: + +```bash +dosh update +``` + Install the client on Windows PowerShell: ```powershell diff --git a/SPEC.md b/SPEC.md index 357710c..1390a1b 100644 --- a/SPEC.md +++ b/SPEC.md @@ -451,6 +451,8 @@ Client config: `~/.config/dosh/client.toml` ```toml server = "user@example.com" +update_repo = "https://git.palav.dev/Palav/dosh.git" +update_port = 50000 ssh_auth_command = "~/.local/bin/dosh-auth" # ssh_port = 22 dosh_port = 50000 diff --git a/install.ps1 b/install.ps1 index a7ab3e8..adc1006 100644 --- a/install.ps1 +++ b/install.ps1 @@ -47,8 +47,11 @@ try { $clientConfig = Join-Path $configDir "client.toml" if ($ForceConfig -or -not (Test-Path $clientConfig)) { $defaultServer = if ($Server) { $Server } else { "user@example.com" } + $updateRepo = if ($Repo) { $Repo } else { "https://git.palav.dev/Palav/dosh.git" } $doshHostLine = if ($DoshHost) { "dosh_host = `"$DoshHost`"" } else { "# dosh_host = `"public.example.com`"" } @" +update_repo = "$updateRepo" +update_port = $Port server = "$defaultServer" $doshHostLine ssh_auth_command = "~/.local/bin/dosh-auth" diff --git a/install.sh b/install.sh index 208f3e6..f89e128 100755 --- a/install.sh +++ b/install.sh @@ -207,12 +207,15 @@ if [ "$role" = "client" ] || [ "$role" = "both" ]; then client_config="$config_dir/client.toml" if [ "$force_config" -eq 1 ] || [ ! -f "$client_config" ]; then default_server="${server:-user@example.com}" + update_repo="${repo:-https://git.palav.dev/Palav/dosh.git}" if [ -n "$dosh_host" ]; then dosh_host_line="dosh_host = \"$dosh_host\"" else dosh_host_line="# dosh_host = \"public.example.com\"" fi cat >"$client_config" < 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, diff --git a/src/config.rs b/src/config.rs index 97c6aff..1382559 100644 --- a/src/config.rs +++ b/src/config.rs @@ -44,6 +44,8 @@ impl Default for ServerConfig { #[derive(Debug, Clone, Serialize, Deserialize)] pub struct ClientConfig { + pub update_repo: Option, + pub update_port: Option, pub server: String, pub dosh_host: Option, pub ssh_auth_command: Option, @@ -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()),