diff options
author | rhatto <rhatto@04377dda-e619-0410-9926-eae83683ac58> | 2007-04-04 02:08:28 +0000 |
---|---|---|
committer | rhatto <rhatto@04377dda-e619-0410-9926-eae83683ac58> | 2007-04-04 02:08:28 +0000 |
commit | 181d919bf4af7e9b150f24f9d2ae1bd8a1aa4829 (patch) | |
tree | 4b4c91ce0540104afceea5a4f4cdd5ee362daedc /trunk/src/templatepkg | |
parent | 9fd9f2355cbfc030d16c5ca24433a87c88889637 (diff) | |
download | simplepkg-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
Diffstat (limited to 'trunk/src/templatepkg')
-rwxr-xr-x | trunk/src/templatepkg | 110 |
1 files changed, 98 insertions, 12 deletions
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 |