2017-09-16 16:22:31 +00:00
|
|
|
#!/bin/bash
|
2018-12-20 17:53:37 +00:00
|
|
|
set -euo pipefail
|
|
|
|
IFS=$'\n\t'
|
2017-09-16 16:22:31 +00:00
|
|
|
|
2019-01-31 07:46:20 +00:00
|
|
|
# Vars.
|
|
|
|
export BOOK_NAME="sre-book"
|
|
|
|
export BOOK_NAME_FULL="Site Reliability Engineering"
|
|
|
|
BOOK_FILE="google-${BOOK_NAME}"
|
|
|
|
TOC_URL="https://landing.google.com/sre/${BOOK_NAME}/toc/index.html"
|
|
|
|
IMGS_DOMAIN="lh3.googleusercontent.com"
|
|
|
|
|
2018-12-20 17:53:37 +00:00
|
|
|
# Make sure that links are relative \
|
|
|
|
# # Remove the /sre/ directories
|
|
|
|
# Save stuff in html/ directory
|
|
|
|
# Do not create a landing.google.com directory
|
|
|
|
# Enable recursion, timestamping (--mirror)
|
|
|
|
# Images are hosted elsewhere, download them as well.
|
|
|
|
# We need to go up a level from /toc/ where we start
|
|
|
|
wget \
|
2019-01-31 07:46:20 +00:00
|
|
|
--convert-links \
|
2018-12-20 17:53:37 +00:00
|
|
|
--directory-prefix=html \
|
2019-01-31 07:46:20 +00:00
|
|
|
--page-requisites \
|
|
|
|
--adjust-extension \
|
|
|
|
--span-hosts \
|
|
|
|
--trust-server-names \
|
|
|
|
--backup-converted \
|
|
|
|
--mirror \
|
|
|
|
--no-verbose \
|
|
|
|
--recursive \
|
|
|
|
--domains=${IMGS_DOMAIN},landing.google.com ${TOC_URL}
|
2017-09-16 16:22:31 +00:00
|
|
|
|
2019-01-31 07:46:20 +00:00
|
|
|
#
|
2018-12-20 17:53:37 +00:00
|
|
|
MODE=${1:-}
|
2017-09-16 16:22:31 +00:00
|
|
|
|
2018-12-20 17:53:37 +00:00
|
|
|
if [ "$MODE" != "docker" ];then
|
2018-05-16 20:24:54 +00:00
|
|
|
bundle install
|
|
|
|
fi
|
|
|
|
|
2019-01-31 07:47:14 +00:00
|
|
|
# Add extension to files.
|
|
|
|
# That because `pandoc` cannot generate the right `mime type` without the extension.
|
|
|
|
# https://github.com/captn3m0/google-sre-ebook/issues/19
|
2019-01-31 10:01:32 +00:00
|
|
|
IMGS_FILES="$(ls html/${IMGS_DOMAIN}/*)"
|
2019-01-31 07:47:14 +00:00
|
|
|
for FILE_NAME_FULL in ${IMGS_FILES}; do
|
|
|
|
|
|
|
|
# Get file vars.
|
|
|
|
FILE_NAME_BASE="$(basename ${FILE_NAME_FULL})"
|
|
|
|
FILE_TYPE=$(file -b -- "${FILE_NAME_FULL}" | cut -f1 -d " ")
|
|
|
|
|
|
|
|
# Rename and replace file.
|
|
|
|
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"
|
|
|
|
|
|
|
|
done
|
|
|
|
|
2019-01-31 10:01:32 +00:00
|
|
|
bundle exec ruby generate.rb
|
|
|
|
pushd html/landing.google.com/sre/${BOOK_NAME}/toc
|
2019-01-31 09:53:27 +00:00
|
|
|
pandoc --from=html --to=epub \
|
|
|
|
--output=../../../../../${BOOK_FILE}.epub \
|
2019-01-31 09:55:03 +00:00
|
|
|
--epub-metadata=../../../../../${BOOK_NAME}.xml \
|
|
|
|
--epub-cover-image=../../../../../${BOOK_NAME}.jpg \
|
2019-01-17 13:44:58 +00:00
|
|
|
complete.html
|
2018-01-16 16:59:30 +00:00
|
|
|
popd
|
2018-05-16 20:24:54 +00:00
|
|
|
|
2019-01-31 07:46:20 +00:00
|
|
|
for EXTENSION in mobi pdf; do
|
|
|
|
ebook-convert ${BOOK_FILE}.epub ${BOOK_FILE}.${EXTENSION}
|
|
|
|
done
|
|
|
|
|
2018-05-16 20:24:54 +00:00
|
|
|
if [ "$1"=="docker" ]; then
|
2019-01-31 07:46:20 +00:00
|
|
|
chown -v $(id -u):$(id -g) ${BOOK_FILE}.*
|
|
|
|
mv -f ${BOOK_FILE}.* /output
|
2018-05-16 20:24:54 +00:00
|
|
|
fi
|