X-Git-Url: https://git.rmz.io/dotfiles.git/blobdiff_plain/cdd2aa65ee027cf62e7be13e10f33fe8549d9dc2..fa17f6dc11ab3a15f051dee0172f296fd0f2cf9d:/bin/socheck?ds=inline diff --git a/bin/socheck b/bin/socheck index ef724e9..ab6a411 100755 --- a/bin/socheck +++ b/bin/socheck @@ -1,30 +1,57 @@ #!/bin/bash -sudo -v +version="0.1" -files=$(find /usr/bin /extra/usr/bin -maxdepth 1 -type f) -libs=$(find /usr/lib/*.so* /extra/usr/lib/*.so* -maxdepth 1 -type f) +function usage () +{ + echo "Usage : $0 [options] [PATH] + Checks installed libraries for missing dynamic links. -clear -echo "Searching broken binaries...." + Options: + -d,--depth Max depth to search + -h,--help Display this message + -v,--version Display script version" +} + +checkso() { + for f in ${@}; do + if sudo LD_LIBRARY_PATH=$LD_LIBRARY_PATH ldd $f | grep -q "not found"; then + echo "$(LC_ALL=C pacman -Qoq $f) $f seems broken!" + fi + done +} -for binary in $files ; do - parse=$(sudo ldd ${binary} | grep "not found") - if [ "${parse}" != "" ] ; then - echo "$(LC_ALL=C pacman -Qo $binary) seem broken!" - fi - unset parse +# Parse arguments +declare -a args +while [[ $# > 0 ]]; do + opt="$1" + + case $opt in + -d|--depth) depth=$2; shift 2 ;; + -h|--help) usage; exit 0 ;; + -v|--version) echo "$0 -- Version $version"; exit 0 ;; + -* ) + echo -e "\n Option does not exist : $opt\n" + usage; exit 1 ;; + + *) args+=($opt); shift ;; + esac done +path="${args[0]}" + +declare -a findopts +[[ $depth ]] && findopts+=(-maxdepth "$depth") + +sudo -v + +echo "${findopts[@]}" +echo "Searching broken binaries...." +binpath=${path:-/usr/bin} +bins=( $(find "$binpath" "${findopts[@]}" -type f -executable) ) +checkso ${bins[@]} echo " " echo "Searching broken libs...." - -for lib in $libs ; do - if [ -x ${lib} ] ; then - parse=$(sudo ldd ${lib} | grep "not found") - if [ "${parse}" != "" ] ; then - echo "$(LC_ALL=C pacman -Qo $lib) seem broken!" - fi - unset parse - fi -done +libpath=${path:-/usr/lib} +libs=( $(find $libpath "${findopts[@]}" -name '*.so' -type f -executable) ) +checkso ${libs[@]}