4 # Copyright (C) 2000-2011 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 if (url ~/^(http|https):\/\/www2\.aquamaniac\.de\/sites\/download\//) {
276 url = "http://www2.aquamaniac.de/sites/download/packages.php"
277 d("aquamaniac.de tarball url, mungled url to: " url)
280 d("Retrieving: " url)
281 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"
282 cmd = "wget -t 2 -T 45 --user-agent \"" user_agent "\" -nv -O - \"" url "\" --passive-ftp --no-check-certificate > " tmpfile " 2> " tmpfileerr
288 d("Reading failure response...")
290 while (getline oneline < tmpfileerr)
291 wholeerr = (wholeerr " " oneline)
292 d("Error Response: " wholeerr)
294 system("rm -f " tmpfile)
295 system("rm -f " tmpfileerr)
296 retval = ("WGET ERROR: " errno ": " wholeerr)
299 system("rm -f " tmpfileerr)
302 sub(/[^\/]+$/, "", urldir)
305 cmd = extract_links_cmd(tmpfile)
306 while (cmd | getline) {
308 link = substr($0, length(tag) + 2)
310 if (tag == "iframe") {
317 if (link_seen(link)) {
320 retval = (retval " " get_links(link))
323 if (link_seen(link)) {
327 retval = (retval " " link)
331 system("rm -f " tmpfile)
333 d("Returning: [" retval "]")
338 d("Reading success response...")
339 while (getline oneline < tmpfile) {
340 wholeodp = (wholeodp " " oneline)
341 # d("Response: " wholeodp)
343 d("Reponse read done...")
344 system("rm -f " tmpfile)
346 while (match(wholeodp, /<([aA]|[fF][rR][aA][mM][eE])[ \t][^>]*>/) > 0) {
347 d("Processing links...")
348 odp = substr(wholeodp,RSTART,RLENGTH);
349 wholeodp = substr(wholeodp,RSTART+RLENGTH);
351 lowerodp = tolower(odp);
352 if (lowerodp ~ /<frame[ \t]/) {
353 sub(/[sS][rR][cC]=[ \t]*/, "src=", odp);
354 match(odp, /src="[^"]+"/)
355 newurl = substr(odp, RSTART+5, RLENGTH-6)
357 if (newurl !~ /\//) {
358 newurl=(urldir newurl)
359 d("Frame->: " newurl)
362 if (link_seen(newurl)) {
367 retval = (retval " " get_links(newurl))
368 } else if (lowerodp ~ /href=[ \t]*"[^"]*"/) {
369 sub(/[hH][rR][eE][fF]=[ \t]*"/,"href=\"",odp)
370 match(odp,/href="[^"]*"/)
371 link=substr(odp,RSTART,RLENGTH)
372 odp=substr(odp,1,RSTART) substr(odp,RSTART+RLENGTH)
373 link=substr(link,7,length(link)-7)
374 link=postfix_link(url, link)
376 if (link_seen(link)) {
381 retval = (retval " " link)
382 d("href(\"\"): " link)
383 } else if (lowerodp ~ /href=[ \t]*'[^']*'/) {
384 sub(/[hH][rR][eE][fF]=[ \t]*'/,"href='",odp)
385 match(odp,/href='[^']*'/)
386 link=substr(odp,RSTART,RLENGTH)
387 odp=substr(odp,1,RSTART) substr(odp,RSTART+RLENGTH)
388 link=substr(link,7,length(link)-7)
389 link=postfix_link(url, link)
391 if (link_seen(link)) {
396 retval = (retval " " link)
398 } else if (lowerodp ~ /href=[ \t]*[^ \t>]*/) {
399 sub(/[hH][rR][eE][fF]=[ \t]*/,"href=",odp)
400 match(odp,/href=[^ \t>]*/)
401 link=substr(odp,RSTART,RLENGTH)
402 odp=substr(odp,1,RSTART) substr(odp,RSTART+RLENGTH)
403 link=substr(link,6,length(link)-5)
405 if (link_seen(link)) {
410 retval = (retval " " link)
413 # <a ...> but not href - skip
414 d("skipping <a > without href: " odp)
418 d("Returning: [" retval "]")
422 function subst_defines(var,defs) {
423 # substitute all possible RPM macros
424 while ((var ~ /%{.*}/) || (var ~ /%[A-Za-z0-9_]+/)) {
427 gsub("%{" j "}", defs[j], var)
428 gsub("%" j , defs[j], var)
442 function find_mirror(url) {
444 while (succ = (getline line < "mirrors")) {
445 if (succ==-1) { return url }
446 nf=split(line,fields,"|")
451 prefix=substr(url,1,length(origin))
453 d("Mirror found at " mname)
455 return mirror substr(url,length(origin)+1)
463 function process_source(number, lurl, name, version) {
464 # fetches file list, and compares version numbers
465 d("Processing " lurl)
467 if (index(lurl, version) == 0) {
468 d("There is no version number ["version"] in ["lurl"]")
474 gsub("[^/]*$",":&",lurl)
481 if (index(dir,version)) {
482 # directory name as version maching mode:
483 # if /something/version/name-version.tarball then check
484 # in /something/ looking for newer directory
485 dir=substr(dir,1,index(dir,version)-1)
487 sub("(\.tar\.(bz|bz2|gz|lzma|xz)|zip)$","",filename)
490 d("Will check a directory: " dir)
491 d("and a file: " filename)
494 gsub("[+]","\\+",filenameexp)
495 sub(version,"[A-Za-z0-9.]+",filenameexp)
496 gsub("[.]","\\.",filenameexp)
497 d("Expression: " filenameexp)
498 match(filename,version)
499 prever=substr(filename,1,RSTART-1)
500 postver=substr(filename,RSTART+RLENGTH)
501 d("Before number: " prever)
502 d("and after: " postver)
503 newurl=find_mirror(acc "://" host dir)
504 #print acc "://" host dir
505 #newurl=url[1]"://"url[2]url[3]url[4]
506 #newurl=acc "://" host dir filename
507 d("Looking at " newurl)
512 odp = get_links(newurl, filename)
513 if( odp ~ "ERROR: ") {
514 print name "(" number ") " odp
516 d("WebPage downloaded")
518 for (nr=1; nr<=c; nr++) {
521 d("Found link: " addr)
523 # github has very different tarball links that clash with this safe check
524 if (!(newurl ~/^(http|https):\/\/github.com\/.*\/tarball/)) {
525 if (addr ~ "[-_.0-9A-Za-z~]" filenameexp) {
530 if (addr ~ filenameexp) {
531 match(addr,filenameexp)
532 newfilename=substr(addr,RSTART,RLENGTH)
533 d("Hypothetical new: " newfilename)
534 newfilename=fixedsub(prever,"",newfilename)
535 newfilename=fixedsub(postver,"",newfilename)
536 d("Version: " newfilename)
537 if (newfilename ~ /\.(asc|sig|pkg|bin|binary|built)$/) continue
538 # strip ending (happens when in directiory name as version matching mode)
539 sub("(\.tar\.(bz|bz2|gz|lzma|xz)|zip)$","",newfilename)
541 if ( compare_ver_dec(version, newfilename)==1 ) {
542 d("Yes, there is new one")
546 } else if ( compare_ver(version, newfilename)==1 ) {
547 d("Yes, there is new one")
554 print name "(" number ") seems ok: " oldversion
556 print name "(" number ") [OLD] " oldversion " [NEW] " version
560 function rss_upgrade(name, ver, url, regex, cmd, nver) {
561 regex = "s/.*<title>" regex "<\/title>.*/\\1/p"
562 cmd = "wget -t 2 -T 45 -q -O - " url " | sed -nre '" regex "' | head -n1"
564 d("rss_upgrade_cmd: " cmd)
568 if (compare_ver(ver, nver)) {
569 print name " [OLD] " ver " [NEW] " nver
571 print name " seems ok: " ver
575 # check for ZF upgrade from rss
576 function zf_upgrade(name, ver) {
577 rss_upgrade(name, ver, \
578 "http://devzone.zend.com/tag/Zend_Framework_Management/format/rss2.0", \
579 "Zend Framework ([^\\s]+) Released" \
583 function hudson_upgrade(name, ver) {
584 rss_upgrade(name, ver, \
585 "https://hudson.dev.java.net/servlets/ProjectRSS?type=news", \
586 "Hudson ([0-9.]+) released" \
590 # upgrade check for pear package using PEAR CLI
591 function pear_upgrade(name, ver, pname, pearcmd, nver) {
593 sub(/^php-pear-/, "", pname);
595 pearcmd = "pear remote-info " pname " | awk '/^Latest/{print $NF}'"
596 d("pearcmd: " pearcmd)
597 pearcmd | getline nver
600 if (compare_ver(ver, nver)) {
601 print name " [OLD] " ver " [NEW] " nver
603 print name " seems ok: " ver
609 function vim_upgrade(name, ver, mver, nver, vimcmd) {
610 # %patchset_source -f ftp://ftp.vim.org/pub/editors/vim/patches/7.2/7.2.%03g 1 %{patchlevel}
611 mver = substr(ver, 0, 4)
612 vimcmd = "wget -q -O - ftp://ftp.vim.org/pub/editors/vim/patches/"mver"/MD5SUMS|grep -vF .gz|tail -n1|awk '{print $2}'"
614 vimcmd | getline nver
617 if (compare_ver(ver, nver)) {
618 print name " [OLD] " ver " [NEW] " nver
620 print name " seems ok: " ver
624 function process_data(name, ver, rel, src) {
625 if (name ~ /^php-pear-/) {
626 return pear_upgrade(name, ver);
628 if (name == "ZendFramework") {
629 return zf_upgrade(name, ver);
631 if (name == "hudson") {
632 return hudson_upgrade(name, ver);
635 return vim_upgrade(name, ver);
637 if (name == "xulrunner") {
638 ver = subst_defines(DEFS["firefox_ver"], DEFS)
639 d("package xulrunner, change version to firefox ["ver"]")
642 # this function checks if substitutions were valid, and if true:
643 # processes each URL and tries to get current file list
645 if (src[i] ~ /%{nil}/) {
646 gsub(/\%\{nil\}/, "", src[i])
648 if ( src[i] !~ /%{.*}/ && src[i] !~ /%[A-Za-z0-9_]/ ) {
650 process_source(i, src[i], name, ver)
652 print FNAME ":" i ": impossible substitution: " src[i]
658 # if U want to use DEBUG, run script with "-v DEBUG=1"
659 # or uncomment the line below
662 errno=system("wget --help > /dev/null 2>&1")
663 if (errno && errno != 3) {
664 print "No wget installed!"
667 if (ARGC>=3 && ARGV[2]=="-n") {
669 for (i=3; i<ARGC; i++) ARGV[i-1]=ARGV[i]
676 # clean frameseen for each ARG
677 for (i in frameseen) {
682 process_data(NAME,VER,REL,SRC)
683 NAME="" ; VER="" ; REL=""
684 for (i in DEFS) delete DEFS[i]
685 for (i in SRC) delete SRC[i]
688 DEFS["_alt_kernel"]=""
692 /^[Uu][Rr][Ll]:/&&(URL=="") { URL=subst_defines($2,DEFS) ; DEFS["url"]=URL }
693 /^[Nn]ame:/&&(NAME=="") { NAME=subst_defines($2,DEFS) ; DEFS["name"]=NAME }
694 /^[Vv]ersion:/&&(VER=="") { VER=subst_defines($2,DEFS) ; DEFS["version"]=VER }
695 /^[Rr]elease:/&&(REL=="") { REL=subst_defines($2,DEFS) ; DEFS["release"]=REL }
696 /^[Ss]ource[0-9]*:/ { if (/(ftp|http|https):\/\//) SRC[FNR]=subst_defines($2,DEFS) }
697 /%define/ { DEFS[$2]=subst_defines($3,DEFS) }
700 process_data(NAME,VER,REL,SRC)