rationalize_categories 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. #!/bin/sh
  2. #Barry Kauler, Oct 2010
  3. #3builddistro to call this.
  4. #there is a problem with packages, say abiword, abiword_DEV, abiword_DOC, abiword_NLS
  5. #maybe each being in a different category. see info:
  6. #puppy package database format:
  7. #pkgname|nameonly|version|pkgrelease|category|size|path|fullfilename|dependencies|description|compileddistro|compiledrelease|repo|
  8. #...'compileddistro|compiledrelease' (fields 11,12) identify where the package was compiled.
  9. #in the PPM it is better if they are grouped in same category.
  10. #120812 db category now allows optional subcategory (for which an icons exists in /usr/local/lib/X11/mini-icons).
  11. #ie: pkgname|nameonly|version|pkgrelease|category[;category]|size|path|fullfilename|dependencies|description|compileddistro|compiledrelease|repo|
  12. #ex: before:
  13. #homebank-4.3-w5|homebank|4.3-w5||Business|604K||homebank-4.3-w5.pet|+gtk+|HomeBank finance management|puppy|wary5||
  14. #homebank_DOC-4.3-w5|homebank_DOC|4.3-w5||BuildingBlock|1892K||homebank_DOC-4.3-w5.pet||personal finance||||
  15. #homebank_NLS-4.3-w5|homebank_NLS|4.3-w5||BuildingBlock|1972K||homebank_NLS-4.3-w5.pet|+homebank|personal finance||||
  16. #after:
  17. #homebank-4.3-w5|homebank|4.3-w5||Business|604K||homebank-4.3-w5.pet|+gtk+|HomeBank finance management|puppy|wary5||
  18. #homebank_DOC-4.3-w5|homebank_DOC|4.3-w5||Business|1892K||homebank_DOC-4.3-w5.pet||personal finance||||
  19. #homebank_NLS-4.3-w5|homebank_NLS|4.3-w5||Business|1972K||homebank_NLS-4.3-w5.pet|+homebank|personal finance||||
  20. [ ! $1 ] && exit 1
  21. DBFILE="$1" #ex: Packages-puppy-wary5-official
  22. [ ! -f $DBFILE ] && exit 1
  23. echo -n '' > /tmp/rationalized_categories
  24. echo "Rationalizing categories in ${DBFILE}, please wait..."
  25. cat $DBFILE |
  26. while read ONEDBENTRY
  27. do
  28. ENTRYfixed="$ONEDBENTRY"
  29. DB_nameonly="`echo -n "$ONEDBENTRY" | cut -f 2 -d '|'`"
  30. if [ "`echo -n "$DB_nameonly" | grep -E '_DEV|_DOC|_NLS'`" = "" ];then
  31. DB_category="`echo -n "$ONEDBENTRY" | cut -f 5 -d '|' | cut -f 1 -d ';'`" #120812
  32. nameonlyref="$DB_nameonly"
  33. else
  34. #big assumption that these are listed in db afterward...
  35. nameonlybase="`echo -n "$DB_nameonly" | rev | cut -c 5-999 | rev`" #remove the '_DEV' part.
  36. #echo "nameonlyref=$nameonlyref nameonlybase=$nameonlybase" #TEST
  37. if [ "$nameonlybase" = "$nameonlyref" ];then
  38. ENTRYfixed="`echo -n "$ONEDBENTRY" | tr '|' '\n' | head -n 4 | tr '\n' '|'`"
  39. ENTRYfixed="${ENTRYfixed}${DB_category}|"
  40. ENTRYfixed="${ENTRYfixed}`echo -n "$ONEDBENTRY" | tr '|' '\n' | tail -n +6 | tr '\n' '|'`"
  41. fi
  42. fi
  43. echo "$ENTRYfixed" >> /tmp/rationalized_categories
  44. done
  45. exit 0
  46. ###END###