1#!/bin/sh
2# @(#) $Id: update-ethercodes.sh.in 1529 2021-12-15 00:47:54Z leres $ (LBL)
3#
4#  Generate ethercodes.dat
5#
6
7prog="`basename $0`"
8
9PATH=/usr/local/bin:${PATH}
10export PATH
11
12t1=/tmp/${prog}.1.$$
13
14trap 'rm -f ${t1}; exit 1' 1 2 3 15 EXIT
15
16if [ ! -f arp.dat ]; then
17	cd /usr/local/arpwatch || exit 1
18fi
19
20fn=ethercodes.dat
21url=http://standards-oui.ieee.org/oui/oui.csv
22
23if [ -x /usr/bin/fetch ]; then
24	cmd1="fetch -q -o - ${url}"
25else
26	cmd1="wget -q --output-document=- ${url}"
27fi
28
29fn2=massagevendor.py
30if [ -x ${fn2} ]; then
31	# XXX
32	## cmd2="@PYTHON@ ${fn2}"
33	cmd2="/usr/local/bin/python ${fn2}"
34else
35	cmd2=./massagevendor
36fi
37
38# Emit exit status of first command in pipe
39# https://unix.stackexchange.com/a/70675
40((((${cmd1}; echo $? >&3) | ${cmd2} >&4) 3>&1) | (read xs; exit ${xs})) 4> ${t1}
41if [ $? -ne 0 ]; then
42	rm -f ${t1}
43fi
44mv ${t1} ${fn}
45