blob: 3b4f59d9a70af87154c0019252a2bceaee611c6a (
plain)
1 #!/bin/sh -
2 #@ Update protocols and services from IANA.
3 #@ Taken from ArchLinux script written by Gaetan Bisson. Adjusted for CRUX.
4
5 awk=awk
6 curl=curl
7 url_pn='https://www.iana.org/assignments/protocol-numbers/protocol-numbers.xml'
8 url_snpn="https://www.iana.org/assignments/service-names-port-numbers/\
9 service-names-port-numbers.xml"
10
11 download() {
12 datetime=`date +'%FT%T%z'`
13 echo 'Downloading protocols'
14 ${curl} -o protocols.xml ${url_pn}
15 [ ${?} -eq 0 ] || exit 20
16 echo 'Downloading services'
17 ${curl} -o services.xml ${url_snpn}
18 [ ${?} -eq 0 ] || exit 21
19 }
20
21 process() {
22 echo 'Processing protocols'
23 ${awk} -F "[<>]" -v URL="${url_pn}" -v DT="${datetime}" '
24 BEGIN{
25 print "# /etc/protocols, created " DT
26 print "# Source: " URL
27 }
28 /<record/ {v = n = ""}
29 /<value/ {v = $3}
30 /<name/ && $3!~/ / {n = $3}
31 /<\/record/ && n && v != ""{
32 printf "%-12s %3i %s\n", tolower(n), v, n
33 }
34 ' < protocols.xml > protocols.new
35 [ ${?} -eq 0 ] || exit 30
36
37 echo 'Processing services'
38 ${awk} -F "[<>]" -v URL="${url_snpn}" -v DT="${datetime}" '
39 BEGIN{
40 print "# /etc/services, created " DT
41 print "# Source: " URL
42 }
43 /<record/ {n = u = p = c = ""}
44 /<name/ && !/\(/ {n = $3}
45 /<number/ {u = $3}
46 /<protocol/ {p = $3}
47 /Unassigned/ || /Reserved/ || /historic/ {c = 1}
48 /<\/record/ && n && u && p && !c{
49 printf "%-15s %5i/%s\n", n, u, p
50 }
51 ' < services.xml > services.new
52 [ ${?} -eq 0 ] || exit 31
53 }
54
55 update() {
56 mv protocols.new protocols
57 [ ${?} -eq 0 ] || exit 40
58 mv services.new services
59 [ ${?} -eq 0 ] || exit 41
60 rm -f protocols.xml services.xml
61 [ ${?} -eq 0 ] || exit 42
62 }
63
64 download
65 process
66 update
|