Add dosh update command
This commit is contained in:
@@ -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
|
| 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:
|
Install the client on Windows PowerShell:
|
||||||
|
|
||||||
```powershell
|
```powershell
|
||||||
|
|||||||
@@ -451,6 +451,8 @@ Client config: `~/.config/dosh/client.toml`
|
|||||||
|
|
||||||
```toml
|
```toml
|
||||||
server = "user@example.com"
|
server = "user@example.com"
|
||||||
|
update_repo = "https://git.palav.dev/Palav/dosh.git"
|
||||||
|
update_port = 50000
|
||||||
ssh_auth_command = "~/.local/bin/dosh-auth"
|
ssh_auth_command = "~/.local/bin/dosh-auth"
|
||||||
# ssh_port = 22
|
# ssh_port = 22
|
||||||
dosh_port = 50000
|
dosh_port = 50000
|
||||||
|
|||||||
@@ -47,8 +47,11 @@ try {
|
|||||||
$clientConfig = Join-Path $configDir "client.toml"
|
$clientConfig = Join-Path $configDir "client.toml"
|
||||||
if ($ForceConfig -or -not (Test-Path $clientConfig)) {
|
if ($ForceConfig -or -not (Test-Path $clientConfig)) {
|
||||||
$defaultServer = if ($Server) { $Server } else { "user@example.com" }
|
$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`"" }
|
$doshHostLine = if ($DoshHost) { "dosh_host = `"$DoshHost`"" } else { "# dosh_host = `"public.example.com`"" }
|
||||||
@"
|
@"
|
||||||
|
update_repo = "$updateRepo"
|
||||||
|
update_port = $Port
|
||||||
server = "$defaultServer"
|
server = "$defaultServer"
|
||||||
$doshHostLine
|
$doshHostLine
|
||||||
ssh_auth_command = "~/.local/bin/dosh-auth"
|
ssh_auth_command = "~/.local/bin/dosh-auth"
|
||||||
|
|||||||
@@ -207,12 +207,15 @@ if [ "$role" = "client" ] || [ "$role" = "both" ]; then
|
|||||||
client_config="$config_dir/client.toml"
|
client_config="$config_dir/client.toml"
|
||||||
if [ "$force_config" -eq 1 ] || [ ! -f "$client_config" ]; then
|
if [ "$force_config" -eq 1 ] || [ ! -f "$client_config" ]; then
|
||||||
default_server="${server:-user@example.com}"
|
default_server="${server:-user@example.com}"
|
||||||
|
update_repo="${repo:-https://git.palav.dev/Palav/dosh.git}"
|
||||||
if [ -n "$dosh_host" ]; then
|
if [ -n "$dosh_host" ]; then
|
||||||
dosh_host_line="dosh_host = \"$dosh_host\""
|
dosh_host_line="dosh_host = \"$dosh_host\""
|
||||||
else
|
else
|
||||||
dosh_host_line="# dosh_host = \"public.example.com\""
|
dosh_host_line="# dosh_host = \"public.example.com\""
|
||||||
fi
|
fi
|
||||||
cat >"$client_config" <<EOF
|
cat >"$client_config" <<EOF
|
||||||
|
update_repo = "$update_repo"
|
||||||
|
update_port = $port
|
||||||
server = "$default_server"
|
server = "$default_server"
|
||||||
$dosh_host_line
|
$dosh_host_line
|
||||||
ssh_auth_command = "~/.local/bin/dosh-auth"
|
ssh_auth_command = "~/.local/bin/dosh-auth"
|
||||||
|
|||||||
+44
-1
@@ -17,7 +17,7 @@ use serde::{Deserialize, Serialize};
|
|||||||
use std::fs;
|
use std::fs;
|
||||||
use std::io::{Read, Write};
|
use std::io::{Read, Write};
|
||||||
use std::net::{SocketAddr, ToSocketAddrs};
|
use std::net::{SocketAddr, ToSocketAddrs};
|
||||||
use std::process::Command;
|
use std::process::{Command, Stdio};
|
||||||
use std::time::{Duration, Instant, SystemTime, UNIX_EPOCH};
|
use std::time::{Duration, Instant, SystemTime, UNIX_EPOCH};
|
||||||
use tokio::net::UdpSocket;
|
use tokio::net::UdpSocket;
|
||||||
use tokio::sync::mpsc;
|
use tokio::sync::mpsc;
|
||||||
@@ -76,6 +76,9 @@ struct CachedCredential {
|
|||||||
async fn main() -> Result<()> {
|
async fn main() -> Result<()> {
|
||||||
let args = Args::parse();
|
let args = Args::parse();
|
||||||
let config = load_client_config(None).unwrap_or_default();
|
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 server = args.server.unwrap_or(config.server);
|
||||||
let session = select_session(args.session.as_deref(), args.new, &config.default_session);
|
let session = select_session(args.session.as_deref(), args.new, &config.default_session);
|
||||||
let mode = if args.view_only || config.view_only {
|
let mode = if args.view_only || config.view_only {
|
||||||
@@ -208,6 +211,46 @@ async fn main() -> Result<()> {
|
|||||||
run_terminal(socket, cred, Some(first)).await
|
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(
|
fn local_bootstrap(
|
||||||
session: &str,
|
session: &str,
|
||||||
mode: &str,
|
mode: &str,
|
||||||
|
|||||||
@@ -44,6 +44,8 @@ impl Default for ServerConfig {
|
|||||||
|
|
||||||
#[derive(Debug, Clone, Serialize, Deserialize)]
|
#[derive(Debug, Clone, Serialize, Deserialize)]
|
||||||
pub struct ClientConfig {
|
pub struct ClientConfig {
|
||||||
|
pub update_repo: Option<String>,
|
||||||
|
pub update_port: Option<u16>,
|
||||||
pub server: String,
|
pub server: String,
|
||||||
pub dosh_host: Option<String>,
|
pub dosh_host: Option<String>,
|
||||||
pub ssh_auth_command: Option<String>,
|
pub ssh_auth_command: Option<String>,
|
||||||
@@ -59,6 +61,8 @@ pub struct ClientConfig {
|
|||||||
impl Default for ClientConfig {
|
impl Default for ClientConfig {
|
||||||
fn default() -> Self {
|
fn default() -> Self {
|
||||||
Self {
|
Self {
|
||||||
|
update_repo: None,
|
||||||
|
update_port: None,
|
||||||
server: "user@example.com".to_string(),
|
server: "user@example.com".to_string(),
|
||||||
dosh_host: None,
|
dosh_host: None,
|
||||||
ssh_auth_command: Some("~/.local/bin/dosh-auth".to_string()),
|
ssh_auth_command: Some("~/.local/bin/dosh-auth".to_string()),
|
||||||
|
|||||||
Reference in New Issue
Block a user