#! /bin/sh -

#######################################################################
#                                                                     #
#                              OCamlGen                               #
#                                                                     #
#                       OCaml module Generator                        #
#                                                                     #
#               EPI Pomdapi, INRIA Paris - Rocquencourt               #
#                                                                     #
#  Copyright 1997-2014 INRIA.                                         #
#  Institut National de Recherche en Informatique et en Automatique.  #
#  All rights reserved. This file is distributed only by permission.  #
#                                                                     #
#  Pierre Weis <Pierre.Weis@inria.fr>                                 #
#                                                                     #
#######################################################################

# $Id: unconfigure_user,v 1.9 2014/01/31 09:51:51 fclement Exp $

DEBUG_MODE=false

SCRIPT=`basename $0`

if test "$0" != "./$SCRIPT"; then
    echo "$SCRIPT: error: only launch this script using \"./$SCRIPT\"." 1>&2
    exit 155
fi

debug () {
    if ${DEBUG_MODE:?}; then
        echo "$SCRIPT: $1." 1>&2
    fi
}

debug "Script started"

RM="rm -fr"

# Use an absolute path or die! As we may act after ``cd'' commands...
PROJECT_ROOT_DIR="${PWD:?}"
PROJECT_CONFIG_DIR="$PROJECT_ROOT_DIR/config"
PROJECT_CHECKPOINTS_DIR="$PROJECT_CONFIG_DIR/checkpoints"

# Configuration checkpoint present?
USER_CONFIGURE_CHECKPOINT="$PROJECT_CHECKPOINTS_DIR/configure.done"
if ! test -f "$USER_CONFIGURE_CHECKPOINT"; then
    echo "Nothing to unconfigure."
    exit 0
fi

# Remove configuration checkpoint.
$RM "$USER_CONFIGURE_CHECKPOINT"

# First source generic unconfiguration profile.
PROFILE="$PROJECT_ROOT_DIR/pph/user/scripts/unconfigure.profile"
debug "Launching generic profile"
. "$PROFILE"

# Then source specific unconfiguration profile if present.
PROFILE="$PROJECT_CONFIG_DIR/specific_unconfigure.profile"
if test -f "$PROFILE"; then
    debug "Launching specific profile"
    . "$PROFILE"
fi

$RM "${PROJECT_SUMMARIES_DIR:?}"

debug "Script done"

exit 0
