mirror of
https://github.com/outbackdingo/scratchpkg.git
synced 2026-03-19 23:13:41 +00:00
131 lines
3.1 KiB
Bash
Executable File
131 lines
3.1 KiB
Bash
Executable File
#!/bin/bash -e
|
|
|
|
INDEX_DIR="/var/lib/scratchpkg/index"
|
|
|
|
RED='\e[0;31m' #Red
|
|
GREEN='\e[0;32m' #Green
|
|
CRESET='\e[0m' #Reset color
|
|
|
|
msg() {
|
|
echo -e "${GREEN}==>${CRESET} $1"
|
|
}
|
|
|
|
msgerr() {
|
|
echo -e "${RED}==> ERROR:${CRESET} $1"
|
|
}
|
|
|
|
onepkg() {
|
|
|
|
pushd / >/dev/null
|
|
echo -ne "Checking $1...\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}')
|
|
for i in $LIB_NAME; do
|
|
echo -e "(${GREEN}$1${CRESET}) $line ${GREEN}>>>${CRESET} $i"
|
|
done
|
|
MISSING=yes
|
|
fi ;;
|
|
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" != "yes" ] && msg "Packages '$1' is doing fine."
|
|
MISSING=
|
|
}
|
|
|
|
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' ' ')
|
|
for i in $LIB_NAME; do
|
|
echo -e "(${GREEN}$PKG_NAME${CRESET}) $line ${GREEN}>>>${CRESET} $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 < <(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
|
|
echo
|
|
echo "This package(s) required rebuild:"
|
|
for rebuild in ${ALLPKG[@]}; do
|
|
echo -e "${GREEN}>>>${CRESET} $rebuild"
|
|
done
|
|
else
|
|
msg "All packages is doing fine."
|
|
fi
|
|
|
|
}
|
|
|
|
help() {
|
|
|
|
cat << EOF
|
|
$(basename $0) is script to scan broken package
|
|
|
|
scanned directory/files:
|
|
/bin /usr/bin /sbin /usr/sbin /usr/libexec *.so.*
|
|
|
|
Usage:
|
|
revdep [ pkgname ]
|
|
|
|
Options:
|
|
-h, --help show this help page and exit
|
|
EOF
|
|
|
|
}
|
|
|
|
parse_options() {
|
|
|
|
while [ "$1" ]; do
|
|
case "$1" in
|
|
-h|--help) help; exit 0 ;;
|
|
*) PKG+=($1) ;;
|
|
esac
|
|
shift
|
|
done
|
|
|
|
}
|
|
|
|
parse_options "$@"
|
|
|
|
if [ "${#PKG[@]}" -gt 0 ]; then
|
|
for pkg in ${PKG[@]}; do
|
|
if [ ! -f "$INDEX_DIR/$pkg/.files" ]; then
|
|
msgerr "Package '$pkg' not installed."
|
|
else
|
|
onepkg "$pkg"
|
|
fi
|
|
done
|
|
else
|
|
allpkg
|
|
fi
|
|
|
|
exit 0
|