]> git.pld-linux.org Git - packages/rpm-build-tools.git/blame - pldnotify.awk
- and more updates
[packages/rpm-build-tools.git] / pldnotify.awk
CommitLineData
6fb3305d
SZ
1#!/bin/awk -f
2
70a5e8d4
SZ
3function compare_ver(v1,v2) {
4# compares version numbers
5 while (match(v1,/[a-zA-Z][0-9]|[0-9][a-zA-Z]/))
6 v1=(substr(v1,1,RSTART) "." substr(v1,RSTART+RLENGTH-1))
7 while (match(v2,/[a-zA-Z][0-9]|[0-9][a-zA-Z]/))
8 v2=(substr(v2,1,RSTART) "." substr(v2,RSTART+RLENGTH-1))
9 sub("^0*","",v1)
10 sub("^0*","",v2)
11 if (DEBUG) print "v1 == " v1
12 if (DEBUG) print "v2 == " v2
13 count=split(v1,v1a,"\.")
14 count2=split(v2,v2a,"\.")
15
16 if (count<count2) mincount=count
17 else mincount=count2
18
19 for (i=1; i<=mincount; i++) {
db83adc3
SZ
20 if (v1a[i]=="") v1a[i]=0
21 if (v2a[i]=="") v2a[i]=0
70a5e8d4
SZ
22 if (DEBUG) print "i == " i
23 if (DEBUG) print "v1[i] == " v1a[i]
24 if (DEBUG) print "v2[i] == " v2a[i]
25 if ((v1a[i]~/[0-9]/)&&(v2a[i]~/[0-9]/)) {
26 if (length(v2a[i])>length(v1a[i]))
27 return 1
28 else if (v2a[i]>v1a[i])
29 return 1
30 else if (length(v1a[i])>length(v2a[i]))
31 return 0
32 else if (v1a[i]>v2a[i])
33 return 0
34 } else if ((v1a[i]~/[A-Za-z]/)&&(v2a[i]~/[A-Za-z]/)) {
35 if (v2a[i]>v1a[i])
36 return 1
37 else if (v1a[i]>v2a[i])
38 return 0
39 } else if ((v1a[i]~"pre")||(v1a[i]~"beta")||(v1a[i]~"^b$"))
40 return 1
41 else
42 return 0
43 }
44 if ((count2==mincount)&&(count!=count2)) {
45 for (i=count2+1; i<=count; i++)
46 if ((v1a[i]~"pre")||(v1a[i]~"beta")||(v1a[i]~"^b$"))
47 return 1
48 return 0
49 } else if (count!=count2) {
50 for (i=count+1; i<=count2; i++)
51 if ((v2a[i]~"pre")||(v2a[i]~"beta")||(v2a[i]~"^b$"))
52 return 0
53 return 1
54 }
55return 0
56}
57
58function get_http_links(host,dir,port) {
59# get all <A HREF=..> tags from specified URL
60 cmd=("nc " host " " port " > .tmp")
61 finished=0
62
63 print ("GET " dir) | cmd
64 close(cmd)
65
66 while (getline reply < ".tmp") {
67 odp=(odp reply)
68 }
69 system("rm -f .tmp")
70
71 if ( DEBUG ) print "Odpowiedz: " odp
72 while (tolower(odp) ~ /href=/) {
73 match(tolower(odp),/href="[^"]+"/)
74 link=substr(odp,RSTART,RLENGTH)
75 odp=substr(odp,RSTART+RLENGTH)
76 link=substr(link,7,length(link)-7)
77 print link
78 }
79}
80
6fb3305d 81function subst_defines(var,defs) {
3255b4c7 82# substitute all possible RPM macros
6fb3305d
SZ
83 while ((var ~ /%{.*}/) || (var ~ /%[A-Za-z0-9_]+/)) {
84 oldvar=var
85 for (j in defs) {
86 gsub("%{" j "}", defs[j], var)
87 gsub("%" j , defs[j], var)
88 }
89 if (var==oldvar) {
90 if ( DEBUG ) for (i in defs) print i " == " defs[i]
91 return var
92 }
93 }
94 return var
95}
96
70a5e8d4 97function process_source(lurl,name,version) {
3255b4c7
SZ
98# fetches file list, and compares version numbers
99 if ( DEBUG ) print "Przetwarzam " lurl
6fb3305d
SZ
100 sub("://",":",lurl)
101 sub("/",":/",lurl)
102 gsub("[^/]*$",":&",lurl)
103 split(lurl,url,":")
104 acc=url[1]
105 host=url[2]
106 dir=url[3]
70a5e8d4
SZ
107 filename=url[4]
108
109 if ( index(dir,version) ) {
110 dir=substr(dir,1,index(dir,version)-1)
111 sub("[^/]*$","",dir)
112 sub("(\.tar\.(bz|bz2|gz)|zip)$","",filename)
113 if ( DEBUG ) print "Sprawdze katalog: " dir
114 if ( DEBUG ) print "i plik: " filename
115 }
116
117 filenameexp=filename
118 gsub("\+","\\+",filenameexp)
119 sub(version,"[A-Za-z0-9\\.]+",filenameexp)
120 if ( DEBUG ) print "Wzorzec: " filenameexp
121 match(filename,version)
122 prever=substr(filename,1,RSTART-1)
123 postver=substr(filename,RSTART+RLENGTH)
124 if ( DEBUG ) print "Przed numerkiem: " prever
125 if ( DEBUG ) print "i po: " postver
126
3255b4c7 127 if ( DEBUG ) print "LYNX " acc "://" host dir
6fb3305d
SZ
128
129 references=0
db83adc3 130 finished=0
81715e32 131 while (("lynx --dump " acc "://" host dir) | getline result) {
3255b4c7
SZ
132 if (result ~ "References") references=1
133 if ((result ~ "[0-9]+\. (ftp|http)://")&&(references==1)) {
6fb3305d
SZ
134 split(result,links)
135 addr=links[2]
3255b4c7 136 if (DEBUG) print "Znaleziony link: " addr
70a5e8d4
SZ
137 if (addr ~ filenameexp) {
138 match(addr,filenameexp)
139 newfilename=substr(addr,RSTART,RLENGTH)
140 if (DEBUG) print "Hipotetyczny nowy: " newfilename
141 sub(prever,"",newfilename)
142 sub(postver,"",newfilename)
143 if (DEBUG) print "Wersja: " newfilename
db83adc3 144 if ( compare_ver(version, newfilename)==1 ) {
81715e32 145 if (DEBUG) print "Tak, jest nowa"
70a5e8d4 146 print name " : [OLD] " version " [NEW] " newfilename
81715e32 147 finished=1
db83adc3 148 }
70a5e8d4 149 }
6fb3305d
SZ
150 }
151 }
81715e32 152 if (finished==0) ptiny name " : seems ok"
70a5e8d4
SZ
153 close("lynx --dump " acc "://" host dir)
154return 0
6fb3305d
SZ
155}
156
3255b4c7
SZ
157function process_data(name,ver,rel,src) {
158# this function checks if substitutions were valid, and if true:
159# processes each URL and tries to get current file list
6fb3305d
SZ
160 for (i in src) {
161 if ( src[i] !~ /%{.*}/ && src[i] !~ /%[A-Za-z0-9_]/ ) {
162 if ( DEBUG ) print "Zrodlo: " src[i]
70a5e8d4 163 process_source(src[i],name,ver)
6fb3305d
SZ
164 } else {
165 print FNAME ":" i ": niemozliwe podstawienie: " src[i]
166 }
167 }
168}
169
170BEGIN {
171 # if U want to use DEBUG, run script with "-v DEBUG=1"
172 # or uncomment the line below
70a5e8d4 173 # DEBUG = 1
6fb3305d
SZ
174}
175
176FNR==1 {
177 if ( ARGIND != 1 ) {
3255b4c7 178 process_data(NAME,VER,REL,SRC)
6fb3305d
SZ
179 NAME="" ; VER="" ; REL=""
180 for (i in DEFS) delete DEFS[i]
181 for (i in SRC) delete SRC[i]
182 }
183 FNAME=FILENAME
184}
185
3255b4c7 186/^[Uu][Rr][Ll]:/&&(URL=="") { URL=subst_defines($2,DEFS) ; DEFS["url"]=URL }
6fb3305d
SZ
187/^[Nn]ame:/&&(NAME=="") { NAME=subst_defines($2,DEFS) ; DEFS["name"]=NAME }
188/^[Vv]ersion:/&&(VER=="") { VER=subst_defines($2,DEFS) ; DEFS["version"]=VER }
189/^[Rr]elease:/&&(REL=="") { REL=subst_defines($2,DEFS) ; DEFS["release"]=REL }
190/^[Ss]ource[0-9]*:/ { if (/(ftp|http):\/\//) SRC[FNR]=subst_defines($2,DEFS) }
191/%define/ { DEFS[$2]=subst_defines($3,DEFS) }
192
193END {
3255b4c7 194 process_data(NAME,VER,REL,SRC)
6fb3305d 195}
This page took 0.054592 seconds and 4 git commands to generate.