#!/bin/sh
set -x
if [ $# -gt 0 ]; then
    razor="$1"
else
    razor=../src/razor
fi
check_file()
{
    $razor list-files | grep -F -x "$1" > /dev/null
    if [ $? -ne 0 ]; then
	echo $1: Not in database >&2
	exit 1
    fi
    if [ ! -e "$tmpdir$1" ]; then 
	echo $1: Not in filesystem >&2
	exit 1
    fi
}
tmpdir=`mktemp -dt` || exit 1
export RAZOR_ROOT="file:$tmpdir"
$razor init || exit 1
export YUM_URL="file:`pwd`/base"
$razor import-yum || exit 1
$razor install zap || exit 1
$razor install --relocate /usr=/opt --relocate /etc=/opt/etc zsh || exit 1
check_file /etc/zsh.conf
check_file /usr/bin/zap
check_file /opt/bin/zip
check_file /opt/bin/zsh
rm -rf "$tmpdir"
