]> git.pld-linux.org Git - packages/rpm-build-tools.git/blobdiff - pldnotify.awk
don't fail if no sources found (hack to allow build nosrc packages)
[packages/rpm-build-tools.git] / pldnotify.awk
index 4e29e8adf69af468540e017ba1c38743b038bdae..8a65dbde4f5c849fec043405c86d2dfbcf971565 100644 (file)
@@ -1,5 +1,12 @@
 #!/bin/awk -f
 # $Revision$, $Date$
+function fixedsub(s1,s2,t,     ind) {
+# substitutes fixed strings (not regexps)
+       if (ind = index(t,s1)) {
+               t = substr(t, 1, ind-1) s2 substr(t, ind+length(s1))
+       }
+       return t
+}
 
 function compare_ver(v1,v2) {
 # compares version numbers
@@ -37,66 +44,71 @@ function compare_ver(v1,v2) {
                                return 1
                        else if (v1a[i]>v2a[i])
                                return 0
-               } else if ((v1a[i]~"pre")||(v1a[i]~"beta")||(v1a[i]~"^b$"))
+               } else if ((v1a[i]~"pre")||(v1a[i]~"beta")||(v1a[i]~"alpha"))
                        return 1
                else
                        return 0
        }
        if ((count2==mincount)&&(count!=count2)) {
                for (i=count2+1; i<=count; i++)
-                       if ((v1a[i]~"pre")||(v1a[i]~"beta")||(v1a[i]~"^b$")) 
+                       if ((v1a[i]~"pre")||(v1a[i]~"beta")||(v1a[i]~"alpha")) 
                                return 1
                return 0
        } else if (count!=count2) {
                for (i=count+1; i<=count2; i++)
-                       if ((v2a[i]~"pre")||(v2a[i]~"beta")||(v2a[i]~"^b$"))
+                       if ((v2a[i]~"pre")||(v2a[i]~"beta")||(v2a[i]~"alpha"))
                                return 0
                return 1
        }
        return 0
 }
 
-function get_http_links(host,dir,port) {
+function get_links(url,        errno,link,oneline,retval,odp,tmpfile) {
 # get all <A HREF=..> tags from specified URL
        "mktemp /tmp/XXXXXX" | getline tmpfile
        close("mktemp /tmp/XXXXXX")
        
-       print ("GET " dir) | ( "nc " host " " port " > " tmpfile )
-       close("nc " host " " port " > " tmpfile)
-       
-       while (getline reply < tmpfile ) {
-               odp=(odp " " reply)
-       }
-
-       system("rm -f " tmpfile)
-       
-       if ( DEBUG ) print "Odpowiedz: " odp
-       while (tolower(odp) ~ /href=/) {
-               match(tolower(odp),/href="[^"]+"/)
-               link=substr(odp,RSTART,RLENGTH)
-               odp=substr(odp,RSTART+RLENGTH)
-               link=substr(link,7,length(link)-7)
-               retval=(retval " " link)
-       }
-       return retval
-}
-
-function get_ftp_links(host,dir,port) {
-       "mktemp /tmp/XXXXXX" | getline tmpfile
-       close("mktemp /tmp/XXXXXX")
-       
-       errno=system("export PLIKTMP=\"" tmpfile "\" FTP_DIR=\"" dir "\" FTP_PASS=\"sebek@sith\" FTP_USERNAME=\"anonymous\" FTP_HOST=\"" host "\" ; nc -e \"./ftplinks.sh\" " host " " port)
+       if (DEBUG) print "Retrieving: " url
+       errno=system("wget --inet -O - \"" url "\" > " tmpfile " 2>/dev/null" )
        
        if (errno==0) {
-               while (getline link < tmpfile)
-                       retval=(retval " " link)
-       } else { retval=("ERROR:" errno) }
-
+               while (getline oneline < tmpfile)
+                       odp=(odp " " oneline)
+               if ( DEBUG ) print "Odpowiedz: " odp
+       }
+               
        close(tmpfile)
        system("rm -f " tmpfile)
+       if ( errno==0) {
+               while ((tolower(odp) ~ /<frame[ \t]/)||(tolower(odp) ~ /href=/)) {
+                       if (tolower(odp) ~ /<frame[ \t]/) {
+                               match(tolower(odp),/<frame[ \t][^>]*>/)
+                               ramka=substr(odp,RSTART,RLENGTH)
+                               odp=substr(odp,RSTART+RLENGTH)
+                               match(tolower(ramka),/src="[^"]+"/)
+                               newurl=substr(ramka,RSTART+5,RLENGTH-6)
+                               if (DEBUG) print "Ramka: " newurl
+                               retval=(retval " " get_links(newurl))
+                       } else if (tolower(odp) ~ /href="[^"]+"/) {
+                               match(tolower(odp),/href="[^"]+"/)
+                               link=substr(odp,RSTART,RLENGTH)
+                               odp=substr(odp,RSTART+RLENGTH)
+                               link=substr(link,7,length(link)-7)
+                               retval=(retval " " link)
+                       } else {
+                               match(tolower(odp),/href=[^ \t>]+/)
+                               link=substr(odp,RSTART,RLENGTH)
+                               odp=substr(odp,RSTART+RLENGTH)
+                               link=substr(link,6,length(link)-5)
+                               retval=(retval " " link)
+                       }
+               }
+       } else {
+               retval=("WGET ERROR: " errno)
+       }
        
