From e84622832258152b94e49ffdf388a4cc13e5493e Mon Sep 17 00:00:00 2001 From: Sebastien Douheret Date: Thu, 19 Oct 2017 14:14:56 +0200 Subject: Automatically install gitbook node modules when needed Signed-off-by: Sebastien Douheret --- gendocs.sh | 27 ++++++++++++++++----------- 1 file changed, 16 insertions(+), 11 deletions(-) diff --git a/gendocs.sh b/gendocs.sh index 83c5b93..6c84ce2 100755 --- a/gendocs.sh +++ b/gendocs.sh @@ -1,10 +1,11 @@ #!/bin/bash +# shellcheck disable=SC2086 OUTFILENAME="XDS_UsersGuide" -SCRIPT=$(basename $BASH_SOURCE) +SCRIPT=$(basename "${BASH_SOURCE[@]}") -VERSION=$(grep '"version":' $(dirname $BASH_SOURCE)/book.json | cut -d'"' -f 4) +VERSION=$(grep '"version":' "$(dirname "${BASH_SOURCE[@]}")/book.json" | cut -d'"' -f 4) [ "$VERSION" != "" ] && OUTFILENAME="${OUTFILENAME}_v${VERSION}" @@ -38,11 +39,11 @@ DO_ACTION="" OUT_DIR=./build ARGS="" -[[ $? != 0 ]] && usage +[ $# = 0 ] && usage while [ $# -gt 0 ]; do case "$1" in --debug) DEBUG_FLAG="--log=debug --debug";; - -d|--dry) DRY=echo;; + -d|--dry) DRY="echo";; -h|--help) usage;; pdf | serve | doxygen) DO_ACTION=$1;; --) shift; ARGS="$ARGS $*"; break;; @@ -51,27 +52,31 @@ while [ $# -gt 0 ]; do shift done -cd $(dirname $0) -ROOTDIR=`pwd -P` +cd "$(dirname "$0")" || exit 1 +ROOTDIR=$(pwd -P) # Create out dir if needed [ -d $OUT_DIR ] || mkdir -p $OUT_DIR -if [ "$DO_ACTION" = "pdf" -o "$DO_ACTION" = "serve" ]; then - GITBOOK=`which gitbook` +if [ "$DO_ACTION" = "pdf" ] || [ "$DO_ACTION" = "serve" ]; then + + GITBOOK=$(which gitbook) [ "$?" = "1" ] && { echo "You must install gitbook first, using: sudo npm install -g gitbook-cli"; exit 1; } - EBCONV=`which ebook-convert` + which ebook-convert > /dev/null 2>&1 [ "$?" = "1" ] && { echo "You must install calibre first, using: 'sudo apt install calibre' or refer to https://calibre-ebook.com/download"; exit 1; } + [ ! -d "$ROOTDIR/node_modules" ] && $GITBOOK install + if [ "$DO_ACTION" = "pdf" ]; then # Update cover when book.json has been changed [[ $ROOTDIR/book.json -nt $ROOTDIR/docs/cover.jpg ]] && { echo "Update cover files"; $ROOTDIR/docs/resources/make_cover.sh || exit 1; } OUTFILE=$OUT_DIR/$OUTFILENAME.pdf - $DRY $GITBOOK pdf $ROOTDIR $OUTFILE $DEBUG_FLAG $ARGS - [ "$?" = "0" ] && echo "PDF has been successfully generated in $OUTFILE" + if $DRY $GITBOOK pdf $ROOTDIR $OUTFILE $DEBUG_FLAG $ARGS; then + echo "PDF has been successfully generated in $OUTFILE" + fi else $DRY $GITBOOK serve $DEBUG_FLAG $ARGS fi -- cgit 1.2.3-korg