summaryrefslogtreecommitdiff
path: root/iana-etc
diff options
context:
space:
mode:
authorSteffen Nurpmeso <steffen@sdaoden.eu>2018-05-25 17:20:00 +0200
committerFredrik Rinnestam <fredrik@crux.nu>2018-06-06 23:08:14 +0200
commita042e101a1075df050af9efe41c1c1a1a46e79e6 (patch)
treeca6c2b4d14fcbbc94d146f240f5c773092474537 /iana-etc
parent1f7cd15b02f3d4fc7e871df31a2982ad50a933d3 (diff)
downloadcore-a042e101a1075df050af9efe41c1c1a1a46e79e6.tar.gz
core-a042e101a1075df050af9efe41c1c1a1a46e79e6.tar.xz
iana-etc: add update.sh
Diffstat (limited to 'iana-etc')
-rwxr-xr-xiana-etc/update.sh67
1 files changed, 67 insertions, 0 deletions
diff --git a/iana-etc/update.sh b/iana-etc/update.sh
new file mode 100755
index 00000000..0f79cc88
--- /dev/null
+++ b/iana-etc/update.sh
@@ -0,0 +1,67 @@
+#!/bin/sh -
+#@ Update protocols and services from IANA.
+#@ Taken from ArchLinux script written by Gaetan Bisson. Adjusted for CRUX.
+
+awk=nawk
+curl=curl
+url_pn='https://www.iana.org/assignments/protocol-numbers/protocol-numbers.xml'
+url_snpn="https://www.iana.org/assignments/service-names-port-numbers/\
+service-names-port-numbers.xml"
+
+download() {
+ datetime=`date +'%FT%T%z'`
+ echo 'Downloading protocols'
+ ${curl} -o protocols.xml ${url_pn}
+ [ ${?} -eq 0 ] || exit 20
+ echo 'Downloading services'
+ ${curl} -o services.xml ${url_snpn}
+ [ ${?} -eq 0 ] || exit 21
+}
+
+process() {
+ echo 'Processing protocols'
+ ${awk} -F "[<>]" -v URL="${url_pn}" -v DT="${datetime}" '
+ BEGIN{
+ print "# /etc/protocols, created " DT
+ print "# Source: " URL
+ }
+ /<record/ {v = n = ""}
+ /<value/ {v = $3}
+ /<name/ && $3!~/ / {n = $3}
+ /<\/record/ && n && v != ""{
+ printf "%-12s %3i %s\n", tolower(n), v, n
+ }
+ ' < protocols.xml > protocols.new
+ [ ${?} -eq 0 ] || exit 30
+
+ echo 'Processing services'
+ ${awk} -F "[<>]" -v URL="${url_snpn}" -v DT="${datetime}" '
+ BEGIN{
+ print "# /etc/services, created " DT
+ print "# Source: " URL
+ }
+ /<record/ {n = u = p = c = ""}
+ /<name/ && !/\(/ {n = $3}
+ /<number/ {u = $3}
+ /<protocol/ {p = $3}
+ /Unassigned/ || /Reserved/ || /historic/ {c = 1}
+ /<\/record/ && n && u && p && !c{
+ printf "%-15s %5i/%s\n", n, u, p
+ }
+ ' < services.xml > services.new
+ [ ${?} -eq 0 ] || exit 31
+}
+
+update() {
+ mv protocols.new protocols
+ [ ${?} -eq 0 ] || exit 40
+ mv services.new services
+ [ ${?} -eq 0 ] || exit 41
+ rm -f protocols.xml services.xml
+ md5sum protocols services > .md5sum
+ [ ${?} -eq 0 ] || exit 42
+}
+
+download
+process
+update

Generated by cgit