Script "search-for-rpaths.sh"
#!/bin/sh

# --------------------------
# search-for-rpaths.sh
# version 0.9.3.6
# --------------------------

# Binaries with RPATHs are printed to stderr;
# binaries without RPATHs are printed to stdout.
# To get only "bad" binaries, you can use
#     ./search-for-rpaths.sh 1>/dev/null

# check for required binaries
REQD_BINS=""
which grep >/dev/null 2>&1 || type grep >/dev/null 2>&1 || REQD_BINS="grep,${REQD_BINS}"
which file >/dev/null 2>&1 || type file >/dev/null 2>&1 || REQD_BINS="file,${REQD_BINS}"
which readelf >/dev/null 2>&1 || type readelf >/dev/null 2>&1 || REQD_BINS="readelf,${REQD_BINS}"
if [ ! -z "${REQD_BINS}" ]; then
  echo -e `basename ${0}`: "Required binaries (${REQD_BINS}\010) are not present."
  exit 1
fi

print_rpaths_for_one_binary()
# requires 1 parameter: full name of ELF binary
{
  if [ ! $# -eq 1 ]
  then
    echo "*INTERNAL ERROR*"
  else
    if [ -f "${1}" ] || [ -L "${1}" ]
    then
      LIST_OF_RPATHS=`readelf -d "${1}" 2>/dev/null | grep RPATH`

      if [ ! -z "${LIST_OF_RPATHS}" ]; then
        echo "${1}:" 1>&2
        echo "${LIST_OF_RPATHS}" | while read rpath_entry
        do
          echo -e "\t${rpath_entry}" 1>&2
        done
      else
        echo "${1}: none"
      fi
    else
      echo File \'${1}\' doesn\'t exist.
    fi
  fi
}

found_in_wd=`find ./ -print 2>/dev/null`
echo "${found_in_wd}" | while read file_or_dir
do
  if [ ! -d "${file_or_dir}" ]; then
    is_ELF=`file "${file_or_dir}" | grep ELF`
    if [ ! -z "${is_ELF}" ]; then
      print_rpaths_for_one_binary "${file_or_dir}"
    fi
  fi
done
Unless otherwise stated, the content of this page is licensed under GNU Free Documentation License.