I want to run ShellCheck on scripts embedded within a spec file that will run where the RPM is deployed. I have .spec snippets like,
%setup -q
cat > ./example.sh << EOF
#!/bin/sh
echo "example"
EOF
As well as hooks,
%post
#!/bin/sh
echo "Hello"
Is there some way to programmatically extract these shell snippets to run a script analysis tool like ShellCheck? Like maybe rpmbuild --save-temps
or some concept like this? Or does every script need to be bound by known text so I can use a stream tool (grep
, awk
, sed
, etc.)?
I have a large amount of spec files which I would prefer not to modify. For example to check scripts for security related items, etc. without needing to parse a spec file. Searching for bison + spec
gives the wrong concept and I think you need to parse the RPM macros and a lot of other machinery; or maybe the grammar is simpler than I think?