Files
scratchpkg/revdep
2018-10-31 21:45:23 +08:00

132 lines
3.5 KiB
Bash
Executable File

#!/bin/bash
#
# scratchpkg
#
# Copyright (c) 2018 by Emmett1 (emmett1.2miligrams@gmail.com)
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <https://www.gnu.org/licenses/>.
#
while read line; do
if [[ $(echo ${line::1}) = "/" ]]; then
EXTRA_SEARCH_DIRS+="$line "
fi
done < /etc/ld.so.conf
if [ -d /etc/ld.so.conf.d/ ]; then
for dir in $(ls /etc/ld.so.conf.d/); do
while read line; do
if [[ $(echo ${line::1}) = "/" ]]; then
EXTRA_SEARCH_DIRS+="$line "
fi
done < /etc/ld.so.conf.d/$dir
done
fi
# excluded dirs
EXCLUDE_DIRS="$(cat /etc/revdep.conf 2>/dev/null | grep /$ | sed 's/\/*$//g')"
EXCLUDE_DIRS+=" $(cat /etc/revdep.d/*.conf 2>/dev/null | grep /$ | sed 's/\/*$//g')"
for d in $EXCLUDE_DIRS; do
EXCLUDED_DIRS+="-path $d -prune -o "
done
# excluded files
EXCLUDE_FILES="$(cat /etc/revdep.conf 2>/dev/null | grep -v /$)"
EXCLUDE_FILES+=" $(cat /etc/revdep.d/*.conf 2>/dev/null | grep -v /$)"
for f in $EXCLUDE_FILES; do
EXCLUDED_FILES+="! -path $f "
done
# search dirs
SEARCH_DIRS="/bin /usr/bin /sbin /usr/sbin /lib /usr/lib /lib64 /usr/libexec $EXTRA_SEARCH_DIRS"
INDEX_DIR="/var/lib/scratchpkg/index"
FILE_LIST=/tmp/$(basename $0)-$$
echo "SEARCH DIRS:"
for d in $SEARCH_DIRS; do
echo " $d"
done
echo
echo "EXCLUDED DIRS:"
for dd in $EXCLUDE_DIRS; do
echo " $dd"
done
echo
echo "EXCLUDED FILES:"
for dd in $EXCLUDE_FILES; do
echo " $dd"
done
echo
echo -n "Find all files... "
find ${SEARCH_DIRS[@]} $EXCLUDED_DIRS $EXCLUDED_FILES -type f \( -perm /+u+x -o -name '*.so' -o -name '*.so.*' \) -print 2> /dev/null | sort -u > $FILE_LIST
total=$(cat $FILE_LIST | wc -l)
count=0
echo "$total files found"
echo "Checking for broken linkage..."
while IFS=' ' read -r line; do
count=$(( $count + 1 ))
libname=$(basename "$line")
echo -ne " $(( 100*$count/$total ))% $libname\033[0K\r"
case "$(file -bi "$line")" in
*application/x-sharedlib* | *application/x-executable* | *application/x-pie-executable*)
if [ "$(ldd $line 2>/dev/null | grep "not found")" ]; then
LIB_NAME=$(ldd $line 2>/dev/null | grep "not found" | sort | uniq | awk '{print $1}')
line2=$(echo $line | sed 's#^/##')
PKG_NAME=$(grep -Rx $line2 $INDEX_DIR | cut -d : -f1)
[[ $PKG_NAME ]] || continue
PKG_NAME=$(dirname $(echo $PKG_NAME))
PKG_NAME=$(basename $(echo $PKG_NAME))
REQ_LIB=$(objdump -p $line 2>/dev/null | grep NEEDED | awk '{print $2}' | tr '\n' ' ')
LIB=$(echo $LIB_NAME | tr '\n' ' ')
for i in $LIB_NAME; do
echo -e " $PKG_NAME -> $line (requires $i)"
if echo $REQ_LIB | tr ' ' '\n' | grep -qx $i; then
if [[ "$(echo ${ALLPKG[@]} | tr ' ' '\n' | grep -x "$PKG_NAME")" ]]; then
continue
else
ALLPKG+="$PKG_NAME "
fi
fi
done
fi
;;
esac
done < $FILE_LIST
echo -ne "\033[0K"
if [ "$ALLPKG" ]; then
echo
echo "This package(s) requires rebuild:"
for rebuild in $ALLPKG; do
echo -e "$rebuild"
done
else
echo "All packages is doing fine."
fi
rm -f $FILE_LIST
exit 0