]> gitweb.fluxo.info Git - simplepkg.git/commitdiff
templatepkg: added --import and --export
authorrhatto <rhatto@04377dda-e619-0410-9926-eae83683ac58>
Wed, 4 Apr 2007 02:08:28 +0000 (02:08 +0000)
committerrhatto <rhatto@04377dda-e619-0410-9926-eae83683ac58>
Wed, 4 Apr 2007 02:08:28 +0000 (02:08 +0000)
git-svn-id: svn+slack://slack.fluxo.info/var/svn/simplepkg@213 04377dda-e619-0410-9926-eae83683ac58

trunk/lib/common.sh
trunk/src/templatepkg

index e2dfa6a9c689529f1db2479081a88ff22a10e408..9a1f1e00d94fa3cbf7b3ed810fcb661564cc9887 100644 (file)
@@ -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`"
index 8faab8944954b34e793c49c0c6f9f1bbf702a6c1..4dc7f7b413fc6b993cf7dde2a4820fdc1dfb89bf 100755 (executable)
@@ -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