Files
scratchpkg/extra/revdep
2018-04-10 23:10:01 +08:00

133 lines
3.3 KiB
Bash
Executable File

#!/bin/bash -e
INDEX_DIR="/var/lib/scratchpkg/index"
source "/usr/share/scratchpkg/color"
source "/usr/share/scratchpkg/message"
onepkg() {
pushd / >/dev/null
echo -ne "Checking $1...\033[0K\r"
while IFS=' ' read -r line; do
case "$(file -bi "${line}")" in
*application/x-sharedlib* | *application/x-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}')
LIB=$(echo $LIB_NAME | tr '\n' ' ')
REQ_LIB=$(objdump -p $line 2>/dev/null | grep NEEDED | awk '{print $2}' | tr '\n' ' ')
MISSING_LIB=""
for i in $LIB_NAME; do
if echo $REQ_LIB | grep -q $i; then
MISSING_LIB="$MISSING_LIB $i"
fi
done
if [ "$MISSING_LIB" != "" ]; then
echo "$MISSING_LIB"
fi
MISSING=1
fi ;;
*)
continue ;;
esac
done < <(grep -E '(*\.so\.*|^bin/|^sbin/|^usr/bin/|^usr/sbin/|^usr/libexec)' $INDEX_DIR/$1/.files | grep -Ev "(opt/|firmware/)")
popd >/dev/null
echo -ne "\033[0K"
[ "$MISSING" != 1 ] && msg "Packages '$1' is doing fine."
}
allpkg() {
allpkgs=($(ls ${INDEX_DIR}/*/.files | rev | cut -d '/' -f2 | rev))
totalpkgs=$(echo ${#allpkgs[@]})
pushd / >/dev/null
for pkgs in $(seq 0 $(($totalpkgs -1))); do
echo -ne "[ $((pkgs + 1))/$totalpkgs ] Checking ${allpkgs[pkgs]}...\033[0K\r"
while IFS=' ' read -r line; do
case "$(file -bi "${line}")" in
*application/x-sharedlib* | *application/x-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}')
PKG_NAME=$(basename $(dirname $(grep -Rx $line $INDEX_DIR | cut -d ':' -f1)))
REQ_LIB=$(objdump -p $line 2>/dev/null | grep NEEDED | awk '{print $2}' | tr '\n' ' ')
LIB=$(echo $LIB_NAME | tr '\n' ' ')
MISSING_LIB=""
for i in $LIB_NAME; do
if echo $REQ_LIB | grep -q $i; then
[ "$VERBOSE" ] && echo -e "(${color_green}$PKG_NAME${color_reset}) $line ${color_green}>>>${color_reset} $i"
if [[ "$(echo ${ALLPKG[@]} | tr ' ' '\n' | grep -w "$PKG_NAME")" ]]; then
continue
else
ALLPKG+=($PKG_NAME)
fi
MISSING_LIB="$MISSING_LIB $i"
fi
done
fi ;;
*)
continue ;;
esac
done < <(grep -E '(*\.so\.*|^bin/|^sbin/|^usr/bin/|^usr/sbin/|^usr/libexec)' $INDEX_DIR/${allpkgs[pkgs]}/.files | grep -Ev "(opt/|firmware/|/share/theme/|/share/icons/)")
done
popd >/dev/null
echo -ne "\033[0K"
if [ "${#ALLPKG[@]}" -gt 0 ]; then
[ -z "$VERBOSE" ] || echo
echo "This package(s) need rebuild:"
for rebuild in ${ALLPKG[@]}; do
echo -e "${color_green}>>>${color_reset} $rebuild"
done
else
msg "All packages is doing fine."
fi
}
help() {
cat << EOF
Usage:
revdep [ option | pkgname ]
Options:
-v, --verbose print out missing library
-h, --help show this help page and exit
EOF
}
parse_options() {
while [ "$1" ]; do
case "$1" in
-v|--verbose) VERBOSE=yes ;;
-h|--help) help; exit 0 ;;
*) PKG+=($1) ;;
esac
shift
done
}
parse_options "$@"
if [ "${#PKG[@]}" -gt 0 ]; then
for pkg in ${PKG[@]}; do
if [ ! -d "$INDEX_DIR/$pkg" ]; then
msgerr "Package '$pkg' not installed."
else
onepkg "$pkg"
fi
done
else
allpkg
fi
exit 0