autils

Unnamed repository; edit this file 'description' to name the repository.
git clone https://codeberg.org/emmett1/autils
Log | Files | Refs | README | LICENSE

revdep (1725B)


      1 #!/bin/sh
      2 
      3 SEARCH_DIRS="/bin /usr/bin /sbin /usr/sbin /lib /usr/lib /usr/libexec"
      4 TMPFILE=$(mktemp)
      5 
      6 if [ -d /etc/revdep.d ] && [ "$(ls -1 /etc/revdep.d)" ]; then
      7 	for line in $(cat /etc/revdep.d/*); do
      8 		LD_LIBRARY_PATH="$line:$LD_LIBRARY_PATH"
      9 	done
     10 	export LD_LIBRARY_PATH
     11 fi
     12 
     13 trap 'rm -f $TMPFILE; printf "\033[0K"; exit 1' 1 2 3 15
     14 
     15 while [ "$1" ]; do
     16 	case $1 in
     17 		-v) verbose=1;;
     18 		-h) help=1;;
     19 	esac
     20 	shift
     21 done
     22 
     23 find $SEARCH_DIRS -type f \( -perm /+u+x -o -name '*.so' -o -name '*.so.*' \) -print 2> /dev/null | sort -u > $TMPFILE
     24 total=$(wc -l $TMPFILE | awk '{print $1}')
     25 count=0
     26 while read -r line; do
     27 	count=$(( count + 1 ))
     28 	libname=${line##*/}
     29 	if [ "$verbose" ]; then
     30 		printf " $(( 100*count/total ))%% $libname\033[0K\r"
     31 	fi
     32 	case "$(file -bi "$line")" in
     33 		*application/x-sharedlib* | *application/x-executable* | *application/x-pie-executable*)
     34 			if [ -e /lib/ld-musl-x86_64.so.1 ] || [ -e /usr/lib/ld-musl-x86_64.so.1 ]; then
     35 				# musl system
     36 				missinglib=$(ldd /$line 2>&1 | grep "Error loading shared library" | awk '{print $5}' | sed 's/://' | sort | uniq)
     37 			else
     38 				# glibc system
     39 				missinglib=$(ldd /$line 2>&1 | grep "not found" | awk '{print $1}' | sort | uniq)
     40 			fi
     41 			if [ "$missinglib" ]; then
     42 				for i in $missinglib; do
     43 					objdump -p $line | grep NEEDED | awk '{print $2}' | grep -qx $i && {
     44 						ownby=$(spm -o ^${line#/}$ | head -n1 | awk '{print $1}')
     45 						[ "$ownby" ] || continue
     46 						if [ "$verbose" ]; then
     47 							echo " $ownby: $line (requires $i)"
     48 						else
     49 							[ "$(echo "$p" | tr ' ' '\n' | grep -x $ownby)" ] || {
     50 								echo $ownby
     51 								p="$p $ownby"
     52 							}
     53 						fi
     54 					}
     55 				done
     56 			fi;;
     57 	esac
     58 done < $TMPFILE
     59 printf "\033[0K"
     60 
     61 rm -f $TMPFILE
     62 
     63 exit 0