findnames.sh 9.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168
  1. #!/bin/sh
  2. #(c) Copyright Barry Kauler 2009, puppylinux.com
  3. #2009 Lesser GPL licence v2 (http://www.fsf.org/licensing/licenses/lgpl.html).
  4. #called from /usr/local/petget/pkg_chooser.sh
  5. # ENTRY1 is a string, to search for a package.
  6. #101129 checkboxes for show EXE DEV DOC NLS. fixed some search bugs.
  7. #110223 run message as separate process.
  8. #110530 ignore packages with different kernel version number, format -k2.6.32.28- in pkg name (also filterpkgs.sh)...
  9. #120203 BK: internationalized.
  10. #120323 replace 'xmessage' with 'pupmessage'.
  11. #120410 Mavrothal: fix "getext" typo.
  12. #120504 Mavrothal: search with multiple keywords, both pkg name and description.
  13. #120504 some files moved into /tmp/petget
  14. #120515 common code from pkg_chooser.sh, findnames.sh, filterpkgs.sh, extracted to /usr/local/petget/postfilterpkgs.sh.
  15. #120529 fix if icon name appended each line.
  16. #120811 category field now supports sub-category |category;subcategory|, use as icon in ppm main window.
  17. #120819 fix for 120811.
  18. #120827 search may find pkgs that are already installed, mark with mini-tick icon.
  19. #120908 need version field. (used in show_installed_version_diffs.sh). 120909 bug fix.
  20. #puppy package database format:
  21. #pkgname|nameonly|version|pkgrelease|category|size|path|fullfilename|dependencies|description|compileddistro|compiledrelease|repo|
  22. #...'compileddistro|compiledrelease' (fields 11,12) identify where the package was compiled.
  23. export TEXTDOMAIN=petget___findnames.sh
  24. export OUTPUT_CHARSET=UTF-8
  25. . /etc/DISTRO_SPECS #has DISTRO_BINARY_COMPAT, DISTRO_COMPAT_VERSION
  26. . /root/.packages/DISTRO_PKGS_SPECS #has PKGS_SPECS_TABLE.
  27. . /root/.packages/DISTRO_PET_REPOS #has PET_REPOS, PACKAGELISTS_PET_ORDER
  28. #120504 Mavrothal:
  29. if [ "$ENTRY1" = "" ] ; then
  30. exit 0
  31. fi
  32. entryPATTERN1="`echo -n "$ENTRY1" | sed -e 's%\\-%\\\\-%g' -e 's%\\.%\\\\.%g' -e 's%\\*%.*%g' | awk '{print $1}'`"
  33. entryPATTERN2="`echo -n "$ENTRY1" | sed -e 's%\\-%\\\\-%g' -e 's%\\.%\\\\.%g' -e 's%\\*%.*%g' | awk '{print $2}'`"
  34. entryPATTERN3="`echo -n "$ENTRY1" | sed -e 's%\\-%\\\\-%g' -e 's%\\.%\\\\.%g' -e 's%\\*%.*%g' | awk '{print $3}'`"
  35. entryPATTERN4="`echo -n "$ENTRY1" | sed -e 's%\\-%\\\\-%g' -e 's%\\.%\\\\.%g' -e 's%\\*%.*%g' | awk '{print $4}'`"
  36. CURRENTREPO="`cat /tmp/petget/current-repo-triad`" #search here first.
  37. ALLACTIVEREPOS="`cat /tmp/petget_active_repo_list`"
  38. #120504 ask which repos...
  39. export ASKREPO_DIALOG="<window title=\"$(gettext 'PPM: search')\" icon-name=\"gtk-about\">
  40. <vbox>
  41. <frame $(gettext 'Search only current repository')>
  42. <hbox>
  43. <text><label>\"${CURRENTREPO}\"</label></text>
  44. <vbox>
  45. <button><label>$(gettext 'Search')</label><action type=\"exit\">BUTTON_SEARCH_CURRENT</action></button>
  46. </vbox>
  47. </hbox>
  48. </frame>
  49. <frame $(gettext 'Search all repositories')>
  50. <hbox>
  51. <text><label>\"${ALLACTIVEREPOS}\"</label></text>
  52. <vbox>
  53. <button><label>$(gettext 'Search')</label><action type=\"exit\">BUTTON_SEARCH_ALL</action></button>
  54. </vbox>
  55. </hbox>
  56. </frame>
  57. </vbox>
  58. </window>
  59. "
  60. RETPARAMS="`gtkdialog4 --center --program=ASKREPO_DIALOG`"
  61. eval "$RETPARAMS"
  62. [ "$EXIT" != "BUTTON_SEARCH_CURRENT" -a "$EXIT" != "BUTTON_SEARCH_ALL" ] && exit
  63. SEARCH_REPOS_FLAG="current"
  64. [ "$EXIT" = "BUTTON_SEARCH_ALL" ] && SEARCH_REPOS_FLAG="all"
  65. if [ "$SEARCH_REPOS_FLAG" = "current" ];then #120504
  66. REPOLIST="$CURRENTREPO"
  67. else
  68. REPOLIST="`echo "$ALLACTIVEREPOS" | tr '\n' ' '`"
  69. fi
  70. FNDIT=no
  71. echo -n "" > /tmp/petget/filterpkgs.results
  72. for ONEREPO in $REPOLIST
  73. do
  74. #120908 need version field (#3)...
  75. #120827 need nameonly field (#2)...
  76. #120811 need category field (#5), and subcategory part of it...
  77. #120504 Mavrothal:
  78. if [ "$entryPATTERN4" != "" ]; then
  79. FNDENTRIES="`cat /root/.packages/Packages-${ONEREPO} | cut -f1,2,3,5,10 -d \| | grep -i "$entryPATTERN1" | grep -i "$entryPATTERN2" | grep -i "$entryPATTERN3" | grep -i "$entryPATTERN4"`" #120827
  80. elif [ "$entryPATTERN3" != "" ]; then
  81. FNDENTRIES="`cat /root/.packages/Packages-${ONEREPO} | cut -f1,2,3,5,10 -d \| | grep -i "$entryPATTERN1" | grep -i "$entryPATTERN2" | grep -i "$entryPATTERN3"`" #120827
  82. elif [ "$entryPATTERN2" != "" ]; then
  83. FNDENTRIES="`cat /root/.packages/Packages-${ONEREPO} | cut -f1,2,3,5,10 -d \| | grep -i "$entryPATTERN1" | grep -i "$entryPATTERN2"`" #120827
  84. else
  85. FNDENTRIES="`cat /root/.packages/Packages-${ONEREPO} | cut -f1,2,3,5,10 -d \| | grep -i "$entryPATTERN1"`" #120827
  86. fi
  87. if [ "$FNDENTRIES" != "" ];then
  88. FIRSTCHAR="`echo "$FNDENTRIES" | cut -c 1 | tr '\n' ' ' | sed -e 's% %%g'`"
  89. #write these just in case needed...
  90. ALPHAPRE="`cat /tmp/petget_pkg_first_char`"
  91. #this is read when update TREE1 in pkg_chooser.sh...
  92. #echo "$FNDENTRIES" | cut -f 1,10 -d '|' > /tmp/petget/filterpkgs.results
  93. repoPTN="s%$%|${ONEREPO}|%" #note, '|' on the end also, needed below by printcols.
  94. FPR="`echo "$FNDENTRIES" | sed "$repoPTN"`"
  95. if [ "$FPR" = "|${ONEREPO}" ];then
  96. echo -n "" > /tmp/petget/filterpkgs.results #nothing.
  97. else
  98. echo "$FPR" >> /tmp/petget/filterpkgs.results #120504 append repo-triad each line.
  99. fi
  100. FNDIT=yes
  101. #120504 break
  102. fi
  103. done
  104. #110530 ignore packages with different kernel version number, format -k2.6.32.28- in pkg name...
  105. if [ "$FNDIT" = "yes" ];then
  106. GOODKERNPTN="`uname -r | sed -e 's%\.%\\\.%g' -e 's%^%\\\-k%' -e 's%$%$%'`" #ex: \-k2.6.32$
  107. BADKERNPTNS="`grep -o '\-k2\.6\.[^-|a-zA-Z]*' /tmp/petget/filterpkgs.results | cut -f 1 -d '|' | grep -v "$GOODKERNPTN" | sed -e 's%$%-%' -e 's%\.%\\\.%g' -e 's%\-%\\\-%g'`" #ex: \-k2\.6\.32\.28\-
  108. if [ "$BADKERNPTNS" ];then
  109. echo "$BADKERNPTNS" >> /tmp/petget_badkernptns
  110. grep -v -f /tmp/petget_badkernptns /tmp/petget/filterpkgs.results > /tmp/petget/filterpkgs.resultsxxx
  111. mv -f /tmp/petget/filterpkgs.resultsxxx /tmp/petget/filterpkgs.results
  112. fi
  113. fi
  114. if [ "$FNDIT" = "no" ];then
  115. #120909 these files may have been created at previous search, it will upset show_installed_version_diffs.sh if still exist...
  116. [ -f /tmp/petget/filterpkgs.results.installed ] && rm -f /tmp/petget/filterpkgs.results.installed
  117. [ -f /tmp/petget/filterpkgs.results.notinstalled ] && rm -f /tmp/petget/filterpkgs.results.notinstalled
  118. pupmessage -bg red -center -title "$(gettext 'PPM find')" "$(gettext 'Sorry, no matching package name')" & #110223 run as separate process.
  119. else
  120. #120827 search may find pkgs that are already installed...
  121. if [ -f /tmp/petget_installed_patterns_all ];then #precaution.
  122. grep -f /tmp/petget_installed_patterns_all -v /tmp/petget/filterpkgs.results > /tmp/petget/filterpkgs.results.notinstalled
  123. grep -f /tmp/petget_installed_patterns_all /tmp/petget/filterpkgs.results > /tmp/petget/filterpkgs.results.installed
  124. cp -f /tmp/petget/filterpkgs.results.notinstalled /tmp/petget/filterpkgs.results
  125. if [ -s /tmp/petget/filterpkgs.results.installed ];then
  126. #change category field to "tick" (postfilerpkgs.sh converts this to "mini-tick", which will display /usr/local/lib/X11/mini-icons/mini-tick.xpm)...
  127. #120908 now have version field (in field #3), ex: xserver-xorg-video-radeon_6.14.99|xserver-xorg-video-radeon|6.14.99|BuildingBlock|X.Org X server -- AMD/ATI Radeon display driver|puppy-noarch-official|
  128. sed -e 's%|%ONEPIPECHAR%' -e 's%|%ONEPIPECHAR%' -e 's%|[^|]*%|tick%' -e 's%|tick|%|tick|(ALREADY INSTALLED) %' -e 's%ONEPIPECHAR%|%g' /tmp/petget/filterpkgs.results.installed >> /tmp/petget/filterpkgs.results
  129. #ex: xserver-xorg-video-radeon_6.14.99|xserver-xorg-video-radeon|6.14.99|tick|(ALREADY INSTALLED) X.Org X server -- AMD/ATI Radeon display driver|puppy-noarch-official|
  130. fi
  131. fi
  132. #remove field #2, so file is same as generated by filterpkgs.sh, and as expected by postfilterpkgs.sh... 120908 remove #3...
  133. cut -f 1,4,5,6,7 -d '|' /tmp/petget/filterpkgs.results > /tmp/petget/filterpkgs.results1 #note, retain | on end.
  134. mv -f /tmp/petget/filterpkgs.results1 /tmp/petget/filterpkgs.results
  135. #120515 post-filter /tmp/petget/filterpkgs.results.post according to EXE,DEV,DOC,NLS checkboxes...
  136. /usr/local/petget/postfilterpkgs.sh
  137. #...main gui will read /tmp/petget/filterpkgs.results.post (actually that happens in ui_Classic or ui_Ziggy, which is included in pkg_chooser.sh).
  138. #120529 hiccup, filterpkgs.results.post may now have icon name appended each line, but filterpkgs.results.post-noicons is backup (created by postfilterpkgs.sh)
  139. #120504 post-process presentation to show which repo...
  140. #filterpkgs.results.post each line has package-name|description|repo-triad
  141. #when we have searched multiple repos, move repo-triad into description field, so that it will show up on main window...
  142. if [ "$SEARCH_REPOS_FLAG" = "all" ];then
  143. #creates descript field like: "[puppy-4-official] Abiword word processor"
  144. #note, printcols (see support/printcols.c in Woof) needs a '|' on the end to work.
  145. #120811 format in /tmp/petget/filterpkgs.results.post now: pkgname|subcategory|description|dbfile,
  146. # ex: htop-0.9-i486|System|View Running Processes|puppy-wary5-official (previously was: pkgname|description|dbfile)
  147. POSTPROCLIST="`printcols /tmp/petget/filterpkgs.results.post 1 2 4 3 4 | sed -e 's%|%FIRSTBARCHAR%' -e 's%|%SECBARCHAR[%' -e 's%|%] %' -e 's%FIRSTBARCHAR%|%' -e 's%SECBARCHAR%|%'`"
  148. echo "$POSTPROCLIST" > /tmp/petget/filterpkgs.results.post
  149. #ex line: abiword-1.2.3|[puppy-4-official] Abiword word processor|puppy-4-official|
  150. fi
  151. fi