#!/bin/sh
# Import content of a sandbox into a Subversion repository
# NOTE: enable-auto-props=yes should be set in $HOME/.subversion/config
# Copyright (C) 2018 FARGOS Development, LLC
# $Id$

svnHost="${SVN_HOST}"
svnPath="${SVN_PATH}"

dirList=""
sawImport=0

while test $# -gt 0
do
	case "${1}" in
	-h | -help | --help)
		printf "usage: %s [--host svnHostURL] [--path repositoryPath] --import [dirName ...]\n" "${0}" >&2
		printf "  --host defaults to SVN_HOST, currently=\"%s\"\n" "${svnHost}"
		printf "  --path defaults to SVN_PATH, currently=\"%s\"\n" "${svnPath}"
		printf "  --import = mandatory flag\n" >&2
		exit 1
		;;
	--host)
		svnHost="${2}"
		shift
		;;
	--path)
		svnPath="${2}"
		shift
		;;
	--import)
		sawImport=1
		;;
	-*)
		printf "%s: unrecognized option: \"%s\"\n" "${0}" "${1}" >&2
		exit 1
		;;
	*)
		dirList="${dirList} ${1}"
	esac
	shift
done
if test -z "${STS}"
then
	printf "%s: not in a sandbox\n" "${0}" >&2
	exit 1
fi
if test "${sawImport}" -eq 0
then
	printf "%s: mandatory --import argument missing\n" "${0}" >&2
	exit 1
fi
cd ${STS}
if test -z "${dirList}"
then
	dirProtoList=`echo *`
	for d in ${dirProtoList}
	do
		if test -d ${d}
		then
			dirList="${dirList} ${d}"
		else
			printf "Cannot import non-directory: \"%s\"\n" "${d}" >&2
		fi
	done
fi
for d in ${dirList}
do
	svn import ${d} ${svnHost}${svnPath}/trunk/${d}
done

