From a042e101a1075df050af9efe41c1c1a1a46e79e6 Mon Sep 17 00:00:00 2001 From: Steffen Nurpmeso Date: Fri, 25 May 2018 17:20:00 +0200 Subject: [PATCH] iana-etc: add update.sh --- iana-etc/update.sh | 67 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 67 insertions(+) create mode 100755 iana-etc/update.sh 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 + } + / 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 + } + / 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