Skip to content

feat(install): auto-install + start sshd during install (close "this needs to be in the install" gap) - #157

Merged
joelteply merged 1 commit into
canaryfrom
feat/install-auto-sshd
Apr 27, 2026
Merged

joelteply merged 1 commit into
canaryfrom
feat/install-auto-sshd

Conversation

@joelteply

Copy link
Copy Markdown
Contributor

Why

Joel via continuum-b69f relay 2026-04-27:

"if we can prompt the user, we do NOT have them do annoying setup shit we automate into install, which gets what it needs done, no later interaction and definitely not MORE after first install. and detect via doctor if missing. and tell them how to remedy."

PR #156 covered (a) doctor probe + (b) remedy text. Missing: (c) install actually running the commands.

Changes

`install.sh` — `_ensure_sshd_running` per-platform, idempotent:

  • macOS: `sudo systemsetup -setremotelogin on` if Remote Login off (one sudo prompt)
  • Linux: `install_with_pkgmgr openssh-server` + `systemctl enable --now ssh|sshd`
  • Windows-bash: self-elevate via `powershell.exe Start-Process -Verb RunAs` running all 3 commands inline (one UAC prompt)
  • `AIRC_SKIP_SSHD=1` opt-out for headless CI

`install.ps1` — `Install-OpenSSHServer`:

  • Mirrors bash for native Windows installer
  • Get-Service / Get-WindowsCapability probe
  • Add-WindowsCapability + Start-Service + Set-Service Automatic
  • Catches admin-required, prints manual fallback (same shape as existing Install-OpenSSHClient)
  • Wired in right after Install-OpenSSHClient

Idempotency

Both short-circuit if sshd already Running. Re-runs of install on a working box don't re-prompt.

Mac regression

  • part_persists: 8/8
  • list: 4/4
  • general_sidecar_default: 12/12
  • platform_adapters: 11/11

…ectural gap)

Joel's directive 2026-04-27 (via continuum-b69f relay through coord
gist):

> "if we can prompt the user, we do NOT have them do annoying setup
> shit we automate into install, which gets what it needs done, no
> later interaction and definitely not MORE after first install. and
> detect via doctor if missing. and tell them how to remedy."

Translation:
1. install.{sh,ps1} does end-to-end setup with elevation prompts (ONE
   elevation moment during first install). No separate post-install
   steps for the user to remember.
2. airc doctor is drift detection — catches when something flipped off
   after install. Already done in PR #156.
3. Remedy commands are AI-runnable — doctor's output is a contract
   with the user's AI. Already done in PR #156.

Missing piece (this PR): install.{sh,ps1} should actually RUN the
missing prereq commands during install, not just probe + report.

## Changes

### install.sh — `_ensure_sshd_running`

Per-platform, idempotent (no-op if already running):

- **macOS**: probes Remote Login state (launchctl/systemsetup); if off,
  runs `sudo systemsetup -setremotelogin on` with one sudo prompt.
- **Linux**: probes systemctl (Debian's ssh and RHEL's sshd unit
  names); if missing, installs openssh-server via the platform's
  package manager + enables-and-starts the right unit.
- **Windows-bash**: probes via `powershell.exe Get-Service sshd`;
  if missing or stopped, self-elevates via
  `powershell.exe Start-Process -Verb RunAs` with all three commands
  inline (Add-WindowsCapability + Start-Service + Set-Service
  Automatic) → ONE UAC prompt for the user.

