William Harrington wrote:
> Use the following script which Armin provided a long time ago:

Oh hey, I can make that seem better to myself:

> #!/bin/sh
> 
> if [ ! $1 ]; then

(doesn't that need quotes?)

>   /bin/echo -e "this script requires one arguments."
>   exit 1
> fi
> 
> rm -f ${PWD}/check

Seems unnecessary, and might be dangerous if there's a "check" file in the
current directory that the user wants to keep?  See also below.

> find {,/usr}/{bin,lib,sbin} -type f ! -path "*/debug/*" ! -path "*/java/*" ! 
> -path "*/syslinux/*" ! -path "*/vmware*/*" 2>/dev/null | while read 
> BUILD_BINARY ; do

Let's hope nobody creates a file with a newline in its name in /usr/bin...
which is perfectly legal to do, if perhaps a bad idea.  :-)

Mind you, you're running shell "case" statements ... so I don't know how
possible it would be to change this into a find -exec.  Thinking about it a
little though...

> case "$(file -bi "${BUILD_BINARY}")" in
> *application/x-sharedlib* | *application/x-executable*)
>   readelf -d ${BUILD_BINARY} | grep "NEEDED" | grep $1 > /dev/null
>   if [ $? -eq 0 ]; then

if readelf -d "${BUILD_BINARY}" | grep -q "NEEDED.*$1"; then

>     /bin/echo ${BUILD_BINARY} >> ${PWD}/check

Personally, I'd just echo this to stdout, and let the user redirect it to a
file (or to less...) if they wish.  But that's just me.

>   fi
> esac
> done

Getting back to that find ... hmm.

What about dumping the middle piece into a separate script, say:

#!/bin/bash

TARGET="$1"
shift

# This might be doable with just "for file"?
for filename in "$@" ; do
  case $(file -bi "$filename") in
  *foo*|*bar*)
    if readelf -d "$filename" | grep -q "NEEDED.*$TARGET"; then
      /bin/echo "$filename"
    fi
  esac
done

And then in the original script:

find {,/usr}/{bin,lib,sbin} -type f ! -path {foo...} -exec newscript.sh "$1" {} 
+

Then the output of the whole thing can be sent to wherever, as well.  The +
ensures that find forks the fewest number of times possible (it's a GNU
extension just like -print0, but here, the same setup will work with \;
instead if you don't have that particular extension available).

And then you almost don't need the wrapper script.  You can just do the find
yourself, and pass the correct first argument to newscript.sh.  (Because
obviously everyone knows how find works, right?  Uh...  never mind.  ;-) )

...But this is mostly just me trying to be weird with shell.  Don't mind me.
:-)

Attachment: signature.asc
Description: OpenPGP digital signature

-- 
http://lists.linuxfromscratch.org/listinfo/lfs-dev
FAQ: http://www.linuxfromscratch.org/faq/
Unsubscribe: See the above information page

Reply via email to