openssh: Add helper scripts to fix service binPath and autostart#7666
openssh: Add helper scripts to fix service binPath and autostart#7666SwingURM wants to merge 2 commits intoScoopInstaller:masterfrom
Conversation
|
All changes look good. Wait for review from human collaborators. openssh
|
|
@coderabbitai review |
✅ Actions performedReview triggered.
|
📝 WalkthroughWalkthroughAdded post-install PowerShell commands to the OpenSSH manifest that resolve the real installation path (follow symlinks), create a fix script to rewrite service binPath to absolute targets, and create an autostart script to set sshd and ssh-agent to Automatic startup. Changes
Sequence Diagram(s)sequenceDiagram
participant Scoop as Installer (Scoop)
participant Post as post_install script
participant FS as Filesystem / Symlink
participant FixPS as fix.ps1
participant SCM as Service Control Manager / Registry
participant AutostartPS as autostart-sshd.ps1
Scoop->>Post: run post_install commands
Post->>FS: resolve real directory for `current` symlink
Post->>FixPS: create fix.ps1 with resolved absolute paths
FixPS->>SCM: update `sshd` and `ssh-agent` service `binPath` to absolute targets
Post->>AutostartPS: create autostart-sshd.ps1
AutostartPS->>SCM: set `sshd` and `ssh-agent` StartupType = Automatic
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Tip Issue Planner is now in beta. Read the docs and try it out! Share your feedback on Discord. Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🧹 Nitpick comments (1)
bucket/openssh.json (1)
47-47: Note the re-run requirement afterscoop updatein the notes.
fix.ps1embeds the resolved absolute versioned path at install time (e.g.,...\openssh\10.0.0.0p2\sshd.exe). Scoop runspost_installon updates as well, expanding$dirto thecurrentjunction path, so each update regeneratesfix.ps1with the new version's path — but the service registry entry is not automatically updated. Users must re-runsudo fix.ps1after everyscoop update opensshfor the service to point to the new binary.Consider expanding the note to reflect this:
📝 Proposed note update
- "Run 'sudo $dir\\fix.ps1' to fix service binPath to absolute path.", + "Run 'sudo $dir\\fix.ps1' to fix service binPath to absolute path. Re-run after every 'scoop update openssh'.",Also applies to: 54-54
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@bucket/openssh.json` at line 47, The post_install script writes fix.ps1 embedding the resolved versioned path (via Set-Content writing to "$dir\\fix.ps1"), but Scoop re-runs post_install on updates using the current junction path and does not update existing Windows service registry entries, so users must re-run sudo fix.ps1 after every scoop update openssh to repoint services to the new binary; update the notes referenced (and the duplicate at the second occurrence) to explicitly state that after running scoop update openssh the user must re-run sudo fix.ps1 (or re-create the sshd/ssh-agent service entries) to update the service binPath to the new version.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@bucket/openssh.json`:
- Line 45: The post_install line using [IO.Directory]::ResolveLinkTarget($dir,
$true).FullName is a .NET 6+ API and will throw on Windows PowerShell 5.1;
replace that call with the PowerShell 5.0+ compatible approach using (Get-Item
$dir -Force).Target and keep the existing fallback logic (i.e., assign the
target to $real and if it's null/empty set $real = $dir) so junction targets are
resolved when present but the script continues when not a link; update the
expression that sets $real to use the (Get-Item ...).Target lookup and preserve
the subsequent if (!$real) { $real = $dir } behavior.
---
Nitpick comments:
In `@bucket/openssh.json`:
- Line 47: The post_install script writes fix.ps1 embedding the resolved
versioned path (via Set-Content writing to "$dir\\fix.ps1"), but Scoop re-runs
post_install on updates using the current junction path and does not update
existing Windows service registry entries, so users must re-run sudo fix.ps1
after every scoop update openssh to repoint services to the new binary; update
the notes referenced (and the duplicate at the second occurrence) to explicitly
state that after running scoop update openssh the user must re-run sudo fix.ps1
(or re-create the sshd/ssh-agent service entries) to update the service binPath
to the new version.
|
@coderabbitai review |
✅ Actions performedReview triggered.
|
There was a problem hiding this comment.
Actionable comments posted: 1
🧹 Nitpick comments (1)
bucket/openssh.json (1)
44-45:(Get-Item $dir -Force).Targetaddresses the previous PS 5.1 compatibility concern.The
.ResolveLinkTargetissue from the prior review is resolved. Two small notes:
.Targetresolves only one level of indirection, unlike the earlierResolveLinkTarget($dir, $true)(recursive). For Scoop's single-layercurrentjunction this is sufficient.Get-Item $dirtreats the path as a glob pattern, so a Scoop root containing[,], or*characters would silently fail to match.-LiteralPathavoids this:🔧 Optional: use
-LiteralPath- "$real = (Get-Item $dir -Force).Target; if (!$real) { $real = $dir }", + "$real = (Get-Item -LiteralPath $dir -Force).Target; if (!$real) { $real = $dir }",🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@bucket/openssh.json` around lines 44 - 45, The current post_install snippet uses (Get-Item $dir -Force).Target which works but treats $dir as a glob; update the Get-Item call to use -LiteralPath to avoid accidental glob expansion (i.e., replace Get-Item $dir -Force with Get-Item -LiteralPath $dir -Force) while keeping the existing $real fallback logic (post_install, $real, and the !$real check) intact; note that .Target is single-level resolution which is acceptable for Scoop's single-layer junction usage.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@bucket/openssh.json`:
- Around line 46-47: The generated fix.ps1 currently uses a $q helper and writes
sc.exe config lines that lose their surrounding double-quotes when PowerShell
evaluates them; remove the "$q = [char]34" helper and change the two sc.exe
strings written by Set-Content (the sc.exe config sshd binPath= ... and sc.exe
config ssh-agent binPath= ... entries) to use a parenthesised single-quoted
expression that includes literal double-quote characters around the real path
(e.g. use ('"'+ <real path> + '"' ) style so the resulting ImagePath in the
registry includes the quote characters and preserves paths with spaces).
---
Nitpick comments:
In `@bucket/openssh.json`:
- Around line 44-45: The current post_install snippet uses (Get-Item $dir
-Force).Target which works but treats $dir as a glob; update the Get-Item call
to use -LiteralPath to avoid accidental glob expansion (i.e., replace Get-Item
$dir -Force with Get-Item -LiteralPath $dir -Force) while keeping the existing
$real fallback logic (post_install, $real, and the !$real check) intact; note
that .Target is single-level resolution which is acceptable for Scoop's
single-layer junction usage.
| "$q = [char]34", | ||
| "Set-Content \"$dir\\fix.ps1\" @(\"sc.exe config sshd binPath= ${q}${real}\\sshd.exe${q}\", \"sc.exe config ssh-agent binPath= ${q}${real}\\ssh-agent.exe${q}\") -Encoding UTF8", |
There was a problem hiding this comment.
Generated fix.ps1 drops the binPath quotes, breaking paths with spaces.
The post-install command writes sc.exe config sshd binPath= "…\sshd.exe" into fix.ps1. When PowerShell 5.1 later executes that line it treats the outer "…" as a string literal, strips the delimiters, and hands sc.exe the bare path. For paths without spaces the stored registry ImagePath is correct; but for a Scoop root that contains spaces (e.g. C:\Users\My User\scoop\…), sc.exe stores an unquoted path and the SCM tokenises at the first space on service start — exactly the failure mode this PR is trying to fix.
The registry ImagePath must contain the path wrapped in double-quote characters for SCM to handle spaces correctly.
Replace the $q auxiliary line and both sc.exe strings with a parenthesised single-quoted expression — ('"…"') — which produces a PS string value that includes the literal double-quote chars and forwards them untouched to sc.exe:
🐛 Proposed fix for sc.exe binPath quoting
- "$q = [char]34",
- "Set-Content \"$dir\\fix.ps1\" @(\"sc.exe config sshd binPath= ${q}${real}\\sshd.exe${q}\", \"sc.exe config ssh-agent binPath= ${q}${real}\\ssh-agent.exe${q}\") -Encoding UTF8",
+ "Set-Content \"$dir\\fix.ps1\" @(\"sc.exe config sshd binPath= ('`\"${real}\\sshd.exe`\"')\", \"sc.exe config ssh-agent binPath= ('`\"${real}\\ssh-agent.exe`\"')\") -Encoding UTF8",The generated fix.ps1 will then contain lines such as:
sc.exe config sshd binPath= ('"C:\actual\path\sshd.exe"')
sc.exe config ssh-agent binPath= ('"C:\actual\path\ssh-agent.exe"')The single-quoted expression '"…"' evaluates to a string value that carries the double-quote characters, so sc.exe receives and stores "C:\actual\path\sshd.exe" (with quotes) in ImagePath. This is safe for both spaced and space-free paths.
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.
In `@bucket/openssh.json` around lines 46 - 47, The generated fix.ps1 currently
uses a $q helper and writes sc.exe config lines that lose their surrounding
double-quotes when PowerShell evaluates them; remove the "$q = [char]34" helper
and change the two sc.exe strings written by Set-Content (the sc.exe config sshd
binPath= ... and sc.exe config ssh-agent binPath= ... entries) to use a
parenthesised single-quoted expression that includes literal double-quote
characters around the real path (e.g. use ('"'+ <real path> + '"' ) style so the
resulting ImagePath in the registry includes the quote characters and preserves
paths with spaces).
Closes #7665
<manifest-name[@version]|chore>: <general summary of the pull request>Add
post_installscripts that are generated on install:sshdandssh-agentservicebinPathto the real absolute path.sshdandssh-agentservices toAutomaticstartup type.Summary by CodeRabbit
New Features
Chores