Skip to content

Commit

Permalink
Cleaned up the scripts and merged the html and html-single into one b…
Browse files Browse the repository at this point in the history
…uild to save time.
  • Loading branch information
Lee Newson committed Jan 31, 2014
1 parent 163220a commit 4c8c22a
Show file tree
Hide file tree
Showing 7 changed files with 224 additions and 998 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
*.*~

16 changes: 0 additions & 16 deletions PressZilla.meta.js~

This file was deleted.

530 changes: 0 additions & 530 deletions PressZilla.user.js~

This file was deleted.

230 changes: 103 additions & 127 deletions build_books.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,30 +2,30 @@

function cleanHTMLDir()
{
CLEAN_DIR=$1
CLEAN_DIR=$1

if [ -d /var/www/html/${CLEAN_DIR} ] || [ -e /var/www/html/${CLEAN_DIR} ]
then
rm -rf /var/www/html/${CLEAN_DIR}
fi
if [ -d /var/www/html/${CLEAN_DIR} ] || [ -e /var/www/html/${CLEAN_DIR} ]
then
rm -rf /var/www/html/${CLEAN_DIR}
fi

}

function backupAndCleanHTMLDir()
{
CLEAN_DIR=$1
CLEAN_DIR=$1

if [ -d /var/www/html/${CLEAN_DIR} ] || [ -e /var/www/html/${CLEAN_DIR} ]
then
if [ -d /var/www/html/backup/${CLEAN_DIR} ] || [ -e /var/www/html/backup/${CLEAN_DIR} ]
then
rm -rf /var/www/html/backup/${CLEAN_DIR}
fi
if [ -d /var/www/html/${CLEAN_DIR} ] || [ -e /var/www/html/${CLEAN_DIR} ]
then
if [ -d /var/www/html/backup/${CLEAN_DIR} ] || [ -e /var/www/html/backup/${CLEAN_DIR} ]
then
rm -rf /var/www/html/backup/${CLEAN_DIR}
fi

mkdir -p /var/www/html/backup/${CLEAN_DIR}
cp -r /var/www/html/${CLEAN_DIR} /var/www/html/backup/${CLEAN_DIR}
rm -rf /var/www/html/${CLEAN_DIR}
fi
mkdir -p /var/www/html/backup/${CLEAN_DIR}
cp -r /var/www/html/${CLEAN_DIR} /var/www/html/backup/${CLEAN_DIR}
rm -rf /var/www/html/${CLEAN_DIR}
fi

}

Expand All @@ -41,8 +41,8 @@ PUBLICAN_BOOK_ZIPS_COMPLETE=${APACHE_HTML_DIR}${PUBLICAN_BOOK_ZIPS}

if [ "$#" -lt ${EXPECTED_ARGS} ]
then
echo ERROR! Expected more arguments.
exit 1
echo ERROR! Expected more arguments.
exit 1
fi

# Get the suffix on the directory
Expand All @@ -51,145 +51,121 @@ shift

while (( "$#" ))
do
IFS='=' read -ra ADDR <<< "$1"

# Extract the language, Common Content language and CSP id
# from the command line argument
BUILD_LANG=${ADDR[0]}
PUBLICAN_LANG=${ADDR[1]}
CSPID=${ADDR[2]}
IFS='=' read -ra ADDR <<< "$1"

# Shift the arguments down
shift
# Extract the language, Common Content language and CSP id
# from the command line argument
BUILD_LANG=${ADDR[0]}
PUBLICAN_LANG=${ADDR[1]}
CSPID=${ADDR[2]}

# Start with a clean temp dir for every build
if [ -d ${TMP_DIR}${DIR_SUFFIX} ]
then
rm -rf ${TMP_DIR}${DIR_SUFFIX}
fi

mkdir ${TMP_DIR}${DIR_SUFFIX}
# Shift the arguments down
shift

# Enter the temp directory
pushd ${TMP_DIR}${DIR_SUFFIX}
# Start with a clean temp dir for every build
if [ -d ${TMP_DIR}${DIR_SUFFIX} ]
then
rm -rf ${TMP_DIR}${DIR_SUFFIX}
fi

# Build the book as HTML-SINGLE with no overrides
date > build.log
mkdir ${TMP_DIR}${DIR_SUFFIX}

echo "csprocessor build --lang ${BUILD_LANG} --flatten --editor-links --show-report --target-lang ${PUBLICAN_LANG} --output ${BOOKNAME}.zip ${CSPID} >> build.log"
csprocessor build --lang ${BUILD_LANG} --flatten --editor-links --show-report --target-lang ${PUBLICAN_LANG} --output ${BOOKNAME}.zip ${CSPID} >> build.log
# Enter the temp directory
pushd ${TMP_DIR}${DIR_SUFFIX}

