#!/bin/sh ######################################################################## # # This script is invoked by "commitinfo" just after the incoming file has # been uploaded to the server. It gets passed these arguments: # # tidy-bowl file ... # # If we approve of the commit for EVERY file in the list, then we return # a zero (0). Any non-zero return aborts the commit, so we must be very # careful here. # # AFAIK, the $PWD is the temporary file where the incoming "file" is located, # but that needs to be verified. # # For every "file" that ends with ".xml", we will attempt to normalize the # formatting by using tidy(1) to prettyprint it. We must overwrite "file" so # that the rest of CVS knows where to find the file. # # There doesn't seem to be any way to return error messages, so we'll just bang # them out to "/var/log/messages". # ######################################################################## # exit 0 # Early exit while frobbing around ######################################################################## # All ancillary files should be in the same directory as this script ME=`/bin/basename $0` PREFIX=`/usr/bin/dirname $0` ######################################################################## USAGE="Usage: ${ME} [-T tool] [-n] [-t tool-args] file..." NORMTOOL=${PREFIX}/xmlformat NORMARGS="-v -f ${PREFIX}/xmlformat-fdp.conf" INPLACE='-i' while getopts T:nt: c do case "${c}" in T) NORMTOOL="${OPTARG}";; n) INPLACE="";; t) NORMARGS="${OPTARG}";; *) /bin/echo "${USAGE}" >&2; exit 1;; esac done shift `/usr/bin/expr "${OPTIND}" - 1` ######################################################################## for fn in $@ do case "${fn}" in *.xml ) # Make sure we can find the input file # /bin/echo "$0: XML file ${fn} prettyprinted." if [ ! -f "${fn}" ]; then # A non-readable file may be removed. Ever # think of that? # /bin/echo $0 "Cannot find '${fn}'" exit 0 fi # Try to clean it up ${NORMTOOL} ${NORMARGS} ${INPLACE} "${fn}" if [ $? -ne 0 ]; then /bin/echo $0 "File '${fn}' unclean." exit 1 fi ;; * ) # Some other kind of file. DO NOTHING!!! # /bin/echo "$0: file ${fn} left unchanged." ;; esac done exit 0