#!/bin/bash
# Version: 0.0.3
# Copyright (c) 2007 - 2026:
#   Darren 'Tadgy' Austin <darren (at) afterdark.org.uk>
# Licensed under the terms of the GNU General Public License version 3.
#
# This is a quick^Wslow dirty hack to check binaries and libraries for missing
# dependancies using ldd.  Only those files with missing dependancies (along
# with the missing library information itself) will be written to stderr.
# Redirecting stderr to a file is advised, since this can produce a large
# volume of output on a system with many missing libraries.

echo "This will take a little while..."

{ find -P "${1:-/}" -regextype posix-extended \
    \( -regex "^/(boot|data|dev|etc|home|lost\+found|media|mnt|proc|root|run|srv|sys|tmp|var)" -a -prune \) -o \
    \( -regex "^/lib(64)?/ld-.*" -a -prune \) -o \
    \( -regex "^/lib/(dhcpcd|firmware|modprobe\.d|modules)" -a -prune \) -o \
    \( -regex "^/(opt|usr|usr/local)/(doc|etc|include|info|man|share|src)" -a -prune \) -o \
    \( -regex "^/usr/lib(64)?/(firefox|java|jdk|jre|seamonkey|thunderbird)-.*" -a -prune \) -o \
    \( -regex "^/usr/lib(64)?/(locale|qt/plugins/.*.debug)" -a -prune \) -o \
    -type f -print0 | xargs -0 -r file -N -0 | grep -E -a ".*ELF.*(executable|shared object).*dynamically" | cut -d $'\0' -f1 | sort | \
    xargs -r ldd 2>/dev/null | grep -E "(^/|not found)" | grep -E -B 1 "^[[:space:]]" | grep -E -v "^--"; } >&2
