| 1 |
#!/bin/bash |
| 2 |
# |
| 3 |
# Copyright (C) 2012-2020 SUSE Software Solutions Germany GmbH |
| 4 |
# |
| 5 |
# Author: |
| 6 |
# Frank Sundermeyer <fsundermeyer at opensuse dot org> |
| 7 |
# |
| 8 |
# Checks for missing dependencies for DAPS |
| 9 |
# |
| 10 |
|
| 11 |
function check_prg { |
| 12 |
which $1 2>/dev/null || return 1 |
| 13 |
} |
| 14 |
|
| 15 |
function print_prg { |
| 16 |
# $1: program to check |
| 17 |
# $2: warn level |
| 18 |
# $3: additional information |
| 19 |
|
| 20 |
local _COL _LEVEL _PRG |
| 21 |
|
| 22 |
[[ "FATAL ERROR" = $2 ]] && _COL="$fatal_col" |
| 23 |
[[ IMPORTANT = $2 ]] && _COL="$important_col" |
| 24 |
[[ INFO = $2 ]] && _COL="$info_col" |
| 25 |
|
| 26 |
_PRG=$(check_prg "$1") |
| 27 |
if [[ 1 -eq $? ]]; then |
| 28 |
echo -e "${_COL}${2}: \"$1\" is missing${3}${end_col}" |
| 29 |
else |
| 30 |
echo -e "${ok_col}OK: ${_PRG}${end_col}" |
| 31 |
fi |
| 32 |
} |
| 33 |
|
| 34 |
function check_cat_entries { |
| 35 |
local ROOT_CATALOG="/etc/xml/catalog" |
| 36 |
local IFS=$'\n' |
| 37 |
for _cat_entry in $@; do |
| 38 |
xmlcatalog --noout "$ROOT_CATALOG" "$_cat_entry" >/dev/null 2>&1 |
| 39 |
[[ 0 -eq $? ]] && return 0 |
| 40 |
done |
| 41 |
return 1 |
| 42 |
} |
| 43 |
|
| 44 |
############################### |
| 45 |
|
| 46 |
fatal_col="\e[1;31m" |
| 47 |
important_col="\e[1;35m" |
| 48 |
info_col="\e[1;36m" |
| 49 |
ok_col="\e[1;32m" |
| 50 |
end_col="\e[0m" |
| 51 |
|
| 52 |
|
| 53 |
_havedb4=0 |
| 54 |
_havedb5=0 |
| 55 |
_nodb=0 |
| 56 |
_havedbxslt4=0 |
| 57 |
_havedbxslt5=0 |
| 58 |
_noxslt=0 |
| 59 |
_jing="" |
| 60 |
_xmllint="" |
| 61 |
_nolint=0 |
| 62 |
|
| 63 |
# DB4 catalog entries to check |
| 64 |
|
| 65 |
_DB4_prefix="-//OASIS//DTD DocBook XML" |
| 66 |
declare -a DB4_CAT=( |
| 67 |
"${_DB4_prefix} V4.1.2//EN" |
| 68 |
"${_DB4_prefix} V4.2//EN" |
| 69 |
"${_DB4_prefix} V4.3//EN" |
| 70 |
"${_DB4_prefix} V4.4//EN" |
| 71 |
"${_DB4_prefix} V4.5//EN" |
| 72 |
) |
| 73 |
|
| 74 |
# DB5 catalog entries to check |
| 75 |
|
| 76 |
_DB50_prefix="http://docbook.org/xml/5.0/rng" |
| 77 |
_DB51_prefix="http://docbook.org/xml/5.1/rng" |
| 78 |
declare -a DB5_CAT=( |
| 79 |
"${_DB50_prefix}/docbookxi.rng" |
| 80 |
"${_DB50_prefix}/docbookxi.rnc" |
| 81 |
"${_DB50_prefix}/docbook.rng" |
| 82 |
"${_DB50_prefix}/docbook.rnc" |
| 83 |
"${_DB51_prefix}/docbookxi.rng" |
| 84 |
"${_DB51_prefix}/docbookxi.rnc" |
| 85 |
"${_DB51_prefix}/docbook.rng" |
| 86 |
"${_DB51_prefix}/docbook.rnc" |
| 87 |
"${_DB51_prefix}/assembly.rng" |
| 88 |
"${_DB51_prefix}/assembly.rnc" |
| 89 |
"${_DB51_prefix}/dbits.rng" |
| 90 |
"${_DB51_prefix}/dbits.rnc" |
| 91 |
) |
| 92 |
|
| 93 |
# DB 4 Stylesheets |
| 94 |
|
| 95 |
DB4_XSLT_prefix="http://docbook.sourceforge.net/release/xsl/current" |
| 96 |
declare -a DB4_XSLT_CAT=( |
| 97 |
"${DB4_XSLT_prefix}/common/common.xsl" |
| 98 |
"${DB4_XSLT_prefix}/epub/docbook.xsl" |
| 99 |
"${DB4_XSLT_prefix}/fo/docbook.xsl" |
| 100 |
"${DB4_XSLT_prefix}/html/chunk.xsl" |
| 101 |
"${DB4_XSLT_prefix}/html/docbook.xsl" |
| 102 |
"${DB4_XSLT_prefix}/lib/lib.xsl" |
| 103 |
"${DB4_XSLT_prefix}/manpages/docbook.xsl" |
| 104 |
"${DB4_XSLT_prefix}/profiling/profile.xsl" |
| 105 |
"${DB4_XSLT_prefix}/xhtml/chunk.xsl" |
| 106 |
"${DB4_XSLT_prefix}/xhtml/docbook.xsl" |
| 107 |
) |
| 108 |
|
| 109 |
# DB 5 Stylesheets |
| 110 |
|
| 111 |
DB5_XSLT_prefix="http://docbook.sourceforge.net/release/xsl-ns/current" |
| 112 |
declare -a DB5_XSLT_CAT=( |
| 113 |
"${DB5_XSLT_prefix}/common/common.xsl" |
| 114 |
"${DB5_XSLT_prefix}/epub/docbook.xsl" |
| 115 |
"${DB5_XSLT_prefix}/fo/docbook.xsl" |
| 116 |
"${DB5_XSLT_prefix}/html/chunk.xsl" |
| 117 |
"${DB5_XSLT_prefix}/html/docbook.xsl" |
| 118 |
"${DB5_XSLT_prefix}/lib/lib.xsl" |
| 119 |
"${DB5_XSLT_prefix}/manpages/docbook.xsl" |
| 120 |
"${DB5_XSLT_prefix}/profiling/profile.xsl" |
| 121 |
"${DB5_XSLT_prefix}/xhtml/chunk.xsl" |
| 122 |
"${DB5_XSLT_prefix}/xhtml/docbook.xsl" |
| 123 |
) |
| 124 |
|
| 125 |
echo "DAPS dependency check on $HOSTNAME ($(date))" |
| 126 |
echo -e "------------------------------------------------------------------------\n" |
| 127 |
|
| 128 |
########### FATAL ############################### |
| 129 |
|
| 130 |
echo "##### Checking for fatal dependency failures #####" |
| 131 |
|
| 132 |
# bash 4 |
| 133 |
if [[ $BASH_VERSINFO -lt 4 ]]; then |
| 134 |
echo -e "${fatal_col}FATAL: Bash version 4 or higher is required${end_col}" |
| 135 |
else |
| 136 |
echo -e "${ok_col}OK: Bash $BASH_VERSINFO${end_col}" |
| 137 |
fi |
| 138 |
|
| 139 |
# DocBook |
| 140 |
# |
| 141 |
# DocBook4 |
| 142 |
check_cat_entries "${DB4_CAT[@]}" |
| 143 |
[[ 0 -eq $? ]] && _havedb4=1 |
| 144 |
#DocBook5 |
| 145 |
check_cat_entries "${DB5_CAT[@]}" |
| 146 |
[[ 0 -eq $? ]] && _havedb5=1 |
| 147 |
|
| 148 |
if [[ 0 -eq $_havedb4 && 0 -eq $_havedb5 ]]; then |
| 149 |
_nodb=1 |
| 150 |
echo -e "${fatal_col}FATAL: DocBook (version 4 or 5) is required ${end_col}" |
| 151 |
fi |
| 152 |
|
| 153 |
# DocBook Stylesheets |
| 154 |
# |
| 155 |
# DocBook4 Stylesheets |
| 156 |
check_cat_entries "${DB4_XSLT_CAT[@]}" |
| 157 |
[[ 0 -eq $? ]] && _havedb4xslt=1 |
| 158 |
#DocBook5 |
| 159 |
check_cat_entries "${DB5_XSLT_CAT[@]}" |
| 160 |
[[ 0 -eq $? ]] && _havedb5xslt=1 |
| 161 |
|
| 162 |
if [[ 0 -eq $_havedb4xslt && 0 -eq $_havedb5xslt ]]; then |
| 163 |
_noxslt=1 |
| 164 |
echo -e "${fatal_col}FATAL: DocBook stylesheets (version 4 or 5) are required ${end_col}" |
| 165 |
fi |
| 166 |
|
| 167 |
# make |
| 168 |
print_prg "make" "FATAL ERROR" |
| 169 |
|
| 170 |
# fop |
| 171 |
print_prg "fop" "FATAL ERROR" |
| 172 |
|
| 173 |
# xmlstarlet |
| 174 |
print_prg "xmlstarlet" "FATAL ERROR" |
| 175 |
|
| 176 |
# xsltproc |
| 177 |
print_prg "xsltproc" "FATAL ERROR" |
| 178 |
|
| 179 |
# xmllint and jing |
| 180 |
_jing=$(check_prg "jing") |
| 181 |
_xmllint=$(check_prg "xmllint") |
| 182 |
if [[ -z $_jing && -z $_xmllint ]]; then |
| 183 |
_nolint=1 |
| 184 |
echo -e "${fatal_col}FATAL ERROR: Neither \"xmllint\" nor \"jing\" is installed${end_col}" |
| 185 |
fi |
| 186 |
|
| 187 |
########## IMPORTANT ############################ |
| 188 |
|
| 189 |
echo -e "\n##### Checking for important (but not fatal) dependency failures #####" |
| 190 |
|
| 191 |
# One of DocBook 4/5 is missing |
| 192 |
if [[ 0 -eq $_nodb ]]; then |
| 193 |
if [[ 0 -eq $_havedb4 ]]; then |
| 194 |
echo -e "${important_col}IMPORTANT: No DocBook 4 support${end_col}" |
| 195 |
else |
| 196 |
echo -e "${ok_col}OK: DocBook 4${end_col}" |
| 197 |
fi |
| 198 |
if [[ 0 -eq $_havedb5 ]]; then |
| 199 |
echo -e "${important_col}IMPORTANT: No DocBook 5 support${end_col}" |
| 200 |
else |
| 201 |
echo -e "${ok_col}OK: DocBook 5${end_col}" |
| 202 |
fi |
| 203 |
fi |
| 204 |
|
| 205 |
# jing |
| 206 |
if [[ 0 -eq $_nolint ]]; then |
| 207 |
if [[ -z $_jing ]]; then |
| 208 |
echo -e "${important_col}IMPORTANT: \"jing\" is missing (no DocBook 5 support)${end_col}" |
| 209 |
else |
| 210 |
echo -e "${ok_col}OK: ${_jing}${end_col}" |
| 211 |
fi |
| 212 |
fi |
| 213 |
|
| 214 |
# aspell |
| 215 |
print_prg "aspell" "IMPORTANT" " (subcommand 'spellcheck' not supported)" |
| 216 |
|
| 217 |
# exiftool |
| 218 |
print_prg "exiftool" "IMPORTANT" " (subcommand 'optipng' not supported)" |
| 219 |
|
| 220 |
# optipng |
| 221 |
print_prg "optipng" "IMPORTANT" " (subcommand 'optipng' not supported)" |
| 222 |
|
| 223 |
# suse-doc-style-checker |
| 224 |
print_prg "suse-doc-style-checker" "IMPORTANT" " (subcommand 'stylecheck' not supported)" |
| 225 |
|
| 226 |
# w3m |
| 227 |
print_prg "w3m" "IMPORTANT" " (subcommand 'text' not supported)" |
| 228 |
|
| 229 |
# xmlformat |
| 230 |
for _xmlfmt in xmlformat{,.rb,.pl}; do |
| 231 |
_xmlfmt_cmd=$(check_prg "$_xmlfmt") && break |
| 232 |
done |
| 233 |
if [[ -z $_xmlfmt_cmd ]]; then |
| 234 |
echo -e "${important_col}IMPORTANT: \"xmlformat\" is missing (subcommand 'xmlformat' not supported)${end_col}" |
| 235 |
else |
| 236 |
echo -e "${ok_col}OK: $_xmlfmt_cmd${end_col}" |
| 237 |
fi |
| 238 |
|
| 239 |
# xmllint |
| 240 |
if [[ 0 -eq $_nolint ]]; then |
| 241 |
if [[ -z $_xmllint ]]; then |
| 242 |
echo -e "${important_col}IMPORTANT: \"xmllint\" is missing (no DocBook 4 support)${end_col}" |
| 243 |
else |
| 244 |
echo -e "${ok_col}OK: ${_xmllint}${end_col}" |
| 245 |
fi |
| 246 |
fi |
| 247 |
|
| 248 |
# asciidoc/asciidoctor |
| 249 |
for _adoc in asciidoctor asciidoc; do |
| 250 |
_adoc_cmd=$(check_prg "$_adoc") && break |
| 251 |
done |
| 252 |
if [[ -z $_adoc_cmd ]]; then |
| 253 |
echo -e "${important_col}IMPORTANT: \"asciidoc\" or \"asciidoctor\" is missing (no ASCIIDoc support)${end_col}" |
| 254 |
else |
| 255 |
echo -e "${ok_col}OK: $_adoc_cmd${end_col}" |
| 256 |
fi |
| 257 |
|
| 258 |
|
| 259 |
########### Functions not working ################ |
| 260 |
|
| 261 |
echo -e "\n##### Checking for non-critical dependency failures #####" |
| 262 |
|
| 263 |
# calibre |
| 264 |
print_prg "calibre" "INFO" " (no .mobi e-book support)" |
| 265 |
|
| 266 |
# epubcheck |
| 267 |
print_prg "epubcheck" "INFO" " (option '--check' for subcommand 'epub' will not work)" |
| 268 |
|
| 269 |
# remake |
| 270 |
print_prg "remake" "INFO" " (debug output will look less pretty)" |
| 271 |
|
| 272 |
# xep |
| 273 |
print_prg "xep" "INFO" " (PDF formatter XEP not supported, FOP will be used)" |
| 274 |
|
| 275 |
echo |