debdb2pupdb.bac 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312
  1. REM (c) Copyright Barry Kauler 2012
  2. REM in woof, script 0setup downloads a debian/ubuntu pkg db file, then pre-formats it.
  3. REM the pre-formatted filename /tmp/woof-debdb.in is opened and read, and converted
  4. REM to Puppy db format on stdout.
  5. REM require pass compat-distro and compat-version on commandline. ex: ubuntu precise
  6. REM homepages get logged to /tmp/woof-homepages.acc
  7. REM 121111 first version.
  8. REM 121112 significant speedup, no longer call find_cat. loads categories.dat. 121113 tidy up.
  9. REM 121113 read Ubuntu-db 'Section' parameter to help assign category.
  10. REM 121113 last field of ubuntu pkg db cannot be guaranteed. introduce STARTMARKER (refer 0setup).
  11. REM 130126 no longer find category. find_cat is called afterward (see 0setup).
  12. REM 130221 forgot &gt deps case.
  13. REM 130225 awkward situation, "|" OR operator gets converted to a space back in prefiltering in 0setup.
  14. REM 130305 0setup creeates /tmp/0setupcompletelistpkgs, list of all pkgs in repo, all on one line.
  15. REM 130316 debdb2pupdb does not use /tmp/0setupcompletelistpkgs in a running puppy.
  16. REM 130512 vercmp failed this test: if vercmp 2.2.1 ge 2.2~2011week36; then echo 'greater'; fi
  17. REM declare an associative array, containing strings...
  18. DECLARE assocarray$ ASSOC STRING
  19. assocarray$("Description")=""
  20. assocarray$("Filename")=""
  21. assocarray$("Package")=""
  22. assocarray$("InstalledSize")=""
  23. assocarray$("Architecture")=""
  24. assocarray$("Version")=""
  25. assocarray$("Depends")=""
  26. assocarray$("Homepage")=""
  27. assocarray$("Section")=""
  28. assocarray$("STARTMARKER")=""
  29. endflag=0
  30. REM require pass compat-distro and compat-version on commandline...
  31. SPLIT ARGUMENT$ BY " " TO commandline$ SIZE dim0
  32. IF dim0 < 3 THEN END 1
  33. compatdistro$=commandline$[1]
  34. compatversion$=commandline$[2]
  35. test1=FILEEXISTS("/tmp/woof-debdb.in")
  36. IF test1 EQ 0 THEN END 1
  37. runningpuppy=0
  38. test2=FILEEXISTS("/tmp/0setupcompletelistpkgs")
  39. IF test2 EQ 0 THEN runningpuppy=1
  40. IF runningpuppy EQ 0 THEN
  41. REM open file with list of all pkgs, all on one line...
  42. OPEN "/tmp/0setupcompletelistpkgs" FOR READING AS completelistfile
  43. READLN completelist$ FROM completelistfile
  44. CLOSE FILE completelistfile
  45. OPEN "/tmp/0setupnewinvaliddeps" FOR WRITING AS newinvaliddepsfile
  46. ELSE
  47. REM created by debdb2pupdb in Woof, copied into rootfs-complete by 3builddistro...
  48. test2=FILEEXISTS("/usr/local/petget/invaliddepslist")
  49. IF test2 EQ 0 THEN END 1
  50. OPEN "/usr/local/petget/invaliddepslist" FOR READING AS invaliddepslistfile
  51. READLN invaliddepslist$ FROM invaliddepslistfile
  52. CLOSE FILE invaliddepslistfile
  53. END IF
  54. REM open a file to accumulate homepages...
  55. test1=FILEEXISTS("/tmp/woof-homepages.acc")
  56. IF test1 NE 0 THEN DELETE FILE "/tmp/woof-homepages.acc"
  57. OPEN "/tmp/woof-homepages.acc" FOR WRITING AS homepagesfile
  58. REM open intermediate input file (refer 0setup)...
  59. OPEN "/tmp/woof-debdb.in" FOR READING AS myfile
  60. WHILE NOT(ENDFILE(myfile)) DO
  61. READLN oneline$ FROM myfile
  62. IF NOT(ENDFILE(myfile)) THEN
  63. len0=LEN(oneline$)
  64. IF len0 EQ 0 THEN CONTINUE
  65. REM evaluate the line...
  66. SPLIT oneline$ BY "|" TO splitarray$ SIZE dimension
  67. onevariable$=splitarray$[0]
  68. onecontent$=""
  69. IF dimension >= 2 THEN onecontent$=splitarray$[1]
  70. assocarray$(onevariable$)=onecontent$
  71. REM 121113 hmmm, precise has some db's Homepage field last. introduce STARTMARKER...
  72. REM debian squeeze and earlier has Description field last, wheezy has Filename field last...
  73. IF onevariable$ = "STARTMARKER" THEN
  74. len2=LEN(assocarray$("Package"))
  75. IF len2 NE 0 THEN endflag=1
  76. END IF
  77. IF endflag = 1 THEN
  78. REM Filename ex: pool/main/f/firefox/abrowser-branding_11.0+build1-0ubuntu4_i386.deb
  79. len1=LEN(assocarray$("Filename"))
  80. IF len1 > 0 THEN
  81. pos1=INSTRREV(assocarray$("Filename"),"/")
  82. DB_fullfilename$=RIGHT$(assocarray$("Filename"),len1-pos1)
  83. DB_path$=LEFT$(assocarray$("Filename"),pos1-1)
  84. REM Version ex: 0.140
  85. REM Version ex: 1:2.0.10-1ubuntu3 <<<want to remove leading and trailing, to give: 2.0.10
  86. REM remove leading...
  87. revver1$=REVERSE$(assocarray$("Version"))
  88. pos1=REGEX(revver1$,":[0-9]$")
  89. IF pos1 = 0 THEN
  90. ver2$=assocarray$("Version")
  91. ELSE
  92. revver2$=LEFT$(revver1$,pos1-1)
  93. ver2$=REVERSE$(revver2$)
  94. END IF
  95. REM 130512 vercmp failed this test: if vercmp 2.2.1 ge 2.2~2011week36; then echo 'greater'; fi
  96. REM remove ~ char and all past it... see also same code for deps further down.
  97. pos1=REGEX(ver2$,"~")
  98. IF pos1 != 0 THEN
  99. ver2a$=LEFT$(ver2$,pos1-1)
  100. ver2$=ver2a$
  101. END IF
  102. REM remove trailing...
  103. REM note: could use compatdistro$ for improved efficiency...
  104. pos1=REGEX(ver2$,"\\-[0-9.]*ubuntu[0-9.]*$")
  105. IF pos1=0 THEN pos1=REGEX(ver2$,"\\+[0-9.]*ubuntu[0-9.]*$")
  106. IF pos1=0 THEN pos1=REGEX(ver2$,"\\-[0-9.]*debian[0-9.]*$")
  107. IF pos1=0 THEN pos1=REGEX(ver2$,"\\+[0-9.]*debian[0-9.]*$")
  108. IF pos1=0 THEN pos1=REGEX(ver2$,"\\-[0-9.]*raspbian[0-9.]*$")
  109. IF pos1=0 THEN pos1=REGEX(ver2$,"\\+[0-9.]*raspbian[0-9.]*$")
  110. IF pos1=0 THEN pos1=REGEX(ver2$,"\\-[0-9.]*build[0-9.]*$")
  111. IF pos1=0 THEN pos1=REGEX(ver2$,"\\+[0-9.]*build[0-9.]*$")
  112. IF pos1 = 0 THEN
  113. DB_version$=ver2$
  114. DB_pkgrelease$=""
  115. ELSE
  116. DB_version$=LEFT$(ver2$,pos1-1)
  117. len1=LEN(ver2$)
  118. DB_pkgrelease$=RIGHT$(ver2$,len1-pos1)
  119. END IF
  120. DB_nameonly$=assocarray$("Package")
  121. DB_pkgname$=CONCAT$(DB_nameonly$,"_",DB_version$)
  122. desc0$=assocarray$("Description")
  123. REM get rid of some chars that mess up find_cat (0setup already took out \t"|` ...
  124. desc1$=REPLACE$(desc0$,"'","")
  125. desc2$=REPLACE$(desc1$,"(","")
  126. desc3$=REPLACE$(desc2$,")","")
  127. desc4$=REPLACE$(desc3$,",","")
  128. DB_description$=desc4$
  129. REM find_cat is in Woof in support/find_cat, but this app must also execute in a running puppy when the PPM
  130. REM updates the DBs, in which case path is /usr/local/petget/find_cat -- always use latter.
  131. REM for debian, ubuntu, use the generic name provided in the DB_path$, instead of DB_nameonly$, for find_cat...
  132. len3=LEN(DB_path$)
  133. IF len3 EQ 0 THEN
  134. xPackage$=DB_nameonly$
  135. ELSE
  136. REM use the basename of the path...
  137. pos3=INSTRREV(DB_path$,"/")
  138. xPackage$=RIGHT$(DB_path$,len3-pos3)
  139. END IF
  140. REM previously had "find_cat" code in here.
  141. REM 121113 use Section as fallback. values found in ubuntu 'main' db:
  142. REM admin cli-mono comm database debug devel doc editors fonts games gnome graphics httpd interpreters introspection java kde kernel libdevel libs lisp localization mail math metapackages misc net ocaml oldlibs otherosfs perl php python ruby science shells sound tex text translations utils vcs video web x11 zope
  143. REM values found in ubuntu 'universe' db:
  144. REM universe/admin universe/cli-mono universe/comm universe/database universe/debug universe/devel universe/doc universe/editors universe/electronics universe/embedded universe/fonts universe/games universe/gnome universe/gnu-r universe/gnustep universe/graphics universe/hamradio universe/haskell universe/httpd universe/interpreters universe/introspection universe/java universe/kde universe/kernel universe/libdevel universe/libs universe/lisp universe/localization universe/mail universe/math universe/metapackages universe/misc universe/net universe/news universe/ocaml universe/oldlibs universe/otherosfs universe/perl universe/php universe/python universe/ruby universe/science universe/shells universe/sound universe/tex universe/text universe/utils universe/vcs universe/video universe/web universe/x11 universe/xfce universe/zope
  145. REM note, most of these so-called categories are not suitable for classifying into a menu structure.
  146. DB_category$=assocarray$("Section")
  147. REM ...these will get replaced by correct category in find_cat.
  148. REM Depends ex: firefox (>= 9.0)
  149. REM Depends ex: libc6 (>= 2.4), libdbus-1-3 (>= 1.0.2), libdbus-glib-1-2 (>= 0.88), libglib2.0-0 (>= 2.25.11), libpolkit-gobject-1-0 (>= 0.101), libaccountsservice0 (= 0.6.15-2ubuntu9), dbus
  150. REM Depends ex: x11-xserver-utils, acpid (>= 1.0.4-1ubuntu4), hdparm, lsb-base (>= 1.3-9ubuntu3), powermgmt-base, laptop-detect, dmidecode (>= 2.7-1), libc6 (>= 2.4), pm-utils, consolekit
  151. DB_dependencies$=""
  152. SPLIT assocarray$("Depends") BY "," TO deparray$ SIZE dimension5
  153. IF dimension5 > 0 THEN
  154. FOR cnt5 = 0 TO dimension5-1
  155. choppeddep0$=CHOP$(deparray$[cnt5])
  156. REM remove ")" and anything past it...
  157. pos7=INSTR(choppeddep0$,")")
  158. IF pos7 > 0 THEN choppeddep$=LEFT$(choppeddep0$,pos7-1)
  159. ELSE choppeddep$=choppeddep0$
  160. pos5=INSTR(choppeddep$," ")
  161. depver$=""
  162. IF pos5 EQ 0 THEN
  163. depname$=choppeddep$
  164. ELSE
  165. depname$=LEFT$(choppeddep$,pos5-1)
  166. len7=LEN(choppeddep$)
  167. IF len7 > pos5 THEN
  168. depver1$=RIGHT$(choppeddep$,len7-pos5)
  169. REM depver1$ ex: "(>= 1.15.4"
  170. SPLIT depver1$ BY " " TO depverarray$ SIZE dim1
  171. IF dim1 > 1 THEN
  172. SELECT depverarray$[0]
  173. CASE "(>="
  174. relation$="&ge"
  175. CASE "(<="
  176. relation$="&le"
  177. REM 130221 forgot this...
  178. CASE "(>>"
  179. relation$="&gt"
  180. CASE "(="
  181. relation$="&eq"
  182. DEFAULT
  183. relation$=""
  184. END SELECT
  185. REM 130225 awkward situation, "|" OR operator gets converted to a space back in prefiltering in 0setup, so
  186. REM an original: Depends: libc6 (>= 2.3.4), udev | makedev (>= 2.3.1-24)
  187. REM gets passed in here as: Depends|libc6 (>= 2.3.4), udev makedev (>= 2.3.1-24)
  188. IF relation$ = "" THEN
  189. depver$=""
  190. ELSE
  191. REM for compatibility with earlier, have to strip leading and trailing stuff...
  192. REM remove leading...
  193. revver1$=REVERSE$(depverarray$[1])
  194. pos1=REGEX(revver1$,":[0-9]$")
  195. IF pos1 = 0 THEN
  196. ver2$=depverarray$[1]
  197. ELSE
  198. revver2$=LEFT$(revver1$,pos1-1)
  199. ver2$=REVERSE$(revver2$)
  200. END IF
  201. REM 130512 vercmp failed this test: if vercmp 2.2.1 ge 2.2~2011week36; then echo 'greater'; fi
  202. REM remove ~ char and all past it...
  203. pos1=REGEX(ver2$,"~")
  204. IF pos1 != 0 THEN
  205. ver2a$=LEFT$(ver2$,pos1-1)
  206. ver2$=ver2a$
  207. END IF
  208. REM remove trailing...
  209. REM note: could use compatdistro$ for improved efficiency...
  210. pos1=REGEX(ver2$,"\\-[0-9.]*ubuntu[0-9.]*$")
  211. IF pos1=0 THEN pos1=REGEX(ver2$,"\\+[0-9.]*ubuntu[0-9.]*$")
  212. IF pos1=0 THEN pos1=REGEX(ver2$,"\\-[0-9.]*debian[0-9.]*$")
  213. IF pos1=0 THEN pos1=REGEX(ver2$,"\\+[0-9.]*debian[0-9.]*$")
  214. IF pos1=0 THEN pos1=REGEX(ver2$,"\\-[0-9.]*raspbian[0-9.]*$")
  215. IF pos1=0 THEN pos1=REGEX(ver2$,"\\+[0-9.]*raspbian[0-9.]*$")
  216. IF pos1=0 THEN pos1=REGEX(ver2$,"\\-[0-9.]*build[0-9.]*$")
  217. IF pos1=0 THEN pos1=REGEX(ver2$,"\\+[0-9.]*build[0-9.]*$")
  218. IF pos1 = 0 THEN
  219. ver2b$=ver2$
  220. ELSE
  221. ver2b$=LEFT$(ver2$,pos1-1)
  222. END IF
  223. depver$=CONCAT$(relation$,ver2b$)
  224. REM depver$ ex: "&ge2.15"
  225. END IF
  226. END IF
  227. END IF
  228. END IF
  229. len6=LEN(depname$)
  230. IF len6 NE 0 THEN
  231. REM 130305 check if dep exists...
  232. depptn$=CONCAT$(" ",depname$," ")
  233. IF runningpuppy EQ 0 THEN
  234. pkgoffset=INSTR(completelist$,depptn$)
  235. IF pkgoffset EQ 0 THEN
  236. WRITELN depname$ TO newinvaliddepsfile
  237. END IF
  238. ELSE
  239. REM a much smaller list, of invalid deps only...
  240. pkgoffset=ISFALSE(INSTR(invaliddepslist$,depptn$))
  241. END IF
  242. IF pkgoffset NE 0 THEN
  243. len5=LEN(DB_dependencies$)
  244. IF len5 EQ 0 THEN DB_dependencies$=CONCAT$(DB_dependencies$,"+",depname$,depver$)
  245. ELSE DB_dependencies$=CONCAT$(DB_dependencies$,",+",depname$,depver$)
  246. END IF
  247. END IF
  248. NEXT
  249. END IF
  250. DB_size$=assocarray$("InstalledSize")
  251. len9=LEN(DB_size$)
  252. IF len9 EQ 0 THEN DB_size$="0"
  253. REM screen out all debug pkgs...
  254. pos4=REGEX(DB_nameonly$,"\\-dbg$")
  255. IF pos4 EQ 0 THEN
  256. REM print puppy-format db line to stdout...
  257. PRINT DB_pkgname$,"|",DB_nameonly$,"|",DB_version$,"|",DB_pkgrelease$,"|",DB_category$,"|",DB_size$,"K|",DB_path$,"|",DB_fullfilename$,"|",DB_dependencies$,"|",DB_description$,"|",compatdistro$,"|",compatversion$,"|"
  258. END IF
  259. REM also accumulate the homepages...
  260. len9=LEN(assocarray$("Homepage"))
  261. REM IF len9 NE 0 THEN WRITELN DB_nameonly$," ",assocarray$("Homepage") TO homepagesfile
  262. REM xPackage$ is the base path, which is usually the generic name for this pkg...
  263. REM IF xPackage$ NE DB_nameonly$ THEN WRITELN xPackage$," ",assocarray$("Homepage") TO homepagesfile
  264. IF len9 NE 0 THEN WRITELN xPackage$," ",assocarray$("Homepage") TO homepagesfile
  265. END IF
  266. assocarray$("Description")=""
  267. assocarray$("Filename")=""
  268. assocarray$("Package")=""
  269. assocarray$("InstalledSize")=""
  270. assocarray$("Architecture")=""
  271. assocarray$("Version")=""
  272. assocarray$("Depends")=""
  273. assocarray$("Homepage")=""
  274. assocarray$("Section")=""
  275. assocarray$("STARTMARKER")=""
  276. endflag=0
  277. END IF
  278. ENDIF
  279. WEND
  280. CLOSE FILE myfile
  281. CLOSE FILE homepagesfile
  282. IF runningpuppy EQ 0 THEN CLOSE FILE newinvaliddepsfile