mirror of https://github.com/tLDP/LDP
new and updates
This commit is contained in:
parent
e39d919ea9
commit
23d6cfad15
|
@ -4,6 +4,8 @@
|
|||
#
|
||||
# Generator script
|
||||
#
|
||||
# $Id$
|
||||
#
|
||||
# Requires: htmldoc recode docbook-utils-pdf
|
||||
#
|
||||
# Changelog
|
||||
|
@ -20,10 +22,28 @@
|
|||
# support also ldp.dsl stored in same directory as the script
|
||||
# 20110509/PB: add charset meta header on each html page to force UTF-8
|
||||
|
||||
# $Id$
|
||||
loglevel=6
|
||||
|
||||
# parse options
|
||||
while getopts "ql:" opt; do
|
||||
case $opt in
|
||||
q)
|
||||
loglevel=4
|
||||
;;
|
||||
l)
|
||||
loglevel=$OPTARG
|
||||
echo "INFO : set loglevel to: $loglevel"
|
||||
;;
|
||||
\?)
|
||||
echo "Invalid option: -$OPTARG" >&2
|
||||
;;
|
||||
esac
|
||||
done
|
||||
|
||||
shift $((OPTIND-1))
|
||||
|
||||
# Renice script
|
||||
renice -n 10 $$
|
||||
renice -n 10 $$ >/dev/null
|
||||
|
||||
if [ -z "$1" ]; then
|
||||
file_input="Linux+IPv6-HOWTO.sgml"
|
||||
|
@ -132,39 +152,42 @@ done
|
|||
# echo "WARN: cannot execute 'runsgmlfix.sh'"
|
||||
#fi
|
||||
|
||||
export SP_ENCODING=UTF-8
|
||||
export SP_CHARSET_FIXED=yes
|
||||
|
||||
## Functions
|
||||
validate_sgml() {
|
||||
# remove tags <dummy>, </dummy>
|
||||
perl -pi -e 's|</?dummy>||g' "$file_input"
|
||||
|
||||
echo "INF: Validate SGML/XML code '$file_input'"
|
||||
echo "INFO : Validate SGML/XML code '$file_input'"
|
||||
if [ "$doctype" = "XML" ]; then
|
||||
local options="$file_xmldcl"
|
||||
fi
|
||||
set -x
|
||||
SP_ENCODING=UTF-8 SP_CHARSET_FIXED=yes $ONSGMLS -s $options $file_input
|
||||
[ $loglevel -ge 7 ] && set -x
|
||||
|
||||
$ONSGMLS -s $options $file_input
|
||||
local retval=$?
|
||||
set +x
|
||||
[ $loglevel -ge 7 ] && set +x
|
||||
if [ $retval -gt 0 ]; then
|
||||
echo "ERR: Validation results in errors!"
|
||||
return 1
|
||||
else
|
||||
echo "INF: Validation was successfully"
|
||||
echo "INFO : Validation was successfully"
|
||||
fi
|
||||
}
|
||||
|
||||
create_html_multipage() {
|
||||
echo "INF: Create HTML multipages"
|
||||
echo "INFO : Create HTML multipages"
|
||||
if [ ! -d "$file_base" ]; then
|
||||
mkdir "$file_base" || exit 1
|
||||
fi
|
||||
pushd "$file_base" || exit 1
|
||||
pushd "$file_base" >/dev/null || exit 1
|
||||
rm -f *
|
||||
set -x
|
||||
SP_ENCODING=UTF-8 $JADE -t sgml -i html -D $dir_dssslstylesheets -d "${file_ldpdsl}#html" ../$file_input
|
||||
[ $loglevel -ge 7 ] && set -x
|
||||
$JADE -t sgml -i html -D $dir_dssslstylesheets -d "${file_ldpdsl}#html" ../$file_input
|
||||
local retval=$?
|
||||
set +x
|
||||
[ $loglevel -ge 7 ] && set +x
|
||||
|
||||
perl -pi -e 's#><META#><meta http-equiv="Content-Type" content="text/html; charset=UTF-8"\n><META#o' *.html
|
||||
local r=$?
|
||||
|
@ -172,16 +195,16 @@ create_html_multipage() {
|
|||
retval=$?
|
||||
fi
|
||||
|
||||
popd
|
||||
popd >/dev/null
|
||||
return $retval
|
||||
}
|
||||
|
||||
create_html_singlepage() {
|
||||
echo "INF: Create HTML singlepage '$file_html'"
|
||||
set -x
|
||||
SP_ENCODING=UTF-8 $JADE -t sgml -i html -V nochunks -d "${file_ldpdsl}#html" $file_input >$file_html
|
||||
set +x
|
||||
echo "INFO : Create HTML singlepage '$file_html'"
|
||||
[ $loglevel -ge 7 ] && set -x
|
||||
$JADE -t sgml -i html -V nochunks -d "${file_ldpdsl}#html" $file_input >$file_html
|
||||
local retval=$?
|
||||
[ $loglevel -ge 7 ] && set +x
|
||||
|
||||
perl -pi -e 's#><META#><meta http-equiv="Content-Type" content="text/html; charset=UTF-8"\n><META#o' $file_html
|
||||
local r=$?
|
||||
|
@ -190,7 +213,7 @@ create_html_singlepage() {
|
|||
fi
|
||||
|
||||
if [ $retval -eq 0 ]; then
|
||||
echo "INF: Create HTML singlepage - done"
|
||||
echo "INFO : Create HTML singlepage - done"
|
||||
else
|
||||
echo "ERR: Create HTML singlepage - an error occurs!"
|
||||
fi
|
||||
|
@ -198,13 +221,13 @@ create_html_singlepage() {
|
|||
}
|
||||
|
||||
create_rtf() {
|
||||
echo "INF: Create RTF file '$file_rtf'"
|
||||
set -x
|
||||
SP_ENCODING=UTF-8 $JADE -t rtf -d ${file_ldpdsl} $file_input
|
||||
set +x
|
||||
echo "INFO : Create RTF file '$file_rtf'"
|
||||
[ $loglevel -ge 7 ] && set -x
|
||||
$JADE -t rtf -d ${file_ldpdsl} $file_input
|
||||
local retval=$?
|
||||
[ $loglevel -ge 7 ] && set +x
|
||||
if [ $retval -eq 0 ]; then
|
||||
echo "INF: Create RTF file - done"
|
||||
echo "INFO : Create RTF file - done"
|
||||
else
|
||||
echo "ERR: Create RTF file - an error occurs!"
|
||||
fi
|
||||
|
@ -212,13 +235,13 @@ create_rtf() {
|
|||
}
|
||||
|
||||
create_ps() {
|
||||
echo "INF: Create PS file '$file_ps'"
|
||||
set -x
|
||||
echo "INFO : Create PS file '$file_ps'"
|
||||
[ $loglevel -ge 7 ] && set -x
|
||||
$DB2PS --dsl ${file_ldpdsl} $file_input
|
||||
set +x
|
||||
local retval=$?
|
||||
[ $loglevel -ge 7 ] && set +x
|
||||
if [ $retval -eq 0 ]; then
|
||||
echo "INF: Create PS file - done"
|
||||
echo "INFO : Create PS file - done"
|
||||
else
|
||||
echo "ERR: Create PS file - an error occurs!"
|
||||
fi
|
||||
|
@ -228,25 +251,25 @@ create_ps() {
|
|||
create_pdf() {
|
||||
if [ "$LDP_PDFPS" = "yes" ]; then
|
||||
# Use LDP conform mechanism
|
||||
echo "INF: Create PDF file (LDP conform) '$file_pdf' from HTML file '$file_html'"
|
||||
echo "INFO : Create PDF file (LDP conform) '$file_pdf' from HTML file '$file_html'"
|
||||
|
||||
if [ $file_html -ot $file_input ]; then
|
||||
echo "ERR: Create PDF file - needed single page HTML file '$file_html' is older than original '$file_input'"
|
||||
return 1
|
||||
fi
|
||||
set -x
|
||||
SP_ENCODING=UTF-8 $LDP_PRINT $file_html
|
||||
set +x
|
||||
[ $loglevel -ge 7 ] && set -x
|
||||
$LDP_PRINT $file_html
|
||||
local retval=$?
|
||||
[ $loglevel -ge 7 ] && set +x
|
||||
else
|
||||
echo "INF: Create PDF file (NOT LDP conform) '$file_pdf'"
|
||||
set -x
|
||||
SP_ENCODING=UTF-8 $DB2PDF --dsl ${file_ldpdsl} $file_input
|
||||
set +x
|
||||
echo "INFO : Create PDF file (NOT LDP conform) '$file_pdf'"
|
||||
[ $loglevel -ge 7 ] && set -x
|
||||
$DB2PDF --dsl ${file_ldpdsl} $file_input
|
||||
local retval=$?
|
||||
[ $loglevel -ge 7 ] && set +x
|
||||
fi
|
||||
if [ $retval -eq 0 ]; then
|
||||
echo "INF: Create PDF file - done"
|
||||
echo "INFO : Create PDF file - done"
|
||||
else
|
||||
echo "ERR: Create PDF file - an error occurs!"
|
||||
fi
|
||||
|
@ -254,19 +277,19 @@ create_pdf() {
|
|||
}
|
||||
|
||||
create_txt() {
|
||||
echo "INF: Create TXT file '$file_txt' from PS file '$file_ps'"
|
||||
echo "INFO : Create TXT file '$file_txt' from PS file '$file_ps'"
|
||||
[ -f $file_txt ] && rm $file_txt
|
||||
if [ -f $file_ps ]; then
|
||||
echo "INF: Create TXT file '$file_txt'"
|
||||
set -x
|
||||
echo "INFO : Create TXT file '$file_txt'"
|
||||
[ $loglevel -ge 7 ] && set -x
|
||||
$PS2ASCII $file_ps > $file_txt
|
||||
set +x
|
||||
local retval=$?
|
||||
[ $loglevel -ge 7 ] && set +x
|
||||
else
|
||||
echo "ERR: Cannot create TXT because of missing PS file"
|
||||
fi
|
||||
if [ $retval -eq 0 ]; then
|
||||
echo "INF: Create TXT file - done"
|
||||
echo "INFO : Create TXT file - done"
|
||||
else
|
||||
echo "ERR: Create TXT file - an error occurs!"
|
||||
fi
|
||||
|
|
|
@ -0,0 +1,257 @@
|
|||
#!/bin/bash
|
||||
#
|
||||
# (P) & (C) 2011 - 2011 by Dr. Peter Bieringer <pb@bieringer.de>
|
||||
#
|
||||
# wrapper script for generate.sh
|
||||
#
|
||||
# 20110517/PB: initial release
|
||||
# 20110518/PB: minor improvements
|
||||
|
||||
|
||||
URL_BASE="http://cvs.tldp.org/go.to/LDP/LDP/users/Peter-Bieringer/"
|
||||
|
||||
FILE_EN="Linux+IPv6-HOWTO.sgml"
|
||||
FILE_DE="Linux+IPv6-HOWTO.de.sgml"
|
||||
FILE_FR="Linux+IPv6-HOWTO.fr.sgml"
|
||||
FILE_PT_BR="Linux+IPv6-HOWTO.pt_BR.sgml"
|
||||
|
||||
options_wget="--quiet"
|
||||
DIR_DOWNLOAD="download"
|
||||
|
||||
DIR_DEST_BASE="/var/www/html/howto"
|
||||
|
||||
## logging
|
||||
log() {
|
||||
local level="$1"
|
||||
shift
|
||||
|
||||
printf "%-6s: %s\n" "$level" "$*"
|
||||
}
|
||||
|
||||
## download file
|
||||
download() {
|
||||
local url_base="$1"
|
||||
local file="$2"
|
||||
|
||||
if [ -z "$url_base" ]; then
|
||||
log "ERROR" "'url_base' empty"
|
||||
return 1
|
||||
fi
|
||||
|
||||
if [ -z "$file" ]; then
|
||||
log "ERROR" "'file' empty"
|
||||
return 1
|
||||
fi
|
||||
|
||||
if [ -z "$DIR_DOWNLOAD" ]; then
|
||||
log "ERROR" "no download directory given"
|
||||
return 1
|
||||
fi
|
||||
|
||||
if [ ! -d "$DIR_DOWNLOAD" ]; then
|
||||
log "ERROR" "download directory doesn't exist: $DIR_DOWNLOAD"
|
||||
return 1
|
||||
fi
|
||||
|
||||
if [ "force_download" != "1" ]; then
|
||||
log "NOTICE" "skip download $url_base/$file (use option -f)"
|
||||
return 0
|
||||
fi
|
||||
|
||||
log "INFO" "start download $url_base/$file to directory $DIR_DOWNLOAD"
|
||||
wget $options_wget -N -P "$DIR_DOWNLOAD" "$url_base/$file"
|
||||
local result=$?
|
||||
if [ $result -eq 0 ]; then
|
||||
log "INFO" "download successful: $url_base/$file (stored to $DIR_DOWNLOAD)"
|
||||
else
|
||||
log "ERROR" "download not successful: $url_base/$file"
|
||||
fi
|
||||
|
||||
return $result
|
||||
}
|
||||
|
||||
## check, whether processing should be started
|
||||
check() {
|
||||
local file="$1"
|
||||
local dir="$2"
|
||||
|
||||
if [ -z "$file" ]; then
|
||||
log "ERROR" "'file' empty"
|
||||
return 1
|
||||
fi
|
||||
|
||||
if [ -z "$dir" ]; then
|
||||
log "ERROR" "'dir' empty"
|
||||
return 1
|
||||
fi
|
||||
|
||||
log "INFO" "check file: $file"
|
||||
|
||||
if [ ! -f "$DIR_DOWNLOAD/$file" ]; then
|
||||
log "WARN" "no downloaded file available: $DIR_DOWNLOAD/$file"
|
||||
return 1
|
||||
fi
|
||||
|
||||
if [ ! -f "$file" ]; then
|
||||
log "NOTICE" "no 'old' file available: $file (copy now)"
|
||||
cp -p "$DIR_DOWNLOAD/$file" "$file"
|
||||
if [ $? -ne 0 ]; then
|
||||
log "ERROR" "can't copy 'new' file to 'old' file: $DIR_DOWNLOAD/$file -> $file"
|
||||
return 1
|
||||
fi
|
||||
|
||||
return 0
|
||||
else
|
||||
# check contents of destination directory
|
||||
log "INFO" "check directory: $dir"
|
||||
|
||||
if [ ! -d "$dir" ]; then
|
||||
log "NOTICE" "directory still not exist: $dir"
|
||||
return 0
|
||||
fi
|
||||
|
||||
local num_files="`find "$dir" -mindepth 1 -maxdepth 1 -type f | wc -l`"
|
||||
if [ $num_files -eq 0 ]; then
|
||||
# directory is empty
|
||||
log "NOTICE" "directory is empty: $dir"
|
||||
return 0
|
||||
fi
|
||||
|
||||
local num_files_old="`find "$dir" -mindepth 1 -maxdepth 1 -type f ! -newer "$file" | wc -l`"
|
||||
if [ $num_files_old -ne 0 ]; then
|
||||
# force regeneration
|
||||
log "NOTICE" "directory contains old files: $dir ($num_files_old)"
|
||||
return 0
|
||||
fi
|
||||
|
||||
# 'old' file already exists
|
||||
if [ "$file" -nt "$DIR_DOWNLOAD/$file" ]; then
|
||||
log "WARN" "'old' is newer than 'new' file: $file"
|
||||
return 1
|
||||
fi
|
||||
|
||||
if cmp -s "$file" "$DIR_DOWNLOAD/$file"; then
|
||||
log "INFO" "'old' is identical with 'new' file: $file"
|
||||
return 1
|
||||
fi
|
||||
fi
|
||||
|
||||
# nothing to do
|
||||
log "DEBUG" "no indication for start processing file found: $file"
|
||||
return 1
|
||||
}
|
||||
|
||||
## process/generate output
|
||||
process() {
|
||||
log "INFO" "start processing file: $file"
|
||||
./generate.sh "$file"
|
||||
}
|
||||
|
||||
|
||||
## copy output
|
||||
copy() {
|
||||
local file="$1"
|
||||
|
||||
if [ -z "$DIR_DEST_BASE" ]; then
|
||||
log "ERROR" "destination directory for output not given 'DIR_DEST_BASE'"
|
||||
fi
|
||||
|
||||
if [ ! -d "$DIR_DEST_BASE" ]; then
|
||||
log "ERROR" "destination directory for output doesn't exist: $DIR_DEST_BASE"
|
||||
return 1
|
||||
fi
|
||||
|
||||
log "INFO" "start syncing files of master file: $file"
|
||||
|
||||
local file_pdf="${file/.sgml/.pdf}"
|
||||
local file_html="${file/.sgml/.html}"
|
||||
|
||||
local dir_html="${file/.sgml}"
|
||||
|
||||
log "INFO" "copy PDF file: $file_pdf"
|
||||
cp -p "$file_pdf" "$DIR_DEST_BASE/$file_pdf"
|
||||
if [ $? -ne 0 ]; then
|
||||
log "ERROR" "can't copy PDF file: $file_pdf"
|
||||
return 1
|
||||
fi
|
||||
chmod 644 "$DIR_DEST_BASE/$file_pdf"
|
||||
|
||||
log "INFO" "copy HTML file: $file_html"
|
||||
cp -p "$file_html" "$DIR_DEST_BASE/$file_html"
|
||||
if [ $? -ne 0 ]; then
|
||||
log "ERROR" "can't copy HTML file: $file_html"
|
||||
return 1
|
||||
fi
|
||||
chmod 644 "$DIR_DEST_BASE/$file_html"
|
||||
|
||||
if [ ! -d "$DIR_DEST_BASE/$dir_html" ]; then
|
||||
log "ERROR" "destination directory for html doesn't exist: $DIR_DEST_BASE/$dir_html"
|
||||
return 1
|
||||
fi
|
||||
|
||||
log "INFO" "copy HTML directory: $dir_html -> $DIR_DEST_BASE/$dir_html"
|
||||
rsync --delete -r "$dir_html/" "$DIR_DEST_BASE/$dir_html/"
|
||||
if [ $? -ne 0 ]; then
|
||||
log "ERROR" "can't sync HTML dir: $dir_html"
|
||||
return 1
|
||||
fi
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
## main
|
||||
main() {
|
||||
for file in $*; do
|
||||
download "$URL_BASE" "$file"
|
||||
if [ $? -ne 0 ]; then
|
||||
continue
|
||||
fi
|
||||
|
||||
dir="${file/.sgml}"
|
||||
|
||||
check "$file" "$dir"
|
||||
if [ $? -eq 0 ]; then
|
||||
process "$file"
|
||||
fi
|
||||
|
||||
copy "$file"
|
||||
done
|
||||
}
|
||||
|
||||
|
||||
# parse options
|
||||
while getopts "d" opt; do
|
||||
case $opt in
|
||||
d)
|
||||
# no download
|
||||
force_download=1
|
||||
;;
|
||||
\?)
|
||||
echo "Invalid option: -$OPTARG" >&2
|
||||
;;
|
||||
esac
|
||||
done
|
||||
|
||||
shift $((OPTIND-1))
|
||||
|
||||
case $1 in
|
||||
'de')
|
||||
files="$FILE_DE"
|
||||
;;
|
||||
'en')
|
||||
files="$FILE_EN"
|
||||
;;
|
||||
'fr')
|
||||
files="$FILE_FR"
|
||||
;;
|
||||
'pt')
|
||||
files="$FILE_PT_BR"
|
||||
;;
|
||||
'all')
|
||||
files="$FILE_EN $FILE_DE $FILE_FR $FILE_PT_BR"
|
||||
;;
|
||||
esac
|
||||
|
||||
main $files
|
Loading…
Reference in New Issue