dependencies.sh 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233
  1. #!/bin/sh
  2. #called from /usr/local/petget/installpreview.sh
  3. #/tmp/petget_installpreview_pkgname (writen in installpreview.sh) has name of package being
  4. # previewed prior to installation. ex: abiword-1.2.3
  5. #/tmp/petget/current-repo-triad has the repository that installing from (written in pkgchooser.sh).
  6. # ex: slackware-12.2-slacky
  7. # ...full package database file is /root/.packages/Packages-slackware-12.2-slacky
  8. #/tmp/petget_missingpkgs_patterns (written in findmissingpkgs.sh) has a list of missing dependencies, format ex:
  9. # |kdebase|
  10. # |kdelibs|
  11. # |mesa-lib|
  12. # |qt|
  13. # ...that is, pkg name-only with vertical-bars on both ends, one name per line.
  14. #/tmp/petget_installed_patterns_all (writen in findmissingpkgs.sh) has a list of already installed
  15. # packages, both builtin and user-installed. One on each line, exs:
  16. # |915resolution|
  17. # |a52dec|
  18. # |absvolume_puppy|
  19. # |alsa\-lib|
  20. # |cyrus\-sasl|
  21. # ...notice the '-' are backslashed.
  22. #110722 versioning info added to dependencies.
  23. #110723 remove hardcoded path /root/.packages, so can run script in Woof.
  24. #110822 versioning operators can be chained, ex: +linux_kernel&ge2.6.32&lt2.6.33
  25. #111107 01micko: fix for '||' messing things up.
  26. #120203 BK: internationalized.
  27. #120221 jemimah: grep '[a-zA-Z]' so as to find deps with all capitals (ex: SDL).
  28. #120831 npierce, jemimah: findmissingpkgs.sh creates /tmp/petget_missingpkgs_patterns and /tmp/petget_missingpkgs_patterns_with_versioning, need to use latter here.
  29. # refer: http://www.murga-linux.com/puppy/viewtopic.php?p=648934#648934
  30. #120903 revert 120831, broken.
  31. #120903 improve pkg db selection. fixes for versioned dependencies.
  32. #120905 search 4 levels for dependencies.
  33. #120907 max 11 levels, greatly improved speed. progress display at top of screen.
  34. #121102 Packages-puppy-${DISTRO_FILE_PREFIX}- (or Packages-puppy-${DISTRO_COMPAT_VERSION}-) is now Packages-puppy-${DISTRO_DB_SUBNAME}-. refer /etc/DISTRO_SPECS.
  35. #130511 vercmp failed this test: if vercmp 2.2.1 ge 2.2~2011week36; then echo 'greater'; fi -- have solved this in woof, support debdb2pupdb.bac
  36. export TEXTDOMAIN=petget___dependencies.sh
  37. export OUTPUT_CHARSET=UTF-8
  38. if [ -f ./PKGS_MANAGEMENT ];then #110723
  39. . ./PKGS_MANAGEMENT
  40. . ./DISTRO_PET_REPOS
  41. . ./DISTRO_SPECS
  42. RUNNINGWOOF='yes'
  43. PREPATH='./'
  44. else
  45. . /root/.packages/PKGS_MANAGEMENT #has PKG_ALIASES_INSTALLED
  46. . /root/.packages/DISTRO_PET_REPOS
  47. . /etc/DISTRO_SPECS
  48. RUNNINGWOOF='no'
  49. PREPATH='/root/.packages/'
  50. fi
  51. #a problem is that the dependencies may have their own dependencies. Some pkg
  52. #databases have all dependencies up-front, whereas some only list the higher-level
  53. #dependencies and the dependencies of those have to be looked for.
  54. yaf-splash -bg orange -close never -text "$(gettext 'Please wait, processing package database files...')" &
  55. X1PID=$!
  56. ALLINSTALLEDPKGS="`cat /tmp/petget_installed_patterns_all`"
  57. TREE1="`cat /tmp/petget_installpreview_pkgname`"
  58. #this is the db of the main pkg...
  59. DB_MAIN="${PREPATH}Packages-`cat /tmp/petget/current-repo-triad`" #ex: Packages-slackware-12.2-official 110723
  60. if [ "$RUNNINGWOOF" = "no" ];then
  61. #...should have first preference when looking for dependencies...
  62. DB_OTHERS="`ls -1 ${PREPATH}Packages-* | grep -v "$DB_MAIN"`"
  63. #120903 improve pkg db selection...
  64. case $DB_MAIN in
  65. *-puppy-2-*) DB_OTHERS="" ;;
  66. *-puppy-3-*) DB_OTHERS="" ;;
  67. *-puppy-4-*) DB_OTHERS="" ;;
  68. *-puppy-5-*) DB_OTHERS="" ;;
  69. *) DB_OTHERS="`echo "$DB_OTHERS" | grep -v '\\-puppy\\-[2345]\\-'`" ;; #do not look in puppy-2, puppy-3, puppy-4 or puppy-5.
  70. esac
  71. case $DB_MAIN in
  72. *-puppy-*)
  73. true
  74. ;;
  75. *)
  76. #looking in a compat-distro db, then only puppy db allow is Packages-puppy-${DISTRO_DB_SUBNAME}-* 121102
  77. DB_OTHERS="$(echo "$DB_OTHERS" | grep -v '\-puppy\-')"
  78. PUPDB="$(ls -1 ${PREPATH}Packages-puppy-${DISTRO_DB_SUBNAME}-* 2>/dev/null)" #121102
  79. [ "$PUPDB" ] && DB_OTHERS="$DB_OTHERS
  80. $PUPDB"
  81. ;;
  82. esac
  83. else
  84. #running woof, restrict search for deps to only the one pkg db file.
  85. DB_OTHERS=""
  86. fi
  87. DB_OTHERS="`echo "$DB_OTHERS" | tr '\n' ' '`"
  88. #the question is, how deep to search for deps? i'll go down 2 levels... make it 3...
  89. #120905 ubuntu precise: vlc: finds deps for -main, -universe: 3-deep: 24 23, 4-deep: 33 23, 5-deep: 36 23, 6-deep: 38 23, 7-deep: 40 23. 10-deep: 72 23.
  90. # ...never-ending. bump to 4, final "check deps" window (after installation) will identify more missing deps. 120907 bump to 11.
  91. SIZE2=0 #120907
  92. echo -n "" > /tmp/petget_missingpkgs_patterns_acc #120903
  93. echo -n "" > /tmp/petget_missingpkgs_patterns_acc0 #120903
  94. cp -f /tmp/petget_missingpkgs_patterns /tmp/petget_missingpkgs_patternsx
  95. echo "$(gettext 'HIERARCHY OF MISSING DEPENDENCIES OF PACKAGE') $TREE1" > /tmp/petget_deps_visualtreelog #w017
  96. echo "$(gettext "Format of each line: 'a-missing-dependent-pkg: missing dependencies of a-missing-dependent-pkg'")" >> /tmp/petget_deps_visualtreelog #w017
  97. for ONELEVEL in 1 2 3 4 5 6 7 8 9 10 11
  98. do
  99. [ $ONELEVEL -gt 1 ] && pupkill $XXPID #120907
  100. yaf-splash -bg "#FF8080" -placement top -close never -fontsize large -text "$(gettext 'Number of missing dependencies:') ${SIZE2}" & #120907
  101. XXPID=$!
  102. echo "" >> /tmp/petget_deps_visualtreelog #w017
  103. echo -n "" > /tmp/petget_missingpkgs_patterns2
  104. for depPATTERN in `cat /tmp/petget_missingpkgs_patternsx`
  105. do
  106. ONEDEP="`echo -n "$depPATTERN" | sed -e 's%|%%g'`" #convert to exact name, ex: abiword
  107. depPATTERN="`echo -n "$depPATTERN" | sed -e 's%\\-%\\\\-%g'`" #backslash '-'
  108. #find database entry for this package...
  109. for ONEDB in $DB_MAIN $DB_OTHERS
  110. do
  111. DB_dependencies="`cat $ONEDB | cut -f 1,2,9 -d '|' | grep "$depPATTERN" | cut -f 3 -d '|' | head -n 1 | sed -e 's%,$%%'`"
  112. xDB_dependencies="" #120903
  113. if [ "$DB_dependencies" != "" ];then
  114. xDB_dependencies="`echo -n "$DB_dependencies" | tr ',' '\n' | cut -f 1 -d '&' | tr '\n' ','`" #120903 chop off any versioning info.
  115. ALLDEPS_PATTERNS="`echo -n "$xDB_dependencies" | tr ',' '\n' | grep '^+' | sed -e 's%^+%%' -e 's%$%|%' -e 's%^%|%'`" #put '|' on each end.
  116. echo "$ALLDEPS_PATTERNS" > /tmp/petget_subpkg_deps_patterns
  117. cp -f /tmp/petget_installed_patterns_all /tmp/petget_installed_patterns_allxx #120907
  118. cat /tmp/petget_missingpkgs_patterns_acc >> /tmp/petget_installed_patterns_allxx #120907 greatly speeds search, improves hierarchy view.
  119. MISSINGDEPS_PATTERNS="`grep --file=/tmp/petget_installed_patterns_allxx -v /tmp/petget_subpkg_deps_patterns`"
  120. echo "$MISSINGDEPS_PATTERNS" >> /tmp/petget_missingpkgs_patterns2
  121. #w017 log a visual tree...
  122. MISSDEPSLIST="`echo "$MISSINGDEPS_PATTERNS" | sed -e 's%|%%g' | tr '\n' ' '`"
  123. case $ONELEVEL in
  124. 1) echo "$ONEDEP: $MISSDEPSLIST" >> /tmp/petget_deps_visualtreelog ;;
  125. 2) echo " $ONEDEP: $MISSDEPSLIST" >> /tmp/petget_deps_visualtreelog ;;
  126. 3) echo " $ONEDEP: $MISSDEPSLIST" >> /tmp/petget_deps_visualtreelog ;;
  127. 4) echo " $ONEDEP: $MISSDEPSLIST" >> /tmp/petget_deps_visualtreelog ;;
  128. 5) echo " $ONEDEP: $MISSDEPSLIST" >> /tmp/petget_deps_visualtreelog ;;
  129. 6) echo " $ONEDEP: $MISSDEPSLIST" >> /tmp/petget_deps_visualtreelog ;;
  130. 7) echo " $ONEDEP: $MISSDEPSLIST" >> /tmp/petget_deps_visualtreelog ;;
  131. 8) echo " $ONEDEP: $MISSDEPSLIST" >> /tmp/petget_deps_visualtreelog ;;
  132. 9) echo " $ONEDEP: $MISSDEPSLIST" >> /tmp/petget_deps_visualtreelog ;;
  133. 10) echo " $ONEDEP: $MISSDEPSLIST" >> /tmp/petget_deps_visualtreelog ;;
  134. 11) echo " $ONEDEP: $MISSDEPSLIST" >> /tmp/petget_deps_visualtreelog ;;
  135. esac
  136. break
  137. fi
  138. done
  139. done
  140. cp -f /tmp/petget_missingpkgs_patterns_acc /tmp/petget_missingpkgs_patterns_acc-prev #120907
  141. sort -u /tmp/petget_missingpkgs_patterns2 > /tmp/petget_missingpkgs_patternsx0
  142. grep -v '^$' /tmp/petget_missingpkgs_patternsx0 > /tmp/petget_missingpkgs_patternsx
  143. cat /tmp/petget_missingpkgs_patternsx >> /tmp/petget_missingpkgs_patterns_acc0 #accumulate them.
  144. sort -u /tmp/petget_missingpkgs_patterns_acc0 > /tmp/petget_missingpkgs_patterns_acc
  145. #120907 get out of loop when no more missing deps found...
  146. SIZE1=$(cat /tmp/petget_missingpkgs_patterns_acc-prev | wc -l)
  147. SIZE2=$(cat /tmp/petget_missingpkgs_patterns_acc | wc -l)
  148. [ $SIZE1 -eq $SIZE2 ] && break
  149. done
  150. pupkill $XXPID
  151. #120903 bring back the versioning info from level1 (/tmp/petget_missingpkgs_patterns_with_versioning is created in findmissingpkgs.sh)...
  152. #restore the format ex |abiword|gt3.4| becomes |abiword&gt3.4| ...
  153. grep -v --file=/tmp/petget_missingpkgs_patterns /tmp/petget_missingpkgs_patterns_acc > /tmp/petget_missingpkgs_patterns_accx #make sure that 2nd file does not have any level1 deps.
  154. mv -f /tmp/petget_missingpkgs_patterns_accx /tmp/petget_missingpkgs_patterns_acc
  155. sed -e 's%|%\&%g' -e 's%^\&%|%' -e 's%\&$%|%' /tmp/petget_missingpkgs_patterns_with_versioning >> /tmp/petget_missingpkgs_patterns_acc
  156. sort -u /tmp/petget_missingpkgs_patterns_acc > /tmp/petget_missingpkgs_patternsx
  157. mv -f /tmp/petget_missingpkgs_patternsx /tmp/petget_missingpkgs_patterns_and_versioning_level1
  158. #...be careful here, _with_versioning file has |abiword|gt3.4|, _and_versioning has |abiword&gt3.4| format.
  159. #...a limitation, only versioning of the "level 1" deps is being retained here.
  160. #now find the entries in the databases...
  161. rm -f /tmp/petget_missing_dbentries* 2>/dev/null
  162. #111107 01micko: fix for '||' messing things up...
  163. for depPATTERN in `grep '[a-zA-Z]' /tmp/petget_missingpkgs_patterns_and_versioning_level1` #ex depPATTERN=|kdelibs| ex2: |kdelibs&gt2.3.6|. 120221 jemimah. 120903 versioning.
  164. do
  165. #110722 separate out any versioning... (see also findmissingpkgs.sh)
  166. xdepPATTERN="`echo -n "$depPATTERN" | sed -e 's%&.*%|%'`" #ex: changes |kdelibs&gt2.3.6| to |kdelibs|
  167. depVERSIONING="`echo -n "$depPATTERN" | grep -o '&.*' | tr -d '|'`" #ex: &gt2.3.6
  168. if [ "$depVERSIONING" ];then
  169. #110822 similar code in support/findpkgs in woof...
  170. DEPCONDS="`echo -n "$depVERSIONING" | cut -f 2-9 -d '&' | tr '&' ' '`" #can have chained operators, ex: ge2.6.32 lt2.6.33
  171. fi
  172. depPATTERN="`echo -n "$xdepPATTERN" | sed -e 's%\\-%\\\\-%g'`" #backslash '-'. 120903 fix.
  173. for ONEREPODB in $DB_MAIN $DB_OTHERS
  174. do
  175. DBFILE="`basename $ONEREPODB`" #ex: Packages-slackware-12.2-official
  176. #find database entry(s) for this package...
  177. DB_ENTRIES="`cat $ONEREPODB | grep "$depPATTERN"`" #120903 more than one entry may have been found.
  178. if [ "$DB_ENTRIES" != "" ];then
  179. echo "$DB_ENTRIES" | #120903
  180. while read DB_ENTRY
  181. do
  182. DB_version="`echo -n "$DB_ENTRY" | cut -f 3 -d '|'`"
  183. if [ "$depVERSIONING" ];then #110722
  184. #110822 support chained operators...
  185. condFLG='good'
  186. for ACOND in $DEPCONDS #ex: gt5.6.7 lt6.7.8
  187. do
  188. DEPOP="`echo -n "$ACOND" | cut -c 1,2`"
  189. DEPVER="`echo -n "$ACOND" | cut -c 3-99`"
  190. if ! vercmp ${DB_version} ${DEPOP} ${DEPVER};then
  191. condFLG='bad'
  192. fi
  193. done
  194. if [ "$condFLG" = "good" ];then
  195. echo "$DB_ENTRY" >> /tmp/petget_missing_dbentries-${DBFILE}-2
  196. break 2
  197. fi
  198. else
  199. echo "$DB_ENTRY" >> /tmp/petget_missing_dbentries-${DBFILE}-2
  200. break 2
  201. fi
  202. done
  203. fi
  204. done
  205. done
  206. #clean them up...
  207. for ONEREPODB in $DB_MAIN $DB_OTHERS
  208. do
  209. DBFILE="`basename $ONEREPODB`" #ex: Packages-slackware-12.2-official
  210. if [ -f /tmp/petget_missing_dbentries-${DBFILE}-2 ];then
  211. sort -u /tmp/petget_missing_dbentries-${DBFILE}-2 > /tmp/petget_missing_dbentries-${DBFILE}
  212. rm -f /tmp/petget_missing_dbentries-${DBFILE}-2
  213. fi
  214. done
  215. kill $X1PID
  216. ###END###