mirror of https://github.com/tLDP/LDP
445 lines
8.8 KiB
Bash
Executable File
445 lines
8.8 KiB
Bash
Executable File
#!/bin/bash
|
|
|
|
CHECK_ERROR=0
|
|
SGML_DIR=/usr/share/sgml
|
|
DOCBOOK_DIR=${SGML_DIR}/docbook
|
|
|
|
#
|
|
# check
|
|
#
|
|
check()
|
|
{
|
|
local mode="$1"; shift
|
|
local name="$1"; shift
|
|
local error="$1"; shift
|
|
|
|
if [ "${mode}" = "quiet" ]; then
|
|
"$@"
|
|
else
|
|
echo -n "Checking ${name} ... "
|
|
if "$@"; then
|
|
echo "Ok"
|
|
return 0
|
|
fi
|
|
echo "No"
|
|
if [ -n "${error}" ]; then
|
|
local type=ERROR
|
|
[ "${mode}" = "warning" ] && type=WARNING
|
|
echo "${type}: ${error}"
|
|
fi
|
|
[ "${mode}" = "exit" ] && exit -1
|
|
[ "${mode}" = "count" ] && CHECK_ERROR=$( expr ${CHECK_ERROR} + 1 )
|
|
return 1
|
|
fi
|
|
}
|
|
|
|
#
|
|
# check_file
|
|
#
|
|
check_file()
|
|
{
|
|
check "$1" "$2" "$3" test -r "$2"
|
|
}
|
|
|
|
which_test()
|
|
{
|
|
WHICH_FILE=$( which "$@" 2> /dev/null )
|
|
[ -x "${WHICH_FILE}" ]
|
|
}
|
|
|
|
#
|
|
# check_which
|
|
#
|
|
check_which()
|
|
{
|
|
check "$1" "$2" "Can't find $2 in \$PATH" which_test "$2"
|
|
}
|
|
|
|
#
|
|
# check_www_user
|
|
#
|
|
check_www_user()
|
|
{
|
|
WWW_USER=$1
|
|
echo -n "Checking for user ${WWW_USER} in /etc/passwd ... "
|
|
grep "^${WWW_USER}:" /etc/passwd > /dev/null && echo "Ok." && return 0
|
|
echo "No."
|
|
echo "Is apache installed?"
|
|
CHECK_ERROR=$( expr ${CHECK_ERROR} + 1 )
|
|
return 1
|
|
}
|
|
|
|
#
|
|
# identify_dist
|
|
#
|
|
identify_dist()
|
|
{
|
|
DIST_NAME=redhat
|
|
DIST_FILE=/etc/redhat-release
|
|
check_file quiet ${DIST_FILE} && return 0
|
|
|
|
DIST_NAME=debian
|
|
DIST_FILE=/etc/debian_version
|
|
check_file quiet ${DIST_FILE} && return 0
|
|
|
|
DIST_NAME=suse
|
|
DIST_FILE=/etc/SuSE-release
|
|
check_file quiet ${DIST_FILE} && return 0
|
|
|
|
DIST_NAME=unknown
|
|
unset DIST_FILE
|
|
return 1
|
|
}
|
|
|
|
#
|
|
# check_redhat
|
|
#
|
|
check_dist_redhat()
|
|
{
|
|
local mode=$1
|
|
local dir=$( ls ${DOCBOOK_DIR} | sed -n -e '
|
|
/^xml-dtd-4.1.2/ {
|
|
p
|
|
q
|
|
}
|
|
' )
|
|
|
|
dir=${DOCBOOK_DIR}/${dir}
|
|
local error="'docbook-dtds' is not installed."
|
|
XML_DTD_412=${dir}/docbookx.dtd
|
|
check_file ${mode} ${XML_DTD_412} "${error}"
|
|
|
|
XML_ISO_NUM=${dir}/ent/iso-num.ent
|
|
check_file ${mode} ${XML_ISO_NUM} "${error}"
|
|
|
|
local dir=${DOCBOOK_DIR}/xsl-stylesheets/html
|
|
local error="'docbook-style-xsl' is not installed."
|
|
|
|
HTML_CHUNK=${dir}/chunk.xsl
|
|
check_file ${mode} ${HTML_CHUNK} "${error}"
|
|
|
|
HTML_DOCBOOK=${dir}/docbook.xsl
|
|
check_file ${mode} ${HTML_DOCBOOK} "${error}"
|
|
|
|
check_www_user apache
|
|
}
|
|
|
|
#
|
|
# check_debian
|
|
#
|
|
check_dist_debian()
|
|
{
|
|
local mode=$1
|
|
|
|
# 2.2r6 = /usr/lib/sgml/dtd/docbook-xml/docbookx.dtd?
|
|
XML_DTD_412=${DOCBOOK_DIR}/dtd/xml/4.1.2/docbookx.dtd
|
|
check_file ${mode} ${XML_DTD_412} "'docbook-xml' is not installed."
|
|
|
|
# 2.2r6 = /usr/lib/sgml/entities/iso-num.ent?
|
|
XML_ISO_NUM=${SGML_DIR}/entities/xml-iso-entities-8879.1986/ISOnum.ent
|
|
check_file ${mode} ${XML_ISO_NUM} "'sgml-data' is not installed."
|
|
|
|
local dir=${DOCBOOK_DIR}/stylesheet/xsl/nwalsh/html
|
|
local error="'docbook-xsl-stylesheets' is not installed."
|
|
|
|
HTML_CHUNK=${dir}/chunk.xsl
|
|
check_file ${mode} ${HTML_CHUNK} "${error}"
|
|
|
|
HTML_DOCBOOK=${dir}/docbook.xsl
|
|
check_file ${mode} ${HTML_DOCBOOK} "${error}"
|
|
|
|
check_www_user www-data
|
|
}
|
|
|
|
#
|
|
# check_suse
|
|
#
|
|
check_dist_suse()
|
|
{
|
|
local mode=$1
|
|
local dir=${SGML_DIR}/db41xml
|
|
local error="'docbook_4' is not installed."
|
|
|
|
XML_DTD_412=${dir}/docbookx.dtd
|
|
check_file ${mode} ${XML_DTD_412} "${error}"
|
|
|
|
XML_ISO_NUM=${dir}/ent/iso-num.ent
|
|
check_file ${mode} ${XML_ISO_NUM} "${error}"
|
|
|
|
dir=$( ls ${DOCBOOK_DIR} | sed -n -e '
|
|
/^docbook-xsl-stylesheets-/ {
|
|
p
|
|
q
|
|
}
|
|
' )
|
|
local dir=${DOCBOOK_DIR}/${dir}/html
|
|
local error="'docbook-style-xsl' is not installed."
|
|
|
|
HTML_CHUNK=${dir}/chunk.xsl
|
|
check_file ${mode} ${HTML_CHUNK} "${error}"
|
|
|
|
HTML_DOCBOOK=${dir}/docbook.xsl
|
|
check_file ${mode} ${HTML_DOCBOOK} "${error}"
|
|
|
|
check_www_user wwwrun
|
|
}
|
|
|
|
#
|
|
# check_perl_module
|
|
#
|
|
check_perl_module()
|
|
{
|
|
local module=$1
|
|
local error=$2
|
|
|
|
echo -n "Checking perl module ${module} ... "
|
|
perl <<EOF 2> /dev/null
|
|
use ${module};
|
|
use HTML::Entities;
|
|
print "Ok.\n";
|
|
exit 0
|
|
EOF
|
|
[ $? == 0 ] && return 0
|
|
echo "No."
|
|
echo "ERROR: Missing perl module ${module}."
|
|
[ -z "${error}" ] && echo "ERROR: ${error}"
|
|
CHECK_ERROR=$( expr ${CHECK_ERROR} + 1 )
|
|
return 1
|
|
}
|
|
|
|
#
|
|
# check_html_parser
|
|
#
|
|
check_html_parser()
|
|
{
|
|
check_perl_module "HTML::Entities" && return 0
|
|
echo "ERROR: HTML-Parser is not installed (required for wt2db)."
|
|
case ${DIST_NAME} in
|
|
debian) pkg=libhtml-parser-perl ;;
|
|
redhat) pkg=perl-HTML-Parser ;;
|
|
suse) pkg=perl-HTML-Parser ;;
|
|
esac
|
|
[ -n "${pkg}" ] && error="The package is called '${pkg}'."
|
|
return 1
|
|
}
|
|
|
|
#
|
|
# check_postgres
|
|
#
|
|
check_postgres()
|
|
{
|
|
check_which count psql "Can't find package 'postgresql'"
|
|
if ! check_which count pg_config; then
|
|
case ${DIST_NAME} in
|
|
debian) pkg=postgresql-dev ;;
|
|
redhat) pkg=postgresql-devel ;;
|
|
suse) pkg=postgresql-devel ;;
|
|
esac
|
|
[ -n "${pkg}" ] && error="The package is called '${pkg}'."
|
|
fi
|
|
}
|
|
|
|
#
|
|
# check_xsltproc
|
|
#
|
|
check_xsltproc()
|
|
{
|
|
check_which count xsltproc && return 0
|
|
case ${DIST_NAME} in
|
|
debian) pkg=xsltproc ;;
|
|
redhat) pkg=libxslt ;;
|
|
suse) pkg=libxslt ;;
|
|
esac
|
|
[ -n "${pkg}" ] && echo "The package is called '${pkg}'."
|
|
return 1
|
|
}
|
|
|
|
#
|
|
# check_python_version
|
|
#
|
|
check_python_version()
|
|
{
|
|
local python=$1
|
|
|
|
echo -n "${python} -V = "
|
|
local line=$( ( ${python} -V 2>&1 ) | sed -n "1 p" )
|
|
echo -n "${line} ... "
|
|
|
|
local version="${line#Python }"
|
|
if [ "${version}" != "${line}" ]; then
|
|
version="${version%%.*}"
|
|
if [ "${version}" -ge 2 ]; then
|
|
echo "Ok."
|
|
return 0
|
|
fi
|
|
fi
|
|
echo "No."
|
|
return 1
|
|
}
|
|
|
|
#
|
|
# check_python
|
|
#
|
|
check_python()
|
|
{
|
|
local mode="$1"
|
|
|
|
check_which ${mode} python || return 1
|
|
check_python_version ${WHICH_FILE} && PYTHON=${WHICH_FILE} && return 0
|
|
|
|
check_which ${mode} python2 || return 1
|
|
check_python_version ${WHICH_FILE} && PYTHON=${WHICH_FILE} && return 0
|
|
}
|
|
|
|
#
|
|
# check_python_import
|
|
#
|
|
check_python_import()
|
|
{
|
|
for module in "$@"; do
|
|
echo -n "Checking python module ${module} ... "
|
|
${PYTHON} -c "import ${module}" 2> /dev/null
|
|
[ $? == 0 ] && echo "Ok." && continue
|
|
echo "No."
|
|
echo "ERROR: Missing python module ${module}."
|
|
CHECK_ERROR=$( expr ${CHECK_ERROR} + 1 )
|
|
done
|
|
}
|
|
|
|
#
|
|
# patch_xsl
|
|
#
|
|
patch_xsl()
|
|
{
|
|
local prefix='^\([[:space:]]*<xsl:import[[:space:]]\{1,\}href=\"\)'
|
|
local postfix='\(\".*\)$'
|
|
|
|
for file in xsl/*.xsl; do
|
|
echo -n "Patching ${file} ... "
|
|
sed -e "s|${prefix}.*\/chunk.xsl${postfix}|\1${HTML_CHUNK}\2|" \
|
|
-e "s|${prefix}.*\/docbook.xsl${postfix}|\1${HTML_DOCBOOK}\2|" \
|
|
${file} > ${file}.tmp
|
|
if [ $? != 0 ] || ! mv -f ${file}.tmp ${file}; then
|
|
echo "No."
|
|
return 1
|
|
fi
|
|
echo "Ok"
|
|
done
|
|
return 0
|
|
}
|
|
|
|
#
|
|
# patch_setenv_sh
|
|
#
|
|
patch_setenv_sh()
|
|
{
|
|
local file=$1
|
|
local prefix='^[[:space:]]*export[[:space:]]\{1,\}LAMPADAS_'
|
|
|
|
echo -n "Patching ${file} ... "
|
|
sed -e "s|\(${prefix}ROOT=\).*|\1\"${PWD}\"|" \
|
|
-e "s|\(${prefix}XML_DTD_412=\).*|\1\"${XML_DTD_412}\"|" \
|
|
-e "s|\(${prefix}XML_ISO_NUM=\).*|\1\"${XML_ISO_NUM}\"|" \
|
|
-e "s|\(${prefix}WWW_USER=\).*|\1\"${WWW_USER}\"|" \
|
|
${file} > ${file}.tmp
|
|
if [ $? != 0 ] || ! mv -f ${file}.tmp ${file}; then
|
|
echo "No."
|
|
return 1
|
|
fi
|
|
echo "Ok"
|
|
echo -n "Sourcing in ${file} ... "
|
|
. ${file}
|
|
echo "Ok."
|
|
return 0
|
|
}
|
|
|
|
#
|
|
# create_setenv_csh
|
|
#
|
|
create_setenv_csh()
|
|
{
|
|
local input=$1
|
|
local csh=$2
|
|
local conf=$3
|
|
|
|
local prefix='^[[:space:]]*export[[:space:]]\{1,\}'
|
|
local header="# Generated by configure. Do not modify.\n"
|
|
|
|
echo -n "Generating ${csh} and ${conf} ... "
|
|
|
|
echo "$header" > ${csh}
|
|
echo "$header" > ${conf}
|
|
sed -ne "s/${prefix}\([[:alnum:]_]\{1,\}\)=.*/\1/p" \
|
|
< ${input} \
|
|
| while read var
|
|
do
|
|
echo "setenv ${var} \"${!var}\"" >> ${csh}
|
|
echo "PythonOption ${var} \"${!var}\"" >> ${conf}
|
|
done
|
|
|
|
echo "Ok."
|
|
return 0
|
|
}
|
|
|
|
#
|
|
# patch_http_conf
|
|
#
|
|
patch_http_conf()
|
|
{
|
|
local prefix='\([[:space:]'\'']*\)[[:alnum:]\.\-_/]*'
|
|
|
|
for file in "$@"; do
|
|
echo -n "Patching ${file} ... "
|
|
sed -e "s#${prefix}/pylib\>#\1${LAMPADAS_LIB}#g" \
|
|
-e "s#${prefix}\(/www/\)#\1${LAMPADAS_ROOT}\2#g" \
|
|
< ${file} > ${file}.tmp \
|
|
&& mv -f ${file}.tmp ${file} \
|
|
&& echo "Ok."
|
|
done
|
|
}
|
|
|
|
#
|
|
# main
|
|
#
|
|
if [ ! -x ${PWD}/configure ]; then
|
|
echo "ERROR: Can't find myself in current directory."
|
|
echo "Please start this script as ./configure"
|
|
exit -1
|
|
fi
|
|
|
|
identify_dist
|
|
echo "Identified this installation as '${DIST_NAME}'."
|
|
cat ${DIST_FILE}
|
|
check_dist_${DIST_NAME} "count"
|
|
|
|
for app in iconv m4 make perl sed tar; do
|
|
check_which count ${app}
|
|
done
|
|
|
|
if ! check_which warning docbook-to-man; then
|
|
if ! check_which count docbook2man; then
|
|
echo "ERROR: Neither docbook-to-man nor " \
|
|
"docbook2man (package docbook-utils) installed."
|
|
fi
|
|
fi
|
|
|
|
check_postgres
|
|
|
|
check_xsltproc
|
|
check_html_parser
|
|
check_which count wt2db
|
|
check_python count
|
|
check_python_import os pyPgSQL # DateTime
|
|
|
|
if [ ${CHECK_ERROR} -ne 0 ]; then
|
|
echo "${CHECK_ERROR} errors."
|
|
exit -1
|
|
fi
|
|
|
|
echo "No errors."
|
|
patch_xsl || exit -1
|
|
patch_setenv_sh bin/setenv.sh || exit -1
|
|
create_setenv_csh bin/setenv.sh bin/setenv.csh bin/setenv.python \
|
|
|| exit -1
|
|
patch_http_conf conf/*.conf || exit -1
|