revdep-rebuild 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212
  1. #!/bin/bash
  2. # revdep-rebuild: Reverse dependency rebuilder.
  3. # Author: Stanislav Brabec <utx@gentoo.org>
  4. # Milis e uyarlanması
  5. # Author: milisarge <milisarge@gmail.com>
  6. # Mask of specially evaluated libraries (exactly one space separated).
  7. LD_LIBRARY_MASK="libodbcinst.so libodbc.so libjava.so libjvm.so"
  8. # List of directories to be searched (feel free to edit it)
  9. # Note /usr/libexec and /usr/local/subprefix contradicts FHS, but are present
  10. SEARCH_DIRS="/lib /bin /sbin /usr/lib /usr/bin /usr/sbin /usr/libexec /usr/local /usr/qt* /usr/kde/*/bin /usr/lib/MozillaFirefox /usr/kde/*/lib /usr/*-*-linux-gnu"
  11. EXCLUDE_DIRS="/opt/ptsp /usr/lib/xorg/nvidia* /usr/lib/debug"
  12. # Base of temporary files names.
  13. LIST=~/.revdep-rebuild
  14. VT="/var/lib/pkg/DB"
  15. shopt -s nullglob
  16. shopt -s expand_aliases
  17. unalias -a
  18. NO="\x1b[0;0m"
  19. BR="\x1b[0;01m"
  20. CY="\x1b[36;01m"
  21. GR="\x1b[32;01m"
  22. RD="\x1b[31;01m"
  23. YL="\x1b[33;01m"
  24. BL="\x1b[34;01m"
  25. alias echo_v=echo
  26. SONAME="not found"
  27. SONAME_GREP=fgrep
  28. SEARCH_BROKEN=true
  29. while : ; do
  30. case "$1" in
  31. -h | --help )
  32. echo "Usage: $0 [OPTIONS] [--]"
  33. echo
  34. echo "Sistemdeki ters gereklerin kırık kontrolü."
  35. echo
  36. echo
  37. echo " --force remove old revdep-rebuild files"
  38. echo
  39. echo " --soname SONAME recompile packages using library with SONAME instead"
  40. echo " of broken library (SONAME providing library must be"
  41. echo " present in the system)"
  42. echo " --soname-regexp SONAME"
  43. echo " the same as --soname, but accepts grep-style regexp"
  44. echo " -q, --quiet be less verbose"
  45. echo
  46. exit 0
  47. ;;
  48. -q | --quiet )
  49. alias echo_v=:
  50. shift
  51. ;;
  52. --soname=* )
  53. SONAME="${1#*=}"
  54. SEARCH_BROKEN=false
  55. shift
  56. ;;
  57. --soname )
  58. SONAME="$2"
  59. SEARCH_BROKEN=false
  60. shift 2
  61. ;;
  62. --soname-regexp=* )
  63. SONAME="${1#*=}"
  64. SONAME_GREP=grep
  65. SEARCH_BROKEN=false
  66. shift
  67. ;;
  68. --soname-regexp )
  69. SONAME="$2"
  70. SONAME_GREP=grep
  71. SEARCH_BROKEN=false
  72. shift 2
  73. ;;
  74. --force )
  75. FORCE=true
  76. shift
  77. ;;
  78. -- )
  79. shift
  80. break
  81. ;;
  82. * )
  83. break
  84. ;;
  85. esac
  86. done
  87. function set_trap () {
  88. trap "rm_temp $1" SIGHUP SIGINT SIGQUIT SIGABRT SIGTERM
  89. }
  90. function rm_temp () {
  91. echo " terminated."
  92. echo "Removing incomplete $1."
  93. rm $1
  94. echo
  95. exit 1
  96. }
  97. if $FORCE ; then
  98. rm -f /root/.revdep-rebuild*
  99. fi
  100. if $SEARCH_BROKEN ; then
  101. SONAME_SEARCH="$SONAME"
  102. LLIST=$LIST
  103. HEAD_TEXT="broken by any package update"
  104. OK_TEXT="Dynamic linking on your system is consistent"
  105. WORKING_TEXT=" tutarlılık modu"
  106. else
  107. SONAME_SEARCH=" $SONAME "
  108. LLIST=${LIST}_$(echo "$SONAME_SEARCH$SONAME" | md5sum | head -c 8)
  109. HEAD_TEXT="using given shared object name"
  110. OK_TEXT="There are no dynamic links to $SONAME"
  111. WORKING_TEXT=""
  112. fi
  113. echo
  114. echo "Ters bağımlılıklar kontrol ediliyor..."
  115. echo
  116. echo -n -e "${GR}Sistemdeki ikili ve kütüphane dosyaları toplanıyor...${NO}"
  117. if [ -f $LIST.1_files ] ; then
  118. echo "var olan $LIST.1_files dosyası kullanılacak"
  119. else
  120. set_trap "$LIST.1_files"
  121. EXCLUDED_DIRS=
  122. for d in $EXCLUDE_DIRS; do
  123. EXCLUDED_DIRS+="-path $d -prune -o "
  124. done
  125. find $SEARCH_DIRS $EXCLUDED_DIRS -type f \( -perm /+u+x -o -name '*.so' -o -name '*.so.*' \) 2>/dev/null >$LIST.1_files
  126. echo -e " tamamlandı.\n ($LIST.1_files)"
  127. fi
  128. if $SEARCH_BROKEN ; then
  129. echo
  130. echo -n -e "${GR}Toplama tamamlandı LD_LIBRARY_PATH...${NO}"
  131. if [ -f $LIST.2_ldpath ] ; then
  132. echo " var olan $LIST.2_ldpath dosyası kullanılacak."
  133. else
  134. set_trap "$LIST.2_ldpath"
  135. (
  136. grep '.*\.so\(\|\..*\)$' <$LIST.1_files | sed 's:/[^/]*$::'
  137. sed '/^#/d;s/#.*$//' </etc/ld.so.conf
  138. ) | sort -u |
  139. tr '\n' : | tr -d '\r' | sed 's/:$//' >$LIST.2_ldpath
  140. echo -e " tamamlandı.\n ($LIST.2_ldpath)"
  141. fi
  142. export COMPLETE_LD_LIBRARY_PATH="$(cat $LIST.2_ldpath)"
  143. fi
  144. echo
  145. echo -n -e "${GR}Dinamik bağlamlar kontrol ediliyor$WORKING_TEXT...${NO}"
  146. if [ -f $LLIST.3_rebuild ] ; then
  147. echo " var olan $LLIST.3_rebuild dosyası kullanılıyor"
  148. else
  149. echo_v
  150. set_trap "$LLIST.3_rebuild"
  151. LD_MASK="\\( $(echo "$LD_LIBRARY_MASK" | sed 's/\./\\./g;s/ / \\| /g') \\)"
  152. echo -n >$LLIST.3_rebuild
  153. cat $LIST.1_files | while read FILE ; do
  154. # Note: double checking seems to be faster than single
  155. # with complete path (special add ons are rare).
  156. if ldd "$FILE" 2>/dev/null | grep -v "$LD_MASK" |
  157. $SONAME_GREP -q "$SONAME_SEARCH" ; then
  158. if $SEARCH_BROKEN ; then
  159. if LD_LIBRARY_PATH="$COMPLETE_LD_LIBRARY_PATH" \
  160. ldd "$FILE" 2>/dev/null | grep -v "$LD_MASK" |
  161. $SONAME_GREP -q "$SONAME_SEARCH" ; then
  162. echo "$FILE" >>$LLIST.3_rebuild
  163. echo_v " kırık $FILE (gerekli $(ldd "$FILE" | sed -n 's/ \(.*\) => not found$/\1/p' | tr '\n' ' ' | sed 's/ $//' ))"
  164. fi
  165. else
  166. echo "$FILE" >>$LLIST.3_rebuild
  167. echo_v " $FILE bulundu"
  168. fi
  169. fi
  170. done
  171. echo -e " tamamlandı.\n ($LLIST.3_rebuild)"
  172. fi
  173. echo
  174. echo -n -e "${GR}Paket isimleri tespit ediliyor$WORKING_TEXT...${NO}"
  175. if [ -f $LLIST.4_names ] ; then
  176. echo " var olan $LLIST.4_names dosyası kullanılacak"
  177. else
  178. echo_v
  179. set_trap "$LLIST.4_names"
  180. for i in `cat $LLIST.3_rebuild`
  181. do
  182. basename $(dirname $(grep -rli "$i" $VT)) >> $LLIST.tmp
  183. done
  184. cat $LLIST.tmp | sort -d | uniq > $LLIST.4_names
  185. rm -f $LLIST.tmp
  186. echo -e " tamamlandı.\n ($LIST.4_names)"
  187. fi
  188. echo "Yeniden derlenmesi gerekenler"
  189. echo "-----------------------------"
  190. cat $LLIST.4_names