diff --git a/scripts/jw-pkg b/scripts/jw-pkg index aba08f40..b95d0181 100644 --- a/scripts/jw-pkg +++ b/scripts/jw-pkg @@ -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 "$@" ;;