4 # Copyright (C) 2000-2010 PLD-Team <feedback@pld-linux.org>
6 # Sebastian Zagrodzki <zagrodzki@pld-linux.org>
7 # Jacek Konieczny <jajcus@pld-linux.org>
8 # Andrzej Krzysztofowicz <ankry@pld-linux.org>
9 # Jakub Bogusz <qboosh@pld-linux.org>
10 # Elan Ruusamäe <glen@pld-linux.org>
12 # See cvs log pldnotify.awk for list of contributors
15 # - "SourceXDownload" support (use given URLs if present instead of cut-down SourceX URLs)
16 # - "SourceXActiveFTP" support
17 # - support debian/watch http://wiki.debian.org/debian/watch/
25 # print strftime("%Y-%m-%d %H:%M:%S ") s >> "/dev/stderr"
26 print s >> "/dev/stderr"
29 function fixedsub(s1,s2,t, ind) {
30 # substitutes fixed strings (not regexps)
31 if (ind = index(t,s1)) {
32 t = substr(t, 1, ind-1) s2 substr(t, ind+length(s1))
38 if ((s~"pre")||(s~"PRE")||(s~"beta")||(s~"BETA")||(s~"alpha")||(s~"ALPHA")||(s~"rc")||(s~"RC")) {
46 function compare_ver(v1,v2) {
47 # compares version numbers
48 while (match(v1,/[a-zA-Z][0-9]|[0-9][a-zA-Z]/))
49 v1=(substr(v1,1,RSTART) "." substr(v1,RSTART+RLENGTH-1))
50 while (match(v2,/[a-zA-Z][0-9]|[0-9][a-zA-Z]/))
51 v2=(substr(v2,1,RSTART) "." substr(v2,RSTART+RLENGTH-1))
58 count=split(v1,v1a,"\.")
59 count2=split(v2,v2a,"\.")
61 if (count<count2) mincount=count
64 for (i=1; i<=mincount; i++) {
65 if (v1a[i]=="") v1a[i]=0
66 if (v2a[i]=="") v2a[i]=0
70 if ((v1a[i]~/[0-9]/)&&(v2a[i]~/[0-9]/)) {
71 if (length(v2a[i])>length(v1a[i]))
73 else if (v2a[i]>v1a[i])
75 else if (length(v1a[i])>length(v2a[i]))
77 else if (v1a[i]>v2a[i])
79 } else if ((v1a[i]~/[A-Za-z]/)&&(v2a[i]~/[A-Za-z]/)) {
82 else if (v1a[i]>v2a[i])
84 } else if (ispre(v1a[i]) == 1)
89 if ((count2==mincount)&&(count!=count2)) {
90 for (i=count2+1; i<=count; i++)
91 if (ispre(v1a[i]) == 1)
94 } else if (count!=count2) {
95 for (i=count+1; i<=count2; i++)
96 if (ispre(v2a[i]) == 1)
103 function compare_ver_dec(v1,v2) {
104 # compares version numbers as decimal floats
105 while (match(v1,/[0-9][a-zA-Z]/))
106 v1=(substr(v1,1,RSTART) "." substr(v1,RSTART+RLENGTH-1))
107 while (match(v2,/[0-9][a-zA-Z]/))
108 v2=(substr(v2,1,RSTART) "." substr(v2,RSTART+RLENGTH-1))
113 count=split(v1,v1a,"\.")
114 count2=split(v2,v2a,"\.")
116 if (count<count2) mincount=count
119 for (i=1; i<=mincount; i++) {
120 if (v1a[i]=="") v1a[i]=0
121 if (v2a[i]=="") v2a[i]=0
123 d("v1[i] == " v1a[i])
124 d("v2[i] == " v2a[i])
125 if ((v1a[i]~/[0-9]/)&&(v2a[i]~/[0-9]/)) {
127 if (0+("." v2a[i])>0+("." v1a[i]))
129 else if (0+("." v1a[i])>0+("." v2a[i]))
132 if (length(v2a[i])>length(v1a[i]))
134 else if (v2a[i]>v1a[i])
136 else if (length(v1a[i])>length(v2a[i]))
138 else if (v1a[i]>v2a[i])
141 } else if ((v1a[i]~/[A-Za-z]/)&&(v2a[i]~/[A-Za-z]/)) {
144 else if (v1a[i]>v2a[i])
146 } else if (ispre(v1a[i]) == 1)
151 if ((count2==mincount)&&(count!=count2)) {
152 for (i=count2+1; i<=count; i++)
153 if (ispre(v1a[i]) == 1)
156 } else if (count!=count2) {
157 for (i=count+1; i<=count2; i++)
158 if (ispre(v2a[i]) == 1)
165 function link_seen(link) {
166 for (seenlink in frameseen) {
167 if (seenlink == link) {
168 d("Link: [" link "] seen already, skipping...")
176 function mktemp( _cmd, _tmpfile) {
177 _cmd = "mktemp /tmp/XXXXXX"
178 _cmd | getline _tmpfile
183 # fix link to artificial one that will be recognized rest of this script
184 function postfix_link(url, link, oldlink) {
186 if ((url ~/^(http|https):\/\/github.com\//) && (link ~ /.*\/tarball\//)) {
187 gsub(".*\/tarball\/", "", link)
188 link = link ".tar.gz"
190 if (oldlink != link) {
191 d("POST FIXED URL [ " oldlink " ] to [ " link " ]")
196 # use perl HTML::TreeBuilder module to extract links from html
197 # it returns TAGNAME LINK in output which is pretty stright forward to parse in awk
198 function extract_links_cmd(tmpfile) {
199 return "perl -MHTML::TreeBuilder -e ' \
200 my $content = join q//, <>; \
201 my $root = new HTML::TreeBuilder; \
202 $root->parse($content); \
205 for (@{$root->extract_links(qw(a iframe))}) { \
206 my($link, $element, $attr, $tag) = @$_; \
207 $links{$link} = $tag; \
210 while (my($link, $tag) = each %links) { \
211 print $tag, q/ /, $link, $/; \
216 # get all <A HREF=..> tags from specified URL
217 function get_links(url,filename, errno,link,oneline,retval,odp,wholeodp,lowerodp,tmpfile,cmd) {
222 tmpfileerr = mktemp()
224 if (url ~ /^http:\/\/(download|downloads|dl)\.(sf|sourceforge)\.net\//) {
225 # http://downloads.sourceforge.net/project/mediainfo/source/mediainfo/
226 gsub("^http://(download|dl)\.(sf|sourceforge)\.net/", "", url)
227 # http://downloads.sourceforge.net/project/mediainfo/source/mediainfo/
228 gsub("^http://downloads\.(sf|sourceforge)\.net/project/", "", url)
231 url = "http://sourceforge.net/projects/" url "/files/"
232 d("sf url, mungled url to: " url)
235 if (url ~ /^http:\/\/(.*)\.googlecode\.com\/files\//) {
236 gsub("^http://", "", url)
237 gsub("\..*", "", url)
238 url = "http://code.google.com/p/" url "/downloads/list"
239 d("googlecode url, mungled url to: " url)
242 if (url ~ /^http:\/\/pecl.php.net\/get\//) {
243 gsub("-.*", "", filename)
244 url = "http://pecl.php.net/package/" filename
245 d("pecl.php.net url, mungled url to: " url)
248 if (url ~ /^(http|ftp):\/\/mysql.*\/Downloads\/MySQL-5.1\//) {
249 url = "http://dev.mysql.com/downloads/mysql/5.1.html#source"
250 d("mysql 5.1 url, mungled url to: " url)
253 if (url ~/^(http|https):\/\/launchpad\.net\/(.*)\//) {
254 gsub("^(http|https):\/\/launchpad\.net\/", "", url)
255 gsub("\/.*/", "", url)
256 url = "https://code.launchpad.net/" url "/+download"
257 d("main launchpad url, mungled url to: " url)
260 if (url ~/^(http|https):\/\/edge\.launchpad\.net\/(.*)\//) {
261 gsub("^(http|https):\/\/edge\.launchpad\.net\/", "", url)
262 gsub("\/.*/", "", url)
263 url = "https://edge.launchpad.net/" url "/+download"
264 d("edge launchpad url, mungled url to: " url)
267 if (url ~/^(http|https):\/\/github.com\/.*\/(.*)\/tarball\//) {
268 gsub("\/tarball\/.*", "/downloads", url)
269 d("github tarball url, mungled url to: " url)
272 if (url ~/^(http|https):\/\/cgit\..*\/(.*)\/snapshot\//) {
273 gsub("\/snapshot\/.*", "/", url)
274 d("cgit snapshot tarball url, mungled url to: " url)
277 d("Retrieving: " url)
278 cmd = "wget --user-agent \"Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:1.9.2) Gecko/20100129 PLD/3.0 (Th) Iceweasel/3.6\" -nv -O - \"" url "\" -t 2 -T 45 --passive-ftp --no-check-certificate > " tmpfile " 2> " tmpfileerr
284 d("Reading failure response...")
286 while (getline oneline < tmpfileerr)
287 wholeerr = (wholeerr " " oneline)
288 d("Error Response: " wholeerr)
290 system("rm -f " tmpfile)
291 system("rm -f " tmpfileerr)
292 retval = ("WGET ERROR: " errno ": " wholeerr)
295 system("rm -f " tmpfileerr)
298 sub(/[^\/]+$/, "", urldir)
301 cmd = extract_links_cmd(tmpfile)
302 while (cmd | getline) {
304 link = substr($0, length(tag) + 2)
306 if (tag == "iframe") {
313 if (link_seen(link)) {
316 retval = (retval " " get_links(link))
319 if (link_seen(link)) {
323 retval = (retval " " link)
327 system("rm -f " tmpfile)
329 d("Returning: [" retval "]")
334 d("Reading success response...")
335 while (getline oneline < tmpfile) {
336 wholeodp = (wholeodp " " oneline)
337 # d("Response: " wholeodp)
339 d("Reponse read done...")
340 system("rm -f " tmpfile)
342 while (match(wholeodp, /<([aA]|[fF][rR][aA][mM][eE])[ \t][^>]*>/) > 0) {
343 d("Processing links...")
344 odp = substr(wholeodp,RSTART,RLENGTH);
345 wholeodp = substr(wholeodp,RSTART+RLENGTH);
347 lowerodp = tolower(odp);
348 if (lowerodp ~ /<frame[ \t]/) {
349 sub(/[sS][rR][cC]=[ \t]*/, "src=", odp);
350 match(odp, /src="[^"]+"/)
351 newurl = substr(odp, RSTART+5, RLENGTH-6)
353 if (newurl !~ /\//) {
354 newurl=(urldir newurl)
355 d("Frame->: " newurl)
358 if (link_seen(newurl)) {
363 retval = (retval " " get_links(newurl))
364 } else if (lowerodp ~ /href=[ \t]*"[^"]*"/) {
365 sub(/[hH][rR][eE][fF]=[ \t]*"/,"href=\"",odp)
366 match(odp,/href="[^"]*"/)
367 link=substr(odp,RSTART,RLENGTH)
368 odp=substr(odp,1,RSTART) substr(odp,RSTART+RLENGTH)
369 link=substr(link,7,length(link)-7)
370 link=postfix_link(url, link)
372 if (link_seen(link)) {
377 retval = (retval " " link)
378 d("href(\"\"): " link)
379 } else if (lowerodp ~ /href=[ \t]*'[^']*'/) {
380 sub(/[hH][rR][eE][fF]=[ \t]*'/,"href='",odp)
381 match(odp,/href='[^']*'/)
382 link=substr(odp,RSTART,RLENGTH)
383 odp=substr(odp,1,RSTART) substr(odp,RSTART+RLENGTH)
384 link=substr(link,7,length(link)-7)
385 link=postfix_link(url, link)
387 if (link_seen(link)) {
392 retval = (retval " " link)
394 } else if (lowerodp ~ /href=[ \t]*[^ \t>]*/) {
395 sub(/[hH][rR][eE][fF]=[ \t]*/,"href=",odp)
396 match(odp,/href=[^ \t>]*/)
397 link=substr(odp,RSTART,RLENGTH)
398 odp=substr(odp,1,RSTART) substr(odp,RSTART+RLENGTH)
399 link=substr(link,6,length(link)-5)
401 if (link_seen(link)) {
406 retval = (retval " " link)
409 # <a ...> but not href - skip
410 d("skipping <a > without href: " odp)
414 d("Returning: [" retval "]")
418 function subst_defines(var,defs) {
419 # substitute all possible RPM macros
420 while ((var ~ /%{.*}/) || (var ~ /%[A-Za-z0-9_]+/)) {
423 gsub("%{" j "}", defs[j], var)
424 gsub("%" j , defs[j], var)
438 function find_mirror(url) {
440 while (succ = (getline line < "mirrors")) {
441 if (succ==-1) { return url }
442 nf=split(line,fields,"|")
447 prefix=substr(url,1,length(origin))
449 d("Mirror fount at " mname)
451 return mirror substr(url,length(origin)+1)
459 function process_source(number,lurl,name,version) {
460 # fetches file list, and compares version numbers
461 d("Processing " lurl)
463 if ( index(lurl,version)==0 ) {
464 d("There is no version number.")
470 gsub("[^/]*$",":&",lurl)
477 if (index(dir,version)) {
478 # directory name as version maching mode:
479 # if /something/version/name-version.tarball then check
480 # in /something/ looking for newer directory
481 dir=substr(dir,1,index(dir,version)-1)
483 sub("(\.tar\.(bz|bz2|gz|lzma|xz)|zip)$","",filename)
486 d("Will check a directory: " dir)
487 d("and a file: " filename)
490 gsub("[+]","\\+",filenameexp)
491 sub(version,"[A-Za-z0-9.]+",filenameexp)
492 gsub("[.]","\\.",filenameexp)
493 d("Expression: " filenameexp)
494 match(filename,version)
495 prever=substr(filename,1,RSTART-1)
496 postver=substr(filename,RSTART+RLENGTH)
497 d("Before number: " prever)
498 d("and after: " postver)
499 newurl=find_mirror(acc "://" host dir)
500 #print acc "://" host dir
501 #newurl=url[1]"://"url[2]url[3]url[4]
502 #newurl=acc "://" host dir filename
503 d("Looking at " newurl)
508 odp = get_links(newurl, filename)
509 if( odp ~ "ERROR: ") {
510 print name "(" number ") " odp
512 d("WebPage downloaded")
514 for (nr=1; nr<=c; nr++) {
517 d("Found link: " addr)
519 # github has very different tarball links that clash with this safe check
520 if (!(newurl ~/^(http|https):\/\/github.com\/.*\/tarball/)) {
521 if (addr ~ "[-_.0-9A-Za-z~]" filenameexp) {
526 if (addr ~ filenameexp) {
527 match(addr,filenameexp)
528 newfilename=substr(addr,RSTART,RLENGTH)
529 d("Hypothetical new: " newfilename)
530 newfilename=fixedsub(prever,"",newfilename)
531 newfilename=fixedsub(postver,"",newfilename)
532 d("Version: " newfilename)
533 if (newfilename ~ /\.(asc|sig|pkg|bin|binary|built)$/) continue
534 # strip ending (happens when in directiory name as version matching mode)
535 sub("(\.tar\.(bz|bz2|gz|lzma|xz)|zip)$","",newfilename)
537 if ( compare_ver_dec(version, newfilename)==1 ) {
538 d("Yes, there is new one")
542 } else if ( compare_ver(version, newfilename)==1 ) {
543 d("Yes, there is new one")
550 print name "(" number ") seems ok: " oldversion
552 print name "(" number ") [OLD] " oldversion " [NEW] " version
556 function rss_upgrade(name, ver, url, regex, cmd, nver) {
557 regex = "s/.*<title>" regex "<\/title>.*/\\1/p"
558 cmd = "wget -q -O - " url " | sed -nre '" regex "' | head -n1"
560 d("rss_upgrade_cmd: " cmd)
564 if (compare_ver(ver, nver)) {
565 print name " [OLD] " ver " [NEW] " nver
567 print name " seems ok: " ver
571 # check for ZF upgrade from rss
572 function zf_upgrade(name, ver) {
573 rss_upgrade(name, ver, \
574 "http://devzone.zend.com/tag/Zend_Framework_Management/format/rss2.0", \
575 "Zend Framework ([^\\s]+) Released" \
579 function hudson_upgrade(name, ver) {
580 rss_upgrade(name, ver, \
581 "https://hudson.dev.java.net/servlets/ProjectRSS?type=news", \
582 "Hudson ([0-9.]+) released" \
586 # upgrade check for pear package using PEAR CLI
587 function pear_upgrade(name, ver, pname, pearcmd, nver) {
589 sub(/^php-pear-/, "", pname);
591 pearcmd = "pear remote-info " pname " | awk '/^Latest/{print $NF}'"
592 d("pearcmd: " pearcmd)
593 pearcmd | getline nver
596 if (compare_ver(ver, nver)) {
597 print name " [OLD] " ver " [NEW] " nver
599 print name " seems ok: " ver
605 function vim_upgrade(name, ver, mver, nver, vimcmd) {
606 # %patchset_source -f ftp://ftp.vim.org/pub/editors/vim/patches/7.2/7.2.%03g 1 %{patchlevel}
607 mver = substr(ver, 0, 4)
608 vimcmd = "wget -q -O - ftp://ftp.vim.org/pub/editors/vim/patches/"mver"/MD5SUMS|grep -vF .gz|tail -n1|awk '{print $2}'"
610 vimcmd | getline nver
613 if (compare_ver(ver, nver)) {
614 print name " [OLD] " ver " [NEW] " nver
616 print name " seems ok: " ver
620 function process_data(name,ver,rel,src) {
621 if (name ~ /^php-pear-/) {
622 return pear_upgrade(name, ver);
624 if (name == "ZendFramework") {
625 return zf_upgrade(name, ver);
627 if (name == "hudson") {
628 return hudson_upgrade(name, ver);
631 return vim_upgrade(name, ver);
634 # this function checks if substitutions were valid, and if true:
635 # processes each URL and tries to get current file list
637 if ( src[i] ~ /%{nil}/ ) {
638 gsub(/\%\{nil\}/, "", src[i])
640 if ( src[i] !~ /%{.*}/ && src[i] !~ /%[A-Za-z0-9_]/ ) {
642 process_source(i,src[i],name,ver)
644 print FNAME ":" i ": impossible substitution: " src[i]
650 # if U want to use DEBUG, run script with "-v DEBUG=1"
651 # or uncomment the line below
654 errno=system("wget --help > /dev/null 2>&1")
656 print "No wget installed!"
659 if (ARGC>=3 && ARGV[2]=="-n") {
661 for (i=3; i<ARGC; i++) ARGV[i-1]=ARGV[i]
668 # clean frameseen for each ARG
669 for (i in frameseen) {
674 process_data(NAME,VER,REL,SRC)
675 NAME="" ; VER="" ; REL=""
676 for (i in DEFS) delete DEFS[i]
677 for (i in SRC) delete SRC[i]
680 DEFS["_alt_kernel"]=""
684 /^[Uu][Rr][Ll]:/&&(URL=="") { URL=subst_defines($2,DEFS) ; DEFS["url"]=URL }
685 /^[Nn]ame:/&&(NAME=="") { NAME=subst_defines($2,DEFS) ; DEFS["name"]=NAME }
686 /^[Vv]ersion:/&&(VER=="") { VER=subst_defines($2,DEFS) ; DEFS["version"]=VER }
687 /^[Rr]elease:/&&(REL=="") { REL=subst_defines($2,DEFS) ; DEFS["release"]=REL }
688 /^[Ss]ource[0-9]*:/ { if (/(ftp|http|https):\/\//) SRC[FNR]=subst_defines($2,DEFS) }
689 /%define/ { DEFS[$2]=subst_defines($3,DEFS) }
692 process_data(NAME,VER,REL,SRC)