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|dl)\.(sf|sourceforge)\.net\//) {
225 # http://downloads.sourceforge.net/project/mediainfo/source/mediainfo/
226 gsub("^http://(download|dl)\.(sf|sourceforge)\.net/", "", url)
229 url = "http://sourceforge.net/projects/" url "/files/"
230 d("sf url, mungled url to: " url)
233 if (url ~ /^http:\/\/(.*)\.googlecode\.com\/files\//) {
234 gsub("^http://", "", url)
235 gsub("\..*", "", url)
236 url = "http://code.google.com/p/" url "/downloads/list"
237 d("googlecode url, mungled url to: " url)
240 if (url ~ /^http:\/\/pecl.php.net\/get\//) {
241 gsub("-.*", "", filename)
242 url = "http://pecl.php.net/package/" filename
243 d("pecl.php.net url, mungled url to: " url)
246 if (url ~ /^(http|ftp):\/\/mysql.*\/Downloads\/MySQL-5.1\//) {
247 url = "http://dev.mysql.com/downloads/mysql/5.1.html#source"
248 d("mysql 5.1 url, mungled url to: " url)
251 if (url ~/^(http|https):\/\/launchpad\.net\/(.*)\//) {
252 gsub("^(http|https):\/\/launchpad\.net\/", "", url)
253 gsub("\/.*/", "", url)
254 url = "https://code.launchpad.net/" url "/+download"
255 d("main launchpad url, mungled url to: " url)
258 if (url ~/^(http|https):\/\/edge\.launchpad\.net\/(.*)\//) {
259 gsub("^(http|https):\/\/edge\.launchpad\.net\/", "", url)
260 gsub("\/.*/", "", url)
261 url = "https://edge.launchpad.net/" url "/+download"
262 d("edge launchpad url, mungled url to: " url)
265 if (url ~/^(http|https):\/\/github.com\/.*\/(.*)\/tarball\//) {
266 gsub("\/tarball\/.*", "/downloads", url)
267 d("github tarball url, mungled url to: " url)
270 if (url ~/^(http|https):\/\/cgit\..*\/(.*)\/snapshot\//) {
271 gsub("\/snapshot\/.*", "/", url)
272 d("cgit snapshot tarball url, mungled url to: " url)
275 d("Retrieving: " url)
276 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
282 d("Reading failure response...")
284 while (getline oneline < tmpfileerr)
285 wholeerr = (wholeerr " " oneline)
286 d("Error Response: " wholeerr)
288 system("rm -f " tmpfile)
289 system("rm -f " tmpfileerr)
290 retval = ("WGET ERROR: " errno ": " wholeerr)
293 system("rm -f " tmpfileerr)
296 sub(/[^\/]+$/, "", urldir)
299 cmd = extract_links_cmd(tmpfile)
300 while (cmd | getline) {
302 link = substr($0, length(tag) + 2)
304 if (tag == "iframe") {
311 if (link_seen(link)) {
314 retval = (retval " " get_links(link))
317 if (link_seen(link)) {
321 retval = (retval " " link)
325 system("rm -f " tmpfile)
327 d("Returning: [" retval "]")
332 d("Reading success response...")
333 while (getline oneline < tmpfile) {
334 wholeodp = (wholeodp " " oneline)
335 # d("Response: " wholeodp)
337 d("Reponse read done...")
338 system("rm -f " tmpfile)
340 while (match(wholeodp, /<([aA]|[fF][rR][aA][mM][eE])[ \t][^>]*>/) > 0) {
341 d("Processing links...")
342 odp = substr(wholeodp,RSTART,RLENGTH);
343 wholeodp = substr(wholeodp,RSTART+RLENGTH);
345 lowerodp = tolower(odp);
346 if (lowerodp ~ /<frame[ \t]/) {
347 sub(/[sS][rR][cC]=[ \t]*/, "src=", odp);
348 match(odp, /src="[^"]+"/)
349 newurl = substr(odp, RSTART+5, RLENGTH-6)
351 if (newurl !~ /\//) {
352 newurl=(urldir newurl)
353 d("Frame->: " newurl)
356 if (link_seen(newurl)) {
361 retval = (retval " " get_links(newurl))
362 } else if (lowerodp ~ /href=[ \t]*"[^"]*"/) {
363 sub(/[hH][rR][eE][fF]=[ \t]*"/,"href=\"",odp)
364 match(odp,/href="[^"]*"/)
365 link=substr(odp,RSTART,RLENGTH)
366 odp=substr(odp,1,RSTART) substr(odp,RSTART+RLENGTH)
367 link=substr(link,7,length(link)-7)
368 link=postfix_link(url, link)
370 if (link_seen(link)) {
375 retval = (retval " " link)
376 d("href(\"\"): " link)
377 } else if (lowerodp ~ /href=[ \t]*'[^']*'/) {
378 sub(/[hH][rR][eE][fF]=[ \t]*'/,"href='",odp)
379 match(odp,/href='[^']*'/)
380 link=substr(odp,RSTART,RLENGTH)
381 odp=substr(odp,1,RSTART) substr(odp,RSTART+RLENGTH)
382 link=substr(link,7,length(link)-7)
383 link=postfix_link(url, link)
385 if (link_seen(link)) {
390 retval = (retval " " link)
392 } else if (lowerodp ~ /href=[ \t]*[^ \t>]*/) {
393 sub(/[hH][rR][eE][fF]=[ \t]*/,"href=",odp)
394 match(odp,/href=[^ \t>]*/)
395 link=substr(odp,RSTART,RLENGTH)
396 odp=substr(odp,1,RSTART) substr(odp,RSTART+RLENGTH)
397 link=substr(link,6,length(link)-5)
399 if (link_seen(link)) {
404 retval = (retval " " link)
407 # <a ...> but not href - skip
408 d("skipping <a > without href: " odp)
412 d("Returning: [" retval "]")
416 function subst_defines(var,defs) {
417 # substitute all possible RPM macros
418 while ((var ~ /%{.*}/) || (var ~ /%[A-Za-z0-9_]+/)) {
421 gsub("%{" j "}", defs[j], var)
422 gsub("%" j , defs[j], var)
436 function find_mirror(url) {
438 while (succ = (getline line < "mirrors")) {
439 if (succ==-1) { return url }
440 nf=split(line,fields,"|")
445 prefix=substr(url,1,length(origin))
447 d("Mirror fount at " mname)
449 return mirror substr(url,length(origin)+1)
457 function process_source(number,lurl,name,version) {
458 # fetches file list, and compares version numbers
459 d("Processing " lurl)
461 if ( index(lurl,version)==0 ) {
462 d("There is no version number.")
468 gsub("[^/]*$",":&",lurl)
475 if (index(dir,version)) {
476 # directory name as version maching mode:
477 # if /something/version/name-version.tarball then check
478 # in /something/ looking for newer directory
479 dir=substr(dir,1,index(dir,version)-1)
481 sub("(\.tar\.(bz|bz2|gz|lzma|xz)|zip)$","",filename)
484 d("Will check a directory: " dir)
485 d("and a file: " filename)
488 gsub("[+]","\\+",filenameexp)
489 sub(version,"[A-Za-z0-9.]+",filenameexp)
490 gsub("[.]","\\.",filenameexp)
491 d("Expression: " filenameexp)
492 match(filename,version)
493 prever=substr(filename,1,RSTART-1)
494 postver=substr(filename,RSTART+RLENGTH)
495 d("Before number: " prever)
496 d("and after: " postver)
497 newurl=find_mirror(acc "://" host dir)
498 #print acc "://" host dir
499 #newurl=url[1]"://"url[2]url[3]url[4]
500 #newurl=acc "://" host dir filename
501 d("Looking at " newurl)
506 odp = get_links(newurl, filename)
507 if( odp ~ "ERROR: ") {
508 print name "(" number ") " odp
510 d("WebPage downloaded")
512 for (nr=1; nr<=c; nr++) {
515 d("Found link: " addr)
517 # github has very different tarball links that clash with this safe check
518 if (!(newurl ~/^(http|https):\/\/github.com\/.*\/tarball/)) {
519 if (addr ~ "[-_.0-9A-Za-z~]" filenameexp) {
524 if (addr ~ filenameexp) {
525 match(addr,filenameexp)
526 newfilename=substr(addr,RSTART,RLENGTH)
527 d("Hypothetical new: " newfilename)
528 newfilename=fixedsub(prever,"",newfilename)
529 newfilename=fixedsub(postver,"",newfilename)
530 d("Version: " newfilename)
531 if (newfilename ~ /\.(asc|sig|pkg|bin|binary|built)$/) continue
532 # strip ending (happens when in directiory name as version matching mode)
533 sub("(\.tar\.(bz|bz2|gz|lzma|xz)|zip)$","",newfilename)
535 if ( compare_ver_dec(version, newfilename)==1 ) {
536 d("Yes, there is new one")
540 } else if ( compare_ver(version, newfilename)==1 ) {
541 d("Yes, there is new one")
548 print name "(" number ") seems ok: " oldversion
550 print name "(" number ") [OLD] " oldversion " [NEW] " version
554 function rss_upgrade(name, ver, url, regex, cmd, nver) {
555 regex = "s/.*<title>" regex "<\/title>.*/\\1/p"
556 cmd = "wget -q -O - " url " | sed -nre '" regex "' | head -n1"
558 d("rss_upgrade_cmd: " cmd)
562 if (compare_ver(ver, nver)) {
563 print name " [OLD] " ver " [NEW] " nver
565 print name " seems ok: " ver
569 # check for ZF upgrade from rss
570 function zf_upgrade(name, ver) {
571 rss_upgrade(name, ver, \
572 "http://devzone.zend.com/tag/Zend_Framework_Management/format/rss2.0", \
573 "Zend Framework ([^\\s]+) Released" \
577 function hudson_upgrade(name, ver) {
578 rss_upgrade(name, ver, \
579 "https://hudson.dev.java.net/servlets/ProjectRSS?type=news", \
580 "Hudson ([0-9.]+) released" \
584 # upgrade check for pear package using PEAR CLI
585 function pear_upgrade(name, ver, pname, pearcmd, nver) {
587 sub(/^php-pear-/, "", pname);
589 pearcmd = "pear remote-info " pname " | awk '/^Latest/{print $NF}'"
590 d("pearcmd: " pearcmd)
591 pearcmd | getline nver
594 if (compare_ver(ver, nver)) {
595 print name " [OLD] " ver " [NEW] " nver
597 print name " seems ok: " ver
603 function vim_upgrade(name, ver, mver, nver, vimcmd) {
604 # %patchset_source -f ftp://ftp.vim.org/pub/editors/vim/patches/7.2/7.2.%03g 1 %{patchlevel}
605 mver = substr(ver, 0, 4)
606 vimcmd = "wget -q -O - ftp://ftp.vim.org/pub/editors/vim/patches/"mver"/MD5SUMS|grep -vF .gz|tail -n1|awk '{print $2}'"
608 vimcmd | getline nver
611 if (compare_ver(ver, nver)) {
612 print name " [OLD] " ver " [NEW] " nver
614 print name " seems ok: " ver
618 function process_data(name,ver,rel,src) {
619 if (name ~ /^php-pear-/) {
620 return pear_upgrade(name, ver);
622 if (name == "ZendFramework") {
623 return zf_upgrade(name, ver);
625 if (name == "hudson") {
626 return hudson_upgrade(name, ver);
629 return vim_upgrade(name, ver);
632 # this function checks if substitutions were valid, and if true:
633 # processes each URL and tries to get current file list
635 if ( src[i] ~ /%{nil}/ ) {
636 gsub(/\%\{nil\}/, "", src[i])
638 if ( src[i] !~ /%{.*}/ && src[i] !~ /%[A-Za-z0-9_]/ ) {
640 process_source(i,src[i],name,ver)
642 print FNAME ":" i ": impossible substitution: " src[i]
648 # if U want to use DEBUG, run script with "-v DEBUG=1"
649 # or uncomment the line below
652 errno=system("wget --help > /dev/null 2>&1")
654 print "No wget installed!"
657 if (ARGC>=3 && ARGV[2]=="-n") {
659 for (i=3; i<ARGC; i++) ARGV[i-1]=ARGV[i]
666 # clean frameseen for each ARG
667 for (i in frameseen) {
672 process_data(NAME,VER,REL,SRC)
673 NAME="" ; VER="" ; REL=""
674 for (i in DEFS) delete DEFS[i]
675 for (i in SRC) delete SRC[i]
678 DEFS["_alt_kernel"]=""
682 /^[Uu][Rr][Ll]:/&&(URL=="") { URL=subst_defines($2,DEFS) ; DEFS["url"]=URL }
683 /^[Nn]ame:/&&(NAME=="") { NAME=subst_defines($2,DEFS) ; DEFS["name"]=NAME }
684 /^[Vv]ersion:/&&(VER=="") { VER=subst_defines($2,DEFS) ; DEFS["version"]=VER }
685 /^[Rr]elease:/&&(REL=="") { REL=subst_defines($2,DEFS) ; DEFS["release"]=REL }
686 /^[Ss]ource[0-9]*:/ { if (/(ftp|http|https):\/\//) SRC[FNR]=subst_defines($2,DEFS) }
687 /%define/ { DEFS[$2]=subst_defines($3,DEFS) }
690 process_data(NAME,VER,REL,SRC)