#!/bin/bash # # Written by stickster :) # Mangled by megacoder ;-P # Further editing and packaging by nman64 # # Dedicated to the lazy Fedora Docs heroes. ;-) # # Pull all active FDP docs from CVS, build and install HTML in # PREFIX folder. # ME=$(basename "$0") NOW="$(date +%Y%m%d%H%M%S)" VERBOSE=0 ######################################################################## # die "message" ######################################################################## die () { obit="$1" shift echo "${ME}: $@" >&2 exit ${obit} } ######################################################################## # babble "message" ######################################################################## babble () { level=$1 if [ $level -le ${VERBOSE} ]; then shift LEADIN='. ' for n in $(seq 1 $level) do echo -n "${LEADIN}" >&2 done echo "$@" >&2 fi } ######################################################################## # do_html_chunks ######################################################################## do_html_chunks () { babble 1 "Building chunked HTML for ${DOCBASE}" DESTDIR=${PREFIX}/${DOCBASE} mkdir -p ${DESTDIR} if make -k html >${DESTDIR}/make_chunks_log.txt 2>&1; then babble 2 "All languages built; removing 'make_chunks_log.txt'" rm -f ${DESTDIR}/make_chunks_log.txt else babble 2 "Some locales failed; see 'make_chunks_log.txt'" fi babble 2 "Defined locales '${LANGUAGES}'" for LANG in $LANGUAGES ; do rm -rf ${DESTDIR}/${LANG} if [ -f ${DOCBASE}-${LANG}/index.html ]; then babble 3 "Locale '${LANG}' built" mkdir -p ${DESTDIR}/${LANG} cp -r ${DOCBASE}-${LANG}/* ${DESTDIR}/${LANG}/ else babble 3 "Locale '${LANG}' did not build" fi done } ######################################################################## # do_html_nochunks ######################################################################## do_html_nochunks () { babble 1 "Building no-chunk HTML for ${DOCBASE}" DESTDIR="${PREFIX}/${DOCBASE}" mkdir -p ${DESTDIR} if make -k html-nochunks >${DESTDIR}/make_nochunks_log.txt 2>&1; then babble 2 "All languages built; removing 'make_nochunks_log.txt'" rm -f ${DESTDIR}/make_nochunks_log.txt else babble 2 "Some locales failed; see 'make_nochunks_log.txt'" fi babble 2 "Defined locales '${LANGUAGES}'" for LANG in $LANGUAGES ; do rm -f ${DESTDIR}/${DOCBASE}-${LANG}.html if [ -f ${DOCBASE}-${LANG}.html ]; then babble 3 "Locale '${LANG}' built" cp -r ${DOCBASE}-${LANG}.html ${DESTDIR}/ else babble 3 "Locale '${LANG}' did not build" fi done } ######################################################################## # do_tarball ######################################################################## do_tarball () { babble 1 "Building binary tarball for ${DOCBASE}" DESTDIR=${PREFIX}/${DOCBASE} mkdir -p ${DESTDIR} if make tarball >${DESTDIR}/make_tarball_log.txt 2>&1; then babble 2 "All tarballs built; removing 'make_tarball_log.txt'" rm -f ${DESTDIR}/make_tarball_log.txt else babble 2 "Build failed; see 'make_tarball_log.txt'" fi babble 2 "Defined locales '${LANGUAGES}'" for LANG in ${LANGUAGES} ; do TARBALL=${DOCBASE}-${LANG}.tar.gz rm -f ${DESTDIR}/${TARBALL} if [ -f ${TARBALL} ]; then babble 3 "Locale '${LANG}' tarball installed" cp ${TARBALL} ${DESTDIR}/${TARBALL} else babble 3 "Locale '${LANG}' did not build" fi done } ######################################################################## # do_src_tarball ######################################################################## do_src_tarball () { babble 1 "Building source tarball for ${DOCBASE}" DESTDIR=${PREFIX}/${DOCBASE} if make tarball >${DESTDIR}/make_src_tarball_log.txt 2>&1; then babble 2 \ "All src tarballs built; removing 'make_src_tarball_log.txt'" rm -f ${DESTDIR}/make_src_tarball_log.txt else babble 2 "Build failed; see 'make_src_tarball_log.txt'" fi # Isn't there really only ONE src tarball? babble 2 "Defined locales '${LANGUAGES}'" for LANG in $LANGUAGES ; do TARBALL=${DOCBASE}.src.tar.gz rm -f ${DESTDIR}/${TARBALL} if [ -f ${TARBALL} ]; then babble 3 "Locale '${LANG}' source tarball installed" cp ${TARBALL} ${DESTDIR}/${TARBALL} else babble 3 "Locale '${LANG}' source tarball did not build" fi done } ######################################################################## # do_srpm ######################################################################## do_srpm () { babble 1 "Building SRPM package for ${DOCBASE}" DESTDIR=${PREFIX}/${DOCBASE} mkdir -p ${DESTDIR} if make srpm >${DESTDIR}/make_srpm_log.txt 2>&1; then babble 2 "${DOCBASE} srpm built; removing 'make_srpm_log.txt'" rm -f ${DESTDIR}/make_srpm_log.txt else babble 2 "SRPM failed; see 'make_srpm_log.txt'" fi for x in fedora-doc-${DOCBASE}*.src.rpm do babble 2 "RPM '$x' installed" rm -f ${DESTDIR}/$x cp $x ${DESTDIR}/$x done } ######################################################################## # do_make_spec ######################################################################## do_make_spec () { babble 1 "Building SPEC file for ${DOCBASE}" DESTDIR=${PREFIX}/${DOCBASE} mkdir -p ${DESTDIR} if make spec >${DESTDIR}/make_spec_log.txt 2>&1; then babble 2 "SPEC file built; removing 'make_spec_log.txt'" rm -f ${DESTDIR}/make_spec_log.txt else babble 2 "SPEC file failed; see 'make_spec_log.txt'" fi SPECFILE=${DOCBASE}.spec rm -f ${DESTDIR}/${SPECFILE} if [ -f ${SPECFILE} ]; then babble 2 "${SPECFILE} installed" cp ${SPECFILE} ${DESTDIR}/${SPECFILE} else babble 2 "${SPECFILE} did not build" fi } ######################################################################## # print_usage ######################################################################## print_usage() { echo "Usage: $ME [options...]" FMT=" %-12s : %s\n" printf "${FMT}" "-h" "print usage [this message]" printf "${FMT}" "-D PREFIX" "Built files placed here [${PREFIX}]" printf "${FMT}" "-Q" "CVS checkout is less quiet" printf "${FMT}" "-S" "Build SRPM" printf "${FMT}" "-T" "Build source tarball" printf "${FMT}" "-c" "Build chunked HTML" printf "${FMT}" "-d CVSROOT" "CVS repository info [$CVSROOT]" printf "${FMT}" "-n" "Build non-chunked HTML" printf "${FMT}" "-p" "Build PDF [NOT CURRENTLY WORKING]" printf "${FMT}" "-r REV" "CVS revision to use [${REV}]" printf "${FMT}" "-s" "Build SPEC file" printf "${FMT}" "-t" "Build tarball" printf "${FMT}" "-v" "Increase output details" printf "${FMT}" "-w WORKDIR" "set working directory [${WORKDIR}]" } ######################################################################## # set_vars ######################################################################## set_vars() { : ${WORKDIR:=${TMP:-${TMPDIR:-/tmp}}/build-docs-$$.tmp} : ${PREFIX:=/var/www/webtest/docs} : ${CVSROOT:=:pserver:anonymous@cvs.fedora.redhat.com:/cvs/docs} : ${REV:=HEAD} : ${REDIR:=/dev/null} : ${QUIET:=-Q} : ${VERBOSE:=0} } # just to make sure defaults are read unset WORKDIR PREFIX TAG CHUNKS NOCHUNKS PDF TARBALL CVSROOT BUILDS=0 while getopts "w:D:a:r:QcnpSsTthv" OPT; do case "${OPT}" in w ) WORKDIR="$OPTARG" ;; D ) PREFIX="$OPTARG" ;; d ) CVSROOT="$OPTARG" ;; r ) REV="$OPTARG" ;; Q ) QUIET="-q" ;; c ) CHUNKS="yes" BUILDS=$(($BUILDS+1)) ;; n ) NOCHUNKS="yes" BUILDS=$(($BUILDS+1)) ;; p ) PDF="yes" # But PDF doesn't work yet, don't do this! BUILDS=$(($BUILDS+1)) ;; S ) SRPM="yes" BUILDS=$(($BUILDS+1)) ;; s ) SPEC="yes" BUILDS=$(($BUILDS+1)) ;; T ) SRCTARBALL="yes" BUILDS=$(($BUILDS+1)) ;; t ) TARBALL="yes" BUILDS=$(($BUILDS+1)) ;; h ) set_vars print_usage exit 0 ;; v ) VERBOSE=$(( $VERBOSE + 1 )) ;; * ) echo "${ME}: invalid option: '-${OPT}'" print_usage exit 10 ;; esac done shift $(($OPTIND - 1)) if [ ${BUILDS} -lt 1 ]; then echo "$ME: must select one of [-c|-n|-p|-s|-S|-T|-t]" exit 20 fi set_vars babble 2 "CVSROOT='${CVSROOT}'" export CVSROOT babble 3 "Creating work directory [${WORKDIR}]" mkdir -p ${WORKDIR} || die 254 "Could not mkdir ${WORKDIR}" babble 3 "Creating output directory [${PREFIX}]" mkdir -p ${PREFIX} || die 254 "Could not mkdir ${PREFIX}" babble 0 "Script log is in '${PREFIX}/build-docs_log.txt'" exec >${PREFIX}/build-docs_log.txt 2>&1 ( babble 3 "About to 'cd ${WORKDIR}'" cd ${WORKDIR} DOC=docs-common babble 0 "Module '${DOC}'" if cvs ${QUIET} -z3 co ${DOC} >${DOC}_co_log.txt 2>&1 then babble 2 "${DOC} co succeeded; removing '${DOC}_co_log.txt'" rm -f ${DOC}_co_log.txt else die 2 "Can't proceed without a '${DOC}' module" # NOTREACHED fi [ -f docs-common/bin/active ] || die 2 "cannot find 'docs-common/bin/active'" sort -b -d -f docs-common/bin/active | xargs -n1 | while read DOC do babble 0 "Module '${DOC}'" # babble 1 "Considering module '${DOC}'" if [ "${DOC}" == "docs-common" ]; then babble 1 "Skipping; already done" continue # NOTREACHED fi babble 1 "Removing prior '${DOC}' files" rm -rf ${PREFIX}/${DOC} babble 1 "Checking out module '${DOC}' from CVS" if cvs ${QUIET} -z3 co ${DOC} >${DOC}_co_log.txt 2>&1; then babble 2 \ "${DOC} co succeeded; removing '${DOC}_co_log.txt'" rm -f ${DOC}_co_log.txt else babble 2 "${DOC} co failed; see '${DOC}_co_log.txt'" continue fi ( babble 1 "About to 'cd ${DOC}'" cd ${DOC} babble 1 "Obtaining pertinent variables" eval $(make showvars) LANGUAGES="${PRI_LANG} ${OTHERS}" if [ "${CHUNKS}" = "yes" ]; then do_html_chunks fi if [ "${NOCHUNKS}" = "yes" ]; then do_html_nochunks fi if [ "${TARBALL}" = "yes" ]; then do_tarball fi if [ "${SRCTARBALL}" = "yes" ]; then do_src_tarball fi if [ "${SRPM}" = "yes" ]; then do_srpm fi if [ "${SPEC}" = "yes" ]; then do_make_spec fi ) done ) [ "$WORKDIR" != "/" ] && [ "$WORKDIR" != "$HOME" ] && ( babble 0 "Removing work directory [${WORKDIR}]" rm -rf ${WORKDIR} ) exit 0