diff options
author | rhatto <rhatto@04377dda-e619-0410-9926-eae83683ac58> | 2007-02-09 16:44:20 +0000 |
---|---|---|
committer | rhatto <rhatto@04377dda-e619-0410-9926-eae83683ac58> | 2007-02-09 16:44:20 +0000 |
commit | bd5a14836a8967b9ff8b8ed1c14a0b1d8289ea52 (patch) | |
tree | ec801fc9d595e3cf483c564f0d1d9a0f6858ba52 /src | |
parent | f7595585fae0e0844877ad111388837aaf74028b (diff) | |
download | simplepkg-bd5a14836a8967b9ff8b8ed1c14a0b1d8289ea52.tar.gz simplepkg-bd5a14836a8967b9ff8b8ed1c14a0b1d8289ea52.tar.bz2 |
lots of changes:
- jail-update renamed to jail-commit
- mkjail, jail-commit and templatepkg with svn support
- templates now has permission tracking
- etc
git-svn-id: svn+slack://slack.fluxo.info/var/svn/simplepkg@164 04377dda-e619-0410-9926-eae83683ac58
Diffstat (limited to 'src')
-rwxr-xr-x | src/jail-commit | 93 | ||||
-rwxr-xr-x | src/jail-update | 64 | ||||
-rwxr-xr-x | src/mkjail | 103 |
3 files changed, 175 insertions, 85 deletions
diff --git a/src/jail-commit b/src/jail-commit new file mode 100755 index 0000000..b48a0f9 --- /dev/null +++ b/src/jail-commit @@ -0,0 +1,93 @@ +#!/bin/bash +# +# jail-update: update config files from a jail to a template +# feedback: rhatto@riseup.net | gpl +# +# Jail-update 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-update 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" + +if [ -f "$COMMON" ]; then + source $COMMON +else + echo "error: file $COMMON found, check your `basename $0` installation" + exit 1 +fi + +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 + + rm -f $TEMPLATE_BASE.perms + touch $TEMPLATE_BASE.perms + cd $TEMPLATE_BASE.d + + for file in `find`; do + if [[ -f "$file" && -f "$1/$file" ]]; then + if ! diff $file $1/$file; then + echo updating $file + cp -af $1/$file $file + perms="`numeric_perm $1/$file`" + owner="`get_owner $1/$file`" + group="`get_group $1/$file`" + echo "$file;$owner;$group;$perms" >> $TEMPLATE_BASE.perms + fi + fi + done + +} + +function template_svn_commit { + + if [ "$TEMPLATES_UNDER_SVN" == "1" ] && \ + [ "$TEMPLATE_STORAGE_STYLE" == "own-folder" ]; then + cd `basedir $TEMPLATE_BASE` + svn commit -m "changes for `date`" + fi + +} + +if [ -f $JAIL_LIST ]; then + for jailpath in `cat $JAIL_LIST`; do + jail="`basename $jailpath`" + search_template $jail --update + if [ "$?" == "0" ]; then + echo updating $jailpath... + if [ -d "$TEMPLATE_BASE.d" ] || [ -a "$TEMPLATE_BASE.template" ]; then + templatepkg -a $jail $jailpath + template_merge $jailpath + template_svn_commit $TEMPLATE_BASE + fi + fi + done +fi + +# main jail +search_template main --update +if [ "$?" == "0" ]; then + if [ -a "$TEMPLATE_BASE.template" ] || [ -a "$TEMPLATE_BASE.template" ]; then + echo updating main installation... + templatepkg -a main + template_merge / + template_svn_commit $TEMPLATE_BASE + fi +fi + diff --git a/src/jail-update b/src/jail-update deleted file mode 100755 index 07d1d1b..0000000 --- a/src/jail-update +++ /dev/null @@ -1,64 +0,0 @@ -#!/bin/bash -# -# jail-update: update config files from a jail to a template -# feedback: rhatto@riseup.net | gpl -# -# Jail-update 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-update 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" - -if [ -f "$COMMON" ]; then - source $COMMON -else - echo "error: file $COMMON found, check your `basename $0` installation" - exit 1 -fi - -# TODO: get the correct template folder - -if [ -f $JAIL_LIST ]; then - for jailpath in `cat $JAIL_LIST`; do - jail="`basename $jailpath`" - echo updating $jailpath... - if [ -d "$BASE_CONF/$jail.d" ] || [ -a "$BASE_CONF/$jail.template" ]; then - templatepkg -a $jail $jailpath - cd $BASE_CONF/$jail.d - for file in `find`; do - if [[ -f "$file" && -f "$jailpath/$file" ]]; then - if ! diff $file $jailpath/$file; then - echo updating $file - cp -f $jailpath/$file $file - fi - fi - done - fi - done -fi - -# main jail -if [ -a "$BASE_CONF/main.template" ]; then - echo updating main installation... - templatepkg -a main -fi -if [ -d "$BASE_CONF/main.d" ]; then - cd $BASE_CONF/main.d - for file in `find`; do - if [[ -f "$file" && -f "/$file" ]]; then - if ! diff $file /$file; then - echo updating $file - cp -f /$file $file - fi - fi - done -fi @@ -20,11 +20,6 @@ COMMON="/usr/libexec/simplepkg/common.sh" BASENAME="`basename $0`" -function usage { - echo "usage: [ARCH=arch] [VERSION=version] [ROOT=/otherroot] $BASENAME <jail-name> [template]" - exit 1 -} - if [ -f "$COMMON" ]; then source $COMMON else @@ -32,11 +27,87 @@ else exit 1 fi +function usage { + + echo "usage: [ARCH=arch] [VERSION=version] [ROOT=/otherroot] $BASENAME <jail-name> [template]" + exit 1 + +} + +function copy_template_files { + + # copy template files into jail + # usage: copy_template_files <jail-path> + + if [ -d "$1" ]; then + echo "$BASENAME: copying template files..." + if [ -d "$TEMPLATE_BASE.d" ]; then + if [ "$TEMPLATES_UNDER_SVN" == "1" ]; then + rsync -av --exclude=.svn $TEMPLATE_BASE.d/ $JAIL_ROOT/$server/ + else + rsync -av $TEMPLATE_BASE.d/ $JAIL_ROOT/$server/ + fi + fi + fi + +} + +function set_jail_perms { + + # set template file permissions under a jail + # usage: set_jail_perms <jail-path> + + if [ -s "$TEMPLATE_BASE.perms" ]; then + 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`" + chmod $perms $1/$file + chown $owner:$group $1/$file + fi + done + fi + +} + +function exec_post_install_scripts { + + # exec post installation scripts + # usage: exec_post_install_script <jail-root> <jail-name> + + if [ -z "$2" ]; then + return 1 + fi + + echo "$BASENAME: executing template scripts..." + if [ -d "$TEMPLATE_BASE.s" ]; then + for script in `ls $TEMPLATE_BASE.s/`; do + if [ -x "$TEMPLATE_BASE.s/$script" ]; then + exec $TEMPLATE_BASE.s/$script $1 $2 + fi + done + fi + +} + +function jailist_update { + + # update the jail list file + # usage: jailist_update <jail-path> + + if ! grep -q "^$1" $JAIL_LIST; then + echo $1 >> $JAIL_LIST + fi + +} + if [ -z "$1" ]; then usage else server="$1" - eval_config `basename $0` -u + eval_config $BASENAME -u fi if [ ! -z "$2" ]; then @@ -64,22 +135,12 @@ else fi echo "$BASENAME: instaling packages into $JAIL_ROOT/$server using $TEMPLATE..." -install_packages -echo "$BASENAME: copying template files..." -if [ -d "$TEMPLATE_BASE.d" ]; then - rsync -av $TEMPLATE_BASE.d/ $JAIL_ROOT/$server/ -fi - -echo "$BASENAME: executing template scripts..." -if [ -d "$TEMPLATE.s" ]; then - for script in `ls $TEMPLATE.s/`; do - if [ -x "$TEMPLATE_BASE.s/$script" ]; then - exec $TEMPLATE_BASE.s/$script $JAIL_ROOT $server - fi - done -fi +install_packages +copy_template_files $JAIL_ROOT/$server +set_jail_perms $JAIL_ROOT/$server +exec_post_install_scripts $JAIL_ROOT $server +jailist_update $JAIL_ROOT/$server -echo $JAIL_ROOT/$server >> $JAIL_LIST echo $BASENAME: done creating $server jail |