-       if (DEBUG) print "Odpowiedz: " retval
        
+       if (DEBUG) print "Zwracane: " retval
        return retval
 }
 
@@ -119,6 +131,12 @@ function subst_defines(var,defs) {
 function process_source(number,lurl,name,version) {
 # fetches file list, and compares version numbers
        if ( DEBUG ) print "Przetwarzam " lurl
+
+       if ( index(lurl,version)==0 ) {
+               if (DEBUG) print "Nie ma numeru wersji."
+               return 0
+       }
+
        sub("://",":",lurl)
        sub("/",":/",lurl)
        gsub("[^/]*$",":&",lurl)
@@ -128,14 +146,14 @@ function process_source(number,lurl,name,version) {
        dir=url[3]
        filename=url[4]
 
-       if ( index(dir,version) ) {
+       if (index(dir,version)) {
                dir=substr(dir,1,index(dir,version)-1)
                sub("[^/]*$","",dir)
                sub("(\.tar\.(bz|bz2|gz)|zip)$","",filename)
                if ( DEBUG ) print "Sprawdze katalog: " dir
                if ( DEBUG ) print "i plik: " filename
        }
-               
+
        filenameexp=filename
        gsub("\+","\\+",filenameexp)
        sub(version,"[A-Za-z0-9\\.]+",filenameexp)
@@ -146,19 +164,16 @@ function process_source(number,lurl,name,version) {
        if ( DEBUG ) print "Przed numerkiem: " prever
        if ( DEBUG ) print "i po: " postver
        
-       if ( DEBUG ) print "LYNX " acc "://" host dir 
+       if ( DEBUG ) print "ZaglĀ±dam na " acc "://" host dir 
        
        references=0
        finished=0
        oldversion=version
-       if (acc=="http") 
-               odp=get_http_links(host,dir,80)
-       else {
-               odp=get_ftp_links(host,dir,21)
-       }
-       if(odp ~ "ERROR:") {
-               print retval
+       odp=get_links(acc "://" host dir)
+       if( odp ~ "ERROR: ") {
+               print name "(" number ") " odp
        } else {
+               if (DEBUG) print "Sciagnieta strona"
                c=split(odp,linki)
                for (nr=1; nr<=c; nr++) {
                        addr=linki[nr]
@@ -167,8 +182,8 @@ function process_source(number,lurl,name,version) {
                                match(addr,filenameexp)
                                newfilename=substr(addr,RSTART,RLENGTH)
                                if (DEBUG) print "Hipotetyczny nowy: " newfilename
-                               sub(prever,"",newfilename)
-                               sub(postver,"",newfilename)
+                               newfilename=fixedsub(prever,"",newfilename)
+                               newfilename=fixedsub(postver,"",newfilename)
                                if (DEBUG) print "Wersja: " newfilename
                                if ( compare_ver(version, newfilename)==1 ) {
                                        if (DEBUG) print "Tak, jest nowa"
@@ -178,7 +193,7 @@ function process_source(number,lurl,name,version) {
                        }
                }
                if (finished==0)
-                       print name "(" number ") seems ok"
+                       print name "(" number ") seems ok: " oldversion
                else
                        print name "(" number ") [OLD] " oldversion " [NEW] " version
        }
@@ -201,6 +216,12 @@ BEGIN {
        # if U want to use DEBUG, run script with "-v DEBUG=1"
        # or uncomment the line below
        # DEBUG = 1
+
+       errno=system("wget --help > /dev/null 2>&1")
+       if (errno) {
+               print "No wget installed!"
+               exit 1
+       }
 }
 
 FNR==1 {
This page took 0.040246 seconds and 4 git commands to generate.