From 2a37f623091e4a55c366314e18deb3cf6a709533 Mon Sep 17 00:00:00 2001 From: Pierre Pronchery Date: Fri, 9 May 2014 02:23:41 +0200 Subject: [PATCH] Newer version of the script upstream --- doc/docbook.sh | 81 +++++++++++++++++++++++++++++++++++++++++--------- 1 file changed, 67 insertions(+), 14 deletions(-) diff --git a/doc/docbook.sh b/doc/docbook.sh index a9d498c..73a435a 100755 --- a/doc/docbook.sh +++ b/doc/docbook.sh @@ -1,6 +1,6 @@ #!/bin/sh #$Id$ -#Copyright (c) 2012-2013 Pierre Pronchery +#Copyright (c) 2012-2014 Pierre Pronchery # #Redistribution and use in source and binary forms, with or without #modification, are permitted provided that the following conditions are met: @@ -26,12 +26,14 @@ #variables PREFIX="/usr/local" -. "../config.sh" +[ -f "../config.sh" ] && . "../config.sh" #executables DEBUG="_debug" +FOP="fop" INSTALL="install -m 0644" MKDIR="mkdir -m 0755 -p" RM="rm -f" +XMLLINT="xmllint" XSLTPROC="xsltproc --nonet --xinclude" @@ -44,6 +46,53 @@ _debug() } +#docbook +_docbook() +{ + target="$1" + + source="${target%.*}.xml" + ext="${target##*.}" + ext="${ext##.}" + case "$ext" in + html) + XSL="http://docbook.sourceforge.net/release/xsl/current/xhtml/docbook.xsl" + [ -f "${target%.*}.xsl" ] && XSL="${target%.*}.xsl" + $DEBUG $XSLTPROC -o "$target" "$XSL" "$source" + ;; + pdf) + XSL="http://docbook.sourceforge.net/release/xsl/current/fo/docbook.xsl" + [ -f "${target%.*}.xsl" ] && XSL="${target%.*}.xsl" + $DEBUG $XSLTPROC -o "${target%.*}.fo" "$XSL" "$source" && + $DEBUG $FOP -fo "${target%.*}.fo" -pdf "$target" + $RM -- "${target%.*}.fo" + ;; + 1|2|3|4|5|6|7|8|9) + XSL="http://docbook.sourceforge.net/release/xsl/current/manpages/docbook.xsl" + $DEBUG $XSLTPROC -o "$target" "$XSL" "$source" + ;; + *) + echo "$0: $target: Unknown type" 1>&2 + return 2 + ;; + esac + + if [ $? -ne 0 ]; then + echo "$0: $target: Could not create page" 1>&2 + $RM -- "$target" + return 2 + fi +} + + +#error +_error() +{ + echo "docbook.sh: $@" 1>&2 + return 2 +} + + #usage _usage() { @@ -70,7 +119,7 @@ while getopts "ciuP:" name; do uninstall=1 ;; P) - PREFIX="$2" + PREFIX="$OPTARG" ;; ?) _usage @@ -84,12 +133,17 @@ if [ $# -eq 0 ]; then exit $? fi +#check the variables +if [ -z "$PACKAGE" ]; then + _error "The PACKAGE variable needs to be set" + exit $? +fi + [ -z "$DATADIR" ] && DATADIR="$PREFIX/share" [ -z "$MANDIR" ] && MANDIR="$DATADIR/man" while [ $# -gt 0 ]; do target="$1" - source="${target%.*}.xml" shift #determine the type @@ -97,12 +151,16 @@ while [ $# -gt 0 ]; do ext="${ext##.}" case "$ext" in html) - XSL="http://docbook.sourceforge.net/release/xsl/current/xhtml/docbook.xsl" - [ -f "${target%.*}.xsl" ] && XSL="${target%.*}.xsl" + source="${target%.*}.xml" + xpath="string(/refentry/refmeta/manvolnum)" + section=$($XMLLINT --xpath "$xpath" "$source") + [ $? -eq 0 -a -n "$section" ] || exit 2 + instdir="$DATADIR/man/html$section" + ;; + pdf) instdir="$DATADIR/doc/$ext/$PACKAGE" ;; 1|2|3|4|5|6|7|8|9) - XSL="http://docbook.sourceforge.net/release/xsl/current/manpages/docbook.xsl" instdir="$MANDIR/man$ext" ;; *) @@ -123,16 +181,11 @@ while [ $# -gt 0 ]; do #install if [ "$install" -eq 1 ]; then $DEBUG $MKDIR -- "$instdir" || exit 2 - $DEBUG $INSTALL -- "$target" "$instdir/$target" || exit 2 + $DEBUG $INSTALL "$target" "$instdir/$target" || exit 2 continue fi #create - $DEBUG $XSLTPROC -o "$target" "$XSL" "$source" #XXX ignore errors - if [ $? -ne 0 ]; then - echo "$0: $target: Could not create page" 1>&2 - $RM -- "$target" - break - fi + _docbook "$target" || break done