findnames.sh 9.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171
  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. SEARCH_REPOS_FLAG=$1
  39. if [ "$(cat /var/local/petget/ui_choice 2>/dev/null)" = "Classic" ]; then
  40. #120504 ask which repos...
  41. export ASKREPO_DIALOG="<window title=\"$(gettext 'PPM: search')\" icon-name=\"gtk-about\">
  42. <vbox>
  43. <frame $(gettext 'Search only current repository')>
  44. <hbox>
  45. <text><label>\"${CURRENTREPO}\"</label></text>
  46. <vbox>
  47. <button><label>$(gettext 'Search')</label><action type=\"exit\">BUTTON_SEARCH_CURRENT</action></button>
  48. </vbox>
  49. </hbox>
  50. </frame>
  51. <frame $(gettext 'Search all repositories')>
  52. <hbox>
  53. <text><label>\"${ALLACTIVEREPOS}\"</label></text>
  54. <vbox>
  55. <button><label>$(gettext 'Search')</label><action type=\"exit\">BUTTON_SEARCH_ALL</action></button>
  56. </vbox>
  57. </hbox>
  58. </frame>
  59. </vbox>
  60. </window>
  61. "
  62. RETPARAMS="`gtkdialog --center --program=ASKREPO_DIALOG`"
  63. eval "$RETPARAMS"
  64. [ "$EXIT" != "BUTTON_SEARCH_CURRENT" -a "$EXIT" != "BUTTON_SEARCH_ALL" ] && exit
  65. SEARCH_REPOS_FLAG="current"
  66. [ "$EXIT" = "BUTTON_SEARCH_ALL" ] && SEARCH_REPOS_FLAG="all"
  67. fi
  68. if [ "$SEARCH_REPOS_FLAG" = "current" ];then #120504
  69. REPOLIST="$CURRENTREPO"
  70. else
  71. REPOLIST="`echo "$ALLACTIVEREPOS" | tr '\n' ' '`"
  72. fi
  73. FNDIT=no
  74. echo -n "" > /tmp/petget/filterpkgs.results
  75. for ONEREPO in $REPOLIST
  76. do
  77. #120908 need version field (#3)...
  78. #120827 need nameonly field (#2)...
  79. #120811 need category field (#5), and subcategory part of it...
  80. #120504 Mavrothal:
  81. if [ "$entryPATTERN4" != "" ]; then
  82. 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
  83. elif [ "$entryPATTERN3" != "" ]; then
  84. FNDENTRIES="`cat /root/.packages/Packages-${ONEREPO} | cut -f1,2,3,5,10 -d \| | grep -i "$entryPATTERN1" | grep -i "$entryPATTERN2" | grep -i "$entryPATTERN3"`" #120827
  85. elif [ "$entryPATTERN2" != "" ]; then
  86. FNDENTRIES="`cat /root/.packages/Packages-${ONEREPO} | cut -f1,2,3,5,10 -d \| | grep -i "$entryPATTERN1" | grep -i "$entryPATTERN2"`" #120827
  87. else
  88. FNDENTRIES="`cat /root/.packages/Packages-${ONEREPO} | cut -f1,2,3,5,10 -d \| | grep -i "$entryPATTERN1"`" #120827
  89. fi
  90. if [ "$FNDENTRIES" ];then
  91. # FIRSTCHAR="`echo "$FNDENTRIES" | cut -c 1 | tr '\n' ' ' | sed -e 's% %%g'`"
  92. # #write these just in case needed...
  93. # ALPHAPRE="`cat /tmp/petget_pkg_first_char`"
  94. #this is read when update TREE1 in pkg_chooser.sh...
  95. #echo "$FNDENTRIES" | cut -f 1,10 -d '|' > /tmp/petget/filterpkgs.results
  96. repoPTN="s%$%|${ONEREPO}|%" #note, '|' on the end also, needed below by printcols.
  97. FPR="`echo "$FNDENTRIES" | sed "$repoPTN"`"
  98. if [ "$FPR" = "|${ONEREPO}" ];then
  99. echo -n "" > /tmp/petget/filterpkgs.results #nothing.
  100. else
  101. echo "$FPR" >> /tmp/petget/filterpkgs.results #120504 append repo-triad each line.
  102. fi
  103. FNDIT=yes
  104. #120504 break
  105. fi
  106. done
  107. #110530 ignore packages with different kernel version number, format -k2.6.32.28- in pkg name...
  108. if [ "$FNDIT" = "yes" ];then
  109. GOODKERNPTN="`uname -r | sed -e 's%\.%\\\.%g' -e 's%^%\\\-k%' -e 's%$%$%'`" #ex: \-k2.6.32$
  110. 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\-
  111. if [ "$BADKERNPTNS" ];then
  112. echo "$BADKERNPTNS" >> /tmp/petget_badkernptns
  113. grep -v -f /tmp/petget_badkernptns /tmp/petget/filterpkgs.results > /tmp/petget/filterpkgs.resultsxxx
  114. mv -f /tmp/petget/filterpkgs.resultsxxx /tmp/petget/filterpkgs.results
  115. fi
  116. fi
  117. if [ "$FNDIT" = "no" ];then
  118. #120909 these files may have been created at previous search, it will upset show_installed_version_diffs.sh if still exist...
  119. [ -f /tmp/petget/filterpkgs.results.installed ] && rm -f /tmp/petget/filterpkgs.results.installed
  120. [ -f /tmp/petget/filterpkgs.results.notinstalled ] && rm -f /tmp/petget/filterpkgs.results.notinstalled
  121. /usr/lib/gtkdialog/box_ok "$(gettext 'PPM package search')" find.svg "$(gettext 'Sorry, no matching package name')"
  122. else
  123. #120827 search may find pkgs that are already installed...
  124. if [ -f /tmp/petget_installed_patterns_all ];then #precaution.
  125. grep -f /tmp/petget_installed_patterns_all -v /tmp/petget/filterpkgs.results > /tmp/petget/filterpkgs.results.notinstalled
  126. grep -f /tmp/petget_installed_patterns_all /tmp/petget/filterpkgs.results > /tmp/petget/filterpkgs.results.installed
  127. cp -f /tmp/petget/filterpkgs.results.notinstalled /tmp/petget/filterpkgs.results
  128. if [ -s /tmp/petget/filterpkgs.results.installed ];then
  129. #change category field to "complete" (display /usr/share/icons/hicolor/scalable/status/complete.svg)...
  130. #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|
  131. sed -e 's%|%ONEPIPECHAR%' -e 's%|%ONEPIPECHAR%' -e 's%|[^|]*%|complete%' -e 's%|complete|%|complete|(ALREADY INSTALLED) %' -e 's%ONEPIPECHAR%|%g' /tmp/petget/filterpkgs.results.installed >> /tmp/petget/filterpkgs.results
  132. #ex: xserver-xorg-video-radeon_6.14.99|xserver-xorg-video-radeon|6.14.99|complete|(ALREADY INSTALLED) X.Org X server -- AMD/ATI Radeon display driver|puppy-noarch-official|
  133. fi
  134. fi
  135. #remove field #2, so file is same as generated by filterpkgs.sh, and as expected by postfilterpkgs.sh... 120908 remove #3...
  136. cut -f 1,4,5,6,7 -d '|' /tmp/petget/filterpkgs.results > /tmp/petget/filterpkgs.results1 #note, retain | on end.
  137. mv -f /tmp/petget/filterpkgs.results1 /tmp/petget/filterpkgs.results
  138. #120515 post-filter /tmp/petget/filterpkgs.results.post according to EXE,DEV,DOC,NLS checkboxes...
  139. /usr/local/petget/postfilterpkgs.sh
  140. #...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).
  141. #120529 hiccup, filterpkgs.results.post may now have icon name appended each line, but filterpkgs.results.post-noicons is backup (created by postfilterpkgs.sh)
  142. #120504 post-process presentation to show which repo...
  143. #filterpkgs.results.post each line has package-name|description|repo-triad
  144. #when we have searched multiple repos, move repo-triad into description field, so that it will show up on main window...
  145. if [ "$SEARCH_REPOS_FLAG" = "all" ];then
  146. #creates descript field like: "[puppy-4-official] Abiword word processor"
  147. #note, printcols (see support/printcols.c in Woof) needs a '|' on the end to work.
  148. #120811 format in /tmp/petget/filterpkgs.results.post now: pkgname|subcategory|description|dbfile,
  149. # ex: htop-0.9-i486|System|View Running Processes|puppy-wary5-official (previously was: pkgname|description|dbfile)
  150. 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%|%'`"
  151. echo "$POSTPROCLIST" > /tmp/petget/filterpkgs.results.post
  152. #ex line: abiword-1.2.3|[puppy-4-official] Abiword word processor|puppy-4-official|
  153. fi
  154. fi