Initial Dosh implementation
This commit is contained in:
+83
@@ -0,0 +1,83 @@
|
||||
param(
|
||||
[ValidateSet("client")]
|
||||
[string]$Role = $(if ($env:DOSH_ROLE) { $env:DOSH_ROLE } else { "client" }),
|
||||
[string]$Repo = $env:DOSH_REPO,
|
||||
[string]$Server = $env:DOSH_SERVER,
|
||||
[string]$DoshHost = $(if ($env:DOSH_HOST) { $env:DOSH_HOST } else { $env:DOSH_DOSH_HOST }),
|
||||
[int]$Port = $(if ($env:DOSH_PORT) { [int]$env:DOSH_PORT } else { 50000 }),
|
||||
[string]$Prefix = $(if ($env:PREFIX) { $env:PREFIX } else { Join-Path $HOME ".local" }),
|
||||
[switch]$ForceConfig
|
||||
)
|
||||
|
||||
$ErrorActionPreference = "Stop"
|
||||
|
||||
function Require-Command($Name) {
|
||||
if (-not (Get-Command $Name -ErrorAction SilentlyContinue)) {
|
||||
throw "missing required command: $Name"
|
||||
}
|
||||
}
|
||||
|
||||
Require-Command cargo
|
||||
|
||||
$tmp = $null
|
||||
if (Test-Path "Cargo.toml") {
|
||||
$src = (Get-Location).Path
|
||||
} else {
|
||||
if (-not $Repo) {
|
||||
throw "DOSH_REPO is required when running the installer from irm/iex"
|
||||
}
|
||||
Require-Command git
|
||||
$tmp = Join-Path ([System.IO.Path]::GetTempPath()) ("dosh-" + [guid]::NewGuid())
|
||||
git clone --depth 1 $Repo $tmp | Out-Null
|
||||
$src = $tmp
|
||||
}
|
||||
|
||||
try {
|
||||
Push-Location $src
|
||||
cargo build --release --bin dosh-client --bin dosh-bench
|
||||
|
||||
$bindir = Join-Path $Prefix "bin"
|
||||
$configDir = Join-Path $HOME ".config\dosh"
|
||||
New-Item -ItemType Directory -Force -Path $bindir, $configDir | Out-Null
|
||||
|
||||
Copy-Item "target\release\dosh-client.exe" (Join-Path $bindir "dosh-client.exe") -Force
|
||||
Copy-Item "target\release\dosh-client.exe" (Join-Path $bindir "dosh.exe") -Force
|
||||
Copy-Item "target\release\dosh-bench.exe" (Join-Path $bindir "dosh-bench.exe") -Force
|
||||
|
||||
$clientConfig = Join-Path $configDir "client.toml"
|
||||
if ($ForceConfig -or -not (Test-Path $clientConfig)) {
|
||||
$defaultServer = if ($Server) { $Server } else { "user@example.com" }
|
||||
$doshHostLine = if ($DoshHost) { "dosh_host = `"$DoshHost`"" } else { "# dosh_host = `"public.example.com`"" }
|
||||
@"
|
||||
server = "$defaultServer"
|
||||
$doshHostLine
|
||||
ssh_port = 22
|
||||
dosh_port = $Port
|
||||
default_session = "default"
|
||||
reconnect_timeout_secs = 5
|
||||
view_only = false
|
||||
cache_attach_tickets = true
|
||||
credential_cache = "~/.local/share/dosh/credentials"
|
||||
"@ | Set-Content -NoNewline -Encoding utf8 $clientConfig
|
||||
}
|
||||
|
||||
$userPath = [Environment]::GetEnvironmentVariable("Path", "User")
|
||||
if (-not (($userPath -split ';') -contains $bindir)) {
|
||||
[Environment]::SetEnvironmentVariable("Path", "$userPath;$bindir", "User")
|
||||
}
|
||||
|
||||
Write-Host "Installed Dosh client to $bindir"
|
||||
Write-Host "Configured UDP port $Port"
|
||||
Write-Host ""
|
||||
$displayServer = if ($Server) { $Server } else { "user@host" }
|
||||
Write-Host "Client command:"
|
||||
Write-Host " $bindir\dosh.exe $displayServer"
|
||||
Write-Host ""
|
||||
Write-Host "Open a new terminal for PATH changes to apply."
|
||||
}
|
||||
finally {
|
||||
Pop-Location
|
||||
if ($tmp) {
|
||||
Remove-Item -Recurse -Force $tmp
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user