]> git.pld-linux.org Git - packages/rpm-build-tools.git/blame - pldnotify.awk
- misc fixes (still pre-alpha-release :) )
[packages/rpm-build-tools.git] / pldnotify.awk
CommitLineData
6fb3305d
SZ
1#!/bin/awk -f
2
3function subst_defines(var,defs) {
3255b4c7 4# substitute all possible RPM macros
6fb3305d
SZ
5 while ((var ~ /%{.*}/) || (var ~ /%[A-Za-z0-9_]+/)) {
6 oldvar=var
7 for (j in defs) {
8 gsub("%{" j "}", defs[j], var)
9 gsub("%" j , defs[j], var)
10 }
11 if (var==oldvar) {
12 if ( DEBUG ) for (i in defs) print i " == " defs[i]
13 return var
14 }
15 }
16 return var
17}
18
19function process_source(lurl,version) {
3255b4c7
SZ
20# fetches file list, and compares version numbers
21 if ( DEBUG ) print "Przetwarzam " lurl
6fb3305d
SZ
22 sub("://",":",lurl)
23 sub("/",":/",lurl)
24 gsub("[^/]*$",":&",lurl)
25 split(lurl,url,":")
26 acc=url[1]
27 host=url[2]
28 dir=url[3]
3255b4c7 29 if ( DEBUG ) print "LYNX " acc "://" host dir
6fb3305d
SZ
30
31 references=0
3255b4c7
SZ
32 while (("lynx --dump " acc "://" host dir) | getline result ) {
33 if (result ~ "References") references=1
34 if ((result ~ "[0-9]+\. (ftp|http)://")&&(references==1)) {
6fb3305d
SZ
35 split(result,links)
36 addr=links[2]
3255b4c7 37 if (DEBUG) print "Znaleziony link: " addr
6fb3305d
SZ
38 }
39 }
40}
41
3255b4c7
SZ
42function process_data(name,ver,rel,src) {
43# this function checks if substitutions were valid, and if true:
44# processes each URL and tries to get current file list
6fb3305d
SZ
45 for (i in src) {
46 if ( src[i] !~ /%{.*}/ && src[i] !~ /%[A-Za-z0-9_]/ ) {
47 if ( DEBUG ) print "Zrodlo: " src[i]
3255b4c7 48 process_source(src[i],defs["version"])
6fb3305d
SZ
49 } else {
50 print FNAME ":" i ": niemozliwe podstawienie: " src[i]
51 }
52 }
53}
54
55BEGIN {
56 # if U want to use DEBUG, run script with "-v DEBUG=1"
57 # or uncomment the line below
3255b4c7 58 DEBUG = 1
6fb3305d
SZ
59}
60
61FNR==1 {
62 if ( ARGIND != 1 ) {
3255b4c7 63 process_data(NAME,VER,REL,SRC)
6fb3305d
SZ
64 NAME="" ; VER="" ; REL=""
65 for (i in DEFS) delete DEFS[i]
66 for (i in SRC) delete SRC[i]
67 }
68 FNAME=FILENAME
69}
70
3255b4c7 71/^[Uu][Rr][Ll]:/&&(URL=="") { URL=subst_defines($2,DEFS) ; DEFS["url"]=URL }
6fb3305d
SZ
72/^[Nn]ame:/&&(NAME=="") { NAME=subst_defines($2,DEFS) ; DEFS["name"]=NAME }
73/^[Vv]ersion:/&&(VER=="") { VER=subst_defines($2,DEFS) ; DEFS["version"]=VER }
74/^[Rr]elease:/&&(REL=="") { REL=subst_defines($2,DEFS) ; DEFS["release"]=REL }
75/^[Ss]ource[0-9]*:/ { if (/(ftp|http):\/\//) SRC[FNR]=subst_defines($2,DEFS) }
76/%define/ { DEFS[$2]=subst_defines($3,DEFS) }
77
78END {
3255b4c7 79 process_data(NAME,VER,REL,SRC)
6fb3305d 80}
This page took 0.039705 seconds and 4 git commands to generate.