Initial Dosh implementation
ci / test (push) Has been cancelled
ci / remote-bench (push) Has been cancelled

This commit is contained in:
Codex
2026-06-11 08:42:28 -04:00
commit 555d738a85
25 changed files with 6039 additions and 0 deletions
Executable
+216
View File
@@ -0,0 +1,216 @@
#!/usr/bin/env sh
set -eu
role="${DOSH_ROLE:-both}"
repo="${DOSH_REPO:-}"
server="${DOSH_SERVER:-}"
dosh_host="${DOSH_HOST:-${DOSH_DOSH_HOST:-}}"
port="${DOSH_PORT:-50000}"
prefix="${PREFIX:-$HOME/.local}"
from_current=0
start_server=1
force_config=0
usage() {
cat <<'EOF'
Usage:
install.sh [server|client|both] [options]
Options:
--repo URL Git repository to clone when not run from a checkout
--server HOST Default SSH target for client config, for example user@host
--dosh-host HOST UDP host for Dosh packets when different from SSH target
--port PORT Dosh UDP port; default 50000
--prefix DIR Install prefix; default ~/.local
--no-start Install server but do not start it
--force-config Rewrite existing ~/.config/dosh/*.toml files
Environment alternatives:
DOSH_REPO, DOSH_ROLE, DOSH_SERVER, DOSH_HOST, DOSH_PORT, PREFIX
EOF
}
while [ "$#" -gt 0 ]; do
case "$1" in
server|client|both)
role="$1"
;;
--repo)
repo="$2"
shift
;;
--server)
server="$2"
shift
;;
--dosh-host)
dosh_host="$2"
shift
;;
--port)
port="$2"
shift
;;
--prefix)
prefix="$2"
shift
;;
--from-current)
from_current=1
;;
--no-start)
start_server=0
;;
--force-config)
force_config=1
;;
-h|--help)
usage
exit 0
;;
*)
echo "unknown argument: $1" >&2
usage >&2
exit 2
;;
esac
shift
done
case "$role" in
server|client|both) ;;
*)
echo "role must be server, client, or both" >&2
exit 2
;;
esac
need() {
if ! command -v "$1" >/dev/null 2>&1; then
echo "missing required command: $1" >&2
exit 1
fi
}
need cargo
cleanup() {
if [ -n "${tmpdir:-}" ]; then
rm -rf "$tmpdir"
fi
}
trap cleanup EXIT INT TERM
if [ "$from_current" -eq 1 ] || [ -f Cargo.toml ]; then
src_dir="$(pwd)"
else
if [ -z "$repo" ]; then
echo "DOSH_REPO or --repo is required when running the installer from curl" >&2
exit 2
fi
need git
tmpdir="$(mktemp -d)"
git clone --depth 1 "$repo" "$tmpdir/dosh" >/dev/null
src_dir="$tmpdir/dosh"
fi
cd "$src_dir"
if [ "$role" = "client" ]; then
cargo build --release --bin dosh-client --bin dosh-bench
else
cargo build --release
fi
bindir="$prefix/bin"
config_dir="$HOME/.config/dosh"
data_dir="$HOME/.local/share/dosh"
systemd_user_dir="$HOME/.config/systemd/user"
mkdir -p "$bindir" "$config_dir" "$data_dir"
install -m 0755 target/release/dosh-client "$bindir/dosh-client"
ln -sf dosh-client "$bindir/dosh"
if [ "$role" = "server" ] || [ "$role" = "both" ]; then
install -m 0755 target/release/dosh-server "$bindir/dosh-server"
install -m 0755 target/release/dosh-auth "$bindir/dosh-auth"
fi
if [ -f target/release/dosh-bench ]; then
install -m 0755 target/release/dosh-bench "$bindir/dosh-bench"
fi
if [ "$role" = "server" ] || [ "$role" = "both" ]; then
server_config="$config_dir/server.toml"
if [ "$force_config" -eq 1 ] || [ ! -f "$server_config" ]; then
cat >"$server_config" <<EOF
port = $port
bind = "0.0.0.0"
scrollback = 5000
auth_ttl_secs = 30
attach_ticket_ttl_secs = 3600
allow_attach_tickets = true
client_timeout_secs = 30
retransmit_window = 256
default_input_mode = "read-write"
prewarm_sessions = ["default"]
create_on_attach = true
shell = "/bin/sh"
sessions_dir = "~/.local/share/dosh/sessions"
secret_path = "~/.config/dosh/secret"
EOF
fi
if command -v systemctl >/dev/null 2>&1; then
mkdir -p "$systemd_user_dir"
sed "s#ExecStart=%h/.local/bin/dosh-server serve#ExecStart=$bindir/dosh-server serve#" \
packaging/systemd/dosh-server.service >"$systemd_user_dir/dosh-server.service"
if [ "$start_server" -eq 1 ] && systemctl --user daemon-reload >/dev/null 2>&1; then
systemctl --user enable --now dosh-server.service
fi
elif [ "$start_server" -eq 1 ]; then
nohup "$bindir/dosh-server" serve >"$data_dir/dosh-server.log" 2>&1 &
fi
fi
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}"
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" <<EOF
server = "$default_server"
$dosh_host_line
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"
EOF
fi
fi
cat <<EOF
Installed Dosh to $bindir
Configured UDP port $port
EOF
if [ "$role" = "client" ] || [ "$role" = "both" ]; then
cat <<EOF
Client command:
$bindir/dosh ${server:-user@host}
EOF
fi
if [ "$role" = "server" ] || [ "$role" = "both" ]; then
cat <<EOF
Server command:
$bindir/dosh-server serve
EOF
fi