Skip to content

Add shell-deps subcommand to tw#218

Merged
aborrero merged 12 commits intochainguard-dev:mainfrom
smoser:feat/shell-deps
Jan 27, 2026
Merged

Add shell-deps subcommand to tw#218
aborrero merged 12 commits intochainguard-dev:mainfrom
smoser:feat/shell-deps

Conversation

@smoser
Copy link
Copy Markdown
Contributor

@smoser smoser commented Oct 17, 2025

shell-deps parses shell scripts and determines dependencies.
See README.md for more info.

@smoser
Copy link
Copy Markdown
Contributor Author

smoser commented Oct 17, 2025

This is untested other than what claude did.
I did not sanity check the output.

The idea is just to be able to identify dependencies of a shell script that are missing.

Ideally, I'd ultimately like to be able to point it at a image and have it spit out things that it thinks are missing.

$ tw  shell-deps scan-image cgr.dev/chainguard/my-image:latest

Right now it only handles local files or directory tree.

@smoser smoser requested review from kranurag7 and rawlingsj October 17, 2025 21:31
Copy link
Copy Markdown
Member

@kranurag7 kranurag7 left a comment

Choose a reason for hiding this comment

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

sorry for coming late on this, great work Scott

It would be awesome to have scan supported on files and directories both then we can do things like fd -e sh -x tw shell-deps scan

@smoser
Copy link
Copy Markdown
Contributor Author

smoser commented Jan 22, 2026

@Aditevil ,
thanks for pushing on this a bit.

From our meet session, think we came up with:

  • Your recent commit adds coreutils compatibility checks, which i think is super awesome. I'd like to make sure that the code is actually checking specific commands and arguments found in a script versus just regex comparing to lines. (ie, we want it to catch split across a newline chmod \\\n --reference foo bar , but not believe that this line contains a call to chmod with --reference: chmod 644 foo && some-command --reference foo)

  • Our goal is to expose 2 different pipelines for melange testing:

    1. full package check uses: test/tw/shell-deps-check-package .
      this would commonly call tw shell-deps check -package ${{context.name}}

    2. check specific scripts or directories : uses: test/tw/shell-deps .
      this one requires a files or other input to check.

      The files would be explicit paths to files to check this has the potential of bit-rotting and missing newly added scripts, but allows us to not cast as wide a net and may avoid some false positives.

    both of these can take a path argument, but would default to a path of /usr/local/bin:/usr/bin and possibly with /opt/iamguarded in there.. i'm not opposed to that. Then it would a given script uses only programs that are in the path provided.

  • I think that tw shell-deps show does much of 2 above, so i'm not convinced we should/would need a new command for that. I think that --missing should basically be --path and it should not just look through an entire directory recursively, but expect a given path.

  • automatic gnu/coreutils detection. The coreutils compatibility stuff is wonderful, but I'd like it to just do the right thing by default. Given a system, you can easily determine if chmod is provided by busybox or coreutils by looking at the target of the symlink. If a script needs chmod from coreutils due to --reference use, then it should look at the chmod that is found in --path and if that is coreutils, then it looks good. If it is busybox, it should fail.

    the reason for this is the following workflow:

    • we add this package test
    • package test fails because coreutils is not installed and chmod --reference is used.
    • we add a dependency in the package on coreutils
    • package test runs and sees /usr/bin/chmod is now coreutils, so there is not a problem.

@smoser
Copy link
Copy Markdown
Contributor Author

smoser commented Jan 22, 2026

So I think basically, what I'm asaying we want in tw shell-deps is 3 sub-commands, all which take '--path' argumetn rather than --missing.

  • tw shell-deps check file [.....]
  • tw shell-deps check-package package-name

maybe we still keep 'show' to just show fuller output and not check deps? we can ditch scan for now.. that was to be pointed at a full image, we can maybe add it back later when its needed.

@smoser
Copy link
Copy Markdown
Contributor Author

smoser commented Jan 23, 2026

this doesn't seem right:

smoser@work:~/src/tw/tw$ apk info -v | grep vim
neovim-0.11.5-r0
vim-9.1.2103-r0
smoser@work:~/src/tw/tw$ ./bin/tw shell-deps check-package vim
Error: package vim not found in .
2026/01/23 12:46:57 ERROR failed to execute command: package vim not found in .

i have vim intsalled, i wanted it to check all the shell scripts installed by vim.

@Aditevil Aditevil force-pushed the feat/shell-deps branch 2 times, most recently from 18e5ec0 to fc9a287 Compare January 23, 2026 22:36
smoser and others added 12 commits January 26, 2026 17:04
This is a pattern I often use to execute a functions
parameters after logging them.
Signed-off-by: Aditya Tirmanwar <aditya.tirmanwar@chainguard.dev>
…dency validation

Signed-off-by: Aditya Tirmanwar <aditya.tirmanwar@chainguard.dev>
Signed-off-by: Aditya Tirmanwar <aditya.tirmanwar@chainguard.dev>
Signed-off-by: Aditya Tirmanwar <aditya.tirmanwar@chainguard.dev>
Signed-off-by: Aditya Tirmanwar <aditya.tirmanwar@chainguard.dev>
Invoking via symlink as seen below would show usage error after failure
in parsing.

    ./bin/shell-deps check --path=/usr/local/bin /tmp/my-script
@smoser
Copy link
Copy Markdown
Contributor Author

smoser commented Jan 26, 2026

@Aditevil i pushed one change that fixed the symlink usage I think I'm pretty happy with this.
there one thing remaining is to add pipelines for test/tw/shell-deps-check-package and test/tw/shell-deps-check

then we need to get someone else's review and land this.l

@Aditevil
Copy link
Copy Markdown
Member

there one thing remaining is to add pipelines for test/tw/shell-deps-check-package and test/tw/shell-deps-check

raised a draft PR for this - https://github.com/chainguard-dev/stereo/pull/13152

Copy link
Copy Markdown
Contributor

@aborrero aborrero left a comment

Choose a reason for hiding this comment

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

LGTM.

@aborrero aborrero merged commit 3ff64f6 into chainguard-dev:main Jan 27, 2026
5 checks passed
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.

4 participants