#!/bin/bash
#
#   YADT - an Augmented Deployment Tool
#   Copyright (C) 2010-2014  Immobilien Scout GmbH
#
#   This program is free software: you can redistribute it and/or modify
#   it under the terms of the GNU General Public License as published by
#   the Free Software Foundation, either version 3 of the License, or
#   (at your option) any later version.
#
#   This program is distributed in the hope that it will be useful,
#   but WITHOUT ANY WARRANTY; without even the implied warranty of
#   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#   GNU General Public License for more details.
#
#   You should have received a copy of the GNU General Public License
#   along with this program.  If not, see <http://www.gnu.org/licenses/>.

[[ -e /etc/bashrc ]] && source /etc/bashrc
[[ -e ~/.bashrc ]] && source ~/.bashrc

source /usr/bin/yadtshell-activate

TARGETS_DIR=/etc/yadtshell/targets

if [[ -d $TARGETS_DIR ]]; then
    echo "changing to $TARGETS_DIR"
    cd $TARGETS_DIR
fi

if [[ -n "$YADT_TARGET" ]]; then
    echo "using target $YADT_TARGET"
    if [[ -d $YADT_TARGET ]]; then
        cd $YADT_TARGET
        yadtshell status
    else
        echo "target $YADT_TARGET does not exist, sorry"
    fi
fi

using() {
    if [[ ! -n "$1" ]]; then
        echo "Usage : using <TARGET>"
        return 1
    else
        TARGET=$1
        cd $TARGETS_DIR/$TARGET
        yadtshell status
    fi
}

return 0
