From 9e11a804a8604fa8e379fe8f342aa8135d042faa Mon Sep 17 00:00:00 2001 From: rhatto Date: Thu, 5 Apr 2007 23:14:35 +0000 Subject: templatepkg: added -t and -p jail-update: added --help jail-commit: added --help and --all git-svn-id: svn+slack://slack.fluxo.info/var/svn/simplepkg@268 04377dda-e619-0410-9926-eae83683ac58 --- trunk/src/jail-commit | 10 ++++-- trunk/src/jail-update | 2 +- trunk/src/templatepkg | 91 ++++++++++++++++++++++++++++++++++++++++++++++++++- 3 files changed, 99 insertions(+), 4 deletions(-) diff --git a/trunk/src/jail-commit b/trunk/src/jail-commit index d398e0f..61b93bf 100755 --- a/trunk/src/jail-commit +++ b/trunk/src/jail-commit @@ -30,7 +30,9 @@ fi function usage { echo $BASENAME: commit a jail configuration into a template - echo usage: $BASENAME [ [template]] + echo "usage: $BASENAME [ [template]]" + echo " $BASENAME --all to commit all templates" + echo " $BASENAME --help for help" } @@ -129,7 +131,11 @@ function do_commit { } -if [ ! -z "$1" ]; then +if [ "$1" == "--help" ]; then + usage +elif [ "$1" == "--all" ]; then + template_svn_commit $BASE_CONF/templates +elif [ ! -z "$1" ]; then do_commit $1 $2 else if [ -f $JAIL_LIST ]; then diff --git a/trunk/src/jail-update b/trunk/src/jail-update index 1a6ea9b..b845674 100755 --- a/trunk/src/jail-update +++ b/trunk/src/jail-update @@ -34,7 +34,7 @@ function usage { } -if [ -z "$1" ]; then +if [ -z "$1" ] || [ "$1" == "--help" ]; then usage exit 1 fi diff --git a/trunk/src/templatepkg b/trunk/src/templatepkg index 912f591..858911d 100755 --- a/trunk/src/templatepkg +++ b/trunk/src/templatepkg @@ -72,6 +72,14 @@ function usage { echo "" echo " $BASENAME -l [template-name]" echo "" + echo " -p | --post-install: add or edit post-installation scripts:" + echo "" + echo " $BASENAME -p " + echo "" + echo " -t | --template-edit: edit template package list:" + echo "" + echo " $BASENAME -t " + echo "" echo " -h | --help: display this summary." echo "" echo " for -c, -u and -a jail-root defaults to / if ommited" @@ -491,9 +499,14 @@ function template_remove { basedir="`dirname $TEMPLATE_BASE`" template="`basename $basedir`" + if [ ! -d "$basedir" ]; then + echo $BASENAME: template $template does not exist + exit 1 + fi + if use_svn && [ -d "$basedir/.svn" ]; then cd $BASE_CONF/templates - svn del $template + svn del --force $template if [ "$?" != "0" ]; then echo $BASENAME: error deleting template $template else @@ -529,6 +542,72 @@ function template_list { } +function template_post_install_edit { + + # add or edit a post-installation script + # usage: template_post_install_edit + + if [ -z "$1" ]; then + echo $BASENAME: no template specified + exit 1 + elif echo $1 | grep -q "/"; then + echo $BASENAME: error: invalid script name $1 + fi + + if [ -f "$TEMPLATE_BASE.s/$1" ]; then + sha1sum="`sha1sum $TEMPLATE_BASE.s/$1`" + if [ ! -z "$EDITOR" ]; then + $EDITOR $TEMPLATE_BASE.s/$1 + else + vi $TEMPLATE_BASE.s/$1 + fi + if [ "$sha1sum" != "`sha1sum $TEMPLATE_BASE.s/$1`" ]; then + echo $BASENAME: please run jail-commit to send changes to the repository + fi + else + + if [ -d "$TEMPLATE_BASE.s" ]; then + + touch $TEMPLATE_BASE.s/$1 + chmod +x $TEMPLATE_BASE.s/$1 + + if [ -d "$TEMPLATE_BASE.s/.svn" ]; then + cd $TEMPLATE_BASE.s + svn add $1 + echo "$BASENAME: please run jail-commit to send the script to the repository" + fi + + echo "$BASENAME: script created; run templatepkg -p `basename $TEMPLATE_BASE` $1 again to edit it" + + else + echo $BASENAME: folder not found: $TEMPLATE_BASE.s + fi + + fi + +} + +function template_edit { + + # edit a template package list + # usage: template_edit + + if [ -f "$TEMPLATE_BASE.template" ]; then + sha1sum="`sha1sum $TEMPLATE_BASE.template`" + if [ ! -z "$EDITOR" ]; then + $EDITOR $TEMPLATE_BASE.template + else + vi $TEMPLATE_BASE.template + fi + if [ "$sha1sum" != "`sha1sum $TEMPLATE_BASE.template`" ]; then + echo $BASENAME: please run jail-commit to send changes to the repository + fi + else + echo $BASENAME: file not found: $TEMPLATE_BASE.template + fi + +} + function require { # requires a string @@ -630,6 +709,16 @@ elif [ "$1" == "-l" ] || [ "$1" == "--list" ]; then template_list $2 +elif [ "$1" == "-p" ] || [ "$1" == "--post-install" ]; then + + require $3 + template_post_install_edit $3 + +elif [ "$1" == "-t" ] || [ "$1" == "--template-edit" ]; then + + require $2 + template_edit + elif [ "$1" == "-h" ] || [ "$1" == "--help" ]; then usage -- cgit v1.2.3