aboutsummaryrefslogtreecommitdiff
path: root/tags/0.5.1/src/jail-commit
diff options
context:
space:
mode:
authorrhatto <rhatto@04377dda-e619-0410-9926-eae83683ac58>2007-07-24 02:01:18 +0000
committerrhatto <rhatto@04377dda-e619-0410-9926-eae83683ac58>2007-07-24 02:01:18 +0000
commitb28b0bd5f13135d64dca024f629100b3e30d47b2 (patch)
treeb1b8b18d0eb02939964fc610eaba3a6b1e8ca4fe /tags/0.5.1/src/jail-commit
parent2cb431c8236415e4f4cf24e51e8799c7579dc846 (diff)
downloadsimplepkg-b28b0bd5f13135d64dca024f629100b3e30d47b2.tar.gz
simplepkg-b28b0bd5f13135d64dca024f629100b3e30d47b2.tar.bz2
fixed a bug on 0.5 and tagged as 0.5.1
git-svn-id: svn+slack://slack.fluxo.info/var/svn/simplepkg@407 04377dda-e619-0410-9926-eae83683ac58
Diffstat (limited to 'tags/0.5.1/src/jail-commit')
-rwxr-xr-xtags/0.5.1/src/jail-commit175
1 files changed, 175 insertions, 0 deletions
diff --git a/tags/0.5.1/src/jail-commit b/tags/0.5.1/src/jail-commit
new file mode 100755
index 0000000..f40e5cd
--- /dev/null
+++ b/tags/0.5.1/src/jail-commit
@@ -0,0 +1,175 @@
+#!/bin/bash
+#
+# jail-commit: update config files from a jail to a template
+# feedback: rhatto@riseup.net | gpl
+#
+# Jail-commit is free software; you can redistribute it and/or modify it under the
+# terms of the GNU General Public License as published by the Free Software
+# Foundation; either version 2 of the License, or any later version.
+#
+# Jail-commit is distributed in the hope that it will be useful, but WITHOUT ANY
+# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+# A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License along with
+# this program; if not, write to the Free Software Foundation, Inc., 59 Temple
+# Place - Suite 330, Boston, MA 02111-1307, USA
+#
+
+COMMON="/usr/libexec/simplepkg/common.sh"
+BASENAME="`basename $0`"
+
+if [ -f "$COMMON" ]; then
+ source $COMMON
+ eval_config $BASENAME
+else
+ echo "error: file $COMMON found, check your $BASENAME installation"
+ exit 1
+fi
+
+function usage {
+
+ echo $BASENAME: commit a jail configuration into a template
+ echo "usage: \"$BASENAME [<jail-path> [template]]\""
+ echo " \"$BASENAME --all\" to commit all templates"
+ echo " \"$BASENAME --help\" for help"
+
+}
+
+function template_merge {
+
+ # copy differences between the jail
+ # and the template in the template folder
+
+ # usage: template_merge <jail-path>
+
+ if [ -z "$1" ] || [ ! -d "$TEMPLATE_BASE.d" ]; then
+ return 1
+ fi
+
+ echo "" > $TEMPLATE_BASE.perms.tmp
+ cd $TEMPLATE_BASE.d
+
+ for file in `find | grep -v -e "/.svn$" | grep -v -e "/.svn/" | grep -v -e "^\.$"`; do
+
+ if [[ -e "$file" && -e "$1/$file" ]]; then
+
+ if [ ! -d "$file" ] && [ ! -h "$file" ]; then
+ if ! diff $file $1/$file; then
+ echo Updating $file
+ cp -af $1/$file $file
+ fi
+ elif [ -h "$file" ]; then
+ if [ "`readlink $file`" != "`readlink $1/$file`" ]; then
+ rm -f $file
+ ln -s `readlink $1/$file` $file
+ fi
+ fi
+
+ perms="`numeric_perm $1/$file`"
+ owner="`get_owner $1/$file`"
+ group="`get_group $1/$file`"
+
+ # secure the file
+ chown root.root $TEMPLATE_BASE.d/$file
+ chmod $perms $TEMPLATE_BASE.d/$file
+
+ echo "$file;$owner;$group;$perms" >> $TEMPLATE_BASE.perms.tmp
+
+ else
+ if [ ! -e "$1/$file" ]; then
+ echo $BASENAME: warning: missing file `slash $1/$file`
+ fi
+ fi
+
+ done
+
+ cat $TEMPLATE_BASE.perms.tmp | sed '/^$/d' > $TEMPLATE_BASE.perms
+ rm -f $TEMPLATE_BASE.perms.tmp
+
+ if ! svn_check $TEMPLATE_BASE,perms; then
+ svn add $TEMPLATE_BASE,perms
+ fi
+
+}
+
+function template_svn_commit {
+
+ # issue a svn_commit from a template folder
+ # usage: template_svn_commit <template-folder>
+
+ if use_svn && [ -d "$1/.svn" ]; then
+ cd $1
+ echo First checking out from the repository...
+ svn update
+ echo Commiting changes to the repository...
+ svn commit -m "changes for `date`"
+ if [ "$?" != "0" ]; then
+ echo $BASENAME: commit error
+ fi
+ fi
+
+}
+
+function do_commit {
+
+ # commit jail changes to a repository
+ # usage: do_commit <jailpath> [template]
+
+ local jailpath template
+
+ jailpath="$1"
+ jail="`basename $jailpath`"
+
+ if [ ! -z "$2" ]; then
+ template="$2"
+ else
+ template="$jail"
+ fi
+
+ search_template $template --update
+ if [ "$?" == "0" ] && ! echo "$TEMPLATE_UPDATE_LIST" | grep -q " `basename $TEMPLATE_BASE` "; then
+ TEMPLATE_UPDATE_LIST=" $TEMPLATE_UPDATE_LIST `basename $TEMPLATE_BASE` " # the spaces are important
+ if [ "$jailpath" == "/" ]; then
+ echo Updating main installation...
+ else
+ echo Updating $jailpath...
+ fi
+ if [ -d "$TEMPLATE_BASE.d" ] || [ -a "$TEMPLATE_BASE.template" ]; then
+ SILENT=yes templatepkg -u $template $jailpath
+ template_merge $jailpath
+ fi
+ else
+ if [ -z "$SILENT" ]; then
+ echo $BASENAME: template $template not found
+ fi
+ return 1
+ fi
+
+}
+
+TEMPLATE_UPDATE_LIST=""
+
+if [ "$1" == "--help" ]; then
+ usage
+elif [ "$1" == "--all" ]; then
+ template_svn_commit $BASE_CONF/templates
+elif echo $1 | grep -q -e "^--"; then
+ usage
+elif [ ! -z "$1" ]; then
+ do_commit $1 $2
+ if [ "$?" == "0" ]; then
+ template_svn_commit `dirname $TEMPLATE_BASE`
+ fi
+else
+ SILENT="yes"
+ if [ -e $JAIL_LIST ]; then
+ for jailpath in `cat $JAIL_LIST`; do
+ do_commit $jailpath
+ done
+ fi
+ # main jail
+ do_commit / main
+ template_svn_commit $BASE_CONF/templates
+fi
+