CSP_STATUS=$?

# If the csp build failed then continue to the next item
if [ $CSP_STATUS != 0 ]
then
cleanHTMLDir ${BUILD_LANG}/${CSPID}
# Build the book as HTML-SINGLE with no overrides
date > build.log

mkdir -p /var/www/html/${BUILD_LANG}/${CSPID}
cp build.log /var/www/html/${BUILD_LANG}/${CSPID}
echo "csprocessor build --lang ${BUILD_LANG} --flatten --editor-links --show-report --target-lang ${PUBLICAN_LANG} --output ${BOOKNAME}.zip ${CSPID} >> build.log"
csprocessor build --lang ${BUILD_LANG} --flatten --editor-links --show-report --target-lang ${PUBLICAN_LANG} --output ${BOOKNAME}.zip ${CSPID} >> build.log

continue
fi
CSP_STATUS=$?

unzip ${BOOKNAME}.zip
backupAndCleanHTMLDir ${BUILD_LANG}/${CSPID}
mkdir -p /var/www/html/${BUILD_LANG}/${CSPID}
cp build.log /var/www/html/${BUILD_LANG}/${CSPID}

# The zip file will be extracted to a directory name that
# refelcts the name of the book. We don't know this name,
# but we can loop over the subdirectories and then break
# once we have processed the first directory.
for dir in ./*/
do
# If the csp build failed then continue to the next item
if [ $CSP_STATUS != 0 ]
then
continue
fi

# Enter the extracted book directory
pushd ${dir}
unzip ${BOOKNAME}.zip

# Clone the publican.cfg for the html and remark builds
cp publican.cfg publican-html.cfg
cp publican.cfg publican-remarks.cfg
# The zip file will be extracted to a directory name that
# refelcts the name of the book. We don't know this name,
# but we can loop over the subdirectories and then break
# once we have processed the first directory.
for dir in ./*/
do

# Add the extra options for the html and remark builds
echo -e "\nchunk_first: 1" >> publican-html.cfg
echo -e "\nshow_remarks: 1" >> publican-remarks.cfg
# Enter the extracted book directory
pushd ${dir}

# Do the original publican build
echo "publican build --formats=html-single,pdf --langs=${PUBLICAN_LANG} &> publican.log"
publican build --formats=html-single,pdf --langs=${PUBLICAN_LANG} &> publican.log

PUBLICAN_STATUS=$?
# Clone the publican.cfg for the remark builds
cp publican.cfg publican-remarks.cfg

mkdir -p /var/www/html/${BUILD_LANG}/${CSPID}
cp publican.log /var/www/html/${BUILD_LANG}/${CSPID}
# Add the extra options for the html and remark builds
echo -e "\nchunk_first: 1" >> publican.cfg
echo -e "\nshow_remarks: 1" >> publican-remarks.cfg

backupAndCleanHTMLDir ${BUILD_LANG}/${CSPID}
mkdir -p /var/www/html/${BUILD_LANG}/${CSPID}

