#!/bin/sh
if [ ! -f aaudit-hostname -o ! -f config -o ! -f description -o ! -d objects ]; then
	echo "run in the created git repository"
	exit 1
fi
IP="$(cat aaudit-hostname)"
if ! ssh root@"$IP" 'lbu package -' | gunzip | /usr/libexec/aaudit/aaudit-import-tar; then
	git branch --quiet -D import
	exit 1
fi
if ! git diff --quiet --exit-code master..import; then
	git diff --patch-with-stat master..import | /usr/libexec/aaudit/aaudit-emaildiff "$(cat description)"
	git branch --quiet --force master import
fi
git branch --quiet -D import
