mirror of
ssh://git.janware.com/srv/git/janware/proj/jw-pkg
synced 2026-01-15 03:53:32 +01:00
jw-pkg: Add command list-templates
- Add command list-templates, showing all template files. - Fixes and improvements to compile-templates Signed-off-by: Jan Lindemann <jan@janware.com>
This commit is contained in:
parent
246246573f
commit
44373a7832
1 changed files with 34 additions and 17 deletions
|
|
@ -1,9 +1,5 @@
|
|||
#!/bin/bash
|
||||
|
||||
myname=`basename $0`
|
||||
longname=$0
|
||||
opts="v"
|
||||
|
||||
channel_present()
|
||||
{
|
||||
if smart channel --show $1 2>&1 | grep -q baseurl >/dev/null; then
|
||||
|
|
@ -33,11 +29,12 @@ cat << EOT
|
|||
for others
|
||||
build-date: show installed jannet packages along with build date
|
||||
built-today: show installed jannet packages that were built today
|
||||
list-templates: list templates
|
||||
compile-templates: compile templates
|
||||
|
||||
global options are
|
||||
|
||||
-v be verbose
|
||||
-v be verbose
|
||||
|
||||
package
|
||||
|
||||
|
|
@ -46,9 +43,7 @@ cat << EOT
|
|||
janware packages
|
||||
|
||||
EOT
|
||||
if [ "$1" ]; then
|
||||
exit $1
|
||||
fi
|
||||
[ "$1" ] && exit $1
|
||||
}
|
||||
|
||||
get_opts()
|
||||
|
|
@ -168,26 +163,37 @@ cmd_build_date()
|
|||
done
|
||||
}
|
||||
|
||||
cmd_list_templates()
|
||||
{
|
||||
local ext_from="$template_exts" # TODO: support more than one
|
||||
local ext_from_re=`echo $ext_from | sed 's/\./\\./g'`
|
||||
list_packages "$@" | xargs -r rpm -ql | while read f; do
|
||||
[ -f "$f" ] || continue
|
||||
echo $f | grep -q "$ext_from_re$" || continue
|
||||
echo $f
|
||||
done
|
||||
}
|
||||
|
||||
cmd_compile_templates()
|
||||
{
|
||||
local ext_from=".jw-tmpl"
|
||||
local ext_from="$template_exts" # TODO: support more than one
|
||||
local ext_from_re=`echo $template_exts | sed 's/\./\\./g'`
|
||||
local ext_to=""
|
||||
local ext_tables=".jw-secret .jw-vars"
|
||||
local group=root
|
||||
local owner=root
|
||||
local mode=600
|
||||
local ext_from_re=`echo $ext_from | sed 's/\./\\./g'`
|
||||
local conf_patt="^[ ]*# *conf:"
|
||||
|
||||
# TODO: allow target file attributes to be specified in options
|
||||
# TODO: allow default target file attributes to be specified in options
|
||||
umask 0077
|
||||
|
||||
local f
|
||||
list_packages "$@" | xargs -r rpm -ql | while read f; do
|
||||
echo searching $ext_from_re in $f
|
||||
echo $f | grep -q "$ext_from_re$" || continue
|
||||
cmd_list_templates "$@" | while read f; do
|
||||
local base=`echo $f | sed "s/$ext_from_re$//"`
|
||||
local to=$base$ext_to
|
||||
local table="" ext
|
||||
local table=""
|
||||
local ext
|
||||
for ext in $ext_tables; do
|
||||
table=$base$ext
|
||||
[ -f "$table" ] && break
|
||||
|
|
@ -199,10 +205,11 @@ cmd_compile_templates()
|
|||
# TODO: use mktemp -d and keep temporary files in read-only dir
|
||||
local tmp=$to.tmp
|
||||
echo "Applying macros in $table to $f."
|
||||
sed 's|\([^ ]\+\) \(.*\)|s/\1/\2/g|' $table | sed -f - $f > $tmp
|
||||
eval `sed "/$conf_patt/ !d; s/$conf_patt//" $table`
|
||||
sed 's|^[ ]*#.*||; s|\([^ =]\+\)[ =]\+\(.*\)|s/\1/\2/g|' $table | sed -f - $f > $tmp
|
||||
chmod $mode $tmp
|
||||
chown $owner $tmp
|
||||
chgrp $owner $tmp
|
||||
chgrp $group $tmp
|
||||
mv $tmp $to
|
||||
done
|
||||
}
|
||||
|
|
@ -213,6 +220,13 @@ cmd_built_today()
|
|||
cmd_build_date | grep $today | cut -d' ' -f3
|
||||
}
|
||||
|
||||
# ----- here we go
|
||||
|
||||
myname=`basename $0`
|
||||
longname=$0
|
||||
opts="v"
|
||||
template_exts=".jw-tmpl"
|
||||
|
||||
cmd="$1"
|
||||
shift
|
||||
get_opts $*
|
||||
|
|
@ -281,6 +295,9 @@ rpmnew)
|
|||
compile-templates)
|
||||
cmd_compile_templates "$@"
|
||||
;;
|
||||
list-templates)
|
||||
cmd_list_templates "$@"
|
||||
;;
|
||||
diff)
|
||||
cmd_diff "$@"
|
||||
;;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue