#! /bin/sh

set -e

if ! test -f CMakeLists.txt; then
    echo "this does not look like a Rock CMake library"
    exit 1
fi
if ! grep -q rock_init CMakeLists.txt; then
    echo "this does not look like a Rock CMake library"
    exit 1
fi

if test -d "viz"; then
    echo "the viz directory already exists"
    exit 1
fi

if test -z "$ROCK_TEMPLATE_PREFIX"; then
    ROCK_TEMPLATE_PREFIX=https://github.com/rock-core/base-templates-
    ROCK_TEMPLATE_SUFFIX=.git
fi
git clone ${ROCK_TEMPLATE_PREFIX}vizkit3d_plugin${ROCK_TEMPLATE_SUFFIX} viz

if ! (cd viz ; ./config.sh); then
    echo "vizkit plugin creation failed, deleting the viz/ directory"
    rm -rf viz
fi

