]> git.pld-linux.org Git - packages/rpm-build-tools.git/blame - pldnotify.awk
- frames support for http_get_links
[packages/rpm-build-tools.git] / pldnotify.awk
CommitLineData
6fb3305d 1#!/bin/awk -f
d4089f30 2# $Revision$, $Date$
6fb3305d 3
70a5e8d4
SZ
4function compare_ver(v1,v2) {
5# compares version numbers
6 while (match(v1,/[a-zA-Z][0-9]|[0-9][a-zA-Z]/))
7 v1=(substr(v1,1,RSTART) "." substr(v1,RSTART+RLENGTH-1))
8 while (match(v2,/[a-zA-Z][0-9]|[0-9][a-zA-Z]/))
9 v2=(substr(v2,1,RSTART) "." substr(v2,RSTART+RLENGTH-1))
10 sub("^0*","",v1)
11 sub("^0*","",v2)
12 if (DEBUG) print "v1 == " v1
13 if (DEBUG) print "v2 == " v2
14 count=split(v1,v1a,"\.")
15 count2=split(v2,v2a,"\.")
16
17 if (count<count2) mincount=count
18 else mincount=count2
19
20 for (i=1; i<=mincount; i++) {
db83adc3
SZ
21 if (v1a[i]=="") v1a[i]=0
22 if (v2a[i]=="") v2a[i]=0
70a5e8d4
SZ
23 if (DEBUG) print "i == " i
24 if (DEBUG) print "v1[i] == " v1a[i]
25 if (DEBUG) print "v2[i] == " v2a[i]
26 if ((v1a[i]~/[0-9]/)&&(v2a[i]~/[0-9]/)) {
27 if (length(v2a[i])>length(v1a[i]))
28 return 1
29 else if (v2a[i]>v1a[i])
30 return 1
31 else if (length(v1a[i])>length(v2a[i]))
32 return 0
33 else if (v1a[i]>v2a[i])
34 return 0
35 } else if ((v1a[i]~/[A-Za-z]/)&&(v2a[i]~/[A-Za-z]/)) {
36 if (v2a[i]>v1a[i])
37 return 1
38 else if (v1a[i]>v2a[i])
39 return 0
7f460828 40 } else if ((v1a[i]~"pre")||(v1a[i]~"beta"))
70a5e8d4
SZ
41 return 1
42 else
43 return 0
44 }
45 if ((count2==mincount)&&(count!=count2)) {
46 for (i=count2+1; i<=count; i++)
7f460828 47 if ((v1a[i]~"pre")||(v1a[i]~"beta"))
70a5e8d4
SZ
48 return 1
49 return 0
50 } else if (count!=count2) {
51 for (i=count+1; i<=count2; i++)
7f460828 52 if ((v2a[i]~"pre")||(v2a[i]~"beta"))
70a5e8d4
SZ
53 return 0
54 return 1
55 }
db4f445e 56 return 0
70a5e8d4
SZ
57}
58
3f63995d 59function get_http_links(host,dir,port, errno,link,oneline,retval,odp,tmpfile) {
70a5e8d4 60# get all <A HREF=..> tags from specified URL
db4f445e
SZ
61 "mktemp /tmp/XXXXXX" | getline tmpfile
62 close("mktemp /tmp/XXXXXX")
7f460828
SZ
63 if (DEBUG) print "Retrieving HTML : http://" host ":" port dir
64 errno=system("wget -O - \"http://" host ":" port dir "\" > " tmpfile " 2>/dev/null" )
70a5e8d4 65
3f63995d 66 if (errno==0) {
7f460828
SZ
67 while (getline oneline < tmpfile)
68 odp=(odp " " oneline)
69 if ( DEBUG ) print "Odpowiedz: " odp
70a5e8d4 70 }
3f63995d
SZ
71
72 close(tmpfile)
3f63995d 73 if ( errno==0) {
93c3b403
SZ
74 while ((tolower(odp) ~ /<frame[ \t]/)||(tolower(odp) ~ /href=/)) {
75 if (tolower(odp) ~ /<frame[ \t]/) {
76 match(tolower(odp),/<frame[ \t][^>]*>/)
77 ramka=substr(odp,RSTART,RLENGTH)
78 odp=substr(odp,RSTART+RLENGTH)
79 match(tolower(ramka),/src="[^"]+"/)
80 link=substr(ramka,RSTART+5,RLENGTH-6)
81 if (link !~ /^http:\/\//)
82 newhost=host
83 else {
84 match(link,/^http:\/\/[^\/]*/)
85 newhost=substr(link,RSTART+7,RLENGTH-7)
86 link=substr(link,RSTART+RLENGTH)
87 }
88 if (link !~ /^\//)
89 link=dir link
90 if (DEBUG) print "Ramka: http://" newhost ":" port link
91 retval=(retval " " get_http_links(newhost,link,port))
92 } else {
93 match(tolower(odp),/href="[^"]+"/)
94 link=substr(odp,RSTART,RLENGTH)
95 odp=substr(odp,RSTART+RLENGTH)
96 link=substr(link,7,length(link)-7)
97 retval=(retval " " link)
98 }
3f63995d
SZ
99 }
100 } else {
101 retval=("HTTP ERROR: " errno)
102 }
103
db4f445e 104 system("rm -f " tmpfile)
70a5e8d4 105
3f63995d 106 if (DEBUG) print "Zwracane: " retval
db4f445e
SZ
107 return retval
108}
109
3f63995d 110function get_ftp_links(host,dir,port, tmpfile,link,retval) {
db4f445e
SZ
111 "mktemp /tmp/XXXXXX" | getline tmpfile
112 close("mktemp /tmp/XXXXXX")
113
12a4ed2f 114 errno=system("export PLIKTMP=\"" tmpfile "\" FTP_DIR=\"" dir "\" FTP_PASS=\"pldnotifier@pld.org.pl\" FTP_USERNAME=\"anonymous\" FTP_HOST=\"" host "\" DEBUG=\"" DEBUG "\" ; nc -e \"./ftplinks.sh\" " host " " port)
db4f445e 115
7f460828 116 if (DEBUG) print "Skonczylem sciagac"
188dc51f
SZ
117 if (errno==0) {
118 while (getline link < tmpfile)
119 retval=(retval " " link)
3f63995d
SZ
120 close(tmpfile)
121 } else {
122 retval=("FTP ERROR: " errno)
123 }
188dc51f 124
db4f445e
SZ
125 system("rm -f " tmpfile)
126
3f63995d 127 if (DEBUG) print "Zwracane: " retval
db4f445e 128 return retval
70a5e8d4
SZ
129}
130
6fb3305d 131function subst_defines(var,defs) {
3255b4c7 132# substitute all possible RPM macros
6fb3305d
SZ
133 while ((var ~ /%{.*}/) || (var ~ /%[A-Za-z0-9_]+/)) {
134 oldvar=var
135 for (j in defs) {
136 gsub("%{" j "}", defs[j], var)
137 gsub("%" j , defs[j], var)
138 }
139 if (var==oldvar) {
140 if ( DEBUG ) for (i in defs) print i " == " defs[i]
141 return var
142 }
143 }
144 return var
145}
146
32aede2f 147function process_source(number,lurl,name,version) {
3255b4c7
SZ
148# fetches file list, and compares version numbers
149 if ( DEBUG ) print "Przetwarzam " lurl
3f63995d
SZ
150
151 if ( index(lurl,version)==0 ) {
152 if (DEBUG) print "Nie ma numeru wersji."
153 return 0
154 }
155
6fb3305d
SZ
156 sub("://",":",lurl)
157 sub("/",":/",lurl)
158 gsub("[^/]*$",":&",lurl)
159 split(lurl,url,":")
160 acc=url[1]
161 host=url[2]
162 dir=url[3]
70a5e8d4
SZ
163 filename=url[4]
164
3f63995d 165 if (index(dir,version)) {
70a5e8d4
SZ
166 dir=substr(dir,1,index(dir,version)-1)
167 sub("[^/]*$","",dir)
168 sub("(\.tar\.(bz|bz2|gz)|zip)$","",filename)
169 if ( DEBUG ) print "Sprawdze katalog: " dir
170 if ( DEBUG ) print "i plik: " filename
171 }
3f63995d 172
70a5e8d4
SZ
173 filenameexp=filename
174 gsub("\+","\\+",filenameexp)
175 sub(version,"[A-Za-z0-9\\.]+",filenameexp)
176 if ( DEBUG ) print "Wzorzec: " filenameexp
177 match(filename,version)
178 prever=substr(filename,1,RSTART-1)
179 postver=substr(filename,RSTART+RLENGTH)
180 if ( DEBUG ) print "Przed numerkiem: " prever
181 if ( DEBUG ) print "i po: " postver
182
3f63995d 183