]> git.pld-linux.org Git - packages/rpm-build-tools.git/blame - pldnotify.awk
- allowed to use -ns0 for building, not only getting sources
[packages/rpm-build-tools.git] / pldnotify.awk
CommitLineData
6fb3305d 1#!/bin/awk -f
d4089f30 2# $Revision$, $Date$
2aba2068
SZ
3function fixedsub(s1,s2,t, ind) {
4# substitutes fixed strings (not regexps)
5 if (ind = index(t,s1)) {
6 t = substr(t, 1, ind-1) s2 substr(t, ind+length(s1))
7 }
8 return t
9}
6fb3305d 10
70a5e8d4
SZ
11function compare_ver(v1,v2) {
12# compares version numbers
13 while (match(v1,/[a-zA-Z][0-9]|[0-9][a-zA-Z]/))
14 v1=(substr(v1,1,RSTART) "." substr(v1,RSTART+RLENGTH-1))
15 while (match(v2,/[a-zA-Z][0-9]|[0-9][a-zA-Z]/))
16 v2=(substr(v2,1,RSTART) "." substr(v2,RSTART+RLENGTH-1))
17 sub("^0*","",v1)
18 sub("^0*","",v2)
19 if (DEBUG) print "v1 == " v1
20 if (DEBUG) print "v2 == " v2
21 count=split(v1,v1a,"\.")
22 count2=split(v2,v2a,"\.")
23
24 if (count<count2) mincount=count
25 else mincount=count2
26
27 for (i=1; i<=mincount; i++) {
db83adc3
SZ
28 if (v1a[i]=="") v1a[i]=0
29 if (v2a[i]=="") v2a[i]=0
70a5e8d4
SZ
30 if (DEBUG) print "i == " i
31 if (DEBUG) print "v1[i] == " v1a[i]
32 if (DEBUG) print "v2[i] == " v2a[i]
33 if ((v1a[i]~/[0-9]/)&&(v2a[i]~/[0-9]/)) {
34 if (length(v2a[i])>length(v1a[i]))
35 return 1
36 else if (v2a[i]>v1a[i])
37 return 1
38 else if (length(v1a[i])>length(v2a[i]))
39 return 0
40 else if (v1a[i]>v2a[i])
41 return 0
42 } else if ((v1a[i]~/[A-Za-z]/)&&(v2a[i]~/[A-Za-z]/)) {
43 if (v2a[i]>v1a[i])
44 return 1
45 else if (v1a[i]>v2a[i])
46 return 0
2e301ef5 47 } else if ((v1a[i]~"pre")||(v1a[i]~"beta")||(v1a[i]~"alpha"))
70a5e8d4
SZ
48 return 1
49 else
50 return 0
51 }
52 if ((count2==mincount)&&(count!=count2)) {
53 for (i=count2+1; i<=count; i++)
2e301ef5 54 if ((v1a[i]~"pre")||(v1a[i]~"beta")||(v1a[i]~"alpha"))
70a5e8d4
SZ
55 return 1
56 return 0
57 } else if (count!=count2) {
58 for (i=count+1; i<=count2; i++)
2e301ef5 59 if ((v2a[i]~"pre")||(v2a[i]~"beta")||(v2a[i]~"alpha"))
70a5e8d4
SZ
60 return 0
61 return 1
62 }
db4f445e 63 return 0
70a5e8d4
SZ
64}
65
2e301ef5 66function get_links(url, errno,link,oneline,retval,odp,tmpfile) {
70a5e8d4 67# get all <A HREF=..> tags from specified URL
db4f445e
SZ
68 "mktemp /tmp/XXXXXX" | getline tmpfile
69 close("mktemp /tmp/XXXXXX")
2e301ef5
SZ
70
71 if (DEBUG) print "Retrieving: " url
2d9cc4bb 72 errno=system("wget -O - \"" url "\" -t 3 -T 300 --passive-ftp > " tmpfile " 2>/dev/null" )
70a5e8d4 73
3f63995d 74 if (errno==0) {
7f460828
SZ
75 while (getline oneline < tmpfile)
76 odp=(odp " " oneline)
77 if ( DEBUG ) print "Odpowiedz: " odp
70a5e8d4 78 }
6f57d45d 79
3f63995d 80 close(tmpfile)
2e301ef5 81 system("rm -f " tmpfile)
55658186
JB
82 urldir=url;
83 sub(/[^\/]+$/,"",urldir)
3f63995d 84 if ( errno==0) {
93c3b403
SZ
85 while ((tolower(odp) ~ /<frame[ \t]/)||(tolower(odp) ~ /href=/)) {
86 if (tolower(odp) ~ /<frame[ \t]/) {
87 match(tolower(odp),/<frame[ \t][^>]*>/)
88 ramka=substr(odp,RSTART,RLENGTH)
89 odp=substr(odp,RSTART+RLENGTH)
6f57d45d 90 sub(/[sS][rR][cC]=[ \t]+/,"src=",ramka);
93c3b403 91 match(tolower(ramka),/src="[^"]+"/)
2e301ef5
SZ
92 newurl=substr(ramka,RSTART+5,RLENGTH-6)
93 if (DEBUG) print "Ramka: " newurl
55658186
JB
94 if (newurl !~ /\//) {
95 newurl=(urldir newurl)
96 if (DEBUG) print "Ramka->: " newurl
97 }
2e301ef5 98 retval=(retval " " get_links(newurl))
6f57d45d
JB
99 } else if (tolower(odp) ~ /href=[ \t]*"[^"]+"/) {
100 sub(/[hH][rR][eE][fF]=[ \t]+/,"href=",odp)
93c3b403
SZ
101 match(tolower(odp),/href="[^"]+"/)
102 link=substr(odp,RSTART,RLENGTH)
103 odp=substr(odp,RSTART+RLENGTH)
104 link=substr(link,7,length(link)-7)
105 retval=(retval " " link)
6f57d45d
JB
106 } else if (tolower(odp) ~ /href=[ \t]*[^ \t>]+/) {
107 sub(/[hH][rR][eE][fF]=[ \t]+/,"href=",odp)
8dfac79d
SZ
108 match(tolower(odp),/href=[^ \t>]+/)
109 link=substr(odp,RSTART,RLENGTH)
110 odp=substr(odp,RSTART+RLENGTH)
111 link=substr(link,6,length(link)-5)
112 retval=(retval " " link)
6f57d45d
JB
113 } else {
114 retval=(retval " INTERNAL_ERROR")
115 break
93c3b403 116 }
3f63995d
SZ
117 }
118 } else {
2e301ef5 119 retval=("WGET ERROR: " errno)
3f63995d
SZ
120 }
121
db4f445e 122
3f63995d 123 if (DEBUG) print "Zwracane: " retval
db4f445e 124 return retval
70a5e8d4
SZ
125}
126
6fb3305d 127function subst_defines(var,defs) {
3255b4c7 128# substitute all possible RPM macros
6fb3305d
SZ
129 while ((var ~ /%{.*}/) || (var ~ /%[A-Za-z0-9_]+/)) {
130 oldvar=var
131 for (j in defs) {
132 gsub("%{" j "}", defs[j], var)
133 gsub("%" j , defs[j], var)
134 }
135 if (var==oldvar) {
136 if ( DEBUG ) for (i in defs) print i " == " defs[i]
137 return var
138 }
139 }
140 return var
141}
142
c0bee1bc
JK
143function find_mirror(url) {
144
c54fbfc1
MK
145 while (succ = (getline line < "mirrors")) {
146 if (succ==-1) { return url }
c0bee1bc 147 nf=split(line,fields,"|")
a6f2cc98 148 if (nf>1){
c0bee1bc
JK
149 origin=fields[1]
150 mirror=fields[2]
151 mname=fields[3]
152 prefix=substr(url,1,length(origin))
153 if (prefix==origin){
154 if ( DEBUG ) print "Mirror znaleziony na " mname
155 close("mirrors")
156 return mirror substr(url,length(origin))
157 }
158 }
159 }
160
161 return url
162}
163
32aede2f 164function process_source(number,lurl,name,version) {
3255b4c7
SZ
165# fetches file list, and compares version numbers
166 if ( DEBUG ) print "Przetwarzam " lurl
3f63995d
SZ
167
168 if ( index(lurl,version)==0 ) {
169 if (DEBUG) print "Nie ma numeru wersji."
170 return 0
171 }
172
6fb3305d
SZ
173 sub("://",":",lurl)
174 sub("/",":/",lurl)
175 gsub("[^/]*$",":&",lurl)
176 split(lurl,url,":")
177 acc=url[1]
178 host=url[2]
179 dir=url[3]
70a5e8d4
SZ
180 filename=url[4]
181
3f63995d 182 if (index(dir,version)) {
70a5e8d4
SZ
183 dir=substr(dir,1,index(dir,version)-1)
184 sub("[^/]*$","",dir)
185 sub("(\.tar\.(bz|bz2|gz)|zip)$","",filename)
186 if ( DEBUG ) print "Sprawdze katalog: " dir
187 if ( DEBUG ) print "i plik: " filename
188 }
3f63995d 189
70a5e8d4
SZ
190 filenameexp=filename
191 gsub("\+","\\+",filenameexp)
192 sub(version,"[A-Za-z0-9\\.]+",filenameexp)
193 if ( DEBUG ) print "Wzorzec: " filenameexp
194 match(filename,version)
195 prever=substr(filename,1,RSTART-1)
196 postver=substr(filename,RSTART+RLENGTH)
197 if ( DEBUG ) print "Przed numerkiem: " prever
198 if ( DEBUG ) print "i po: " postver
c0bee1bc 199 newurl=find_mirror(acc "://" host dir)
c54fbfc1
MK
200 #print acc "://" host dir
201 #newurl=url[1]"://"url[2]url[3]url[4]
202 #newurl=acc "://" host dir filename
c0bee1bc 203