# this program; if not, write to the Free Software Foundation, Inc., 59 Temple
# Place - Suite 330, Boston, MA 02111-1307, USA
#
+# $Rev$ - $Author$
+#
BASE_CONF="/etc/simplepkg"
CONF="$BASE_CONF/simplepkg.conf"
function set_constants {
- # Set common constants
- # on/off
- on=1
- off=0
- # yes/no
- yes=1
- no=0
+ # Set common constants
+ # on/off
+ on=1
+ off=0
+ # yes/no
+ yes=1
+ no=0
}
if [ "$TEMPLATE_STORAGE_STYLE" != "simplepkg-folder" ] && \
[ "$TEMPLATE_STORAGE_STYLE" != "templates-folder" ] && \
- [ "$TEMPLATE_STORAGE_STYLE" != "own-folder" ]; then
- TEMPLATE_STORAGE_STYLE="own-folder"
+ [ "$TEMPLATE_STORAGE_STYLE" != "own-folder" ] && \
+ [ "$TEMPLATE_STORAGE_STYLE" != "compact" ]; then
+ TEMPLATE_STORAGE_STYLE="compact"
fi
if [ ! -z "$ROOT" ]; then
elif [ -e "$TEMPLATE_FOLDER/default/default.template" ]; then
TEMPLATE_BASE="$TEMPLATE_FOLDER/default/default"
echo $BASENAME: using default template
+ elif [ -e "$TEMPLATE_FOLDER/default/packages" ]; then
+ TEMPLATE_BASE="$TEMPLATE_FOLDER/default"
+ echo $BASENAME: using default template
elif [ -e "$BASE_CONF/defaults/templates/default/default.template" ]; then
+ TEMPLATE_BASE="$BASE_CONF/defaults/templates/default/default"
+ echo $BASENAME using default template
+ elif [ -e "$BASE_CONF/defaults/templates/default/packages" ]; then
TEMPLATE_BASE="$BASE_CONF/defaults/templates/default"
echo $BASENAME using default template
else
TEMPLATE_BASE="$TEMPLATE_FOLDER/$1"
elif [ -f "$TEMPLATE_FOLDER/$1/$1.template" ]; then
TEMPLATE_BASE="$TEMPLATE_FOLDER/$1/$1"
+ elif [ -f "$TEMPLATE_FOLDER/$1/packages" ]; then
+ TEMPLATE_BASE="$TEMPLATE_FOLDER/$1"
elif [ -f "$BASE_CONF/defaults/templates/$1/$1.template" ] && \
[ "$2" != "--update" ]; then
TEMPLATE_BASE="$BASE_CONF/defaults/templates/$1/$1"
TEMPLATE_BASE="$BASE_CONF/$1"
elif [ "$TEMPLATE_STORAGE_STYLE" == "templates-folder" ]; then
TEMPLATE_BASE="$TEMPLATE_FOLDER/$1"
- else
+ elif [ "$TEMPLATE_STORAGE_STYLE" == "own-folder" ]; then
TEMPLATE_BASE="$TEMPLATE_FOLDER/$1/$1"
+ elif [ "$TEMPLATE_STORAGE_STYLE" == "compact" ]; then
+ TEMPLATE_BASE="$TEMPLATE_FOLDER/$1"
+ else
+ TEMPLATE_BASE="$TEMPLATE_FOLDER/$1"
fi
elif [ "$2" == "--update" ]; then
return 1
}
+function template_packages {
+
+ if [ "$TEMPLATE_STORAGE_STYLE" == "compact" ]; then
+ echo $TEMPLATE_BASE/packages
+ else
+ echo $TEMPLATE_BASE.template
+ fi
+
+}
+
+function template_perms {
+
+ if [ "$TEMPLATE_STORAGE_STYLE" == "compact" ]; then
+ echo $TEMPLATE_BASE/perms
+ else
+ echo $TEMPLATE_BASE.perms
+ fi
+
+}
+
+function template_files {
+
+ if [ "$TEMPLATE_STORAGE_STYLE" == "compact" ]; then
+ echo $TEMPLATE_BASE/files
+ else
+ echo $TEMPLATE_BASE.d
+ fi
+
+}
+
+function template_scripts {
+
+ if [ "$TEMPLATE_STORAGE_STYLE" == "compact" ]; then
+ echo $TEMPLATE_BASE/scripts
+ else
+ echo $TEMPLATE_BASE.s
+ fi
+
+}
+
# -----------------------------------------------
# unix permission functions
# -----------------------------------------------
# update template files from svn
# usage: update_template_files
- if templates_under_svn && [ -d "$TEMPLATE_BASE.d/.svn" ]; then
+ if templates_under_svn && [ -d "`template_files`/.svn" ]; then
echo Checking out last template revision from svn...
cd `dirname $TEMPLATE_BASE`
svn update
# check if installed packages are listed in the template
for pack in `ls -1 $1/var/log/packages/`; do
pack=`package_name $pack`
- if ! `grep -v -e "^#" $TEMPLATE_BASE.template | cut -d : -f 1 | awk '{ print $1 }' | grep -q -e "^$pack\$"`; then
+ if ! `grep -v -e "^#" $(template_packages) | cut -d : -f 1 | awk '{ print $1 }' | grep -q -e "^$pack\$"`; then
ROOT=$1 removepkg $pack
fi
done
# check if each package from the template is installed
- grep -v -e "^#" $TEMPLATE_BASE.template | cut -d : -f 1 | awk '{ print $1 }' | while read pack; do
+ grep -v -e "^#" `template_packages` | cut -d : -f 1 | awk '{ print $1 }' | while read pack; do
# check if the package is installed
pack="`echo $pack | sed -e 's/\+/\\\+/'`"
# usage: copy_template_files <jail-path>
if [ -d "$1" ]; then
- if [ -d "$TEMPLATE_BASE.d" ]; then
+ if [ -d "`template_files`" ]; then
echo "Copying template files to $1..."
- if templates_under_svn && [ -d "$TEMPLATE_BASE.d/.svn" ]; then
- rsync -av --exclude=.svn $TEMPLATE_BASE.d/ $1/
+ if templates_under_svn && [ -d "`template_files`/.svn" ]; then
+ rsync -av --exclude=.svn `template_files`/ $1/
else
- rsync -av $TEMPLATE_BASE.d/ $1/
+ rsync -av `template_files`/ $1/
fi
fi
fi
# set template file permissions under a jail
# usage: set_jail_perms <jail-path>
- if [ -s "$TEMPLATE_BASE.perms" ]; then
+ if [ -s "`template_perms`" ]; then
echo Setting jail $1 permissions...
- cat $TEMPLATE_BASE.perms | while read entry; do
+ cat `template_perms` | while read entry; do
file="`echo $entry | cut -d ";" -f 1`"
- if [ -e "$TEMPLATE_BASE.d/$file" ] && [ -a "$1/$file" ]; then
+ if [ -e "`template_files`/$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`"
#!/bin/bash
#
-# templatepkg v0.3: template maintenance script from simplepkg suite
-#
+# templatepkg: template maintenance script from simplepkg suite
# feedback: rhatto at riseup.net | gpl
#
# Templatepkg is free software; you can redistribute it and/or modify it under the
# this program; if not, write to the Free Software Foundation, Inc., 59 Temple
# Place - Suite 330, Boston, MA 02111-1307, USA
#
+# $Rev$ - $Author$
+#
COMMON="/usr/libexec/simplepkg/common.sh"
BASENAME="`basename $0`"
# create a new template
local template_base info_commit orig_template list
+ local orig_packages orig_perms orig_scripts orig_files
if [ ! -d "`dirname $TEMPLATE_BASE`" ]; then
exit 1
fi
- touch $TEMPLATE_BASE.perms
- touch $TEMPLATE_BASE.template
+ touch `template_perms`
+ touch `template_packages`
if templates_under_svn && [ -d "`dirname $TEMPLATE_BASE`/.svn" ]; then
cd `dirname $TEMPLATE_BASE`
- if ! svn_check $TEMPLATE_BASE.d; then
- svn mkdir $TEMPLATE_BASE.d
+ if ! svn_check `template_files`; then
+ svn mkdir `template_files`
info_commit="yes"
else
- mkdir -p $TEMPLATE_BASE.d
+ mkdir -p `template_files`
fi
- if ! svn_check $TEMPLATE_BASE.s; then
- svn mkdir $TEMPLATE_BASE.s
+ if ! svn_check `template_scripts`; then
+ svn mkdir `template_scripts`
info_commit="yes"
else
- mkdir -p $TEMPLATE_BASE.s
+ mkdir -p `template_scripts`
fi
- if ! svn_check $TEMPLATE_BASE.template; then
- svn add $TEMPLATE_BASE.template
+ if ! svn_check `template_packages`; then
+ svn add `template_packages`
info_commit="yes"
fi
- if ! svn_check $TEMPLATE_BASE.perms; then
- svn add $TEMPLATE_BASE.perms
+ if ! svn_check `template_perms`; then
+ svn add `template_perms`
info_commit="yes"
fi
elif templates_under_svn && [ -d "$TEMPLATE_FOLDER/.svn" ]; then
- mkdir $TEMPLATE_BASE.{d,s}
+ mkdir `template_files` `template_scripts`
cd $TEMPLATE_FOLDER
svn add `basename $TEMPLATE_BASE`
info_commit="yes"
else
- mkdir $TEMPLATE_BASE.{d,s}
+ mkdir `template_files` `template_scripts`
fi
if [ -d "/$ROOT" ]; then
return 1
fi
- if [ -f "$orig_template/$ROOT.perms" ]; then
- cat $orig_template/$ROOT.perms > $TEMPLATE_BASE.perms
+ if [ -e "$orig_template/$ROOT/packages" ]; then
+ orig_packages="$orig_template/$ROOT/packages"
+ orig_perms="$orig_template/$ROOT/perms"
+ orig_scripts="$orig_template/$ROOT/scripts"
+ orig_files="$orig_template/$ROOT/files"
+ else
+ orig_packages="$orig_template/$ROOT.template"
+ orig_perms="$orig_template/$ROOT.perms"
+ orig_scripts="$orig_template/$ROOT.s"
+ orig_files="$orig_template/$ROOT.d"
+ fi
+
+ if [ -f "$orig_perms" ]; then
+ cat $orig_perms > `template_perms`
fi
- if [ -f "$orig_template/$ROOT.template" ]; then
- cat $orig_template/$ROOT.template > $TEMPLATE_BASE.template
+ if [ -f "$orig_packages" ]; then
+ cat $orig_packages > `template_packages`
fi
if templates_under_svn && [ -d "$orig_template/.svn" ]; then
cd `dirname $TEMPLATE_BASE`
- list="`ls $orig_template/$ROOT.d/ 2> /dev/null`"
+ list="`ls $orig_files/ 2> /dev/null`"
if [ ! -z "$list" ]; then
echo Copying files to the new template...
- rsync -av --exclude=.svn $orig_template/$ROOT.d/ $TEMPLATE_BASE.d/
- svn add `basename $TEMPLATE_BASE`.d/*
+ rsync -av --exclude=.svn $orig_files/ `template_files`/
+ svn add `basename $(template_files)`/*
info_commit="yes"
fi
- list="`ls $orig_template/$ROOT.s/ 2> /dev/null`"
+ list="`ls $orig_scripts/ 2> /dev/null`"
if [ ! -z "$list" ]; then
echo Copying scripts to the new template...
- rsync -av --exclude=.svn $orig_template/$ROOT.s/ $TEMPLATE_BASE.s/
- svn add `basename $TEMPLATE_BASE`.s/*
+ rsync -av --exclude=.svn $orig_scripts/ `template_scripts`/
+ svn add `basename $(template_scripts)`/*
info_commit="yes"
fi
else
- list="`ls $orig_template/$ROOT.d/ 2> /dev/null`"
+ list="`ls $orig_files/ 2> /dev/null`"
if [ ! -z "$list" ]; then
echo Copying files to the new template...
- rsync -av $orig_template/$ROOT.d/ $TEMPLATE_BASE.d/
+ rsync -av $orig_files/ `template_files`/
fi
- list="`ls $orig_template/$ROOT.s/ 2> /dev/null`"
+ list="`ls $orig_scripts/ 2> /dev/null`"
if [ ! -z "$list" ]; then
echo Copying scripts to the new template...
- rsync -av $orig_template/$ROOT.s/ $TEMPLATE_BASE.s/
+ rsync -av $orig_scripts/ `template_scripts`/
fi
fi
done
- if ! svn_check $TEMPLATE_BASE.template && [ -d "`dirname $TEMPLATE_BASE`/.svn" ]; then
+ if ! svn_check `template_packages` && [ -d "`dirname $TEMPLATE_BASE`/.svn" ]; then
cd `dirname $TEMPLATE_BASE`
- svn add `basedir $TEMPLATE_BASE`.template
+ svn add `basedir $(template_packages)`
fi
}
jail="/$1"
file="$2"
- if [ -a "$TEMPLATE_BASE.d/$file" ]; then
- if [ -d "$TEMPLATE_BASE.d/$file" ]; then
+ if [ -a "`template_files`/$file" ]; then
+ if [ -d "`template_files`/$file" ]; then
- echo $BASENAME: folder `slash $file` already on $TEMPLATE_BASE.d, checking for contents
+ echo $BASENAME: folder `slash $file` already on `template_files`, checking for contents
cd $jail
for candidate in `find $file`; do
- if [ ! -a "$TEMPLATE_BASE.d/$candidate" ]; then
- mkdir -p $TEMPLATE_BASE.d/`dirname $candidate`
- cp -a $jail/$candidate $TEMPLATE_BASE.d/$candidate
- if templates_under_svn && [ -d "$TEMPLATE_BASE.d/.svn" ]; then
+ if [ ! -a "`template_files`/$candidate" ]; then
+ mkdir -p `template_files`/`dirname $candidate`
+ cp -a $jail/$candidate `template_files`/$candidate
+ if templates_under_svn && [ -d "`template_files`/.svn" ]; then
cwd="`pwd`"
- cd $TEMPLATE_BASE.d
+ cd `template_files`
svn add ./$candidate
if [ "$?" != "0" ]; then
echo $BASENAME: error adding `slash $candidate` into the revision system
cd $cwd
info_commit="yes"
else
- echo Added `slash $jail/$candidate` on `slash $TEMPLATE_BASE.d/$candidate`
+ echo Added `slash $jail/$candidate` on `slash $(template_files)/$candidate`
fi
fi
done
fi
else
- echo $BASENAME: file `slash $file` already on $TEMPLATE_BASE.d
+ echo $BASENAME: file `slash $file` already on `template_files`
exit 1
fi
else
if [ -a "$jail/$file" ]; then
- destination="`echo $TEMPLATE_BASE.d/$file | sed -e 's/\/$//'`"
+ destination="`echo `template_files`/$file | sed -e 's/\/$//'`"
- if templates_under_svn && [ -d "$TEMPLATE_BASE.d/.svn" ]; then
+ if templates_under_svn && [ -d "`template_files`/.svn" ]; then
candidate="./`dirname $file`"
- mkdir -p $TEMPLATE_BASE.d/$candidate
- cd $TEMPLATE_BASE.d/$candidate
+ mkdir -p `template_files`/$candidate
+ cd `template_files`/$candidate
while true; do
if [ -d ".svn" ]; then
svn add `basename $candidate`
cp -a $jail/$file $destination
cwd="`pwd`"
- cd $TEMPLATE_BASE.d
+ cd `template_files`
svn add ./$file
if [ "$?" != "0" ]; then
else
- mkdir -p $TEMPLATE_BASE.d/`dirname $file`/
+ mkdir -p `template_files`/`dirname $file`/
cp -a $jail/$file $destination
echo Added `slash $jail/$file` on `slash $destination`
local components
- components="template perms d s"
+ components="`template_packages` `template_perms` `template_files` `template_scripts`"
if [ ! -d "`dirname $TEMPLATE_BASE`" ]; then
echo $BASENAME: template not found
for component in $components; do
- if [ ! -e "$TEMPLATE_BASE.$component" ]; then
+ if [ ! -e "$component" ]; then
- echo "$BASENAME: template component not found: $TEMPLATE_BASE.$component; creating..."
+ echo "$BASENAME: template component not found: $component; creating..."
cd `dirname $TEMPLATE_BASE`
if [ "$component" == "perms" ] || [ "$component" == "template" ]; then
- touch $TEMPLATE_BASE.$component
+ touch $component
else
- mkdir $TEMPLATE_BASE.$component
+ mkdir $component
fi
if templates_under_svn && [ -d "`dirname $TEMPLATE_BASE`/.svn" ]; then
- svn add $TEMPLATE_BASE.$component
+ svn add $component
info_commit="yes"
fi
elif templates_under_svn && [ -d "`dirname $TEMPLATE_BASE`/.svn" ] && \
- ! svn_check $TEMPLATE_BASE.$component; then
+ ! svn_check $component; then
cd `dirname $TEMPLATE_BASE`
- svn add $TEMPLATE_BASE.$component
+ svn add $component
info_commit="yes"
fi
# delete a file from a template
# usage: template_delete <file> [jail-root]
- if [ -e "$TEMPLATE_BASE.d/$1" ]; then
+ if [ -e "`template_files`/$1" ]; then
# first try to remove the file from the template
- if templates_under_svn && [ -d "$TEMPLATE_BASE.d/.svn" ]; then
- cd $TEMPLATE_BASE.d
+ if templates_under_svn && [ -d "`template_files`/.svn" ]; then
+ cd `template_files`
svn del --force ./$1 || rm -rf ./$1
if [ -z "$SILENT" ]; then
echo "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
+ rm -rf `template_files`/$1
+ echo Removed $1 from `template_files`
fi
# then, if requested, remove the file from the jail
fi
fi
- elif [ -e "$TEMPLATE_BASE.s/$1" ]; then
- if templates_under_svn && [ -d "$TEMPLATE_BASE.s/.svn" ]; then
- cd $TEMPLATE_BASE.s
+ elif [ -e "`template_scripts`/$1" ]; then
+ if templates_under_svn && [ -d "`template_scripts`/.svn" ]; then
+ cd `template_scripts`
svn del --force ./$1 || rm -rf ./$1
if [ -z "$SILENT" ]; then
echo "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
+ rm -rf `template_scripts`/$1
+ echo Removed $1 from `template_scripts`
fi
else
- if [ ! -d "$TEMPLATE_BASE.d" ]; then
- echo $BASENAME: template folder $TEMPLATE_BASE.d not found
+ if [ ! -d "`template_files`" ]; then
+ echo $BASENAME: template folder `template_files` not found
else
- echo $BASENAME: file $1 not found at $TEMPLATE_BASE.d
+ echo $BASENAME: file $1 not found at `template_files`
fi
exit 1
fi
echo $BASENAME: error: invalid script name $1
fi
- if [ -f "$TEMPLATE_BASE.s/$1" ]; then
- sha1sum="`sha1sum $TEMPLATE_BASE.s/$1`"
+ if [ -f "`template_scripts`/$1" ]; then
+ sha1sum="`sha1sum $(template_scripts)/$1`"
if [ ! -z "$EDITOR" ]; then
- $EDITOR $TEMPLATE_BASE.s/$1
+ $EDITOR `template_scripts`/$1
else
- vi $TEMPLATE_BASE.s/$1
+ vi `template_scripts`/$1
fi
- if [ "$sha1sum" != "`sha1sum $TEMPLATE_BASE.s/$1`" ] && \
+ if [ "$sha1sum" != "`sha1sum $(template_scripts)/$1`" ] && \
[ -d "`dirname $TEMPLATE_BASE`/.svn" ] && [ -z "$SILENT" ]; then
echo "Please run 'jail-commit --all' to send changes to the repository"
fi
else
- if [ -e "$TEMPLATE_BASE.s/$1" ]; then
+ if [ -e "`template_scripts`/$1" ]; then
- echo $BASENAME: file $TEMPLATE_BASE.s/$1 not a regular file
+ echo $BASENAME: file `template_scripts`/$1 not a regular file
- elif [ -d "$TEMPLATE_BASE.s" ]; then
+ elif [ -d "`template_scripts`" ]; then
- touch $TEMPLATE_BASE.s/$1
- chmod +x $TEMPLATE_BASE.s/$1
+ touch `template_scripts`/$1
+ chmod +x `template_scripts`/$1
- if [ -d "$TEMPLATE_BASE.s/.svn" ]; then
- cd $TEMPLATE_BASE.s
+ if [ -d "`template_scripts`/.svn" ]; then
+ cd `template_scripts`
svn add $1
if [ -z "$SILENT" ]; then
echo "Please run 'jail-commit --all' to send the script to the repository"
echo "$BASENAME: script created; run templatepkg -p `basename $TEMPLATE_BASE` $1 again to edit it"
else
- echo $BASENAME: folder not found: $TEMPLATE_BASE.s
+ echo $BASENAME: folder not found: `template_scripts`
fi
fi
# edit a template package list
# usage: template_edit
- if [ -f "$TEMPLATE_BASE.template" ]; then
- sha1sum="`sha1sum $TEMPLATE_BASE.template`"
+ if [ -f "`template_packages`" ]; then
+ sha1sum="`sha1sum $(template_packages)`"
if [ ! -z "$EDITOR" ]; then
- $EDITOR $TEMPLATE_BASE.template
+ $EDITOR `template_packages`
else
- vi $TEMPLATE_BASE.template
+ vi `template_packages`
fi
- if [ "$sha1sum" != "`sha1sum $TEMPLATE_BASE.template`" ] && \
+ if [ "$sha1sum" != "`sha1sum $(template_packages)`" ] && \
[ -d "`dirname $TEMPLATE_BASE`/.svn" ] && [ -z "$SILENT" ]; then
echo "Please run 'jail-commit --all' to send changes to the repository"
fi
- elif [ -e "$TEMPLATE_BASE.template" ]; then
- echo $BASENAME: file $TEMPLATE_BASE.template not a regular file
+ elif [ -e "`template_packages`" ]; then
+ echo $BASENAME: file `template_packages` not a regular file
else
- echo $BASENAME: file not found: $TEMPLATE_BASE.template
+ echo $BASENAME: file not found: `template_packages`
fi
}
function create_doinst {
- # create a doinst.sh from a template.perms file
+ # create a doinst.sh from a template perms file
# usage: create_doinst <doinst-path>
rm -f $1/doinst.sh
- if [ -s "$TEMPLATE_BASE.perms" ]; then
+ if [ -s "`template_perms`" ]; then
echo Creating doinst.sh...
- cat $TEMPLATE_BASE.perms | while read entry; do
+ cat `template_perms` | while read entry; do
file="`echo $entry | cut -d ";" -f 1`"
- if [ -e "$TEMPLATE_BASE.d/$file" ]; then
+ if [ -e "`template_files`/$file" ]; then
owner="`echo $entry | cut -d ";" -f 2`"
group="`echo $entry | cut -d ";" -f 3`"
perms="`echo $entry | cut -d ";" -f 4`"
template="`basename $TEMPLATE_BASE`"
- if [ ! -d "$TEMPLATE_BASE.d" ]; then
- $BASENAME: folder not found: $TEMPLATE.base.d
+ if [ ! -d "`template_files`" ]; then
+ $BASENAME: folder not found: `template_files`
return 1
fi
rm -rf $TMP/templatepkg
mkdir -p $TMP/templatepkg
- rsync -av --exclude=.svn $TEMPLATE_BASE.d/ $TMP/templatepkg/
+ rsync -av --exclude=.svn `template_files`/ $TMP/templatepkg/
mkdir $TMP/templatepkg/install
create_doinst $TMP/templatepkg/install
search_template $2 --new
fi
-TEMPLATE="$TEMPLATE_BASE.template"
+TEMPLATE="`template_packages`"
if [ "$1" == "-u" ] || [ "$1" == "--update" ]; then