aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorrhatto <rhatto@04377dda-e619-0410-9926-eae83683ac58>2007-04-04 02:08:28 +0000
committerrhatto <rhatto@04377dda-e619-0410-9926-eae83683ac58>2007-04-04 02:08:28 +0000
commit181d919bf4af7e9b150f24f9d2ae1bd8a1aa4829 (patch)
tree4b4c91ce0540104afceea5a4f4cdd5ee362daedc
parent9fd9f2355cbfc030d16c5ca24433a87c88889637 (diff)
downloadsimplepkg-181d919bf4af7e9b150f24f9d2ae1bd8a1aa4829.tar.gz
simplepkg-181d919bf4af7e9b150f24f9d2ae1bd8a1aa4829.tar.bz2
templatepkg: added --import and --export
git-svn-id: svn+slack://slack.fluxo.info/var/svn/simplepkg@213 04377dda-e619-0410-9926-eae83683ac58
-rw-r--r--trunk/lib/common.sh2
-rwxr-xr-xtrunk/src/templatepkg110
2 files changed, 99 insertions, 13 deletions
diff --git a/trunk/lib/common.sh b/trunk/lib/common.sh
index e2dfa6a..9a1f1e0 100644
--- a/trunk/lib/common.sh
+++ b/trunk/lib/common.sh
@@ -199,7 +199,7 @@ function eval_config {
HTTP_TOOL="`eval_parameter HTTP_TOOL curl`"
CONNECT_TIMEOUT="`eval_parameter CONNECT_TIMEOUT 0`"
TEMPLATE_FOLDER="`eval_parameter TEMPLATE_BASE /etc/simplepkg/templates`"
- TEMPLATE_STORAGE_STYLE="`eval_parameter TEMPLATE_STORAGE_STYLE own_folder`"
+ TEMPLATE_STORAGE_STYLE="`eval_parameter TEMPLATE_STORAGE_STYLE own-folder`"
SIMPLARET_CLEAN="`eval_boolean_parameter SIMPLARET_CLEAN 1`"
SIMPLARET_DELETE_DOWN="`eval_boolean_parameter SIMPLARET_DELETE_DOWN 1`"
diff --git a/trunk/src/templatepkg b/trunk/src/templatepkg
index 8faab89..4dc7f7b 100755
--- a/trunk/src/templatepkg
+++ b/trunk/src/templatepkg
@@ -52,23 +52,102 @@ function usage {
echo ""
echo " $BASENAME -d <template> <file-name>"
echo ""
- echo " -s | --sync: sync a template working copy; arguments are:"
+ echo " -s | --sync: sync $BASE_CONF/templates working copy; arguments are:"
echo ""
echo " $BASENAME -d <template>"
- echo ""
- echo " in all cases (-c, -u and -a), jail-root defaults to /, if ommited"
+ echo ""
+ echo " -e | --export: export $BASE_CONF/templates to a svn repository; arguments are:"
+ echo ""
+ echo " $BASENAME -e <svn-repository>"
+ echo ""
+ echo " -i | --import: grab /etc/simplepkg/templates from a svn repository; arguments are:"
+ echo ""
+ echo " $BASENAME -i <svn-repository>"
+ echo ""
+ echo " in all cases (-c, -u and -a), jail-root defaults to / if ommited"
echo ""
exit
- # TODO: -i | --import: importa em massa
- # -co | --checkout: pega um template existente de um repositorio
+}
+
+function check_svn_repo {
- # formas de iniciar a construcao de templates:
- #
- # - importado o /etc/simplepkg/templates
- # - importado apenas um template?
- # - nao importando nada
- #
+ # check a svn repository URL
+ # usage: set_svn_repo <repository>
+
+ if [ ! -z "$1" ]; then
+ if echo $1 | grep -q -v -e "^svn://"; then
+ if if echo $1 | grep -q -v -e "^svn+ssh://"; then
+ echo $BASENAME: invalid repository URL $1
+ return 1
+ fi
+ fi
+ else
+ echo $BASENAME: no repository defined
+ return 1
+ fi
+
+}
+
+function import_export_templates {
+
+ # import from or export to $BASE_CONF in svn repository
+ # usage: template_export <import|export> <repository>
+
+ local templates_folder basedir repository mode preposition
+
+ if [ "$?" != 0 ]; then
+ usage
+ exit 1
+ elif ! use_svn; then
+ echo $BASENAME: simplepkg not configured to use svn
+ exit 1
+ fi
+
+ templates_folder="$BASE_CONF/templates"
+ basedir="$BASE_CONF"
+ mode="$1"
+ repository="$2"
+ preposition="from"
+
+ check_svn_repo $repository
+
+ if [ ! -z "$2" ]; then
+
+ if [ ! -d "$templates_folder/.svn" ];
+
+ cd $basedir
+
+ if [ "$mode" == "export" ]; then
+ preposition="to"
+ svn import templates $repository
+ if [ "$?" != "0" ]; then
+ echo $BASENAME: export failed
+ exit 1
+ fi
+ fi
+
+ if [ -d "templates" ]; then
+ mv templates templates.old
+ fi
+
+ svn checkout $repository templates
+
+ if [ "$?" == "0" ]; then
+ rm -rf templates.old
+ else
+ rm -rf templates
+ mv templates.old templates
+ echo $BASENAME: $mode failed
+ exit 1
+ fi
+
+ else
+ echo "$BASENAME: $templates_folder seens to be already $mode""ed $preposition $repository"
+ exit 1
+ fi
+
+ fi
}
@@ -228,7 +307,6 @@ function template_add {
else
if [ -a "$jail/$file" ]; then
- # TODO: use svn mkdir if needed
mkdir -p $TEMPLATE_BASE.d/`dirname $file`/
destination="`echo $TEMPLATE_BASE.d/$file | sed -e 's/\/$//'`"
cp -a $jail/$file $destination
@@ -318,6 +396,14 @@ elif [ "$1" == "-s" ] || [ "$1" == "--sync" ]; then
fi
fi
+elif [ "$1" == "-e" ] || [ "$1" == "--export" ]; then
+
+ import_export_templates export $2
+
+elif [ "$1" == "-i" ] || [ "$1" == "--import" ]; then
+
+ import_export_templates import $2
+
else
usage
fi