createtbz 8.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182
  1. #!/bin/sh
  2. #(c) copyright Barry Kauler June 2012
  3. #i wrote another script 'createpackages' that extracts all of the binary pkgs out of a Gentoo distro.
  4. #(i had a sd card image for the raspi).
  5. #'createtbz' converts those binary pkgs to tar.bz2 and creates a db entry.
  6. . /etc/xdg/menus/hierarchy #has PUPHIERARCHY variable.
  7. CURRPATH="`pwd`"
  8. WOOF_HOSTARCH='x86'
  9. WOOF_TARGETARCH='arm'
  10. NLS='_NLS'
  11. EXE=''
  12. DEV='_DEV'
  13. DOC='_DOC'
  14. DB_compileddistro='gentoo'
  15. DB_compiledrelease='gap6' #"Gentoo Arm Puppy for armv6"
  16. DBFILE="Packages-${DB_compileddistro}-${DB_compiledrelease}-official"
  17. #paths ***SET THESE TO SUIT YOURSELF***
  18. BINDIR='0-armv6-gentoo-bin-pkgs' #location of the binary pkgs
  19. DESTDIR="packages-gentoo-gap6" #where the tar.bz2 pkgs are to be created.
  20. [ -d $DESTDIR ] && rm -rf packages-gentoo-gap6/*
  21. #TEMPLATES='packages-templates' #copy this dir out of woof, if running this script elsewhere.
  22. FIND_CAT='./find_cat' #copy this executable out of woof.
  23. [ ! -d $BINDIR ] && exit #sanity check.
  24. mkdir -p $DESTDIR
  25. echo -n "" > $DBFILE
  26. #db fields: pkgname|nameonly|version|pkgrelease|category|size|path|fullfilename|dependencies|description|compileddistro|compiledrelease|repo|
  27. for APKGNAME in `find ${BINDIR} -mindepth 1 -maxdepth 1 -type d | tr '\n' ' '`
  28. do
  29. baseAPKGNAME="`basename $APKGNAME`"
  30. echo "Processing $baseAPKGNAME"
  31. destAPKGNAME="`echo -n "$baseAPKGNAME" | tr '[A-Z]' '[a-z]'`" #ex: abiword-1.2.3-r1
  32. [ -d ${DESTDIR}/${destAPKGNAME} ] && destAPKGNAME="${destAPKGNAME}-SECOND" #precaution.
  33. [ -d ${DESTDIR}/${destAPKGNAME}-SECOND ] && destAPKGNAME="${destAPKGNAME}-THIRD" #precaution.
  34. cp -a -f $APKGNAME ${DESTDIR}/${destAPKGNAME}
  35. #rm -rf sandbox2/* 2>/dev/null
  36. #cp -a -f ${APKGNAME}/* sandbox2/
  37. sync
  38. NAMEONLY="$(echo -n "$destAPKGNAME" | sed -e 's%\-[0-9][0-9.\-].*%%')"
  39. vPTN="s%${NAMEONLY}\-%%"
  40. PKGVERSION="$(echo -n "$destAPKGNAME" | sed -e "$vPTN")"
  41. if [ ! "$PKGVERSION" ];then #destAPKGNAME=abiword-1 does not get split properly.
  42. NAMEONLY="$(echo -n "$destAPKGNAME" | sed -e 's%\-[0-9].*%%')"
  43. vPTN="s%${NAMEONLY}\-%%"
  44. PKGVERSION="$(echo -n "$destAPKGNAME" | sed -e "$vPTN")"
  45. fi
  46. GENERICNAME="$NAMEONLY"
  47. UPKGVERSION="$(echo -n "$PKGVERSION" | sed -e 's%\-r[0-9].*%%')" #ex: 2.3-r1 becomes 2.3
  48. if [ -f ${APKGNAME}/DESCRIPTION ];then
  49. DB_description="$(cat ${APKGNAME}/DESCRIPTION)"
  50. else
  51. DB_description='no description'
  52. fi
  53. DB_category="`${FIND_CAT} $NAMEONLY "$DB_description"`"
  54. #fix icon and category in .desktop file...
  55. #code from 2createpackages...
  56. DEFICON='Executable.xpm'
  57. CATEGORY="$DB_category"
  58. case $CATEGORY in
  59. Desktop) CATEGORY='Desktop;X-Desktop' ; DEFICON='mini.window3d.xpm' ;;
  60. System) CATEGORY='System' ; DEFICON='mini-term.xpm' ;;
  61. Setup) CATEGORY='Setup;X-SetupEntry' ; DEFICON='so.xpm' ;;
  62. Utility) CATEGORY='Utility' ; DEFICON='mini-hammer.xpm' ;;
  63. Filesystem) CATEGORY='Filesystem;FileSystem' ; DEFICON='mini-filemgr.xpm' ;;
  64. Graphic) CATEGORY='Graphic;Presentation' ; DEFICON='image_2.xpm' ;;
  65. Document) CATEGORY='Document;X-Document' ; DEFICON='mini-doc1.xpm' ;;
  66. Business) CATEGORY='Business;X-Calculate' ; DEFICON='mini-calc.xpm' ;; #110821 Calculate is old name, now Business.
  67. Personal) CATEGORY='Personal;X-Personal' ; DEFICON='mini-book2.xpm' ;;
  68. Network) CATEGORY='Network' ; DEFICON='pc-2x.xpm' ;;
  69. Internet) CATEGORY='Internet;X-Internet' ; DEFICON='pc2www.xpm' ;;
  70. Multimedia) CATEGORY='Multimedia;AudioVideo' ; DEFICON='Animation.xpm' ;;
  71. Fun) CATEGORY='Fun;Game' ; DEFICON='mini-maze.xpm' ;;
  72. Develop) CATEGORY='Utility' ; DEFICON='mini-hex.xpm' ;;
  73. Help) CATEGORY='Utility' ; DEFICON='info16.xpm' ;;
  74. esac
  75. cPATTERN="s%^Categories=.*%Categories=${CATEGORY}%"
  76. iPATTERN="s%^Icon=.*%Icon=${DEFICON}%"
  77. for ONEDESKTOP in `find ${DESTDIR}/${destAPKGNAME}/usr/share/applications ${DESTDIR}/${destAPKGNAME}/usr/local/share/applications -type f -name '*.desktop' 2>/dev/null | tr '\n' ' '`
  78. do
  79. #find if category is already valid...
  80. CATFOUND="no"
  81. for ONEORIGCAT in `cat $ONEDESKTOP | grep '^Categories=' | head -n 1 | cut -f 2 -d '=' | tr ';' ' '`
  82. do
  83. oocPATTERN=' '"$ONEORIGCAT"' '
  84. [ "`echo "$PUPHIERARCHY" | tr -s ' ' | cut -f 3 -d ' ' | tr ',' ' ' | sed -e 's%^% %' -e 's%$% %' | grep "$oocPATTERN"`" != "" ] && CATFOUND="yes"
  85. done
  86. if [ "$CATFOUND" = "no" ];then
  87. sed -e "$cPATTERN" $ONEDESKTOP > /tmp/2createpackages-tmp
  88. mv -f /tmp/2createpackages-tmp $ONEDESKTOP
  89. fi
  90. #does the icon exist?... fix .desktop...
  91. ICON="`grep '^Icon=' $ONEDESKTOP | cut -f 2 -d '='`"
  92. if [ "$ICON" != "" ];then
  93. [ -e "${DESTDIR}/${destAPKGNAME}${ICON}" ] && continue #it may have a hardcoded path.
  94. [ -e "${ICON}" ] && continue #it may have a hardcoded path, look in running puppy.
  95. ICONBASE="`basename "$ICON"`"
  96. #first search where jwm looks for icons... check if paths exist...
  97. FNDICON=""
  98. [ -d ${DESTDIR}/${destAPKGNAME}/usr/share/pixmaps ] && FNDICON="`find ${DESTDIR}/${destAPKGNAME}/usr/share/pixmaps -maxdepth 1 -name $ICONBASE -o -name $ICONBASE.png -o -name $ICONBASE.xpm -o -name $ICONBASE.jpg -o -name $ICONBASE.jpeg -o -name $ICONBASE.gif -o -name $ICONBASE.svg | grep -i -E 'png$|xpm$|jpg$|jpeg$|gif$|svg$' | head -n 1`"
  99. [ ! "$FNDICON" ] && [ -d ${DESTDIR}/${destAPKGNAME}/usr/local/lib/X11/mini-icons ] && FNDICON="`find ${DESTDIR}/${destAPKGNAME}/usr/local/lib/X11/mini-icons -maxdepth 1 -name $ICONBASE -o -name $ICONBASE.png -o -name $ICONBASE.xpm -o -name $ICONBASE.jpg -o -name $ICONBASE.jpeg -o -name $ICONBASE.gif -o -name $ICONBASE.svg | grep -i -E 'png$|xpm$|jpg$|jpeg$|gif$|svg$' | head -n 1`"
  100. if [ "$FNDICON" ];then
  101. ICONNAMEONLY="`basename $FNDICON`"
  102. iPTN="s%^Icon=.*%Icon=${ICONNAMEONLY}%"
  103. sed -i -e "$iPTN" $ONEDESKTOP
  104. continue
  105. else
  106. #look elsewhere, including in running puppy... fix for parole /usr/share/parole/parole.png...
  107. xPTN="s%${DESTDIR}/${destAPKGNAME}%%"
  108. FNDICON="`find ${DESTDIR}/${destAPKGNAME} /usr/share/icons /usr/local/share/pixmaps /usr/share/pixmaps -name $ICONBASE -o -name $ICONBASE.png -o -name $ICONBASE.xpm -o -name $ICONBASE.jpg -o -name $ICONBASE.jpeg -o -name $ICONBASE.gif -o -name $ICONBASE.svg | sed -e "${xPTN}" | grep -i -E 'png$|xpm$|jpg$|jpeg$|gif$|svg$' | head -n 1`"
  109. if [ "$FNDICON" ];then
  110. ICONNAMEONLY="`basename "$FNDICON"`"
  111. mkdir -p ${DESTDIR}/${destAPKGNAME}/usr/share/pixmaps
  112. ln -snf "$FNDICON" ${DESTDIR}/${destAPKGNAME}/usr/share/pixmaps/${ICONNAMEONLY}
  113. iPTN="s%^Icon=.*%Icon=${ICONNAMEONLY}%"
  114. sed -i -e "$iPTN" $ONEDESKTOP
  115. continue
  116. fi
  117. fi
  118. #substitute a default icon...
  119. sed -i -e "$iPATTERN" $ONEDESKTOP
  120. fi
  121. done
  122. #for each created dir, create 'pet.specs' db entry...
  123. if [ -f ${APKGNAME}/DEPEND ];then
  124. DB_dependencies="$(cat ${APKGNAME}/DEPEND | tr ' ' '\n' | rev | cut -f 1 -d '/' | rev | cut -f 1 -d ':' | cut -f 1 -d '[' | sed -e 's%\-[0-9][0-9.\-].*%%' -e 's%\-[0-9]$%%' -e 's%^%+%' | sed -e 's%$%,%' | sed -e '/^+[^a-zA-Z]/d' | sort -u | tr '\n' ' ' | tr -d ' ' | sed -e 's%,$%%' | tr '[A-Z]' '[a-z]')"
  125. else
  126. DB_dependencies=''
  127. fi
  128. #db fields: pkgname|nameonly|version|pkgrelease|category|size|path|fullfilename|dependencies|description|compileddistro|compiledrelease|repo|
  129. #if [ -d ${DESTDIR}/${destAPKGNAME} ];then
  130. DB_pkgname="${destAPKGNAME}"
  131. DB_nameonly="${NAMEONLY}"
  132. DB_version="${PKGVERSION}"
  133. DB_size="`du -k -s ${DESTDIR}/${DB_pkgname} | cut -f 1`"
  134. DB_fullfilename="${DB_pkgname}.tar.bz2"
  135. #echo "${DB_pkgname}|${DB_nameonly}|${DB_version}||${DB_category}|${DB_size}K||${DB_fullfilename}|${DB_dependencies}|${DB_description}|${DB_compileddistro}|${DB_compiledrelease}||" > ${DESTDIR}/${DB_pkgname}/pet.specs
  136. echo "${DB_pkgname}|${DB_nameonly}|${DB_version}||${DB_category}|${DB_size}K||${DB_fullfilename}|${DB_dependencies}|${DB_description}|${DB_compileddistro}|${DB_compiledrelease}||" >> $DBFILE
  137. DB_dependencies="+${NAMEONLY}"
  138. [ -f ${DESTDIR}/${DB_pkgname}/CATEGORY ] && rm -f ${DESTDIR}/${DB_pkgname}/CATEGORY
  139. [ -f ${DESTDIR}/${DB_pkgname}/DEPEND ] && rm -f ${DESTDIR}/${DB_pkgname}/DEPEND
  140. [ -f ${DESTDIR}/${DB_pkgname}/DESCRIPTION ] && rm -f ${DESTDIR}/${DB_pkgname}/DESCRIPTION
  141. [ -f ${DESTDIR}/${DB_pkgname}/RDEPEND ] && rm -f ${DESTDIR}/${DB_pkgname}/RDEPEND
  142. [ -f ${DESTDIR}/${DB_pkgname}/SIZE ] && rm -f ${DESTDIR}/${DB_pkgname}/SIZE
  143. #fi
  144. sync
  145. #create tarball...
  146. cd ${DESTDIR}
  147. [ ! -d ${destAPKGNAME} ] && exit #sanity check.
  148. cd ${destAPKGNAME}
  149. tar -c -f ../${destAPKGNAME}.tar *
  150. cd ..
  151. [ ! -f ${destAPKGNAME}.tar ] && exit #sanity check.
  152. bzip2 ${destAPKGNAME}.tar
  153. sync
  154. rm -rf ${destAPKGNAME}
  155. cd ..
  156. sleep 1
  157. done
  158. sort $DBFILE > /tmp/$DBFILE
  159. mv -f /tmp/$DBFILE $DBFILE
  160. sync
  161. echo "...finished"
  162. ###END###