]> git.pld-linux.org Git - packages/rpm-build-tools.git/blame - pldnotify.awk
- add %clean if it isn't there yet...
[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
SZ
73 if ( errno==0) {
74 while (tolower(odp) ~ /href=/) {
75 match(tolower(odp),/href="[^"]+"/)
76 link=substr(odp,RSTART,RLENGTH)
77 odp=substr(odp,RSTART+RLENGTH)
78 link=substr(link,7,length(link)-7)
79 retval=(retval " " link)
80 }
81 } else {
82 retval=("HTTP ERROR: " errno)
83 }
84
db4f445e 85 system("rm -f " tmpfile)
70a5e8d4 86
3f63995d 87 if (DEBUG) print "Zwracane: " retval
db4f445e
SZ
88 return retval
89}
90
3f63995d 91function get_ftp_links(host,dir,port, tmpfile,link,retval) {
db4f445e
SZ
92 "mktemp /tmp/XXXXXX" | getline tmpfile
93 close("mktemp /tmp/XXXXXX")
94
12a4ed2f 95 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 96
7f460828 97 if (DEBUG) print "Skonczylem sciagac"
188dc51f
SZ
98 if (errno==0) {
99 while (getline link < tmpfile)
100 retval=(retval " " link)
3f63995d
SZ
101 close(tmpfile)
102 } else {
103 retval=("FTP ERROR: " errno)
104 }
188dc51f 105
db4f445e
SZ
106 system("rm -f " tmpfile)
107
3f63995d 108 if (DEBUG) print "Zwracane: " retval
db4f445e 109 return retval
70a5e8d4
SZ
110}
111
6fb3305d 112function subst_defines(var,defs) {
3255b4c7 113# substitute all possible RPM macros
6fb3305d
SZ
114 while ((var ~ /%{.*}/) || (var ~ /%[A-Za-z0-9_]+/)) {
115 oldvar=var
116 for (j in defs) {
117 gsub("%{" j "}", defs[j], var)
118 gsub("%" j , defs[j], var)
119 }
120 if (var==oldvar) {
121 if ( DEBUG ) for (i in defs) print i " == " defs[i]
122 return var
123 }
124 }
125 return var
126}
127
32aede2f 128function process_source(number,lurl,name,version) {
3255b4c7
SZ
129# fetches file list, and compares version numbers
130 if ( DEBUG ) print "Przetwarzam " lurl
3f63995d
SZ
131
132 if ( index(lurl,version)==0 ) {
133 if (DEBUG) print "Nie ma numeru wersji."
134 return 0
135 }
136
6fb3305d
SZ
137 sub("://",":",lurl)
138 sub("/",":/",lurl)
139 gsub("[^/]*$",":&",lurl)
140 split(lurl,url,":")
141 acc=url[1]
142 host=url[2]
143 dir=url[3]
70a5e8d4
SZ
144 filename=url[4]
145
3f63995d 146 if (index(dir,version)) {
70a5e8d4
SZ
147 dir=substr(dir,1,index(dir,version)-1)
148 sub("[^/]*$","",dir)
149 sub("(\.tar\.(bz|bz2|gz)|zip)$","",filename)
150 if ( DEBUG ) print "Sprawdze katalog: " dir
151 if ( DEBUG ) print "i plik: " filename
152 }
3f63995d 153
70a5e8d4
SZ
154 filenameexp=filename
155 gsub("\+","\\+",filenameexp)
156 sub(version,"[A-Za-z0-9\\.]+",filenameexp)
157 if ( DEBUG ) print "Wzorzec: " filenameexp
158 match(filename,version)
159 prever=substr(filename,1,RSTART-1)
160 postver=substr(filename,RSTART+RLENGTH)
161 if ( DEBUG ) print "Przed numerkiem: " prever
162 if ( DEBUG ) print "i po: " postver
163
3f63995d 164