#!/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

mkdir $tmpdir/doc

cp -r autotools daemons scripts lib tools test qa $tmpdir
cp -r doc/examples $tmpdir/doc

mv $tmpdir/lib $tmpdir/ganeti
ln -T -s $tmpdir/ganeti $tmpdir/lib

mkdir -p $tmpdir/htools $tmpdir/htest
for hfile in htools ganeti-confd; do
  if [ -e htools/$hfile ]; then
    cp -p htools/$hfile $tmpdir/htools/
  fi
done

for hfile in hpc-htools test offline-test.sh cli-tests-defs.sh \
  hbal hscan hspace hinfo hcheck hail; do
  if [ -e htest/$hfile ]; then
    cp -p htest/$hfile $tmpdir/htest/
  fi
done

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