Last active
March 6, 2020 06:47
-
-
Save chusiang/6673e2af5981975b5cec835d0d6cbd63 to your computer and use it in GitHub Desktop.
A script for auto retry the `gitbook build` command.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# ============================================================================= | |
# Author: Chu-Siang Lai / chusiang.lai (at) gmail.com | |
# Filename: retry_gitbook_build.sh | |
# Modified: 2020-03-04 15:47 | |
# Description: | |
# As the gitbook maintainer, I want to auto retry the "gitbook build" tasks, | |
# so that we can reduce a lot of manual retry actions. | |
# ============================================================================= | |
# Help. | |
if [[ "$1" == "-h" || "$1" == "--help" ]]; then | |
echo 'Usage: retry_gitbook_build.sh "<build_type>"' | |
echo | |
echo '> The gitbook-cli support the html, epub, mobi and pdf types.' | |
echo | |
echo 'Example:' | |
echo ' retry_gitbook_build.sh' | |
echo ' retry_gitbook_build.sh html' | |
echo ' retry_gitbook_build.sh epub' | |
exit 0 | |
fi | |
echo | |
# Define build type. | |
BUILD_TYPE=$1 | |
BUILD_CMD="gitbook build" | |
if [[ "${BUILD_TYPE}" == "" || "${BUILD_TYPE}" == "html" ]]; then | |
echo "==> Command: gitbook build" | |
BUILD_TYPE="html" | |
mkdir -p _book/ | |
echo | |
elif [[ ${BUILD_TYPE} == 'epub' || ${BUILD_TYPE} == 'mobi' || ${BUILD_TYPE} == 'pdf' ]]; then | |
echo "==> Command: gitbook build ${BUILD_TYPE}" | |
BUILD_CMD="gitbook ${BUILD_TYPE}" | |
mkdir -p ${BUILD_TYPE}/ | |
echo | |
else | |
echo "==> Something wrong, please check the args." | |
echo | |
exit | |
fi | |
# Loop for retry. | |
NUM="0" | |
while true; do | |
echo "===> Run \"$BUILD_CMD\" .." | |
echo $BUILD_CMD | sh | |
if (("$?" == "0")); then | |
echo | |
echo "==> DONE. Retry $NUM time. Congratulation !" | |
echo | |
break | |
else | |
NUM=$[$NUM + 1] | |
echo | |
echo "===> Build failed, retry $NUM." | |
sleep 10 | |
fi | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment