]> gitweb.fluxo.info Git - simplepkg.git/commitdiff
templatepkg: now --create can copy from an existing template
authorrhatto <rhatto@04377dda-e619-0410-9926-eae83683ac58>
Thu, 5 Apr 2007 20:27:30 +0000 (20:27 +0000)
committerrhatto <rhatto@04377dda-e619-0410-9926-eae83683ac58>
Thu, 5 Apr 2007 20:27:30 +0000 (20:27 +0000)
git-svn-id: svn+slack://slack.fluxo.info/var/svn/simplepkg@255 04377dda-e619-0410-9926-eae83683ac58

trunk/src/templatepkg

index e73e063bd731f878dc95fa88f822e888b0679b09..0c05fd907533ffbdc13ab3698a96899563d679e6 100755 (executable)
@@ -167,11 +167,7 @@ function template_create {
 
   # create a new template
 
-  # TODO: -c <template> [jail-root|template-name]
-  #       - busca nao soh em /etc/simplepkg/templates
-  #       - mas tambem em /etc/simplepkg/defaults/templates
-
-  local template_base info_commit
+  local template_base info_commit orig_template
 
   if [ ! -d "`dirname $TEMPLATE_BASE`" ]; then
     if use_svn && [ -d "`dirname $TEMPLATE_BASE`/.svn" ]; then
@@ -212,15 +208,42 @@ function template_create {
       info_commit="yes"
     fi
 
-    if [ "$info_commit" == "yes" ]; then
-      echo $BASENAME: please run jail-commit to add files under $file into the svn repository
+  else
+    mkdir $TEMPLATE_BASE.{d,s}
+  fi
+
+  if [ -d "$ROOT" ]; then
+    template_update
+  elif [ ! -z "$ROOT" ]; then
+
+    # copy from an existing template
+
+    if [ -d "$BASE_CONF/templates/$ROOT" ]; then
+      orig_template="$BASE_CONF/templates/$ROOT"
+    elif [ -d "$BASE_CONF/defaults/templates/$ROOT" ]; then
+      orig_template="$BASE_CONF/defaults/templates/$ROOT"
+    else
+      return 1
+    fi
+
+    cat $orig_template/$ROOT.perms > $TEMPLATE_BASE.perms
+    cat $orig_template/$ROOT.template > $TEMPLATE_BASE.template
+      
+    if use_svn && [ -d "$orig_template/.svn" ]; then
+      rsync -av --exclude=.svn $orig_template/$ROOT.d/ $TEMPLATE_BASE.d/
+      svn add $TEMPLATE_BASE.d/*
+      info_commit="yes"
+    else
+      rsync -av $orig_template/$ROOT.d/ $TEMPLATE_BASE.d/
     fi
 
   else
-    mkdir $TEMPLATE_BASE.{d,s}
+    echo $BASENAME: warning: no root directory defined
   fi
 
-  template_update
+  if [ "$info_commit" == "yes" ]; then
+    echo $BASENAME: please run jail-commit to add files under $file into the svn repository
+  fi
 
 }
 
@@ -447,8 +470,18 @@ function template_list {
   # list templates
   # usage: template_list [template_name]
 
-  if [ -d "$BASE_CONF/templates" ]; then
-    ls $BASE_CONF/templates/$1
+  local ls
+
+  ls="`ls $BASE_CONF/defaults/templates/$1 2> /dev/null`"
+  if [ "$?" == "0" ]; then
+    echo Default templates:
+    echo "$ls"
+  fi
+
+  ls="`ls $BASE_CONF/templates/$1 2> /dev/null`"
+  if [ "$?" == "0" ]; then
+    echo Custom templates:
+    ls "$ls"
   fi
 
 }