LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Distributions > Slackware
User Name
Password
Slackware This Forum is for the discussion of Slackware Linux.

Notices


Reply
  Search this Thread
Old 06-22-2004, 03:02 AM   #1
Tinkster
Moderator
 
Registered: Apr 2002
Location: earth
Distribution: slackware by choice, others too :} ... android.
Posts: 23,067
Blog Entries: 11

Rep: Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928
Rudimentary dependency checker :)


Hi Guys ...

Feel free to comment/enhance. It's an ultra-primitive
prototype ... :)

Code:
#!/bin/bash
# dep_check.sh - author Tink
# Inspired by Cameron Kerr's testldddeps,
# it lacks his brevity and elegance but may
# be more readable :)

IFS='
'

# Some preliminary error-checking
if [ $# != "1" ]; then
    echo "Usage: dep_check.sh <target directory>"
    exit 1
fi

if [ ! -d $1 ]; then
    echo $1 " does not exist or is not a directory!"
    exit 2
fi


# Building the list of files ... 
files=`find $1 -type f -perm +111 -xdev ` 
echo "Checking perms!" > /tmp/ldd.cache
for i in $files ; do
    miss_libs=`ldd $i 2>/dev/null | grep "not found"`
    if [ $? == "0" ]; then
        echo $i
        for j in $miss_libs; do
            echo "   " $j
            found=`grep "$j" /var/log/packages/*`
            missing=`grep "$j" /var/log/removed_packages/*`
            if [ ! $found = "" ]; then
                echo $j " from  installed package " $found " is missing!"
            fi
            if [ ! $missing = "" ]; then
                echo $j " was part of removed package " $missing
            fi
        done
        echo ""
     fi
done

Cheers,
Tink
 
Old 08-16-2004, 03:08 PM   #2
thegeekster
Member
 
Registered: Dec 2003
Location: USA (Pacific coast)
Distribution: Vector 5.8-SOHO, FreeBSD 6.2
Posts: 513

Rep: Reputation: 34
Thanx, Tink.........

Just what I'm looking for to use in my Slackware PkgBuild setup I'm working on...........I've already got ideas to expand on this script for a system-wide dep check.......
 
Old 08-18-2004, 12:19 AM   #3
thegeekster
Member
 
Registered: Dec 2003
Location: USA (Pacific coast)
Distribution: Vector 5.8-SOHO, FreeBSD 6.2
Posts: 513

Rep: Reputation: 34
Okay, here's another little script for checking dependencies........

I decided not to use 'ldd' and used 'objdump' instead.........The reason for this is 'ldd' not only returns direct dependencies, but also returns dependencies of dependencies (quite a mouthful, eh), or "indirect" dependencies............The rationale behind this is you only need to worry about dependencies that are called directly by the executable (and not indirectly through one of it's dependencies)...........A proper search will turn up any missing files.........(plus I use 'objdump' for a bit of error-checking)
Code:
#!/bin/sh
#*******************************************************************************
# Name: finddep
# 
# Look for binary dependencies by supplying the name of a file or a directory.
# All output goes to the screen. 
# 
# Some files may return the error message: "File format not recognized". All
# this means is it is not a binary executable or shared object (lib file). It's
# probably a script or other file type.
# 
# TIP: When searching a whole directory, you can limit the output to the screen
#      by grep'ing for the word "MISSING", like so:
# 
#        finddep <directory> | grep 'MISSING'
# 
#      Now, only missing dependencies will be listed on the screen.
#*******************************************************************************

# Check for command line args:
[ $# -ne 1 ] && echo "
  Usage: $0 NAME  (where NAME can be a file or directory)
" && return 1

find_dep() {
  ldd $1 | grep "`$OBJDUMP | grep 'NEEDED' | cut -d' ' -f9`" \
    | sed 's/not\ found/MISSING/' | cut -d ' ' -f1,3  | while read dep
  do
    echo "$1  -->  $dep"
  done
}

# If a file is supplied on the command line:
[ -f "$1" ] && {
  OBJDUMP="objdump -p $1"
  # Use 'objdump' for error-checking:
  [ "`$OBJDUMP 2>/dev/null`" ] && {
    # Look for dependencies:
    [ "`$OBJDUMP | grep 'NEEDED'`" ] && {
      echo "FILE --> DEPENDENCY LOCATION" 
      find_dep "$1"
      # Use 'column' for a bit of formatting:
      } | column -t && echo || echo -e "$1: NO DEPENDENCIES\n"  # Didn't find "NEEDED"
  } || {
    # Using the error message from 'objdump':
    $OBJDUMP 2>&1 | cut -d' ' -f2- && echo
  }
}

# Otherwise, if a directory is supplied on the command line;
[ -d "$1" ] && printf "FILE \t    -->  DEPENDENCY\t LOCATION\n" && {
  # Ignore subdirectories when parsing files in a directory:
  find "$1" -type f -prune | while read d
  do {
    OBJDUMP="objdump -p $d"
    # Use 'objdump' for error-checking:
    [ "`$OBJDUMP 2>/dev/null`" ] && {
      # Look for dependencies:
      [ "`$OBJDUMP | grep 'NEEDED'`" ] && {
        find_dep "$d"
        # Use 'column' for a bit of formatting:
        } | column -t && echo || echo -e "$d: NO DEPENDENCIES\n"  # Didn't find "NEEDED"
    } || {
      # Using the error message from 'objdump':
      $OBJDUMP 2>&1 | cut -d' ' -f2- && echo
    }
  } done
}
The output is also formatted a bit for easier reading, and when searching in directories, subdirectories will be ignored, This is so you can create a list for a single directory...........If you want a recursive search, just place the script in a 'find' command, such as:

find <path> -type d -exec finddep {} \; | grep 'MISSING'

This will search out any missing dependencies............

I plan on expanding this to create a database of dependencies in /var/log/ for Slackware, one for each package installed, much like the "packages" and "scripts" directories in /var/log.......


=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
EDIT: Made changes in the find_dep() function to use 'ldd' instead of 'objdump' for searching dependencies.........

Last edited by thegeekster; 08-20-2004 at 07:03 PM.
 
Old 08-18-2004, 03:15 PM   #4
thegeekster
Member
 
Registered: Dec 2003
Location: USA (Pacific coast)
Distribution: Vector 5.8-SOHO, FreeBSD 6.2
Posts: 513

Rep: Reputation: 34
Okay, stop the presses.....................It seems the 'whereis' command I use for finding the lib dependencies has a serious limitation................it does not know where all the lib directories are. like for KDE or X11 (apparently doesn't use the /etc/ld.so.cache database).......

So the 'whereis' command needs a little help.......or I'll need to use 'ldd' for searching locations for dependencies.......

Anyway, my script needed more work...........so I revised the find_dep() function to use 'ldd' while still retaining 'objdump' for error-checking (it has a more informative error message which I can use).......

The changes are already made in the script above...............

 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
exploit checker linuxtesting2 Linux - Security 3 07-05-2009 02:15 PM
Your Spell-Checker Robert G. Hays LQ Suggestions & Feedback 4 03-23-2005 01:31 PM
sfv checker phatbastard Linux - Software 0 11-18-2004 12:21 PM
how to solve failed dependency when dependency exists dwcramer Linux - Newbie 2 08-24-2004 09:03 PM
virus checker? sk8guitar Linux - Security 6 07-11-2003 02:05 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Distributions > Slackware

All times are GMT -5. The time now is 05:50 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration