aboutsummaryrefslogtreecommitdiff
path: root/trunk/src
diff options
context:
space:
mode:
authorrhatto <rhatto@04377dda-e619-0410-9926-eae83683ac58>2007-04-07 18:14:39 +0000
committerrhatto <rhatto@04377dda-e619-0410-9926-eae83683ac58>2007-04-07 18:14:39 +0000
commit4a79f818f6a77a655199332ef0a7d787d07759cc (patch)
tree08a08da169a749134996c9d1641d5cb52fad0283 /trunk/src
parente2c20ff09c500808300d6a282fc3b200eadf2d77 (diff)
downloadsimplepkg-4a79f818f6a77a655199332ef0a7d787d07759cc.tar.gz
simplepkg-4a79f818f6a77a655199332ef0a7d787d07759cc.tar.bz2
lots of changes, se file doc/CHANGELOG for info
git-svn-id: svn+slack://slack.fluxo.info/var/svn/simplepkg@303 04377dda-e619-0410-9926-eae83683ac58
Diffstat (limited to 'trunk/src')
-rwxr-xr-xtrunk/src/jail-commit2
-rwxr-xr-xtrunk/src/templatepkg317
2 files changed, 232 insertions, 87 deletions
diff --git a/trunk/src/jail-commit b/trunk/src/jail-commit
index 84748aa..50bc6ae 100755
--- a/trunk/src/jail-commit
+++ b/trunk/src/jail-commit
@@ -131,7 +131,7 @@ function do_commit {
echo Updating $jailpath...
fi
if [ -d "$TEMPLATE_BASE.d" ] || [ -a "$TEMPLATE_BASE.template" ]; then
- templatepkg -u $template $jailpath
+ SILENT=yes templatepkg -u $template $jailpath
template_merge $jailpath
fi
fi
diff --git a/trunk/src/templatepkg b/trunk/src/templatepkg
index df6467f..6a3b57d 100755
--- a/trunk/src/templatepkg
+++ b/trunk/src/templatepkg
@@ -28,67 +28,115 @@ else
exit 1
fi
-function usage {
+function usage_summary {
- echo "usage: $BASENAME <option> <template> [arguments]"
echo "options are:"
echo ""
- echo " -c | --create: create a template from a jail or existing template:"
- echo ""
- echo " $BASENAME -c <template> [jail-root|template-name]"
- echo ""
- 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:"
- 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:"
- echo ""
- echo " $BASENAME -d <template> <file-name>"
- echo ""
- 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:"
- echo ""
- echo " $BASENAME -e <svn-repository>"
- echo ""
- echo " -i | --import: grab $BASE_CONF/templates from a svn repository:"
- echo ""
- echo " $BASENAME -i <svn-repository>"
- echo ""
- 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 " -p | --post-install: add or edit post-installation scripts:"
- echo ""
- echo " $BASENAME -p <template-name> <script-name>"
- echo ""
- echo " -t | --template-edit: edit template package list:"
+ echo " -c | --create: create a template from a jail or existing template"
+ echo " -u | --update: update a template from a jail"
+ echo " -a | --add: add files into a template"
+ echo " -d | --delete: delete files or folders from a template"
+ echo " -s | --sync: sync $TEMPLATE_FOLDER working copy"
+ echo " -e | --export: export $TEMPLATE_FOLDER to a svn repository"
+ echo " -i | --import: grab $TEMPLATE_FOLDER from a svn repository"
+ echo " -r | --remove: remove a template"
+ echo " -l | --list: list templates"
+ echo " -b | --batch-edit: add or edit post-installation scripts"
+ echo " -p | --pack: create a package from a template"
+ echo " -t | --template-edit: edit template package list"
+ echo " -h | --help: display this summary"
echo ""
- echo " $BASENAME -t <template-name>"
- echo ""
- echo " -h | --help: display this summary."
- echo ""
- echo " for -c, -u and -a jail-root defaults to / if ommited"
+
+}
+
+function display_help {
+
+ # display help
+ # usage: help [help-topic]
+
+ local option
+
+ if [ -z "$1" ]; then
+ echo "type $BASENAME --help <option> for aditional help"
+ usage_summary
+ exit
+ fi
+
+ option="$1"
+
+ if ! echo $option | grep -q -e "^-"; then
+ option="-`echo $option | sed -e 's/--/-/' -e 's/\(.\).*/\1/'`"
+ else
+ option="`echo $option | sed -e 's/--/-/' -e 's/\(..\).*/\1/'`"
+ fi
+
+ usage_summary | grep -e "^ $option"
+
echo ""
- exit
+ case $option in
+
+ "-c" | "--create")
+ echo " $BASENAME $option <template> [jail-root|template-name]"
+ ;;
+ "-u" | "--update")
+ echo " $BASENAME $option <template> [jail-root]"
+ ;;
+ "-a" | "--add")
+ echo " $BASENAME $option <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"
+ ;;
+ "-d" | "--delete")
+ echo " $BASENAME $option <template> <file-name>"
+ ;;
+ "-s" | "--sync")
+ echo " $BASENAME $option"
+ ;;
+ "-e" | "--export")
+ echo " $BASENAME $option <svn-repository>"
+ ;;
+ "-i" | "--import")
+ echo " $BASENAME $option <svn-repository>"
+ ;;
+ "-r" | "--remove")
+ echo " $BASENAME $option <template-name>"
+ ;;
+ "-l" | "--list")
+ echo " $BASENAME $option [template-name]"
+ ;;
+ "-b" | "--batch-edit")
+ echo " $BASENAME $option <template-name> <script-name>"
+ ;;
+ "-p" | "--pack")
+ echo " $BASENAME $option <template-name> [version] [build] [arch]"
+ ;;
+ "-t" | "--template-edit")
+ echo " $BASENAME $option <template-name>"
+ ;;
+ "-h" | "--help")
+ echo " -h | --help: display this help."
+ ;;
+ *)
+ echo $BASENAME: invalid help option $option
+ esac
+
+ case $option in
+ "-c" | "-u" | "-a")
+ echo ""
+ echo " if ommited, jail-root defaults to /"
+ ;;
+ esac
+
+ echo ""
+
+}
+
+function usage {
- # TODO: opcao para apagar script de pos-instalacao ou integrar no -d
- # TODO: opcao para criar um pacote a partir de um template
- # TODO: TEMPLATE_FOLDER
+ echo "usage: $BASENAME <option> [<template> [arguments]]"
+ usage_summary
+ exit
}
@@ -115,10 +163,10 @@ function check_svn_repo {
function import_export_templates {
- # import from or export to $BASE_CONF in a svn repository
+ # import from or export to $TEMPLATE_FOLDER in a svn repository
# usage: template_export <import|export> <repository>
- local templates_folder basedir repository mode preposition
+ local templates templates_folder basedir repository mode preposition
if [ "$?" != 0 ]; then
usage
@@ -128,8 +176,9 @@ function import_export_templates {
exit 1
fi
- templates_folder="$BASE_CONF/templates"
- basedir="$BASE_CONF"
+ templates_folder="$TEMPLATE_FOLDER"
+ templates="`basename $TEMPLATE_FOLDER`"
+ basedir="`dirname $templates_folder`"
mode="$1"
repository="$2"
preposition="from"
@@ -145,7 +194,7 @@ function import_export_templates {
if [ "$mode" == "export" ]; then
preposition="to"
echo Exporting templates to $repository...
- svn import templates/ $repository/ -m "initial import"
+ svn import $templates/ $repository/ -m "initial import"
if [ "$?" != "0" ]; then
echo $BASENAME: export failed
exit 1
@@ -153,17 +202,17 @@ function import_export_templates {
fi
if [ -d "templates" ]; then
- mv templates templates.old
+ mv $templates $templates.old
fi
echo Checking out templates from $repository...
- svn checkout $repository templates
+ svn checkout $repository $templates
if [ "$?" == "0" ]; then
- rm -rf templates.old
+ rm -rf $templates.old
else
- rm -rf templates
- mv templates.old templates
+ rm -rf $templates
+ mv $templates.old $templates
echo $BASENAME: $mode failed
exit 1
fi
@@ -230,10 +279,10 @@ function template_create {
info_commit="yes"
fi
- elif use_svn && [ -d "$BASE_CONF/templates/.svn" ]; then
+ elif use_svn && [ -d "$TEMPLATE_FOLDER/.svn" ]; then
mkdir $TEMPLATE_BASE.{d,s}
- cd $BASE_CONF/templates
+ cd $TEMPLATE_FOLDER
svn add `basename $TEMPLATE_BASE`
info_commit="yes"
@@ -247,7 +296,9 @@ function template_create {
# copy from an existing template
- if [ -d "$BASE_CONF/templates/$ROOT" ]; then
+ if [ -d "$TEMPLATE_FOLDER/$ROOT" ]; then
+ orig_template="$TEMPLATE_FOLDER/$ROOT"
+ elif [ -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"
@@ -303,7 +354,7 @@ function template_create {
echo $BASENAME: warning: no root directory defined
fi
- if [ "$info_commit" == "yes" ]; then
+ if [ "$info_commit" == "yes" ] && [ -z "$SILENT" ]; then
echo "$BASENAME: please run 'jail-commit --all' to add files under $file into the svn repository"
fi
@@ -405,7 +456,7 @@ function template_add {
fi
done
- if [ "$info_commit" == "yes" ]; then
+ if [ "$info_commit" == "yes" ] && [ -z "$SILENT" ]; then
echo "$BASENAME: please run 'jail-commit --all' to add files under `slash $file` into the svn repository"
fi
@@ -435,7 +486,9 @@ function template_add {
if [ "$?" != "0" ]; then
echo $BASENAME: error adding `slash $candidate` into the revision system
else
- echo "$BASENAME: please run 'jail-commit --all' to add `slash $file` into the svn repository"
+ if [ -z "$SILENT" ]; then
+ echo "$BASENAME: please run 'jail-commit --all' to add `slash $file` into the svn repository"
+ fi
fi
cd $cwd
@@ -500,7 +553,7 @@ function check_template_exist {
done
- if [ "$info_commit" == "yes" ]; then
+ if [ "$info_commit" == "yes" ] && [ -z "$SILENT" ]; then
echo "$BASENAME: please run 'jail-commit --all' to add new files in the svn repository"
fi
@@ -515,11 +568,24 @@ function template_delete {
if use_svn && [ -d "$TEMPLATE_BASE.d/.svn" ]; then
cd $TEMPLATE_BASE.d
svn del --force ./$1 || rm -rf ./$1
- echo "$BASENAME: please run 'jail-commit --all' to del $1 in the svn repository"
+ if [ -z "$SILENT" ]; then
+ echo "$BASENAME: please run 'jail-commit --all' to del $1 in the svn repository"
+ fi
else
rm -rf $TEMPLATE_BASE.d/$1
echo Removed $1 from $TEMPLATE_BASE.d
fi
+ elif [ -e "$TEMPLATE_BASE.s/$1" ]; then
+ if use_svn && [ -d "$TEMPLATE_BASE.s/.svn" ]; then
+ cd $TEMPLATE_BASE.s
+ svn del --force ./$1 || rm -rf ./$1
+ if [ -z "$SILENT" ]; then
+ echo "$BASENAME: please run 'jail-commit --all' to del $1 in the svn repository"
+ fi
+ else
+ rm -rf $TEMPLATE_BASE.s/$1
+ echo Removed $1 from $TEMPLATE_BASE.s
+ fi
else
if [ ! -d "$TEMPLATE_BASE.d" ]; then
echo $BASENAME: template folder $TEMPLATE_BASE.d not found
@@ -547,7 +613,7 @@ function template_remove {
fi
if use_svn && [ -d "$basedir/.svn" ]; then
- cd $BASE_CONF/templates
+ cd $TEMPLATE_FOLDER
svn update
svn del --force $template
if [ "$?" != "0" ]; then
@@ -569,10 +635,13 @@ function template_list {
# list templates
# usage: template_list [template_name]
- # TODO: considerar outros valores de TEMPLATE_STORAGE_STYLE
-
local list basedir template
+ if [ "$TEMPLATE_STORAGE_STYLE" != "own-folder" ]; then
+ echo "$BASENAME: option only available if TEMPLATE_STORAGE_STYLE configured as 'own-folder'"
+ return 1
+ fi
+
if echo $1 | grep -q "/" || [ ! -z "$1" ]; then
template="`echo $1 | cut -d "/" -f 1`"
@@ -585,8 +654,8 @@ function template_list {
fi
fi
- if [ -e "$BASE_CONF/templates/$1" ]; then
- list="`ls $BASE_CONF/templates/$1 2> /dev/null`"
+ if [ -e "$TEMPLATE_FOLDER/$1" ]; then
+ list="`ls $TEMPLATE_FOLDER/$1 2> /dev/null`"
if [ "$?" == "0" ]; then
list="`echo $list | xargs`"
echo "In the custom template $template: $list"
@@ -601,7 +670,7 @@ function template_list {
echo "Default templates: $list"
fi
- list="`ls $BASE_CONF/templates/$1 2> /dev/null`"
+ list="`ls $TEMPLATE_FOLDER/$1 2> /dev/null`"
if [ "$?" == "0" ]; then
list="`echo $list | xargs`"
echo "Custom templates: $list"
@@ -631,7 +700,7 @@ function template_post_install_edit {
vi $TEMPLATE_BASE.s/$1
fi
if [ "$sha1sum" != "`sha1sum $TEMPLATE_BASE.s/$1`" ] && \
- [ -d "`dirname $TEMPLATE_BASE`/.svn" ]; then
+ [ -d "`dirname $TEMPLATE_BASE`/.svn" ] && [ -z "$SILENT" ]; then
echo "$BASENAME: please run 'jail-commit --all' to send changes to the repository"
fi
else
@@ -648,7 +717,9 @@ function template_post_install_edit {
if [ -d "$TEMPLATE_BASE.s/.svn" ]; then
cd $TEMPLATE_BASE.s
svn add $1
- echo "$BASENAME: please run 'jail-commit --all' to send the script to the repository"
+ if [ -z "$SILENT" ]; then
+ echo "$BASENAME: please run 'jail-commit --all' to send the script to the repository"
+ fi
fi
echo "$BASENAME: script created; run templatepkg -p `basename $TEMPLATE_BASE` $1 again to edit it"
@@ -674,7 +745,7 @@ function template_edit {
vi $TEMPLATE_BASE.template
fi
if [ "$sha1sum" != "`sha1sum $TEMPLATE_BASE.template`" ] && \
- [ -d "`dirname $TEMPLATE_BASE`/.svn" ]; then
+ [ -d "`dirname $TEMPLATE_BASE`/.svn" ] && [ -z "$SILENT" ]; then
echo "$BASENAME: please run 'jail-commit --all' to send changes to the repository"
fi
elif [ -e "$TEMPLATE_BASE.template" ]; then
@@ -709,6 +780,74 @@ function setroot {
}
+function create_doinst {
+
+ # create a doinst.sh from a template.perms file
+ # usage: create_doinst <doinst-path>
+
+ rm $1/doinst.sh
+
+ if [ -s "$TEMPLATE_BASE.perms" ]; then
+ echo Setting jail $1 permissions...
+ cat $TEMPLATE_BASE.perms | while read entry; do
+ file="`echo $entry | cut -d ";" -f 1`"
+ if [ -a "$TEMPLATE_BASE.d/$file" ] && [ -a "$1/$file" ]; then
+ owner="`echo $entry | cut -d ";" -f 2`"
+ group="`echo $entry | cut -d ";" -f 3`"
+ perms="`echo $entry | cut -d ";" -f 4`"
+ echo "( chmod $perms /$file )" >> $1/doinst.sh
+ chown "( $owner:$group /$file )" >> $1/doinst.sh
+ fi
+ done
+ fi
+
+}
+
+function package_template {
+
+ # make a package from a template
+ # usage: package_template [version] [build] [arch]
+
+ local template version build arch
+
+ template="`basename $TEMPLATE_BASE`"
+
+ if [ ! -d "$TEMPLATE_BASE.d" ]; then
+ $BASENAME: folder not found: $TEMPLATE.base.d
+ return 1
+ fi
+
+ echo Buiding package for template $template...
+
+ version=${1:=1}
+ build=${2:=1}
+ arch=${3:=noarch}
+
+ TMP=${TMP:=/tmp}
+ rm -rf $TMP/templatepkg
+ mkdir -p $TMP/templatepkg
+
+ rsync --exclude=.svn $TEMPLATE_BASE.d/ $TMP/templatepkg/
+ mkdir $TMP/templatepkg/install
+ create_doinst $TMP/templatepkg/install
+
+ echo "template-$template: template-$template" > $TMP/templatepkg/install/slack-desc
+ echo "template-$template: " >> $TMP/templatepkg/install/slack-desc
+ echo "template-$template: simplepkg template $template" >> $TMP/templatepkg/install/slack-desc
+
+ for ((n=1;n<=8;n++)); do
+ echo "template-$template: " >> $TMP/templatepkg/install/slack-desc
+ done
+
+ cd $TMP/templatepkg
+
+ makepkg -c n -l y $TMP/template-$template-$version-noarch-$build.tgz
+
+ cd $TMP
+ rm -rf templatepkg
+
+}
+
# -----------------------------------------------------
# main
# -----------------------------------------------------
@@ -755,8 +894,8 @@ elif [ "$1" == "-d" ] || [ "$1" == "--delete" ]; then
elif [ "$1" == "-s" ] || [ "$1" == "--sync" ]; then
- if use_svn && [ -d "$BASE_CONF/templates/.svn" ]; then
- ( cd $BASE_CONF/templates && svn update )
+ if use_svn && [ -d "$TEMPLATE_FOLDER/.svn" ]; then
+ ( cd $TEMPLATE_FOLDER && svn update )
true
fi
@@ -779,7 +918,7 @@ elif [ "$1" == "-l" ] || [ "$1" == "--list" ]; then
template_list $2
-elif [ "$1" == "-p" ] || [ "$1" == "--post-install" ]; then
+elif [ "$1" == "-b" ] || [ "$1" == "--batch-edit" ]; then
require $3
template_post_install_edit $3
@@ -789,9 +928,15 @@ elif [ "$1" == "-t" ] || [ "$1" == "--template-edit" ]; then
require $2
template_edit
+elif [ "$1" == "-p" ] || [ "$1" == "--pack" ]; then
+
+ require $2
+ shift
+ package_template $*
+
elif [ "$1" == "-h" ] || [ "$1" == "--help" ]; then
- usage
+ display_help $2
else
usage