]> gitweb.fluxo.info Git - simplepkg.git/commitdiff
templatepkg: added --list, --remove and --help
authorrhatto <rhatto@04377dda-e619-0410-9926-eae83683ac58>
Thu, 5 Apr 2007 18:52:50 +0000 (18:52 +0000)
committerrhatto <rhatto@04377dda-e619-0410-9926-eae83683ac58>
Thu, 5 Apr 2007 18:52:50 +0000 (18:52 +0000)
git-svn-id: svn+slack://slack.fluxo.info/var/svn/simplepkg@253 04377dda-e619-0410-9926-eae83683ac58

trunk/src/templatepkg

index 1f10ebc9daf7e6acacdb621c71e58c2788527f23..ab43bf7b2cb5a1b8221ffad1b6b04e19b18b9ca9 100755 (executable)
@@ -31,40 +31,50 @@ fi
 function usage {
 
   echo "usage: $BASENAME <option> <template> [arguments]"
-  echo "options:"
+  echo "options are:"
   echo ""
-  echo "  -c | --create: create a template from a jail; arguments are:"
+  echo "  -c | --create: create a template from a jail or existing template:"
   echo ""
-  echo "      $BASENAME -c <template> [jail-root]"
+  echo "      $BASENAME -c <template> [jail-root|template-name]"
   echo ""
-  echo "  -u | --update: update a template from a jail; arguments are:"
+  echo "  -u | --update: update a template from a jail:"
   echo ""
   echo "      $BASENAME -u <template> [jail-root]"
   echo ""
-  echo "  -a | --add: add files into a template; arguments for -a are:"
+  echo "  -a | --add: add files into a template:"
   echo ""
   echo "      $BASENAME -a <template> <file-name> [jail-root]"
   echo ""
   echo "      file-name: the file or directory to be added"
   echo "      jail-root: the jail under file-name is located"
   echo ""
-  echo "  -d | --delete: delete files or folders from a template; arguments are:"
+  echo "  -d | --delete: delete files or folders from a template:"
   echo ""
   echo "      $BASENAME -d <template> <file-name>"
   echo ""
-  echo "  -s | --sync: sync $BASE_CONF/templates working copy; arguments are:"
+  echo "  -s | --sync: sync $BASE_CONF/templates working copy:"
   echo ""
   echo "      $BASENAME -s"
   echo ""   
-  echo "  -e | --export: export $BASE_CONF/templates to a svn repository; arguments are:"
+  echo "  -e | --export: export $BASE_CONF/templates to a svn repository:"
   echo ""   
   echo "      $BASENAME -e <svn-repository>"
   echo ""   
-  echo "  -i | --import: grab /etc/simplepkg/templates from a svn repository; arguments are:"   
+  echo "  -i | --import: grab /etc/simplepkg/templates from a svn repository:"   
   echo ""   
   echo "      $BASENAME -i <svn-repository>"
   echo ""   
-  echo "  in all cases (-c, -u and -a), jail-root defaults to / if ommited"
+  echo "  -r | --remove: remove a template:"   
+  echo ""   
+  echo "      $BASENAME -r <template-name>"
+  echo ""   
+  echo "  -l | --list: list templates:"   
+  echo ""   
+  echo "      $BASENAME -l [template-name]"
+  echo ""   
+  echo "  -h | --help: display this summary."   
+  echo ""   
+  echo "  for -c, -u and -a jail-root defaults to / if ommited"
   echo ""
   exit
 
@@ -157,6 +167,10 @@ 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
 
   if [ ! -d "`dirname $TEMPLATE_BASE`" ]; then
@@ -353,26 +367,6 @@ function template_add {
 
 }
 
-function setroot {
-
-  # set ROOT variable
-  # usage: setroot <value1> <value2>
-  
-  if [ -z "$1" ]; then
-    ROOT="/"
-  else
-    ROOT="$1"
-  fi
-
-}
-
-function slash {
-
-  # remove additional slashes
-  echo $1 | sed -e 's/\/\+/\//g'
-
-}
-
 function check_template_exist {
 
   # check if a template exists
@@ -421,29 +415,98 @@ function template_delete {
 
 }
 
+function template_remove {
+
+  # remove a template
+  # usage: template_remove
+
+  local basedir template
+
+  basedir="`dirname $TEMPLATE_BASE`"
+  template="`basename $basedir`"
+
+  if use_svn && [ -d "$basedir/.svn" ]; then
+    cd $BASE_CONF/templates
+    svn del $template
+    if [ "$?" != "0" ]; then
+      echo $BASENAME: error deleting template $template
+    else
+      svn commit -m "deleted $template"
+      if [ "$?" != "0" ]; then
+        echo $BASENAME: error commiting to svn repository
+      fi
+    fi
+  else
+    rm -rf $basedir
+  fi
+
+}
+
+function template_list {
+
+  # list templates
+  # usage: template_list [template_name]
+
+  if [ -d "$BASE_CONF/templates" ]; then
+    ls $BASE_CONF/templates/$1
+  fi
+
+}
+
+function require {
+
+  # requires a string
+  # usage: require [string]
+
+  if [ -z "$1" ]; then
+    usage
+  fi
+
+}
+
+function setroot {
+
+  # set ROOT variable
+  # usage: setroot <value1> <value2>
+  
+  if [ -z "$1" ]; then
+    ROOT="/"
+  else
+    ROOT="$1"
+  fi
+
+}
+
+function slash {
+
+  # remove additional slashes
+  echo $1 | sed -e 's/\/\+/\//g'
+
+}
+
 # -----------------------------------------------------
 #                       main
 # -----------------------------------------------------
 
-if [ -z "$2" ]; then
-  usage
-fi
-
 search_template $2 --new
 TEMPLATE="$TEMPLATE_BASE.template"
 
 if [ "$1" == "-u" ] || [ "$1" == "--update" ]; then
 
+  require $2
   setroot $3
   template_update
 
 elif [ "$1" == "-c" ] || [ "$1" == "--create" ]; then
 
+  require $2
   setroot $3
   template_create
 
 elif [ "$1" == "-a" ] || [ "$1" == "--add" ]; then
 
+  require $2
+
   if [ -z "$3" ]; then
     usage
   else
@@ -454,6 +517,8 @@ elif [ "$1" == "-a" ] || [ "$1" == "--add" ]; then
 
 elif [ "$1" == "-d" ] || [ "$1" == "--delete" ]; then
 
+  require $2
+
   if [ -z "$3" ]; then
     usage
   else
@@ -468,13 +533,28 @@ elif [ "$1" == "-s" ] || [ "$1" == "--sync" ]; then
   fi
 
 elif [ "$1" == "-e" ] || [ "$1" == "--export" ]; then
-  
+  require $2 
   import_export_templates export $2
 
 elif [ "$1" == "-i" ] || [ "$1" == "--import" ]; then
 
+  require $2
   import_export_templates import $2
 
+elif [ "$1" == "-r" ] || [ "$1" == "--remove" ]; then
+
+  require $2
+  template_remove
+
+elif [ "$1" == "-l" ] || [ "$1" == "--list" ]; then
+
+  template_list $2
+
+elif [ "$1" == "-h" ] || [ "$1" == "--help" ]; then
+
+  usage
+
 else
   usage
 fi