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:
Jan Lindemann 2018-11-10 07:53:30 +00:00
commit 44373a7832

View file

@ -1,9 +1,5 @@
#!/bin/bash #!/bin/bash
myname=`basename $0`
longname=$0
opts="v"
channel_present() channel_present()
{ {
if smart channel --show $1 2>&1 | grep -q baseurl >/dev/null; then if smart channel --show $1 2>&1 | grep -q baseurl >/dev/null; then
@ -33,11 +29,12 @@ cat << EOT
for others for others
build-date: show installed jannet packages along with build date build-date: show installed jannet packages along with build date
built-today: show installed jannet packages that were built today built-today: show installed jannet packages that were built today
list-templates: list templates
compile-templates: compile templates compile-templates: compile templates
global options are global options are
-v be verbose -v be verbose
package package
@ -46,9 +43,7 @@ cat << EOT
janware packages janware packages
EOT EOT
if [ "$1" ]; then [ "$1" ] && exit $1
exit $1
fi
} }
get_opts() get_opts()
@ -168,26 +163,37 @@ cmd_build_date()
done 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() 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_to=""
local ext_tables=".jw-secret .jw-vars" local ext_tables=".jw-secret .jw-vars"
local group=root local group=root
local owner=root local owner=root
local mode=600 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 umask 0077
local f local f
list_packages "$@" | xargs -r rpm -ql | while read f; do cmd_list_templates "$@" | while read f; do
echo searching $ext_from_re in $f
echo $f | grep -q "$ext_from_re$" || continue
local base=`echo $f | sed "s/$ext_from_re$//"` local base=`echo $f | sed "s/$ext_from_re$//"`
local to=$base$ext_to local to=$base$ext_to
local table="" ext local table=""
local ext
for ext in $ext_tables; do for ext in $ext_tables; do
table=$base$ext table=$base$ext
[ -f "$table" ] && break [ -f "$table" ] && break
@ -199,10 +205,11 @@ cmd_compile_templates()
# TODO: use mktemp -d and keep temporary files in read-only dir # TODO: use mktemp -d and keep temporary files in read-only dir
local tmp=$to.tmp local tmp=$to.tmp
echo "Applying macros in $table to $f." 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 chmod $mode $tmp
chown $owner $tmp chown $owner $tmp
chgrp $owner $tmp chgrp $group $tmp
mv $tmp $to mv $tmp $to
done done
} }
@ -213,6 +220,13 @@ cmd_built_today()
cmd_build_date | grep $today | cut -d' ' -f3 cmd_build_date | grep $today | cut -d' ' -f3
} }
# ----- here we go
myname=`basename $0`
longname=$0
opts="v"
template_exts=".jw-tmpl"
cmd="$1" cmd="$1"
shift shift
get_opts $* get_opts $*
@ -281,6 +295,9 @@ rpmnew)
compile-templates) compile-templates)
cmd_compile_templates "$@" cmd_compile_templates "$@"
;; ;;
list-templates)
cmd_list_templates "$@"
;;
diff) diff)
cmd_diff "$@" cmd_diff "$@"
;; ;;