-
Notifications
You must be signed in to change notification settings - Fork 8
refactor(inject): format script and check for errors #449
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Signed-off-by: Samuel K <skevetter@pm.me>
Signed-off-by: Samuel K <skevetter@pm.me>
Signed-off-by: Samuel K <skevetter@pm.me>
📝 WalkthroughWalkthroughRefactors Changes
Sequence Diagram(s)sequenceDiagram
participant Client
participant Injector as "inject.sh"
participant Remote as "remote server/URL"
participant Priv as "sudo/su"
participant Parent as "parent process"
Client->>Injector: invoke main()
Injector->>Injector: handshake() - send ping, expect pong
Injector->>Priv: setup_sudo() - determine sudo or su
alt download path
Injector->>Remote: download_binary() (curl/wget, retries)
Remote-->>Injector: binary data
Injector->>Injector: write to temp file -> move to target
else inject path
Client->>Injector: inject_binary() (receive binary stream)
Injector->>Injector: write to temp file -> move to target
end
Injector->>Priv: install_agent() (apply chmod via sudo/su if required)
Injector->>Parent: execute_command() (export URL, run configured command)
Parent-->>Injector: command exit/status
Injector->>Client: final status / done
Estimated code review effort🎯 4 (Complex) | ⏱️ ~45 minutes 🚥 Pre-merge checks | ✅ 2 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing touches
🧪 Generate unit tests (beta)
No actionable comments were generated in the recent review. 🎉 🧹 Recent nitpick comments
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 |
Signed-off-by: Samuel K <skevetter@pm.me>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 1
🤖 Fix all issues with AI agents
In `@pkg/inject/inject.sh`:
- Around line 78-91: The code captures cmd_status after an if compound which
yields 0, so replace the "if $sh_c \"curl ...\"; then break; fi; cmd_status=$?"
and the analogous wget block with a short-circuit form that preserves the actual
tool exit code, e.g. invoke $sh_c "curl -fsSL \"$DOWNLOAD_URL\" -o
\"$temp_file\"" && break || cmd_status=$? (and do the same for wget),
referencing the existing symbols DOWNLOAD_URL, temp_file, cmd_status, sh_c,
command_exists, and the curl/wget branches to locate where to change.
🧹 Nitpick comments (2)
pkg/inject/inject.sh (2)
42-42: Minor:mktempfallback doesn't create the file and reuses the same name across retries.When
mktempfails, the fallbackecho "$INSTALL_PATH.$$"just produces a filename string without creating it — the subsequentcat >orcurl -owill create it, so it works. However,$$is constant for the process, so indownload_binary's retry loop every iteration collides on the same fallback name. This is benign (the file is cleaned up between attempts) but worth noting.Also applies to: 76-76
142-166: Duplicatechmod +xwhen usinginject_binarypath.
inject_binary()already runschmod +xon$INSTALL_PATH(lines 56–61), and theninstall_agent()does it again (lines 161–166). For thedownload_binarypath the outer chmod is needed, but forinject_binaryit's redundant.You could remove the chmod from
inject_binary()and letinstall_agent()be the single place that handles it, since it applies after both paths.
Signed-off-by: Samuel K <skevetter@pm.me>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 1
🤖 Fix all issues with AI agents
In `@pkg/inject/inject.sh`:
- Around line 77-80: The temp file created with mktemp (temp_file) is leaked
when neither curl nor wget is found because the function returns 127 without
removing it; modify the logic around the download-tool check so that before
executing `return 127` the temp_file is removed (rm -f "$temp_file") or, better,
ensure a cleanup trap is set earlier (trap 'rm -f "$temp_file"' EXIT) so
temp_file is always deleted regardless of the early return in the download
branch that currently returns 127.
🧹 Nitpick comments (2)
pkg/inject/inject.sh (2)
82-82: Cleanuprmunderset -ecould abort the retry loop unexpectedly.If
$sh_c "rm -f ..."fails (e.g., directory permissions changed),set -eterminates the script immediately, bypassing the retry logic and error messages below. The same pattern appears ininject_binary(lines 46, 52) and later on line 101. Adding|| truemakes cleanup best-effort and keeps the intended error flow intact.Proposed fix (apply similarly to lines 46, 52, 101)
- $sh_c "rm -f \"$temp_file\"" + $sh_c "rm -f \"$temp_file\"" 2>/dev/null || true
158-162: Quote the template value on line 160 to guard against shell metacharacters.The ShellCheck warnings (SC1083/SC1054) on lines 160–161 and 167 are false positives — they fire because ShellCheck cannot parse Go template
{{ }}braces. These will be replaced before the script executes.However, the rendered URL on line 160 should be quoted to prevent word-splitting or glob expansion if the value ever contains special characters:
Proposed fix
- export DEVPOD_AGENT_URL={{ .DownloadBase }} + export DEVPOD_AGENT_URL="{{ .DownloadBase }}"
Signed-off-by: Samuel K <skevetter@pm.me>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 1
🤖 Fix all issues with AI agents
In `@pkg/inject/inject.sh`:
- Line 161: The export of DEVPOD_AGENT_URL in inject.sh uses an unquoted
template expansion which can cause word splitting or globbing if {{
.DownloadBase }} contains spaces or shell-special chars; update the export so
the template expansion is quoted (i.e., assign the value in quotes) to ensure
the entire string is preserved and safe for shell export when setting
DEVPOD_AGENT_URL.
Signed-off-by: Samuel K <skevetter@pm.me>
Summary by CodeRabbit
New Features
Bug Fixes