\`AIRC_SKIP_SSHD=1\` short-circuits for headless CI / config-managed
environments.

### install.ps1 — `Install-OpenSSHServer`

Mirrors the bash logic for the native Windows installer. Probes
Get-Service sshd, then Get-WindowsCapability for state. Three commands:
Add-WindowsCapability, Start-Service, Set-Service Automatic. Catches
admin-required errors and prints the manual fallback (same shape as
existing Install-OpenSSHClient).

Hooked into the install flow right after Install-OpenSSHClient.

## Idempotency

Both install.sh and install.ps1 short-circuit if sshd is already
Running. Re-running install.sh on a working box doesn't re-prompt
for sudo or UAC. Same for install.ps1.

## Test posture (Mac regression)

- part_persists: 8/8
- list: 4/4
- general_sidecar_default: 12/12
- platform_adapters: 11/11

## Out of scope

End-to-end Mac↔Windows substrate test once both sides have sshd up
(parallel work; not blocked on this PR).
Copilot AI review requested due to automatic review settings April 27, 2026 19:57
@joelteply
joelteply merged commit db48e7a into canary Apr 27, 2026
1 of 2 checks passed
@joelteply
joelteply deleted the feat/install-auto-sshd branch April 27, 2026 19:57

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Note

Copilot was unable to run its full agentic suite in this review.

Adds installer automation to ensure sshd is installed and running during install, closing the gap where doctor could detect/remediate but install didn’t perform the setup.

Changes:

  • Adds _ensure_sshd_running to install.sh with per-OS enable/install/start logic plus AIRC_SKIP_SSHD=1 opt-out.
  • Adds Install-OpenSSHServer to install.ps1 and wires it into the Windows native installer flow.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 5 comments.

File Description
install.sh Adds cross-platform sshd auto-enable/install/start during prereqs.
install.ps1 Adds Windows OpenSSH Server install/start + autostart configuration.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread install.sh
Comment on lines +160 to +176
local _pkgmgr; _pkgmgr=$(detect_pkgmgr)
case "$_pkgmgr" in
apt|dnf|pacman|apk)
install_with_pkgmgr "$_pkgmgr" "openssh-server" 2>&1 || \
warn "openssh-server install failed (already present? Try: airc doctor)."
# After install, enable + start the right unit.
if systemctl list-unit-files 2>/dev/null | grep -q "^ssh\.service"; then
sudo systemctl enable --now ssh 2>&1 \
&& ok "ssh.service enabled + running" \
|| warn "Failed to start ssh.service. Manual: sudo systemctl enable --now ssh"
elif systemctl list-unit-files 2>/dev/null | grep -q "^sshd\.service"; then
sudo systemctl enable --now sshd 2>&1 \
&& ok "sshd.service enabled + running" \
|| warn "Failed to start sshd.service. Manual: sudo systemctl enable --now sshd"
else
warn "Neither ssh.service nor sshd.service found. Check distro docs."
fi

Copilot AI Apr 27, 2026

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

apk (Alpine) typically does not use systemd/systemctl, and the package name is commonly openssh (not openssh-server). As written, the apk path will likely install the wrong package and then fail to start/enable via systemctl. Split apk into its own branch that installs the correct package and uses the native init tooling (e.g., OpenRC rc-service / rc-update), or gate the systemd logic on command -v systemctl and provide an Alpine-specific fallback.

Copilot uses AI. Check for mistakes.
Comment thread install.sh
case "$(uname -s 2>/dev/null)" in
Darwin)
# macOS: sshd is launchd-managed; "Remote Login" toggle drives it.
if launchctl list 2>/dev/null | grep -q "com\.openssh\.sshd" \

Copilot AI Apr 27, 2026

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

On macOS, launchctl list run as a regular user generally does not list system daemons in the system/ domain, so the com.openssh.sshd check is unreliable and may cause unnecessary sudo prompts even when Remote Login is already enabled. Prefer a user-accessible probe (e.g., checking for a listening sshd process/port) or restructure to use a non-interactive sudo probe (sudo -n) to read Remote Login status without prompting when already enabled.

Suggested change
if launchctl list 2>/dev/null | grep -q "com\.openssh\.sshd" \
# Do not use `launchctl list` here: as a regular user it generally
# cannot see system daemons in the `system/` domain, so it can wrongly
# miss an already-enabled sshd and trigger an unnecessary sudo prompt.
if sudo -n systemsetup -getremotelogin 2>/dev/null | grep -qi "Remote Login: On" \

Copilot uses AI. Check for mistakes.
Comment thread install.sh
Comment on lines +199 to +201
powershell.exe -NoProfile -Command "Start-Process powershell -Verb RunAs -ArgumentList '-NoProfile -Command Start-Service sshd; Set-Service sshd -StartupType Automatic'" 2>&1 \
&& ok "sshd started + auto-start configured." \
|| warn "Self-elevation failed. Run in admin PowerShell: Start-Service sshd; Set-Service sshd -StartupType Automatic"

Copilot AI Apr 27, 2026

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Start-Process powershell relies on powershell being resolvable in the elevated context; using powershell.exe explicitly is more robust (avoids PATH/alias differences and PowerShell 7 vs Windows PowerShell ambiguity). Update the Start-Process target to powershell.exe for both elevation calls.

Copilot uses AI. Check for mistakes.
Comment thread install.sh
info "Installing OpenSSH.Server (UAC prompt incoming) — needed for hosting airc rooms."
# Self-elevate, install capability, start service, set automatic.
# All in one elevated process so the user clicks UAC once.
powershell.exe -NoProfile -Command "Start-Process powershell -Verb RunAs -ArgumentList '-NoProfile -Command Add-WindowsCapability -Online -Name OpenSSH.Server~~~~0.0.1.0; Start-Service sshd; Set-Service -Name sshd -StartupType Automatic'" 2>&1 \

Copilot AI Apr 27, 2026

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Start-Process powershell relies on powershell being resolvable in the elevated context; using powershell.exe explicitly is more robust (avoids PATH/alias differences and PowerShell 7 vs Windows PowerShell ambiguity). Update the Start-Process target to powershell.exe for both elevation calls.

Copilot uses AI. Check for mistakes.
Comment thread install.ps1
Comment on lines +167 to +170
$cap = Get-WindowsCapability -Online -Name 'OpenSSH.Server*' -ErrorAction Stop
if ($cap.State -ne 'Installed') {
Add-WindowsCapability -Online -Name $cap.Name -ErrorAction Stop | Out-Null
Write-Host ' OpenSSH.Server capability installed.'

Copilot AI Apr 27, 2026

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Get-WindowsCapability -Name 'OpenSSH.Server*' can return multiple results; in that case $cap.State / $cap.Name become array-like and Add-WindowsCapability -Name $cap.Name may fail or behave unpredictably. Select a single capability explicitly (e.g., exact name match for OpenSSH.Server~~~~0.0.1.0, or filter then take one) before checking .State and passing .Name into Add-WindowsCapability.

Copilot uses AI. Check for mistakes.
joelteply added a commit that referenced this pull request Apr 27, 2026
…g (PR #156/#157 live-test followups) (#158)

fix(sshd-probe): macOS detection without sudo + osascript admin dialog when non-interactive

Two issues found while running PR #157 live on Mac 2026-04-27:

## Bug 1: launchctl list (user scope) doesn't show system services

Pre-fix probe:
```bash
launchctl list 2>/dev/null | grep -q "com\.openssh\.sshd"
```
Bare `launchctl list` is user-scope. Returns user-launched LaunchAgents
only — never system-level launchd jobs like com.openssh.sshd. The
fallback `systemsetup -getremotelogin` requires sudo to read state.

Net: doctor reported `[MISSING] sshd` even when Remote Login was
fully enabled and active sshd-session processes were forking.

Fix: `launchctl print system` (no sudo needed) lists system services
including com.openssh.sshd when Remote Login is on. Anchor regex on
service-id boundary so we don't false-positive on per-connection
session subkeys (com.openssh.sshd.<UUID>) which exist transiently
even when Remote Login is just toggling.

## Bug 2: install.sh sudo path fails in non-interactive contexts

When install.sh runs from a Monitor-spawned shell or curl|bash pipe,
no TTY is attached. `sudo` then says "a terminal is required to read
the password; either use the -S option to read from standard input or
configure an askpass helper." Same problem as Joel hit running this
from his Claude Code Bash tool.

Fix: detect TTY presence (\`[ -t 0 ] && [ -t 1 ]\`); if interactive,
use sudo. If not, fall through to osascript with the native macOS
admin GUI dialog (with a branded prompt explaining what airc is
doing — Joel 2026-04-27 relay through continuum-b69f).

## Live verification

Pre-fix doctor on this Mac (Remote Login enabled live via osascript):
```
[MISSING] sshd -- needed when you HOST a room
```

Post-fix:
```
[ok] sshd (Remote Login enabled)
```

## Same probe in install.sh

The Darwin branch of \`_ensure_sshd_running\` now:
- detects via launchctl print system (matching doctor)
- splits sudo (TTY) vs osascript (non-interactive) for the elevation
- both paths print airc-branded explanation in the admin prompt
joelteply added a commit that referenced this pull request Apr 27, 2026
…gnosis — sshd bind EPERM) (#160)

fix(install,doctor): Windows HNS port-22 reservation + firewall rule (continuum-b69f diagnosis)

Bug found by continuum-b69f mid-Windows-bringup 2026-04-27:
\`Start-Service sshd\` failed with "Cannot bind any address" / permission
denied even with admin. Root cause: Windows HNS (Host Network Service —
backs Hyper-V, WSL2, Docker Desktop) dynamically reserves port ranges
at boot. The reservations rotate per-boot and are NOT visible in
\`netsh int ipv4 show excludedportrange\` (which only shows static admin
reservations). When port 22 randomly falls inside an HNS-held range,
sshd's bind() returns EPERM at OS level, regardless of admin status.

Sources:
- https://keasigmadelta.com/blog/how-to-solve-cannot-bind-to-port-due-to-permission-denied-on-windows/
- https://github.com/docker/for-win/issues/3171
- https://gist.github.com/strayge/481a77d31a94e133a76662877b1a90ca

## Persistent fix (this PR)

Two-step persistent workaround applied during admin-elevated sshd
install. Both ops idempotent — re-run of install on a healthy box
doesn't re-prompt or duplicate state.

1. \`reg add HKLM\\SYSTEM\\CurrentControlSet\\Services\\hns\\State
    /v EnableExcludedPortRange /d 0 /f\`
   Disables HNS auto-exclusion. Survives reboots.
2. \`netsh int ipv4 add excludedportrange protocol=tcp startport=22
    numberofports=1\`
   Explicitly reserves port 22 in the static excluded-port-range so
   HNS can't grab it on subsequent boots.

Plus a New-NetFirewallRule for the OpenSSH-Server-In-TCP rule (the
capability install usually creates it but it can be missing/disabled
on some systems — idempotent check before creating).

## Files changed

- \`install.ps1\` — \`Set-HnsPortFreedomFor22\` helper + wired into
  \`Install-OpenSSHServer\`. Native Windows installer path.
- \`install.sh\` — Windows-bash branch's \`_ensure_sshd_running\` now
  emits a single elevated PowerShell payload that runs ALL the steps
  (capability install + HNS workaround + firewall rule + start +
  persist) so Joel/users click UAC ONCE for the whole sshd setup.
- \`airc doctor\` — \`[MISSING] sshd\` Windows hint now includes the
  reg+netsh lines and explains why (HNS quirk). User can run all five
  commands as a contiguous block to remediate manually.

## Why this matters

Pre-fix, even after the user ran the Add-WindowsCapability + Start-
Service incantation from PR #156's hint or PR #157's auto-install,
they could STILL hit the bind-EPERM if HNS happened to claim port 22
on their boot. Random failure, no diagnostic, looks like a permission
bug. Continuum-b69f's diagnosis turns this from an unsolvable random
into a one-time install action.

## Test posture (Mac regression)

Mac side unchanged behavior; HNS branch only fires on MINGW/MSYS/CYGWIN.

- part_persists: 8/8
- list: 4/4
- general_sidecar_default: 12/12
- platform_adapters: 11/11

## Out of scope

Cross-machine substrate end-to-end test once continuum's Windows host
binds port 22 successfully. Parallel work; not blocked on this PR.
joelteply added a commit that referenced this pull request Apr 27, 2026
…nd-to-end (#177)

fix(msys): export MSYS2_ARG_CONV_EXCL at airc startup — last layer of cross-machine fix (continuum's catch + verify)

continuum-b69f's diagnosis 2026-04-27: even with PR #174 + #176's
argparse `--flags`, MSYS Git Bash on Windows translates argv VALUES
that look like Unix-rooted paths when bash invokes a Windows-native
binary. So `--host-airc-home /Users/joelteply/.airc` arrived at
python.exe as `--host-airc-home C:/Program Files/Git/Users/joelteply/.airc`,
the joiner cached the corrupted path, the SSH command later sent
it to a real Unix host that had no such file. Silent broadcast
failure.

## Fix

```bash
export MSYS2_ARG_CONV_EXCL="${MSYS2_ARG_CONV_EXCL:-/Users/;/home/;/root/}"
```

Set once at airc startup, exported, every airc_core invocation
inherits the same translation policy. Targeted prefix list covers
macOS / Linux / root home prefixes without breaking `/tmp/` or `/c/`
paths (which DO need translation for `--config "$CONFIG"` where
$CONFIG is on the local Windows filesystem). Honors a user override
via the `${...:-...}` default-fallback.

## End-to-end verification

continuum-b69f shipped a test broadcast from Windows after their
local patch:

> WORKING TEST: Windows-Mac airc msg via continuum-msyspatch with
> targeted MSYS exclude. should land!

Verified live in MY host's messages.jsonl on Mac:

```
{"from":"continuum-msyspatch","to":"all","ts":"2026-04-27T23:30:13Z",
 "msg":"WORKING TEST: Windows-Mac airc msg via continuum-msyspatch
 with targeted MSYS exclude. should land!","sig":"..."}
```

**Cross-machine Mac↔Windows airc end-to-end working.** This was the
last bug in the chain that started at PR #153 (Microsoft Store
python3 stub).

## Test posture (Mac, where the env var is a no-op)

- tabs 19/19, identity 19/19, whois 5/5, part_persists 8/8,
  list 4/4, general_sidecar_default 12/12, kick 12/12, events 5/5,
  platform_adapters 11/11, whois_cross_scope 6/6

## Today's full chain of cross-machine fixes

#153 → #154 → #155 → #156 → #157 → #158 → #159 → #160 → #162 →
#164 → #165 → #166 → ... → #176 → this. 27+ PRs to ship a working
cross-machine airc on Windows. Every step revealed a new layer.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants