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