cp -R tmp/${PUBLICAN_LANG}/html-single/* /var/www/html/${BUILD_LANG}/${CSPID}
cp -R tmp/${PUBLICAN_LANG}/pdf/* /var/www/html/${BUILD_LANG}/${CSPID}
# Do the original publican build
echo "publican build --formats=html-single,pdf,html --langs=${PUBLICAN_LANG} &> publican.log"
publican build --formats=html-single,pdf,html --langs=${PUBLICAN_LANG} &> publican.log

# don't bother with the html or remark if the html-single failed
if [ $PUBLICAN_STATUS == 0 ]
then

# Clean up
rm -rf tmp
rm publican.log
PUBLICAN_STATUS=$?

# Do the html publican build
echo "publican build --langs=${PUBLICAN_LANG} --formats=html --config=publican-html.cfg &> publican.log"
cp -R tmp/${PUBLICAN_LANG}/html-single/* /var/www/html/${BUILD_LANG}/${CSPID}
cp -R tmp/${PUBLICAN_LANG}/pdf/* /var/www/html/${BUILD_LANG}/${CSPID}
cp publican.log /var/www/html/${BUILD_LANG}/${CSPID}

publican build --langs=${PUBLICAN_LANG} --formats=html --config=publican-html.cfg &> publican.log
# Copy the html to its own directory
cleanHTMLDir ${BUILD_LANG}/${CSPID}/html
mkdir /var/www/html/${BUILD_LANG}/${CSPID}/html

if [ -d /var/www/html/${BUILD_LANG}/${CSPID}/html ] || [ -e /var/www/html/${BUILD_LANG}/${CSPID}/html ]
then
rm -rf /var/www/html/${BUILD_LANG}/${CSPID}/html
fi
cp -R tmp/${PUBLICAN_LANG}/html/* /var/www/html/${BUILD_LANG}/${CSPID}/html
cp publican.log /var/www/html/${BUILD_LANG}/${CSPID}/html

mkdir /var/www/html/${BUILD_LANG}/${CSPID}/html
cp -R tmp/${PUBLICAN_LANG}/html/. /var/www/html/${BUILD_LANG}/${CSPID}/html
# don't bother with the remark if the html-single failed
if [ $PUBLICAN_STATUS == 0 ]
then

cp publican.log /var/www/html/${BUILD_LANG}/${CSPID}/html
# Clean up
rm -rf tmp
rm publican.log

# Clean up
rm -rf tmp
rm publican.log
# Do the remarks build
echo "publican build --langs=${PUBLICAN_LANG} --formats=html-single --config=publican-remarks.cfg &> publican.log"
publican build --langs=${PUBLICAN_LANG} --formats=html-single --config=publican-remarks.cfg &> publican.log

# Do the remarks build
echo "publican build --langs=${PUBLICAN_LANG} --formats=html-single --config=publican-remarks.cfg &> publican.log"
cleanHTMLDir ${BUILD_LANG}/${CSPID}/remarks
mkdir -p /var/www/html/${BUILD_LANG}/${CSPID}/remarks

publican build --langs=${PUBLICAN_LANG} --formats=html-single --config=publican-remarks.cfg &> publican.log
cp -R tmp/${PUBLICAN_LANG}/html-single/* /var/www/html/${BUILD_LANG}/${CSPID}/remarks
cp publican.log /var/www/html/${BUILD_LANG}/${CSPID}/remarks

if [ -d /var/www/html/${BUILD_LANG}/${CSPID}/remarks ] || [ -e /var/www/html/${BUILD_LANG}/${CSPID}/remarks ]
then
rm -rf /var/www/html/${BUILD_LANG}/${CSPID}/remarks
fi

mkdir -p /var/www/html/${BUILD_LANG}/${CSPID}/remarks
cp -R tmp/${PUBLICAN_LANG}/html-single/. /var/www/html/${BUILD_LANG}/${CSPID}/remarks

cp publican.log /var/www/html/${BUILD_LANG}/${CSPID}/remarks

# # Build the publican zip file without editor links
# DATE_MARKER=$(date '+%Y-%m-%dT%k:%M:%S.000%z')
# BOOK_FILE_NAME="${PUBLICAN_BOOK_ZIPS_COMPLETE}/${BUILD_LANG}/${CSPID} ${DATE_MARKER}.zip"
# # Build the publican zip file without editor links
# DATE_MARKER=$(date '+%Y-%m-%dT%k:%M:%S.000%z')
# BOOK_FILE_NAME="${PUBLICAN_BOOK_ZIPS_COMPLETE}/${BUILD_LANG}/${CSPID} ${DATE_MARKER}.zip"
#
# if [ -f "${BOOK_FILE_NAME}" ]
# then
# rm -rf "${BOOK_FILE_NAME}"
# fi
# if [ -f "${BOOK_FILE_NAME}" ]
# then
# rm -rf "${BOOK_FILE_NAME}"
# fi
#
# echo "csprocessor build --lang ${BUILD_LANG} --output "${BOOK_FILE_NAME}" ${CSPID} >> build.log"
# csprocessor build --lang ${BUILD_LANG} --output "${BOOK_FILE_NAME}" ${CSPID} >> build.log
# echo "csprocessor build --lang ${BUILD_LANG} --target-lang ${PUBLICAN_LANG} --hide-errors --output "${BOOK_FILE_NAME}" ${CSPID} >> build.log"
# csprocessor build --lang ${BUILD_LANG} --target-lang ${PUBLICAN_LANG} --hide-errors --output "${BOOK_FILE_NAME}" ${CSPID} >> build.log

fi

fi
popd

popd

# we only want to process one directory
break
# we only want to process one directory
break

done
done

cp build.log /var/www/html/${BUILD_LANG}/${CSPID}
popd
cp build.log /var/www/html/${BUILD_LANG}/${CSPID}
popd
done

0 comments on commit 4c8c22a

Please sign in to comment.