#!/usr/local/bin/bash
#
# Copyright (c) 2008, Christopher Cowart and contributors
# All rights reserved.
# 
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions 
# are met:
# * Redistributions of source code must retain the above copyright 
#   notice, this list of conditions and the following disclaimer.
# * Redistributions in binary form must reproduce the above copyright 
#   notice, this list of conditions and the following disclaimer in the 
#   documentation and/or other materials provided with the distribution.
# 
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 
# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 
# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 
# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 
# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 
# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED 
# TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 
# PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 
# LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 
# NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 
# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#
# $Id: confadmin.in 556 2011-12-17 02:06:20Z blee $
#

if [ -r /usr/local/share/confman/confmancommon.sh ] ; then
    . /usr/local/share/confman/confmancommon.sh
else
    echo "Can't find confmancommon.sh. Exiting." >&2
    exit 17
fi

# Source the documentation library
if [ -f $REPO_DOCS_CONFADMIN ] ; then
	. $REPO_DOCS_CONFADMIN
else
    echo "Couldn't source the confman shell documentation library" >&2
	exit 1
fi

# Set a default editor
if [ -z ${EDITOR} ] ; then
    EDITOR="vi"
fi

function repo_setup {
    local short_dirs="/trunk /tags /branches /trunk/checkpoints"
    short_dirs="${short_dirs} /trunk/meta /trunk/meta/recipes"
    local dir dirs
    local msg="Initial confman directory setup." 
    if /usr/local/bin/svn ls "`conf_repo_uri`/trunk/checkpoints" >/dev/null 2>&1 ; then
        echo "It looks like this repository has already been setup." >&2
        exit 1
    fi
    for dir in ${short_dirs} ; do
        dirs="${dirs} `conf_repo_uri`/${dir}"
    done
    /usr/local/bin/svn mkdir -m "$msg" ${dirs}
}

# Debug mode?
while getopts "hd" opt ; do
	case $opt in
		d) DEBUG="true" ;;
        h) shift ; print_help "$@" ; conf_cleanExit 0 ;;
		*) print_usage 1 ;;
	esac
done

# Dispatch the subcommand. This must happen last and in the global context.
subcommand=$1
shift

case $subcommand in
    help )                          print_help "$@" ; conf_cleanExit 0 ;;
    setup )                         repo_setup ;;
    * )                             print_usage 1 ;;
esac 

conf_cleanExit 0

# vim:ts=4
