#!/bin/sh
#
# update-fstab - Copy /etc/fstab to the kboot environment, if needed
#
# Written 2005 by Werner Almesberger
#

IN=config/fstab
TMP=${TMPDIR:-/tmp}/.kboot-fstab.$$
OUT_DIR=root/etc
OUT_FILE=$OUT_DIR/fstab
LOCAL=/etc/fstab
CACHE_DIR=root-meta/cache
CACHE_FILE=$CACHE_DIR/fstab
DEPENDENCIES="rm -f kboot-root.cpio.gz"

trap "rm -f $TMP" 0

. scripts/common-config


if [ ! -r $IN -a -r $LOCAL ]; then
    if question copy_fstab "No $IN. Use $LOCAL (and copy to $IN) ?" y; then
	cp $LOCAL $IN
    else
	>$IN
    fi
fi
cp $IN $TMP # need a copy, so that we can do atomic moves

if [ -e $CACHE_FILE ]; then
    if diff -N $TMP $CACHE_FILE >/dev/null; then
	mkdir -p $OUT_DIR
	mv $TMP $OUT_FILE
	exit 0
    fi
fi

#
# Make sure that we'll end up with something that triggers a rebuild if we get
# interrupted anywhere.
#
rm -f $CACHE_FILE
mkdir -p $OUT_DIR
mv $TMP $OUT_FILE
cp $OUT_FILE $TMP
$DEPENDENCIES
mkdir -p $CACHE_DIR
mv $TMP $CACHE_FILE
