#!/bin/sh
# Back-up ntp.drift file changes to flash. 

SRC="/var/db/ntp.drift"
DST="/cfg/local/ntp.drift"

trap "umount /cfg" 1 2 15 EXIT

EX_OK=0
EX_NOINPUT=66
EX_CANTCREAT=73

mount -ro noatime /cfg

# Check whether source exists
if [ ! -r $SRC ]; then
    echo "ERROR: '$SRC' not readable!" 1>&2
    exit $EX_NOINPUT
fi

# Compare files, ignore white spaces, modification, etc
diff -b -B -q ${SRC} ${DST}; RETVAL=$?
if [ $RETVAL -ne 0 ]; then
  # 2: DST does not yet, exists, 1: file differs
  	mount -uwo noatime /cfg
	mkdir -p /cfg/local
  	cp ${SRC} ${DST}
fi

exit $EX_OK
