fix-puppy-dbs 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301
  1. #!/bin/bash
  2. #(c) Copyright Barry Kauler June 2009
  3. #Woof has various Puppy db files, Packages-puppy-[2345]-official and one that is
  4. #for a specific compat-distro build -- for example, a compat-distro build based
  5. #on the Puppy 4.x series has file Packages-puppy-4xx-official (defined in DISTRO_PKGS_SPECS-puppy-4).
  6. #this script synchronises them all, including with the files at ibiblio.org...
  7. #111124 fix finding Packages-puppy-*-official.
  8. #111124 take out the 'clear', difficult to debug.
  9. #111129 recommend not update db files with online entries.
  10. #120315 ignore if repo db file not wanted.
  11. #121102 file DISTRO_SPECS has new variable DISTRO_DB_SUBNAME. ex: for 14.0-based slacko, DISTRO_DB_SUBNAME=slacko14
  12. #121102 pet db file not only, use local file only.
  13. #130306 fix arch linux build.
  14. #db entry format: pkgname|nameonly|version|pkgrelease|category|size|path|fullfilename|dependencies|description|
  15. #ex: abiword-1.2.4|abiword|1.2.4|5|Document|999K|slackware/ab|abiword-1.2.4-5-i486.tgz|+aiksausus,+gtk2|a nice wordprocessor|
  16. #optionally on the end: compileddistro|compiledrelease|repo| (fields 11,12,13)
  17. #ex: slackware|12.2|official|
  18. export LANG=C
  19. [ ! -f ./DISTRO_PET_REPOS ] && exit 1
  20. [ ! -f ./DISTRO_SPECS ] && exit 1
  21. #this script executed with current-directory the main woof dir...
  22. . ./DISTRO_SPECS #has DISTRO_BINARY_COMPAT, DISTRO_COMPAT_VERSION
  23. [ ! "$DISTRO_DB_SUBNAME" ] && DISTRO_DB_SUBNAME="$DISTRO_COMPAT_VERSION" #121102 fallback if DISTRO_DB_SUBNAME not defined in file DISTRO_SPECS.
  24. if [ -f ./DISTRO_PKGS_SPECS-${DISTRO_BINARY_COMPAT}-${DISTRO_COMPAT_VERSION} ];then #w478
  25. . ./DISTRO_PKGS_SPECS-${DISTRO_BINARY_COMPAT}-${DISTRO_COMPAT_VERSION} #has FALLBACKS_COMPAT_VERSIONS
  26. else
  27. . ./DISTRO_PKGS_SPECS-${DISTRO_BINARY_COMPAT} #has FALLBACKS_COMPAT_VERSIONS
  28. fi
  29. . ./DISTRO_PET_REPOS #has PET_REPOS, PACKAGELISTS_PET_ORDER, PKG_DOCS_PET_REPOS
  30. if [ -f ./DISTRO_COMPAT_REPOS-${DISTRO_BINARY_COMPAT}-${DISTRO_COMPAT_VERSION} ];then #w091017
  31. . ./DISTRO_COMPAT_REPOS-${DISTRO_BINARY_COMPAT}-${DISTRO_COMPAT_VERSION}
  32. else
  33. . ./DISTRO_COMPAT_REPOS-${DISTRO_BINARY_COMPAT} #130306
  34. fi
  35. #find out if internet working...
  36. INTERNETWKG="no"
  37. PETREPO="`echo "$PKG_DOCS_PET_REPOS" | tr ' ' '\n' | head -n 1`"
  38. ONE_PET_SITE="`echo -n "$PETREPO" | cut -f 1 -d '|'`"
  39. [ "`wget -t 2 -T 30 --waitretry=20 --spider -S $ONE_PET_SITE -o /dev/stdout 2>/dev/null | grep '200 OK'`" != "" ] && INTERNETWKG="yes"
  40. if [ "$INTERNETWKG" = "no" ];then
  41. echo
  42. echo "Internet not working, so cannot check the Packages-puppy-* files with files at $REPOSITE"
  43. echo "Continuing with local checking only..."
  44. else
  45. #internet connected, check each of Packages-puppy-[2345]-official local against same file at ibiblio...
  46. #111124 fix...
  47. for ONEREPO in `find . -mindepth 1 -maxdepth 1 -name 'Packages-puppy-*-official' | rev | cut -f 1 -d '/' | rev | tr '\n' ' '`
  48. do
  49. REMOTEREPO="`echo "$PKG_DOCS_PET_REPOS" | tr ' ' '\n' | grep "$ONEREPO" | head -n 1 | cut -f 2 -d '|'`"
  50. if [ "$REMOTEREPO" = "" ];then
  51. #echo
  52. #echo "ERROR: an entry for $ONEREPO does not exist in variable PKG_DOCS_PET_REPOS"
  53. #echo "(in file DISTRO_PET_REPOS). Fix it. Quiting."
  54. #exit 1
  55. continue #120315 not an error. just not interested in this db file.
  56. else
  57. echo
  58. echo "Downloading ${ONEREPO}..."
  59. wget --output-document=remotedbfile $REMOTEREPO
  60. if [ $? -ne 0 ];then
  61. if [ -f ./$ONEREPO ];then #121102
  62. echo
  63. echo "ERROR downloading ${ONEREPO}, using local file only."
  64. echo -n "Press ENTER to continue: "
  65. read keepgoing
  66. continue
  67. else
  68. echo
  69. echo "ERROR downloading ${ONEREPO}, quiting."
  70. exit 1
  71. fi
  72. fi
  73. DBDIFFS="`diff $ONEREPO remotedbfile`"
  74. if [ "$DBDIFFS" = "" ];then
  75. echo "...files are the same."
  76. continue
  77. else
  78. NEWREMOTEPKGS="`echo "$DBDIFFS" | grep '^> ' | sed -e 's%^> %%'`"
  79. if [ "$NEWREMOTEPKGS" != "" ];then
  80. echo; echo #clear #echo
  81. echo "The remote $ONEREPO file has these new entries:"
  82. echo -e -n "\\033[1;31m" #red
  83. echo "$NEWREMOTEPKGS"
  84. echo -e -n "\\033[0;39m" #back to black.
  85. echo
  86. echo "Press any printable char then ENTER only to append these to local $ONEREPO"
  87. echo "or press ENTER only to ignore them. If using Woof for first time,"
  88. echo "recommend press ENTER only. Online files modified by other developers"
  89. echo "may introduce unexpected effects to a build."
  90. echo -n "Recommend press ENTER only: "
  91. read ignorethem
  92. if [ "$ignorethem" != "" ];then #111129 reverse logic.
  93. echo "...adding new packages."
  94. echo "$NEWREMOTEPKGS" >> $ONEREPO
  95. fi
  96. fi
  97. NEWLOCALPKGS="`echo "$DBDIFFS" | grep '^< ' | sed -e 's%^< %%'`"
  98. if [ "$NEWLOCALPKGS" != "" ];then
  99. echo; echo #clear #echo
  100. echo "WARNING, local $ONEREPO has these entries that are"
  101. echo "not in the remote db file:"
  102. echo -e -n "\\033[1;31m" #red
  103. echo "$NEWLOCALPKGS"
  104. echo -e -n "\\033[0;39m" #back to black.
  105. echo
  106. echo "...this is a matter for the system admin of remote site."
  107. echo "Note, this script will also check availability of pkgs on remote site and"
  108. echo "optionally delete invalid entries in local $ONEREPO"
  109. echo -n "Press ENTER to continue: "
  110. read keepongoing
  111. fi
  112. fi
  113. rm -f remotedbfile
  114. fi
  115. done
  116. #also check that pkgs actually exist at ibiblio...
  117. echo; echo #clear #echo
  118. echo "Press any printable char to check if PET pkgs in local db files"
  119. echo "actually exist on Internet host site."
  120. echo "WARNING: THIS TAKES A LONG TIME, RECOMMEND BYPASS"
  121. echo -n "or ENTER only to bypass check: "
  122. read dotheyexist
  123. if [ "$dotheyexist" != "" ];then
  124. for ONEREPO in `find . -mindepth 1 -maxdepth 1 -name 'Packages-puppy-*-official' | rev | cut -f 1 -d '/' | rev | tr '\n' ' '`
  125. do
  126. REMOTEURL="`echo "$PKG_DOCS_PET_REPOS" | tr ' ' '\n' | grep "$ONEREPO" | head -n 1 | cut -f 2 -d '|' | rev | cut -f 2-9 -d '/' | rev`"
  127. LOCALPKGS="`cat $ONEREPO`"
  128. echo "$LOCALPKGS" |
  129. while read ONELOCALPKG
  130. do
  131. SUBDIRECTORY="`echo -n "$ONELOCALPKG" | cut -f 7 -d '|'`"
  132. FULLPKGNAME="`echo -n "$ONELOCALPKG" | cut -f 8 -d '|'`"
  133. wget -t 2 -T 20 --waitretry=20 --spider ${REMOTEURL}/${SUBDIRECTORY}/${FULLPKGNAME}
  134. if [ $? -ne 0 ];then
  135. echo; echo #clear #echo
  136. echo -e -n "\\033[1;31m" #red
  137. echo "WARNING, $FULLPKGNAME does not exist at $REMOTEURL"
  138. echo -e -n "\\033[0;39m" #back to black.
  139. echo "This may be ok if you have it locally and want to use it, but it may be"
  140. echo "an old discarded pkg and you might want to delete it from local db file."
  141. echo "Press ENTER only to delete it from local $ONEREPO"
  142. echo "or press 'x' then ENTER to abort this checking,"
  143. echo -n "or any other printable char to keep entry: "
  144. read keepit </dev/tty
  145. [ "$keepit" = "x" ] && break
  146. if [ "$keepit" = "" ];then
  147. echo "...deleting $FULLPKGNAME entry."
  148. fpnPATTERN='|'"$FULLPKGNAME"'|'
  149. grep -v "$fpnPATTERN" $ONEREPO > /tmp/${ONEREPO}-tmp
  150. mv -f /tmp/${ONEREPO}-tmp $ONEREPO
  151. fi
  152. fi
  153. done
  154. done
  155. fi
  156. fi
  157. #120804 the code below doesn't seem to be relevant anymore...
  158. exit ###EXIT HERE###
  159. #the files that have compatible-distro pkg docs (these were downloaded by 0setup)...
  160. PKGLISTS_COMPAT="`echo "$PKG_DOCS_DISTRO_COMPAT" | tr ' ' '\n' | cut -f 3 -d '|' | tr '\n' ' ' | sed -e 's% $%%'`" #see file DISTRO_PKGS_SPECS-ubuntu
  161. #...format Upup ex: 'Packages-ubuntu-intrepid-main Packages-ubuntu-intrepid-universe'
  162. #...Ppup ex: 'Packages-puppy-4xx-official'
  163. PUP_PKGLIST_COMPAT=""
  164. if [ "$DISTRO_BINARY_COMPAT" = "puppy" ];then
  165. num_pkglists_compat=`echo -n "$PKGLISTS_COMPAT" | wc -w`
  166. if [ $num_pkglists_compat -eq 1 ];then
  167. PUP_PKGLIST_COMPAT="$PKGLISTS_COMPAT"
  168. #the compat-distro is a version of puppy, and we are building from file $PUP_PKGLIST_COMPAT
  169. #ex: Packages-puppy-4xx-official
  170. #make sure that entries tally with the other Packages-puppy-[2345]-official files...
  171. echo
  172. echo "Synchronising $PUP_PKGLIST_COMPAT with other Packages-puppy-[2345]-official files..."
  173. echo "Note, $PUP_PKGLIST_COMPAT is the package db file used to build Puppy."
  174. xPUP_PKGLIST_COMPAT="`cat $PUP_PKGLIST_COMPAT`"
  175. echo "$xPUP_PKGLIST_COMPAT" |
  176. while read ONEENTRY
  177. do
  178. [ "$ONEENTRY" = "" ] && continue #precaution.
  179. #decide which Packages-puppy-[2345]-official to check against...
  180. CHECKWITH=""
  181. ONEHOSTENV="`echo -n "$ONEENTRY" | cut -f 11 -d '|'`" #ex: 'puppy'
  182. ONEHOSTREL="`echo -n "$ONEENTRY" | cut -f 12 -d '|'`" #ex: '4'
  183. if [ "$ONEHOSTENV" != "" ];then
  184. if [ "$ONEHOSTREL" != "" ];then
  185. CHECKWITH="Packages-${ONEHOSTENV}-${ONEHOSTREL}-official"
  186. else
  187. CHECKWITH="Packages-${ONEHOSTENV}-${DISTRO_COMPAT_VERSION}-official"
  188. fi
  189. if [ ! -f $CHECKWITH ];then
  190. echo
  191. echo "ERROR in fields 11 and/or 12 of this db entry in ${PUP_PKGLIST_COMPAT}:"
  192. echo "$ONEENTRY"
  193. echo -n "You need to fix it, quiting."
  194. exit 1
  195. fi
  196. fi
  197. [ "$CHECKWITH" = "" ] && CHECKWITH="Packages-${DISTRO_BINARY_COMPAT}-${DISTRO_COMPAT_VERSION}-official" #ex: Packages-puppy-4-official
  198. #ex: entry in Packages-puppy-4xx-official not exist in Packages-puppy-4-official then copy it across...
  199. ONEPKGNAME="`echo -n "$ONEENTRY" | cut -f 1 -d '|'`"
  200. ONENAMEONLY="`echo -n "$ONEENTRY" | cut -f 2 -d '|'`"
  201. opnPATTERN='^'"$ONEPKGNAME"'|'
  202. onoPATTERN='|'"$ONENAMEONLY"'|'
  203. checkpkgnameexist="`grep "$opnPATTERN" $CHECKWITH`"
  204. checknameonlyexist="`grep "$onoPATTERN" $CHECKWITH`"
  205. if [ "$checkpkgnameexist" = "" ];then
  206. if [ "$checknameonlyexist" = "" ];then
  207. echo; echo #clear #echo
  208. echo "Note, $PUP_PKGLIST_COMPAT is the package db file used to build Puppy."
  209. echo
  210. echo "This entry in ${PUP_PKGLIST_COMPAT} does not exist in ${CHECKWITH}:"
  211. cutONEENTRY="`echo -n "$ONEENTRY" | cut -c 1-76`"'...'
  212. echo -e -n "\\033[1;31m" #red
  213. echo "$cutONEENTRY"
  214. echo -e -n "\\033[0;39m"
  215. echo
  216. echo "If this is a valid entry, just press ENTER to copy it across."
  217. echo "If this is now an invalid entry, pkg no longer available, press any other"
  218. echo -n "printable key then ENTER: "
  219. read WAITFORIT </dev/tty
  220. if [ "$WAITFORIT" = "" ];then
  221. echo "...appending to $CHECKWITH"
  222. echo "$ONEENTRY" >> $CHECKWITH
  223. else
  224. echo "...removing entry from $PUP_PKGLIST_COMPAT"
  225. grep -v "$opnPATTERN" $PUP_PKGLIST_COMPAT > /tmp/pup_pkglist_compat-tmp
  226. mv -f /tmp/pup_pkglist_compat-tmp $PUP_PKGLIST_COMPAT
  227. fi
  228. else
  229. echo; echo #clear #echo
  230. echo "Note, $PUP_PKGLIST_COMPAT is the package db file used to build Puppy."
  231. echo
  232. echo "This entry in ${PUP_PKGLIST_COMPAT} does not exist in ${CHECKWITH}:"
  233. cutONEENTRY="`echo -n "$ONEENTRY" | cut -c 1-76`"'...'
  234. echo -e -n "\\033[1;31m" #red
  235. echo -n "$cutONEENTRY"
  236. echo -e "\\033[0;39m"
  237. echo
  238. echo "If this is a valid entry, just press ENTER to copy it across."
  239. echo
  240. echo "However, ${CHECKWITH} already has these alternate versions: "
  241. CNT=1
  242. echo -en "\\033[1;31m" #red
  243. echo "$checknameonlyexist" |
  244. while read ONECHECK
  245. do
  246. cutONECHECK="`echo -n "$ONECHECK" | cut -c 1-73`"'...'
  247. echo "$CNT $cutONECHECK"
  248. CNT=`expr $CNT + 1`
  249. done
  250. echo -n -e "\\033[0;39m" #back to black.
  251. echo
  252. echo "Or, if you want to update ${PUP_PKGLIST_COMPAT}"
  253. echo -n "with one of these alternatives, type a number: "
  254. read CHOOSEALTPKG </dev/tty
  255. if [ "$CHOOSEALTPKG" = "" ];then
  256. echo "...appending to $CHECKWITH"
  257. echo "$ONEENTRY" >> $CHECKWITH
  258. else
  259. if [ "`echo -n "$CHOOSEALTPKG" | grep '^[0-9]$'`" = "" ];then
  260. echo "ERROR, '${CHOOSEALTPKG}' is not a valid number, ignoring"
  261. continue
  262. fi
  263. ALTENTRY="`echo "$checknameonlyexist" | head -n $CHOOSEALTPKG | tail -n 1`"
  264. echo "...updating entry in $PUP_PKGLIST_COMPAT from $CHECKWITH"
  265. grep -v "$opnPATTERN" $PUP_PKGLIST_COMPAT > /tmp/pup_pkglist_compat-tmp
  266. mv -f /tmp/pup_pkglist_compat-tmp $PUP_PKGLIST_COMPAT
  267. echo "$ALTENTRY" >> $PUP_PKGLIST_COMPAT
  268. sort --key=1 --field-separator="|" $PUP_PKGLIST_COMPAT > /tmp/${PUP_PKGLIST_COMPAT}-tmp
  269. mv -f /tmp/${PUP_PKGLIST_COMPAT}-tmp $PUP_PKGLIST_COMPAT
  270. fi
  271. fi
  272. sort --key=1 --field-separator="|" $CHECKWITH > /tmp/${CHECKWITH}-tmp
  273. mv -f /tmp/${CHECKWITH}-tmp $CHECKWITH
  274. continue
  275. fi
  276. done
  277. fi
  278. fi
  279. ###END###