From 246246573faabaea3ed4fbfbad6bf8556a8b3d8b Mon Sep 17 00:00:00 2001 From: Jan Lindemann Date: Fri, 9 Nov 2018 13:18:48 +0000 Subject: [PATCH] jw-pkg: Add command compile-templates Signed-off-by: Jan Lindemann --- scripts/jw-pkg | 85 +++++++++++++++++++++++++++++++++++++------------- 1 file changed, 63 insertions(+), 22 deletions(-) diff --git a/scripts/jw-pkg b/scripts/jw-pkg index b7b0b177..aba08f40 100644 --- a/scripts/jw-pkg +++ b/scripts/jw-pkg @@ -20,19 +20,20 @@ cat << EOT command is one of - help: show this help screen - init: initialize - uninit: undo initialization - install: install packages in [arguments] - update: update all jannet software on the system - restore: restore a previous jannet software version state - info: query information about installed software packages - info-projects: query information about installed software projects - checklog: update the installation log file if necessary - rpmnew: remove superfluous rpmnew files and show conflicts - for others - build-date: show installed jannet packages along with build date - built-today: show installed jannet packages that were built today + help: show this help screen + init: initialize + uninit: undo initialization + install: install packages in [arguments] + update: update all jannet software on the system + restore: restore a previous jannet software version state + info: query information about installed software packages + info-projects: query information about installed software projects + checklog: update the installation log file if necessary + rpmnew: remove superfluous rpmnew files and show conflicts + for others + build-date: show installed jannet packages along with build date + built-today: show installed jannet packages that were built today + compile-templates: compile templates global options are @@ -90,7 +91,7 @@ list_packages() { local names="$1" local rpm_args - if [ "$names" ]; then + if [ -n "$names" ]; then rpm_args="$rpm_args $names" else rpm_args="$rpm_args -a" @@ -103,7 +104,7 @@ list_packages() list_projects() { - list_packages "$@" | xargs rpm -qa --queryformat '%{SOURCERPM}: %{URL}\n' | \ + list_packages "$@" | xargs -r rpm -q --queryformat '%{SOURCERPM}: %{URL}\n' | \ sed 's/\(^[^ ]\+\) *:.*/\1/; s/[ ]*$//; s/-[0-9]\+.*//' |\ sort -u } @@ -113,7 +114,7 @@ cmd_rpmnew() local file list_packages "$@" | - xargs rpm -ql | + xargs -r rpm -ql | while read file; do if [ -e "$file.rpmnew" ]; then if diff -q $file $file.rpmnew; then @@ -137,7 +138,7 @@ cmd_diff() local file list_packages "$@" | - xargs rpm -qV | + xargs -r rpm -qV | sed '/^....L\|^..5/ !d; s%[^/]*/%/%' | while read file; do if diff -q $file $file.rpmnew; then @@ -158,7 +159,7 @@ cmd_diff() cmd_build_date() { list_packages "$@" | - xargs rpm -q --queryformat '%{BUILDTIME} %{NAME}\n' | + xargs -r rpm -q --queryformat '%{BUILDTIME} %{NAME}\n' | sort -n | sed 's/-run\|-devel//' | sort -u | @@ -167,6 +168,45 @@ cmd_build_date() done } +cmd_compile_templates() +{ + local ext_from=".jw-tmpl" + 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'` + + # TODO: allow 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 + local base=`echo $f | sed "s/$ext_from_re$//"` + local to=$base$ext_to + local table="" ext + for ext in $ext_tables; do + table=$base$ext + [ -f "$table" ] && break + done + [ -f $table ] || { + echo "WARNING: No key-value table found for template $f, not compiling." >&2 + continue + } + # 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 + chmod $mode $tmp + chown $owner $tmp + chgrp $owner $tmp + mv $tmp $to + done +} + cmd_built_today() { local today=`date +'%Y-%m-%d'` @@ -222,9 +262,9 @@ checklog) ;; info) if [ "$opt_verbose" = true ]; then - list_packages "$@" | xargs rpm -qi + list_packages "$@" | xargs -r rpm -qi else - list_packages "$@" | xargs rpm -q + list_packages "$@" | xargs -r rpm -q fi ;; info-projects) @@ -238,6 +278,9 @@ cpp-glib) rpmnew) cmd_rpmnew "$@" ;; +compile-templates) + cmd_compile_templates "$@" + ;; diff) cmd_diff "$@" ;; @@ -255,5 +298,3 @@ help) ;; esac - -