mirror of https://github.com/tLDP/LDP
use absolute paths, extend error checking
This commit is contained in:
parent
7b263f10c3
commit
e9a6111062
|
@ -1,4 +1,16 @@
|
|||
#!/bin/bash
|
||||
#
|
||||
# (P) & (C) 2011 - 2011 by Dr. Peter Bieringer <pb@bieringer.de>
|
||||
#
|
||||
# Wrapper script for HOWTO generator script
|
||||
#
|
||||
# Requires: "generate.sh"
|
||||
#
|
||||
# Changelog
|
||||
#
|
||||
#
|
||||
# 20110511/PB: use absolute paths, extend error checking
|
||||
|
||||
|
||||
URL_BASE="http://cvs.tldp.org/go.to/LDP/LDP/users/Peter-Bieringer/"
|
||||
|
||||
|
@ -8,7 +20,9 @@ FILE_FR="Linux+IPv6-HOWTO.fr.sgml"
|
|||
FILE_PT_BR="Linux+IPv6-HOWTO.pt_BR.sgml"
|
||||
|
||||
options_wget="--quiet"
|
||||
DIR_DOWNLOAD="download"
|
||||
|
||||
DIR_BASE="$HOME/howtos"
|
||||
DIR_DOWNLOAD="$HOME/howtos/download"
|
||||
|
||||
DIR_DEST_BASE="/var/www/html/howtos"
|
||||
|
||||
|
@ -64,43 +78,49 @@ download() {
|
|||
|
||||
## check, whether processing should be started
|
||||
check() {
|
||||
local file="$1"
|
||||
local dir="$2"
|
||||
local file_download="$1"
|
||||
local file="$2"
|
||||
local dir_html="$3"
|
||||
|
||||
if [ -z "$file" ]; then
|
||||
log "ERROR" "'file' empty"
|
||||
return 1
|
||||
fi
|
||||
|
||||
if [ -z "$dir" ]; then
|
||||
log "ERROR" "'dir' empty"
|
||||
if [ -z "$file_download" ]; then
|
||||
log "ERROR" "'file_download' empty"
|
||||
return 1
|
||||
fi
|
||||
|
||||
if [ -z "$dir_html" ]; then
|
||||
log "ERROR" "'dir_html' empty"
|
||||
return 1
|
||||
fi
|
||||
|
||||
log "INFO" "check file: $file"
|
||||
|
||||
if [ ! -f "$DIR_DOWNLOAD/$file" ]; then
|
||||
log "WARN" "no downloaded file available: $DIR_DOWNLOAD/$file"
|
||||
if [ ! -f "$file_download" ]; then
|
||||
log "WARN" "no downloaded file available: $file_download"
|
||||
return 1
|
||||
fi
|
||||
|
||||
if [ ! -f "$file" ]; then
|
||||
log "NOTICE" "no 'old' file available: $file (copy now)"
|
||||
cp -p "$DIR_DOWNLOAD/$file" "$file"
|
||||
cp -p "$file_download" "$file"
|
||||
if [ $? -ne 0 ]; then
|
||||
log "ERROR" "can't copy 'new' file to 'old' file: $DIR_DOWNLOAD/$file -> $file"
|
||||
log "ERROR" "can't copy 'new' file to 'old' file: $file_download -> $file"
|
||||
return 1
|
||||
fi
|
||||
|
||||
return 0
|
||||
else
|
||||
if cmp -s "$file" "$DIR_DOWNLOAD/$file"; then
|
||||
if cmp -s "$file_download" "$file"; then
|
||||
log "INFO" "'old' is identical with 'new' file: $file"
|
||||
else
|
||||
log "NOTICE" "'old' is not equal with 'new' file: $file"
|
||||
cp -p "$DIR_DOWNLOAD/$file" "$file"
|
||||
cp -p "$file_download" "$file"
|
||||
if [ $? -ne 0 ]; then
|
||||
log "ERROR" "can't copy 'new' file to 'old' file: $DIR_DOWNLOAD/$file -> $file"
|
||||
log "ERROR" "can't copy 'new' file to 'old' file: $file_download -> $file"
|
||||
return 1
|
||||
fi
|
||||
return 0
|
||||
|
@ -128,12 +148,17 @@ check() {
|
|||
fi
|
||||
|
||||
# 'old' file already exists
|
||||
if [ "$file" -nt "$DIR_DOWNLOAD/$file" ]; then
|
||||
if [ "$file" -nt "$file_download" ]; then
|
||||
log "WARN" "'old' is newer than 'new' file: $file"
|
||||
return 1
|
||||
fi
|
||||
fi
|
||||
|
||||
if [ "$force_generate" = "1" ]; then
|
||||
log "NOTICE" "force regeneration of: $file"
|
||||
return 0
|
||||
fi
|
||||
|
||||
# nothing to do
|
||||
log "DEBUG" "no indication for start processing file found: $file"
|
||||
return 1
|
||||
|
@ -142,7 +167,16 @@ check() {
|
|||
## process/generate output
|
||||
process() {
|
||||
log "INFO" "start processing file: $file"
|
||||
pushd $DIR_BASE >/dev/null || return 1
|
||||
./generate.sh "$file"
|
||||
local result=$?
|
||||
popd >/dev/null
|
||||
if [ $result -ne 0 ]; then
|
||||
log "ERROR" "processing of file not successful: $file"
|
||||
return 1
|
||||
fi
|
||||
|
||||
log "INFO" "processing of file successful: $file"
|
||||
}
|
||||
|
||||
|
||||
|
@ -163,36 +197,79 @@ copy() {
|
|||
|
||||
local file_pdf="${file/.sgml/.pdf}"
|
||||
local file_html="${file/.sgml/.html}"
|
||||
|
||||
local dir_html="${file/.sgml}"
|
||||
|
||||
local file_base="`basename "${file/.sgml}"`"
|
||||
|
||||
local file_dest_pdf="$DIR_DEST_BASE/${file_base}.pdf"
|
||||
local file_dest_html="$DIR_DEST_BASE/${file_base}.html"
|
||||
local dir_dest_html="$DIR_DEST_BASE/$file_base"
|
||||
|
||||
local file_dest_status="$DIR_DEST_BASE/${file_base}.last"
|
||||
|
||||
log "INFO" "copy PDF file: $file_pdf"
|
||||
cp -p "$file_pdf" "$DIR_DEST_BASE/$file_pdf"
|
||||
cp -p "$file_pdf" "$file_dest_pdf"
|
||||
if [ $? -ne 0 ]; then
|
||||
log "ERROR" "can't copy PDF file: $file_pdf"
|
||||
return 1
|
||||
fi
|
||||
chmod 644 "$DIR_DEST_BASE/$file_pdf"
|
||||
|
||||
if [ ! -f "$file_dest_pdf" ]; then
|
||||
log "ERROR" "destination PDF file is not a file or doesn't exist: $file_dest_pdf"
|
||||
return 1
|
||||
fi
|
||||
|
||||
chmod 644 "$file_dest_pdf"
|
||||
if [ $? -ne 0 ]; then
|
||||
log "ERROR" "can't adjust permissions of PDF file: $file_dest_pdf"
|
||||
return 1
|
||||
fi
|
||||
|
||||
log "INFO" "copy HTML file: $file_html"
|
||||
cp -p "$file_html" "$DIR_DEST_BASE/$file_html"
|
||||
cp -p "$file_html" "$file_dest_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"
|
||||
if [ ! -f "$file_dest_html" ]; then
|
||||
log "ERROR" "destination HTML file is not a file or doesn't exist: $file_dest_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/"
|
||||
chmod 644 "$file_dest_html"
|
||||
if [ $? -ne 0 ]; then
|
||||
log "ERROR" "can't adjust permissions of HTML file: $file_dest_html"
|
||||
return 1
|
||||
fi
|
||||
|
||||
if [ ! -d "$dir_html" ]; then
|
||||
log "ERROR" "source directory for HTML doesn't exist: $dir_html"
|
||||
return 1
|
||||
fi
|
||||
|
||||
if [ ! -d "$dir_dest_html" ]; then
|
||||
log "ERROR" "destination directory for HTML doesn't exist: $dir_dest_html"
|
||||
return 1
|
||||
fi
|
||||
|
||||
if [ ! -w "$dir_dest_html" ]; then
|
||||
log "ERROR" "destination directory for HTML isn't writable: $dir_dest_html"
|
||||
return 1
|
||||
fi
|
||||
log "INFO" "copy HTML directory: $dir_html -> $dir_dest_html"
|
||||
rsync --delete -r "$dir_html/" "$dir_dest_html/"
|
||||
if [ $? -ne 0 ]; then
|
||||
log "ERROR" "can't sync HTML dir: $dir_html"
|
||||
return 1
|
||||
fi
|
||||
|
||||
log "INFO" "update status file: $file_dest_status"
|
||||
touch "$file_dest_status"
|
||||
if [ $? -ne 0 ]; then
|
||||
log "ERROR" "can't update status file: $file_dest_status"
|
||||
return 1
|
||||
fi
|
||||
}
|
||||
|
||||
|
||||
|
@ -207,25 +284,28 @@ main() {
|
|||
continue
|
||||
fi
|
||||
|
||||
dir="${file/.sgml}"
|
||||
dir="$DIR_BASE/${file/.sgml}"
|
||||
|
||||
check "$file" "$dir"
|
||||
check "$DIR_DOWNLOAD/$file" "$DIR_BASE/$file" "$dir"
|
||||
if [ $? -eq 0 ]; then
|
||||
process "$file"
|
||||
process "$DIR_BASE/$file"
|
||||
fi
|
||||
|
||||
copy "$file"
|
||||
copy "$DIR_BASE/$file"
|
||||
done
|
||||
}
|
||||
|
||||
|
||||
# parse options
|
||||
while getopts "d" opt; do
|
||||
while getopts "dg" opt; do
|
||||
case $opt in
|
||||
d)
|
||||
# no download
|
||||
force_download=1
|
||||
;;
|
||||
g)
|
||||
force_download=1
|
||||
force_generate=1
|
||||
;;
|
||||
\?)
|
||||
echo "Invalid option: -$OPTARG" >&2
|
||||
;;
|
||||
|
|
Loading…
Reference in New Issue