set debugging mode and tidy up

This commit is contained in:
Ahmed AbouZaid 2019-02-01 08:29:42 +01:00
parent 3d420e075d
commit f05b66ee19
2 changed files with 14 additions and 8 deletions

View File

@ -27,7 +27,7 @@ Available values for `BOOK_SLUG`:
- `srw_book` The Site Reliability Workbook. - `srw_book` The Site Reliability Workbook.
``` ```
$ docker run --rm --volume "$(pwd):/output" captn3m0/google-sre-ebook:latest -e BOOK_SLUG='sre_book' $ docker run --rm --volume "$(pwd):/output" -e BOOK_SLUG='sre_book' captn3m0/google-sre-ebook:latest
``` ```
- You should see the final EPUB/MOBI/PDF files in the `output` directory after the above runs. - You should see the final EPUB/MOBI/PDF files in the `output` directory after the above runs.
@ -38,7 +38,7 @@ $ docker run --rm --volume "$(pwd):/output" captn3m0/google-sre-ebook:latest -e
``` ```
$ mkdir /tmp/sreoutput $ mkdir /tmp/sreoutput
$ chcon -Rt svirt_sandbox_file_t /tmp/sreoutput $ chcon -Rt svirt_sandbox_file_t /tmp/sreoutput
$ docker run --rm --volume "/tmp/sreoutput:/output" captn3m0/google-sre-ebook:latest -e BOOK_SLUG='sre_book' $ docker run --rm --volume "/tmp/sreoutput:/output" -e BOOK_SLUG='sre_book' captn3m0/google-sre-ebook:latest
``` ```
The build for the above Docker image can be audited at <https://cloud.docker.com/swarm/captn3m0/repository/docker/captn3m0/google-sre-ebook/builds>. The build for the above Docker image can be audited at <https://cloud.docker.com/swarm/captn3m0/repository/docker/captn3m0/google-sre-ebook/builds>.

View File

@ -1,4 +1,7 @@
#!/bin/bash #!/bin/bash
if [[ "${DEBUG}" == 1 ]]; then
set -x
fi
set -euo pipefail set -euo pipefail
# Get book details. # Get book details.
@ -6,8 +9,8 @@ source books.sh
export ${BOOKS[${BOOK_SLUG^^}]} export ${BOOKS[${BOOK_SLUG^^}]}
# Common vars. # Common vars.
IMGS_DOMAIN="lh3.googleusercontent.com"
IFS=$'\n\t' IFS=$'\n\t'
IMGS_DOMAIN="lh3.googleusercontent.com"
# #
# Make sure that links are relative \ # Make sure that links are relative \
@ -31,6 +34,7 @@ wget \
--domains=${IMGS_DOMAIN},landing.google.com ${BOOK_TOC_URL} --domains=${IMGS_DOMAIN},landing.google.com ${BOOK_TOC_URL}
# #
echo "Get working mode..."
MODE=${1:-} MODE=${1:-}
if [ "$MODE" != "docker" ];then if [ "$MODE" != "docker" ];then
@ -41,6 +45,7 @@ fi
# Add extension to files. # Add extension to files.
# That because `pandoc` cannot generate the right `mime type` without the extension. # That because `pandoc` cannot generate the right `mime type` without the extension.
# https://github.com/captn3m0/google-sre-ebook/issues/19 # https://github.com/captn3m0/google-sre-ebook/issues/19
echo "Fix images extension issue ..."
IMGS_FILES="$(ls html/${IMGS_DOMAIN}/*)" IMGS_FILES="$(ls html/${IMGS_DOMAIN}/*)"
for FILE_NAME_FULL in ${IMGS_FILES}; do for FILE_NAME_FULL in ${IMGS_FILES}; do
@ -50,17 +55,18 @@ for FILE_NAME_FULL in ${IMGS_FILES}; do
# Rename and replace file. # Rename and replace file.
mv "${FILE_NAME_FULL}" "${FILE_NAME_FULL}.${FILE_TYPE,,}" && mv "${FILE_NAME_FULL}" "${FILE_NAME_FULL}.${FILE_TYPE,,}" &&
grep -rl "${FILE_NAME_BASE}" ./html | xargs sed -i "s/${FILE_NAME_BASE}/${FILE_NAME_BASE}.${FILE_TYPE,,}/g" grep -rl -- "${FILE_NAME_BASE}" ./html | xargs sed -i -- "s/${FILE_NAME_BASE}/${FILE_NAME_BASE}.${FILE_TYPE,,}/g"
done done
# #
# Generate epub from html. # Generate epub from html.
echo "Generate book ..."
bundle exec ruby generate.rb bundle exec ruby generate.rb
pushd html/landing.google.com/sre/${BOOK_NAME}/toc pushd html/landing.google.com/sre/${BOOK_NAME}/toc
pandoc --from=html --to=epub \ pandoc --from=html --to=epub \
--output=../../../../../${BOOK_FILE}.epub \ --output=../../../../../${BOOK_FILE}.epub \
--epub-metadata=../../../../../metadata/${BOOK_NAME}.xml \ --epub-metadata=../../../../../metadata/${BOOK_NAME}.xml \
--epub-cover-image=../../../../../cover/${BOOK_NAME}.jpg \ --epub-cover-image=../../../../../cover/${BOOK_NAME}.jpg \
complete.html complete.html
popd popd
@ -73,7 +79,7 @@ done
# #
# If it works inside docker. # If it works inside docker.
if [ "$1"=="docker" ]; then if [ "$MODE" == "docker" ]; then
chown -v $(id -u):$(id -g) ${BOOK_FILE}.* chown -v $(id -u):$(id -g) ${BOOK_FILE}.*
mv -f ${BOOK_FILE}.* /output mv -f ${BOOK_FILE}.* /output
fi fi