From fcfc2248b2cf6a611836d0635a875fb10f93d74a Mon Sep 17 00:00:00 2001 From: rhatto Date: Thu, 4 Dec 2008 00:50:47 +0000 Subject: new 'compact' template format git-svn-id: svn+slack://slack.fluxo.info/var/svn/simplepkg@634 04377dda-e619-0410-9926-eae83683ac58 --- trunk/src/createpkg | 4 +- trunk/src/jail-commit | 22 +++--- trunk/src/mkjail | 11 +-- trunk/src/templatepkg | 210 +++++++++++++++++++++++++++----------------------- 4 files changed, 131 insertions(+), 116 deletions(-) (limited to 'trunk/src') diff --git a/trunk/src/createpkg b/trunk/src/createpkg index 80f37fc..98dde1f 100644 --- a/trunk/src/createpkg +++ b/trunk/src/createpkg @@ -16,9 +16,9 @@ # this program; if not, write to the Free Software Foundation, Inc., 59 Temple # Place - Suite 330, Boston, MA 02111-1307, USA # -# /etc/simplepkg/slackbuildrc parameters: +# /etc/slackbuildrc parameters: # -# SLACKBUILDS_DIR="/folder/to/place/slackbuilds", defaults to /var/slackbuilds +# SLACKBUILDS_DIR="/path/to/slackbuilds", defaults to /var/simplepkg/slackbuilds # SVN="svn://repository", defaults do http://slack.sarava.org/slackbuilds # SYNC="yes|no", whether to always update the repository # diff --git a/trunk/src/jail-commit b/trunk/src/jail-commit index 278d766..d91a767 100755 --- a/trunk/src/jail-commit +++ b/trunk/src/jail-commit @@ -43,12 +43,12 @@ function template_merge { # usage: template_merge - if [ -z "$1" ] || [ ! -d "$TEMPLATE_BASE.d" ]; then + if [ -z "$1" ] || [ ! -d "`template_files`" ]; then return 1 fi - echo "" > $TEMPLATE_BASE.perms.tmp - cd $TEMPLATE_BASE.d + echo "" > `template_perms`.tmp + cd `template_files` for file in `find | grep -v -e "/.svn$" | grep -v -e "/.svn/" | grep -v -e "^\.$"`; do @@ -71,10 +71,10 @@ function template_merge { group="`get_group $1/$file`" # secure the file - chown root.root $TEMPLATE_BASE.d/$file - chmod $perms $TEMPLATE_BASE.d/$file + chown root.root `template_files`/$file + chmod $perms `template_files`/$file - echo "$file;$owner;$group;$perms" >> $TEMPLATE_BASE.perms.tmp + echo "$file;$owner;$group;$perms" >> `template_perms`.tmp else if [ ! -e "$1/$file" ]; then @@ -84,11 +84,11 @@ function template_merge { done - cat $TEMPLATE_BASE.perms.tmp | sed '/^$/d' > $TEMPLATE_BASE.perms - rm -f $TEMPLATE_BASE.perms.tmp + cat `template_perms`.tmp | sed '/^$/d' > `template_perms` + rm -f `template_perms`.tmp - if templates_under_svn && ! svn_check $TEMPLATE_BASE.perms; then - svn add $TEMPLATE_BASE.perms + if templates_under_svn && ! svn_check `template_perms`; then + svn add `template_perms` fi } @@ -135,7 +135,7 @@ function do_commit { else echo Updating $jailpath... fi - if [ -d "$TEMPLATE_BASE.d" ] || [ -a "$TEMPLATE_BASE.template" ]; then + if [ -d "`template_files`" ] || [ -a "`template_packages`" ]; then SILENT=yes templatepkg -u $template $jailpath template_merge $jailpath fi diff --git a/trunk/src/mkjail b/trunk/src/mkjail index 47930b2..4b00c38 100755 --- a/trunk/src/mkjail +++ b/trunk/src/mkjail @@ -1,7 +1,6 @@ #!/bin/bash # -# mkjail v0.4: chroot jail maker -# +# mkjail: chroot jail maker # feedback: rhatto at riseup.net | GPL # # Mkjail is free software; you can redistribute it and/or modify it under the @@ -16,6 +15,8 @@ # 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`" @@ -46,8 +47,8 @@ function exec_post_install_scripts { fi echo "$BASENAME: executing template scripts..." - if [ -d "$TEMPLATE_BASE.s" ]; then - for file in $TEMPLATE_BASE.s/*; do + if [ -d "`template_scripts`" ]; then + for file in `template_scripts`/*; do if [ -x "$file" ]; then $file $1 $2 fi @@ -89,7 +90,7 @@ if [ "$result" != "0" ]; then exit 1 fi -TEMPLATE="$TEMPLATE_BASE.template" +TEMPLATE="`template_packages`" if [ ! -d "$JAIL_ROOT/$server" ]; then mkdir -p $JAIL_ROOT/$server diff --git a/trunk/src/templatepkg b/trunk/src/templatepkg index e1533c7..2c8e367 100755 --- a/trunk/src/templatepkg +++ b/trunk/src/templatepkg @@ -1,7 +1,6 @@ #!/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 @@ -16,6 +15,8 @@ # 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`" @@ -237,6 +238,7 @@ function template_create { # 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 @@ -254,46 +256,46 @@ function template_create { 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 @@ -312,46 +314,58 @@ function template_create { 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 @@ -415,9 +429,9 @@ function template_update { 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 } @@ -438,19 +452,19 @@ function template_add { 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 @@ -458,7 +472,7 @@ function template_add { 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 @@ -468,20 +482,20 @@ function template_add { 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` @@ -495,7 +509,7 @@ function template_add { cp -a $jail/$file $destination cwd="`pwd`" - cd $TEMPLATE_BASE.d + cd `template_files` svn add ./$file if [ "$?" != "0" ]; then @@ -510,7 +524,7 @@ function template_add { 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` @@ -531,7 +545,7 @@ function check_template_exist { 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 @@ -540,28 +554,28 @@ function check_template_exist { 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 @@ -579,18 +593,18 @@ function template_delete { # delete a file from a template # usage: template_delete [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 @@ -605,22 +619,22 @@ function template_delete { 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 @@ -722,30 +736,30 @@ function template_post_install_edit { 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" @@ -755,7 +769,7 @@ function template_post_install_edit { 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 @@ -767,21 +781,21 @@ function template_edit { # 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 } @@ -812,16 +826,16 @@ function setroot { function create_doinst { - # create a doinst.sh from a template.perms file + # create a doinst.sh from a template perms file # usage: create_doinst 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`" @@ -842,8 +856,8 @@ function package_template { 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 @@ -871,7 +885,7 @@ function package_template { 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 @@ -900,7 +914,7 @@ if [ ! -z "$2" ]; then search_template $2 --new fi -TEMPLATE="$TEMPLATE_BASE.template" +TEMPLATE="`template_packages`" if [ "$1" == "-u" ] || [ "$1" == "--update" ]; then -- cgit v1.2.3