#!/bin/sh # # Script is scanning system to find missing libraries # # Author: Adam Drzewiecki # e-mail: A.Drzewiecki@ztpnet.pl # Last modified: 24 July 2009 # # Do we have sufficient privilleges? if [ $(id -u) -ne 0 ]; then echo "Script \"$(basename $0)\" must be run by root." exit -1 fi # List of standard searching directories DIRECTORIES="/bin /usr/bin /usr/local/bin /sbin /usr/sbin /usr/local/sbin" # List of missing libraries UNAVAILABLE="" # Add directories from PATH environment variable for ITEM in $(echo $PATH | tr ":" " ") ; do # Add directory if it is not listed in DIRECTORIES if ! echo "$DIRECTORIES" | grep $ITEM 1>/dev/null 2>/dev/null ; then # Add only existing directories if [ -e "$ITEM" -a -d "$ITEM" ]; then # Add ITEM to the comma separated DIRECTORIES list if [ -z "$DIRECTORIES" ]; then DIRECTORIES="$ITEM" else DIRECTORIES="$DIRECTORIES $ITEM" fi fi fi done # Print start message echo "Checking programs for missing library dependencies:" echo # For each scanned directory... for DIRECTORY in $DIRECTORIES ; do echo -n "Analyzing directory $DIRECTORY: " # Find ELF executables EXECS=$(find $DIRECTORY | xargs file | grep "executable" | grep "ELF" | cut -f1 -d: | xargs) # Find symbolic link targets LINKS=$(find $DIRECTORY | xargs file | grep "symbolic link" | cut -f1 -d: | xargs) for LINK in $LINKS ; do # Find target of symbolic link REAL=$(readlink -e $LINK) # If target is a ELF executable... if file $REAL | grep "executable" | grep "ELF" 1>/dev/null 2>/dev/null ; then # ...add it to the list of tested executables if ! echo $EXECS | grep $REAL 1>/dev/null 2>/dev/null ; then # Add REAL to the comma separated list in EXECS if [ -z "$EXECS" ]; then EXECS="$REAL" else EXECS="$EXECS $REAL" fi fi fi done # Before the first found missing library scanned directory is OK FAILED="0" # For each tested executables... for EXEC in $EXECS; do # Find missing libraries MISSING=$(ldd $EXEC | grep "not found" | cut -f1 -d" " | sort | uniq | xargs) # If there are any missing libraries if [ -n "$MISSING" ] ; then # Mark directory as tainted if [ $FAILED == "0" ]; then echo "FAILED" echo FAILED="1" fi # Print message echo "Program $EXEC is missing following libraries: $MISSING" # Add each misisng libraries to the list... for LIB in $MISSING; do # ...if it isn't recorded yet if ! echo "$UNAVAILABLE" | grep $LIB 1>/dev/null 2>/dev/null ; then # Add LIB to the comma separated list in UNAVAILABLE if [ -z "$UNAVAILABLE" ]; then UNAVAILABLE="$LIB" else UNAVAILABLE="$UNAVAILABLE $LIB" fi fi done fi done # Print newline after each directory with missing libraries if [ "$FAILED" == "0" ]; then echo "OK" else echo fi done # If missing libraries list is empty... if [ -z "$UNAVAILABLE" ]; then # ...print OK message and return 0... echo echo "System has all necessary libraries." exit 0 else # ...else print list of missing libraries and return 1 echo echo "List of missing libraries: $UNAVAILABLE" exit 1 fi