aboutsummaryrefslogtreecommitdiff
path: root/trunk
diff options
context:
space:
mode:
authorrhatto <rhatto@04377dda-e619-0410-9926-eae83683ac58>2007-04-05 18:52:50 +0000
committerrhatto <rhatto@04377dda-e619-0410-9926-eae83683ac58>2007-04-05 18:52:50 +0000
commitbc54da28ef5d0d6fa89952bdf80f46d6ba2bb307 (patch)
treec4ee810e3ac7a49712b32337ed0e63a896c851a3 /trunk
parent11fdeae3e9f77d855d9eb4e591aaeb890c0f4bc4 (diff)
downloadsimplepkg-bc54da28ef5d0d6fa89952bdf80f46d6ba2bb307.tar.gz
simplepkg-bc54da28ef5d0d6fa89952bdf80f46d6ba2bb307.tar.bz2
templatepkg: added --list, --remove and --help
git-svn-id: svn+slack://slack.fluxo.info/var/svn/simplepkg@253 04377dda-e619-0410-9926-eae83683ac58
Diffstat (limited to 'trunk')
-rwxr-xr-xtrunk/src/templatepkg150
1 files changed, 115 insertions, 35 deletions
diff --git a/trunk/src/templatepkg b/trunk/src/templatepkg
index 1f10ebc..ab43bf7 100755
--- a/trunk/src/templatepkg
+++ b/trunk/src/templatepkg
@@ -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