#!/bin/sh

set -o nounset
set -o errexit

DIR=$1
FILE=$2

DST_DIR=/var/lib/arpwatch
DST_FILE=ethercodes.db

# we only want to act on oui.txt
[ "$FILE" = "oui.txt" ] || exit 0

# if the input file does not exist, exit (ieee-data might not be installed and
# arpwatch can live without ethercodes.db)
[ -f "${DIR}/${FILE}" ] || exit 0

# make sure the destination directory exists
mkdir -p "$DST_DIR"
# create the new database file
massagevendor "${DIR}/${FILE}" > "${DST_DIR}/${DST_FILE}.new"
# atomically replace the database
mv "${DST_DIR}/${DST_FILE}.new" "${DST_DIR}/${DST_FILE}"
