Add dosh update command
This commit is contained in:
+44
-1
@@ -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,
|
||||
|
||||
Reference in New Issue
Block a user