From: Samir Benmendil Date: Sat, 18 Apr 2015 05:16:02 +0000 (+0100) Subject: bin: add depth option and usage X-Git-Url: https://git.rmz.io/dotfiles.git/commitdiff_plain/a55f000ce1ecc9ff47e71dfe7725580b1b421c0e?ds=sidebyside bin: add depth option and usage --- diff --git a/bin/socheck b/bin/socheck index 78a3510..ab6a411 100755 --- a/bin/socheck +++ b/bin/socheck @@ -1,5 +1,18 @@ #!/bin/bash +version="0.1" + +function usage () +{ + echo "Usage : $0 [options] [PATH] + Checks installed libraries for missing dynamic links. + + 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 @@ -8,13 +21,37 @@ checkso() { done } +# 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...." -bins=( $(find /usr/bin -maxdepth 1 -type f -executable) ) +binpath=${path:-/usr/bin} +bins=( $(find "$binpath" "${findopts[@]}" -type f -executable) ) checkso ${bins[@]} echo " " echo "Searching broken libs...." -libs=( $(find /usr/lib/*.so* -maxdepth 1 -type f -executable) ) +libpath=${path:-/usr/lib} +libs=( $(find $libpath "${findopts[@]}" -name '*.so' -type f -executable) ) checkso ${libs[@]}