pkg_chooser.sh 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269
  1. #!/bin/bash
  2. #(c) Copyright Barry Kauler 2009, puppylinux.com
  3. #2009 Lesser GPL licence v2 (/usr/share/doc/legal/lgpl-2.1.txt).
  4. #The Puppy Package Manager main GUI window.
  5. #v424 reintroduce the 'ALL' category, for ppup build only.
  6. #v425 enable ENTER key for find box.
  7. #100116 add quirky repo at ibiblio. 100126: bugfixes.
  8. #100513 reintroduce the 'ALL' category for quirky (t2).
  9. #100903 handle puppy-wary5 repo.
  10. #100911 handle puppy-lucid repo.
  11. #101126 prevent 'puppy-quirky' radiobutton first for quirky 1.4 (based on wary5 pkgs).
  12. #101129 checkboxes for show EXE DEV DOC NLS.
  13. #101205 bugfix for: make sure first radiobutton matches list of pkgs.
  14. #110118 alternate User Interfaces. see also configure.sh.
  15. #110505 support sudo for non-root user.
  16. #110706 fix for deps checking.
  17. #120203 BK: internationalized.
  18. #120327 sometimes the selected repo radiobutton did not match listed packages at startup.
  19. #120504 /tmp/petget_filterversion renamed to /tmp/petget/current-repo-triad
  20. #120504 some files moved into /tmp/petget
  21. #120504b improved separation of dev,doc,nls,exe, enhanced ubuntu,debian pkg support.
  22. #120515 common code from pkg_chooser.sh, findnames.sh, filterpkgs.sh, extracted to /usr/local/petget/postfilterpkgs.sh.
  23. #120527 change gtkdialog3 to gtkdialog4. icon patterns for postfilterpkgs.sh.
  24. #120529 ui may show app thumbnail icons.
  25. #120603 /root/.packages/user-installed-packages missing at first boot.
  26. #120515 gentoo build.
  27. #120811 category field now supports sub-category |category;subcategory|, use as icon in ppm main window.
  28. #120822 in precise puppy have a pet 'cups' instead of the ubuntu debs. the latter are various pkgs, including 'libcups2'. we don't want libcups2 showing up as a missing dependency, so have to screen these alternative names out. see also findmissingpkgs.sh.
  29. #120831 simplify repos radiobuttons. fixes a bug, when make selection in setup wasn't same in main window.
  30. #120903 bugfix for 120831. 120905 fix window too wide.
  31. #121125 offer to download a Service Pack, if available.
  32. #130330 GUI filter. see also ui_Classic, ui_Ziggy, filterpkgs.sh.
  33. #130331 more GUI filter options. See also filterpkgs.sh.
  34. #130511 need to include devx-only-installed-packages, if loaded.
  35. /usr/local/petget/service_pack.sh & #121125 offer download Service Pack.
  36. export TEXTDOMAIN=petget___pkg_chooser.sh
  37. export OUTPUT_CHARSET=UTF-8
  38. [ "`whoami`" != "root" ] && exec sudo -A ${0} ${@} #110505
  39. mkdir -p /tmp/petget #120504
  40. mkdir -p /var/local/petget
  41. . /etc/DISTRO_SPECS #has DISTRO_BINARY_COMPAT, DISTRO_COMPAT_VERSION
  42. . /root/.packages/DISTRO_PKGS_SPECS
  43. . /root/.packages/PKGS_MANAGEMENT #has PKG_REPOS_ENABLED, PKG_NAME_ALIASES
  44. #120529 app icons
  45. touch /root/.packages/user-installed-packages #120603 missing at first boot.
  46. #101129 choose to display EXE, DEV, DOC, NLS pkgs... note, this code-block is also in findnames.sh and filterpkgs.sh...
  47. DEF_CHK_EXE='true'
  48. DEF_CHK_DEV='false'
  49. DEF_CHK_DOC='false'
  50. DEF_CHK_NLS='false'
  51. [ -e /var/local/petget/postfilter_EXE ] && DEF_CHK_EXE="`cat /var/local/petget/postfilter_EXE`"
  52. [ -e /var/local/petget/postfilter_DEV ] && DEF_CHK_DEV="`cat /var/local/petget/postfilter_DEV`"
  53. [ -e /var/local/petget/postfilter_DOC ] && DEF_CHK_DOC="`cat /var/local/petget/postfilter_DOC`"
  54. [ -e /var/local/petget/postfilter_NLS ] && DEF_CHK_NLS="`cat /var/local/petget/postfilter_NLS`"
  55. #120515 the script /usr/local/petget/postfilterpkgs.sh handles checkbox actions, is called from ui_Ziggy and ui_Classic.
  56. #finds all user-installed pkgs and formats ready for display...
  57. /usr/local/petget/finduserinstalledpkgs.sh #writes to /tmp/installedpkgs.results
  58. #130511 need to include devx-only-installed-packages, if loaded...
  59. #note, this code block also in check_deps.sh.
  60. if which gcc;then
  61. cp -f /root/.packages/woof-installed-packages /tmp/ppm-layers-installed-packages
  62. cat /root/.packages/devx-only-installed-packages >> /tmp/ppm-layers-installed-packages
  63. sort -u /tmp/ppm-layers-installed-packages > /root/.packages/layers-installed-packages
  64. else
  65. cp -f /root/.packages/woof-installed-packages /root/.packages/layers-installed-packages
  66. fi
  67. #100711 moved from findmissingpkgs.sh... 130511 rename woof-installed-packages to layers-installed-packages...
  68. if [ ! -f /tmp/petget_installed_patterns_system ];then
  69. INSTALLED_PATTERNS_SYS="`cat /root/.packages/layers-installed-packages | cut -f 2 -d '|' | sed -e 's%^%|%' -e 's%$%|%' -e 's%\\-%\\\\-%g'`"
  70. echo "$INSTALLED_PATTERNS_SYS" > /tmp/petget_installed_patterns_system
  71. #PKGS_SPECS_TABLE also has system-installed names, some of them are generic combinations of pkgs...
  72. INSTALLED_PATTERNS_GEN="`echo "$PKGS_SPECS_TABLE" | grep '^yes' | cut -f 2 -d '|' | sed -e 's%^%|%' -e 's%$%|%' -e 's%\\-%\\\\-%g'`"
  73. echo "$INSTALLED_PATTERNS_GEN" >> /tmp/petget_installed_patterns_system
  74. #120822 in precise puppy have a pet 'cups' instead of the ubuntu debs. the latter are various pkgs, including 'libcups2'.
  75. #we don't want libcups2 showing up as a missing dependency, so have to screen these alternative names out...
  76. case $DISTRO_BINARY_COMPAT in
  77. ubuntu|debian|raspbian)
  78. #for 'cups' pet, we want to create a pattern '/cups|' so can locate all debs with that DB_path entry '.../cups'
  79. INSTALLED_PTNS_PET="$(grep '\.pet|' /root/.packages/layers-installed-packages | cut -f 2 -d '|' | sed -e 's%^%/%' -e 's%$%|%' -e 's%\-%\\-%g')"
  80. if [ "$INSTALLED_PTNS_PET" != "/|" ];then
  81. echo "$INSTALLED_PTNS_PET" > /tmp/petget/installed_ptns_pet
  82. INSTALLED_ALT_NAMES="$(grep --no-filename -f /tmp/petget/installed_ptns_pet /root/.packages/Packages-${DISTRO_BINARY_COMPAT}-${DISTRO_COMPAT_VERSION}-* | cut -f 2 -d '|')"
  83. if [ "$INSTALLED_ALT_NAMES" ];then
  84. INSTALLED_ALT_PTNS="$(echo "$INSTALLED_ALT_NAMES" | sed -e 's%^%|%' -e 's%$%|%' -e 's%\-%\\-%g')"
  85. echo "$INSTALLED_ALT_PTNS" >> /tmp/petget_installed_patterns_system
  86. fi
  87. fi
  88. ;;
  89. esac
  90. sort -u /tmp/petget_installed_patterns_system > /tmp/petget_installed_patterns_systemx
  91. mv -f /tmp/petget_installed_patterns_systemx /tmp/petget_installed_patterns_system
  92. fi
  93. #100711 this code repeated in findmissingpkgs.sh...
  94. cp -f /tmp/petget_installed_patterns_system /tmp/petget_installed_patterns_all
  95. if [ -s /root/.packages/user-installed-packages ];then
  96. INSTALLED_PATTERNS_USER="`cat /root/.packages/user-installed-packages | cut -f 2 -d '|' | sed -e 's%^%|%' -e 's%$%|%' -e 's%\\-%\\\\-%g'`"
  97. echo "$INSTALLED_PATTERNS_USER" >> /tmp/petget_installed_patterns_all
  98. #120822 find alt names in compat-distro pkgs, for user-installed pets...
  99. case $DISTRO_BINARY_COMPAT in
  100. ubuntu|debian|raspbian)
  101. #120904 bugfix, was very slow...
  102. MODIF1=`stat --format=%Y /root/.packages/user-installed-packages` #seconds since epoch.
  103. MODIF2=0
  104. [ -f /var/local/petget/installed_alt_ptns_pet_user ] && MODIF2=`stat --format=%Y /var/local/petget/installed_alt_ptns_pet_user`
  105. if [ $MODIF1 -gt $MODIF2 ];then
  106. INSTALLED_PTNS_PET="$(grep '\.pet|' /root/.packages/user-installed-packages | cut -f 2 -d '|')"
  107. if [ "$INSTALLED_PTNS_PET" != "" ];then
  108. xINSTALLED_PTNS_PET="$(echo "$INSTALLED_PTNS_PET" | sed -e 's%^%/%' -e 's%$%|%' -e 's%\-%\\-%g')"
  109. echo "$xINSTALLED_PTNS_PET" > /tmp/petget/fmp_xipp1
  110. INSTALLED_ALT_NAMES="$(grep --no-filename -f /tmp/petget/fmp_xipp1 /root/.packages/Packages-${DISTRO_BINARY_COMPAT}-${DISTRO_COMPAT_VERSION}-* | cut -f 2 -d '|')"
  111. if [ "$INSTALLED_ALT_NAMES" ];then
  112. INSTALLED_ALT_PTNS="$(echo "$INSTALLED_ALT_NAMES" | sed -e 's%^%|%' -e 's%$%|%' -e 's%\-%\\-%g')"
  113. echo "$INSTALLED_ALT_PTNS" > /var/local/petget/installed_alt_ptns_pet_user
  114. echo "$INSTALLED_ALT_PTNS" >> /tmp/petget_installed_patterns_all
  115. fi
  116. fi
  117. touch /var/local/petget/installed_alt_ptns_pet_user
  118. else
  119. cat /var/local/petget/installed_alt_ptns_pet_user >> /tmp/petget_installed_patterns_all
  120. fi
  121. ;;
  122. esac
  123. fi
  124. #process name aliases into patterns (used in filterpkgs.sh, findmissingpkgs.sh) ... 100126...
  125. xPKG_NAME_ALIASES="`echo "$PKG_NAME_ALIASES" | tr ' ' '\n' | grep -v '^$' | sed -e 's%^%|%' -e 's%$%|%' -e 's%,%|,|%g' -e 's%\\*%.*%g'`"
  126. echo "$xPKG_NAME_ALIASES" > /tmp/petget_pkg_name_aliases_patterns_raw #110706
  127. cp -f /tmp/petget_pkg_name_aliases_patterns_raw /tmp/petget_pkg_name_aliases_patterns #110706 _raw see findmissingpkgs.sh.
  128. #100711 above has a problem as it has wildcards. need to expand...
  129. #ex: PKG_NAME_ALIASES has an entry 'cxxlibs,glibc*,libc-*', the above creates '|cxxlibs|,|glibc.*|,|libc\-.*|',
  130. # after expansion: '|cxxlibs|,|glibc|,|libc-|,|glibc|,|glibc_dev|,|glibc_locales|,|glibc-solibs|,|glibc-zoneinfo|'
  131. echo -n "" > /tmp/petget_pkg_name_aliases_patterns_expanded
  132. for ONEALIASLINE in `cat /tmp/petget_pkg_name_aliases_patterns | tr '\n' ' '` #ex: |cxxlibs|,|glibc.*|,|libc\-.*|
  133. do
  134. echo -n "" > /tmp/petget_temp1
  135. for PARTONELINE in `echo -n "$ONEALIASLINE" | tr ',' ' '`
  136. do
  137. grep "$PARTONELINE" /tmp/petget_installed_patterns_all >> /tmp/petget_temp1
  138. done
  139. ZZZ="`echo "$ONEALIASLINE" | sed -e 's%\.\*%%g' | tr -d '\\'`"
  140. [ -s /tmp/petget_temp1 ] && ZZZ="${ZZZ},`cat /tmp/petget_temp1 | tr '\n' ',' | tr -s ',' | tr -d '\\'`"
  141. ZZZ="`echo -n "$ZZZ" | sed -e 's%,$%%'`"
  142. echo "$ZZZ" >> /tmp/petget_pkg_name_aliases_patterns_expanded
  143. done
  144. cp -f /tmp/petget_pkg_name_aliases_patterns_expanded /tmp/petget_pkg_name_aliases_patterns
  145. #w480 PKG_NAME_IGNORE is definedin PKGS_MANAGEMENT file... 100126...
  146. xPKG_NAME_IGNORE="`echo "$PKG_NAME_IGNORE" | tr ' ' '\n' | grep -v '^$' | sed -e 's%^%|%' -e 's%$%|%' -e 's%,%|,|%g' -e 's%\\*%.*%g' -e 's%\-%\\-%g'`"
  147. echo "$xPKG_NAME_IGNORE" > /tmp/petget_pkg_name_ignore_patterns
  148. repocnt=0
  149. COMPAT_REPO=""
  150. COMPAT_DBS=""
  151. echo -n "" > /tmp/petget_active_repo_list
  152. #120831 simplify...
  153. REPOS_RADIO=""
  154. repocnt=0
  155. #sort with -puppy-* repos last...
  156. if [ "$DISTRO_BINARY_COMPAT" = "puppy" ];then
  157. aPRE="`echo -n "$PKG_REPOS_ENABLED" | tr ' ' '\n' | grep '\-puppy\-' | tr -s '\n' | tr '\n' ' '`"
  158. bPRE="`echo -n "$PKG_REPOS_ENABLED" | tr ' ' '\n' | grep -v '\-puppy\-' | tr -s '\n' | tr '\n' ' '`"
  159. else
  160. aPRE="`echo -n "$PKG_REPOS_ENABLED" | tr ' ' '\n' | grep -v '\-puppy\-' | tr -s '\n' | tr '\n' ' '`"
  161. bPRE="`echo -n "$PKG_REPOS_ENABLED" | tr ' ' '\n' | grep '\-puppy\-' | tr -s '\n' | tr '\n' ' '`"
  162. fi
  163. for ONEREPO in $aPRE $bPRE #ex: ' Packages-puppy-precise-official Packages-puppy-noarch-official Packages-ubuntu-precise-main Packages-ubuntu-precise-multiverse '
  164. do
  165. [ ! -f /root/.packages/$ONEREPO ] && continue
  166. REPOCUT="`echo -n "$ONEREPO" | cut -f 2-4 -d '-'`"
  167. [ "$REPOS_RADIO" = "" ] && FIRST_DB="$REPOCUT"
  168. xREPOCUT="$(echo -n "$REPOCUT" | sed -e 's%\-official$%%')" #120905 window too wide.
  169. REPOS_RADIO="${REPOS_RADIO}<radiobutton><label>${xREPOCUT}</label><action>/tmp/filterversion.sh ${REPOCUT}</action><action>/usr/local/petget/filterpkgs.sh</action><action>refresh:TREE1</action></radiobutton>"
  170. echo "$REPOCUT" >> /tmp/petget_active_repo_list #120903 needed in findnames.sh
  171. repocnt=`expr $repocnt + 1`
  172. #[ $repocnt -ge 5 ] && break # SFR: no limit
  173. done
  174. FILTER_CATEG="Desktop"
  175. #note, cannot initialise radio buttons in gtkdialog...
  176. echo "Desktop" > /tmp/petget_filtercategory #must start with Desktop.
  177. echo "$FIRST_DB" > /tmp/petget/current-repo-triad #ex: slackware-12.2-official
  178. if [ 0 -eq 1 ];then #w020 disable this choice.
  179. #filter pkgs by first letter, for more speed. must start with ab...
  180. echo "ab" > /tmp/petget_pkg_first_char
  181. FIRSTCHARS="
  182. <radiobutton><label>a,b</label><action>echo ab > /tmp/petget_pkg_first_char</action><action>/usr/local/petget/filterpkgs.sh</action><action>refresh:TREE1</action></radiobutton>
  183. <radiobutton><label>c,d</label><action>echo cd > /tmp/petget_pkg_first_char</action><action>/usr/local/petget/filterpkgs.sh</action><action>refresh:TREE1</action></radiobutton>
  184. <radiobutton><label>e,f</label><action>echo ef > /tmp/petget_pkg_first_char</action><action>/usr/local/petget/filterpkgs.sh</action><action>refresh:TREE1</action></radiobutton>
  185. <radiobutton><label>g,h</label><action>echo gh > /tmp/petget_pkg_first_char</action><action>/usr/local/petget/filterpkgs.sh</action><action>refresh:TREE1</action></radiobutton>
  186. <radiobutton><label>i,j</label><action>echo ij > /tmp/petget_pkg_first_char</action><action>/usr/local/petget/filterpkgs.sh</action><action>refresh:TREE1</action></radiobutton>
  187. <radiobutton><label>k,l</label><action>echo kl > /tmp/petget_pkg_first_char</action><action>/usr/local/petget/filterpkgs.sh</action><action>refresh:TREE1</action></radiobutton>
  188. <radiobutton><label>m,n</label><action>echo mn > /tmp/petget_pkg_first_char</action><action>/usr/local/petget/filterpkgs.sh</action><action>refresh:TREE1</action></radiobutton>
  189. <radiobutton><label>o,p</label><action>echo op > /tmp/petget_pkg_first_char</action><action>/usr/local/petget/filterpkgs.sh</action><action>refresh:TREE1</action></radiobutton>
  190. <radiobutton><label>q,r</label><action>echo qr > /tmp/petget_pkg_first_char</action><action>/usr/local/petget/filterpkgs.sh</action><action>refresh:TREE1</action></radiobutton>
  191. <radiobutton><label>s,t</label><action>echo st > /tmp/petget_pkg_first_char</action><action>/usr/local/petget/filterpkgs.sh</action><action>refresh:TREE1</action></radiobutton>
  192. <radiobutton><label>u,v</label><action>echo uv > /tmp/petget_pkg_first_char</action><action>/usr/local/petget/filterpkgs.sh</action><action>refresh:TREE1</action></radiobutton>
  193. <radiobutton><label>w,x</label><action>echo wx > /tmp/petget_pkg_first_char</action><action>/usr/local/petget/filterpkgs.sh</action><action>refresh:TREE1</action></radiobutton>
  194. <radiobutton><label>y,z</label><action>echo yz > /tmp/petget_pkg_first_char</action><action>/usr/local/petget/filterpkgs.sh</action><action>refresh:TREE1</action></radiobutton>
  195. <radiobutton><label>0-9</label><action>echo 0123456789 > /tmp/petget_pkg_first_char</action><action>/usr/local/petget/filterpkgs.sh</action><action>refresh:TREE1</action></radiobutton>
  196. <radiobutton><label>ALL</label><action>echo ALL > /tmp/petget_pkg_first_char</action><action>/usr/local/petget/filterpkgs.sh</action><action>refresh:TREE1</action></radiobutton>
  197. "
  198. xFIRSTCHARS="<hbox>
  199. ${FIRSTCHARS}
  200. </hbox>"
  201. else
  202. #do not dispay the alphabetic radiobuttons...
  203. echo "ALL" > /tmp/petget_pkg_first_char
  204. FIRSTCHARS=""
  205. xFIRSTCHARS=""
  206. fi
  207. #130330 GUI filtering. see also ui_Classic, ui_Ziggy, filterpkgs.sh ...
  208. GUIONLYSTR="$(gettext 'GUI apps only')"
  209. ANYTYPESTR="$(gettext 'Any type')"
  210. GUIEXCSTR="$(gettext 'GUI, not')" #130331 (look in ui_Classic, ui_Ziggy to see context)
  211. NONGUISTR="$(gettext 'Any non-GUI type')" #130331
  212. export GUIONLYSTR ANYTYPESTR GUIEXCSTR NONGUISTR #used in ui_classic and ui_ziggy
  213. [ ! -f /var/local/petget/gui_filter ] && echo -n "$ANYTYPESTR" > /var/local/petget/gui_filter # SFR: any type by default
  214. #finds pkgs in repository based on filter category and version and formats ready for display...
  215. /usr/local/petget/filterpkgs.sh $FILTER_CATEG #writes to /tmp/petget/filterpkgs.results
  216. echo '#!/bin/sh
  217. echo $1 > /tmp/petget/current-repo-triad
  218. ' > /tmp/filterversion.sh
  219. chmod 777 /tmp/filterversion.sh
  220. ALLCATEGORY=''
  221. if [ "$DISTRO_BINARY_COMPAT" = "puppy" ];then #v424 reintroduce the 'ALL' category.
  222. ALLCATEGORY="<radiobutton><label>$(gettext 'ALL')</label><action>/usr/local/petget/filterpkgs.sh ALL</action><action>refresh:TREE1</action></radiobutton>"
  223. fi
  224. #100513 also for 't2' (quirky) builds...
  225. if [ "$DISTRO_BINARY_COMPAT" = "t2" ];then #reintroduce the 'ALL' category.
  226. ALLCATEGORY="<radiobutton><label>$(gettext 'ALL')</label><action>/usr/local/petget/filterpkgs.sh ALL</action><action>refresh:TREE1</action></radiobutton>"
  227. fi
  228. #120515 ditto for gentoo build...
  229. if [ "$DISTRO_BINARY_COMPAT" = "gentoo" ];then #reintroduce the 'ALL' category.
  230. ALLCATEGORY="<radiobutton><label>$(gettext 'ALL')</label><action>/usr/local/petget/filterpkgs.sh ALL</action><action>refresh:TREE1</action></radiobutton>"
  231. fi
  232. DB_ORDERED="$REPOS_RADIO" #120831
  233. #110118 alternate User Interfaces...
  234. touch /var/local/petget/ui_choice
  235. UI="`cat /var/local/petget/ui_choice`"
  236. [ "$UI" = "" ] && UI="Classic"
  237. . /usr/local/petget/ui_${UI}
  238. RETPARAMS="`gtkdialog4 --program=MAIN_DIALOG`"
  239. #eval "$RETPARAMS"
  240. ###END###