#!/bin/bash

# Helper for running things in a temporary directory; used for docs
# building, unittests, etc.

set -e

tmpdir=$(mktemp -d -t gntbuild.XXXXXXXX)
trap "rm -rf $tmpdir" EXIT

cp -r autotools daemons scripts lib tools test $tmpdir
mv $tmpdir/lib $tmpdir/ganeti
ln -T -s $tmpdir/ganeti $tmpdir/lib
mkdir -p $tmpdir/htools
if [ -e htools/test ]; then
  cp -p htools/test $tmpdir/htools/
fi

cd $tmpdir && GANETI_TEMP_DIR="$tmpdir" "$@"