aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rwxr-xr-xsrc/jail-commit4
-rwxr-xr-xsrc/templatepkg207
2 files changed, 156 insertions, 55 deletions
diff --git a/src/jail-commit b/src/jail-commit
index b48a0f9..1013c88 100755
--- a/src/jail-commit
+++ b/src/jail-commit
@@ -72,7 +72,7 @@ if [ -f $JAIL_LIST ]; then
if [ "$?" == "0" ]; then
echo updating $jailpath...
if [ -d "$TEMPLATE_BASE.d" ] || [ -a "$TEMPLATE_BASE.template" ]; then
- templatepkg -a $jail $jailpath
+ templatepkg -u $jail $jailpath
template_merge $jailpath
template_svn_commit $TEMPLATE_BASE
fi
@@ -85,7 +85,7 @@ search_template main --update
if [ "$?" == "0" ]; then
if [ -a "$TEMPLATE_BASE.template" ] || [ -a "$TEMPLATE_BASE.template" ]; then
echo updating main installation...
- templatepkg -a main
+ templatepkg -u main
template_merge /
template_svn_commit $TEMPLATE_BASE
fi
diff --git a/src/templatepkg b/src/templatepkg
index 0029dcd..fb22e62 100755
--- a/src/templatepkg
+++ b/src/templatepkg
@@ -1,7 +1,6 @@
#!/bin/bash
#
-# templatepkg v0.2: create a simplepkg package list from
-# a legacy slackware /var/log/packages
+# templatepkg v0.3: template maintenance script from simplepkg suite
#
# feedback: rhatto at riseup.net | gpl
#
@@ -29,65 +28,167 @@ else
exit 1
fi
-APPEND="0"
-if [[ ! -z "$3" && "$1" == "-a" ]]; then
- ROOT="$3"
- search_template $2 --new
- APPEND="1"
-elif [[ ! -z "$2" && "$1" == "-a" ]]; then
- ROOT="/"
- search_template $2 --new
- APPEND="1"
-elif [[ ! -z "$2" ]]; then
- ROOT="$2"
- search_template $1 --new
-elif [[ ! -z "$1" ]]; then
- search_template $1 --new
- ROOT="/"
-else
- echo "usage: $BASENAME [-a] <template> [root-dir]"
- echo -e "\t-a: append packages into a template"
+function usage {
+
+ echo "usage: $BASENAME <option> <template> [arguments]"
+ echo "options:"
+ echo ""
+ echo " -u: update a template acording a jail; arguments:"
+ echo ""
+ echo " $BASENAME -u <template> [jail-root]"
+ echo ""
+ echo " (if ommited, jail-root defaults to /)"
+ echo ""
+ echo " -a: add files into a template; arguments:"
+ 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 ""
exit 1
-fi
-TEMPLATE="$TEMPLATE_BASE.template"
+}
-if [ ! -d "$ROOT/var/log/packages" ]; then
- echo $ROOT/var/log/packages: directory not found
- exit 1
-elif [[ -f "$TEMPLATE" && "$APPEND" == "0" ]]; then
- rm -f $TEMPLATE
-fi
+function template_update {
+
+ # update the template package list
-for package in `ls -1 $ROOT/var/log/packages/`; do
- pack=`package_name $package`
- if [ -f $TEMPLATE ]; then
- if ! `grep -v -e "^#" $TEMPLATE | cut -d : -f 1 | grep -q -e "^$pack\$"`; then
+ if [ ! -d "$ROOT/var/log/packages" ]; then
+ echo $ROOT/var/log/packages: directory not found
+ exit 1
+ fi
+
+ for package in `ls -1 $ROOT/var/log/packages/`; do
+ pack=`package_name $package`
+ if [ -f $TEMPLATE ]; then
+ if ! `grep -v -e "^#" $TEMPLATE | cut -d : -f 1 | grep -q -e "^$pack\$"`; then
+ package_name $package >> $TEMPLATE
+ fi
+ else
package_name $package >> $TEMPLATE
fi
- else
- package_name $package >> $TEMPLATE
+ done
+
+ # check if each package from the template is installed
+ grep -v -e "^#" $TEMPLATE | cut -d : -f 1 | while read pack; do
+
+ if [ ! -z "$pack" ]; then
+ unset found
+ for candidate in `ls $ROOT/var/log/packages/$pack* 2> /dev/null`; do
+ candidate="`package_name $candidate`"
+ if [ "$pack" == "$candidate" ]; then
+ found="1"
+ break
+ fi
+ done
+ if [ "$found" != "1" ]; then
+ # remove a non-installed package from the template
+ sed "/^$pack$/d" $TEMPLATE | sed "/^$pack $/d" | sed "/^$pack:*/d" > $TEMPLATE.tmp
+ cat $TEMPLATE.tmp > $TEMPLATE
+ rm -f $TEMPLATE.tmp
+ fi
+ fi
+
+ done
+
+}
+
+function template_add {
+
+ # add a file in a template
+ # usage: template_add <jail-root> <file>
+
+ local info_commit
+
+ mkdir -p $TEMPLATE_BASE.d
+
+ if [ -z "$1" ] || [ -z "$2" ]; then
+ return 1
fi
-done
-
-# checks if each package from the template is installed
-grep -v -e "^#" $TEMPLATE | cut -d : -f 1 | while read pack; do
-
- if [ ! -z "$pack" ]; then
- unset found
- for candidate in `ls $ROOT/var/log/packages/$pack* 2> /dev/null`; do
- candidate="`package_name $candidate`"
- if [ "$pack" == "$candidate" ]; then
- found="1"
- break
+
+ jail="/$1"
+ file="$2"
+
+ if [ -a "$TEMPLATE_BASE.d/$file" ]; then
+ if [ -d "$TEMPLATE_BASE.d/$file" ]; then
+
+ echo $BASENAME: folder $file already on $TEMPLATE_BASE.d, checking for contents
+ cd $jail/$file
+ for candidate in `find`; do
+ if [ ! -a "$TEMPLATE_BASE.d/$candidate" ]; then
+ mkdir -p $TEMPLATE_BASE.d/`dirname $candidate`
+ cp -a $candidate $TEMPLATE_BASE.d/$candidate
+
+ if [ "$TEMPLATES_UNDER_SVN" == "1" ]; then
+ ( cd $TEMPLATE_BASE.d && svn add $candidate )
+ info_commit="yes"
+ fi
+
+ fi
+ done
+
+ if [ "$info_commit" == "yes" ]; then
+ echo $BASENAME: please run jail-commit to add files under $file into the svn repository
fi
- done
- if [ "$found" != "1" ]; then
- # removes a non-installed package from the template
- sed "/^$pack$/d" $TEMPLATE | sed "/^$pack $/d" | sed "/^$pack:*/d" > $TEMPLATE.tmp
- cat $TEMPLATE.tmp > $TEMPLATE
- rm -f $TEMPLATE.tmp
+
+ else
+ echo $BASENAME: file $file already on $TEMPLATE_BASE.d
+ exti 1
+ fi
+ else
+ if [ -a "$jail/$file" ]; then
+
+ mkdir -p $TEMPLATE_BASE.d/`dirname $file`/
+ cp -a $jail/$file $TEMPLATE_BASE.d/$file
+ if [ "$TEMPLATES_UNDER_SVN" == "1" ]; then
+ ( cd $TEMPLATE_BASE.d && svn add $file )
+ echo $BASENAME: please run jail-commit to add $file into the svn repository
+ true
+ fi
+
+ else
+ echo $BASENAME: $jail/$file: file not found
+ exit 1
fi
fi
-done
+}
+
+# command line parsing
+
+if [ -z "$2" ]; then
+ usage
+fi
+
+search_template $2 --new
+TEMPLATE="$TEMPLATE_BASE.template"
+
+if [ "$1" == "-u" ] || [ "$1" == "--update" ]; then
+
+ if [ -z "$3" ]; then
+ ROOT="/"
+ else
+ ROOT="/$3"
+ fi
+
+ template_update
+
+elif [ "$1" == "-a" ] || [ "$1" == "--add" ]; then
+
+ if [ -z "$3" ]; then
+ usage
+ else
+ if [ -z "$4" ]; then
+ ROOT="/"
+ else
+ ROOT="$4"
+ fi
+ fi
+
+ template_add $ROOT $3
+
+else
+ usage
+fi
+