#!/usr/bin/env bash echo "Repository name : $DRONE_REPO_NAME" echo "Repository owner: $DRONE_REPO_OWNER" echo "Generating and deploying documentation for user $DRONE_REPO_OWNER and repository $DRONE_REPO_NAME" help() { cat << EOF usage: $0 -d --dir [dir] path to the documentation root - required -t --type [docusaurus|doxygen|swagger] type of documentation generator to use. - required -l --dest [dir] path to where to put the documentation outputs in your CodeDoc space - optional !! cannot be absolute !! EOF exit 1 } DEST="" while [ "$1" ]; do case "$1" in "-l" | "--dest") DEST="$2" shift 1 ;; "-d" | "--dir") DOC_DIR="$2" shift 1 ;; "-t" | "--type") GENERATOR_NAME="$2" GENERATOR_SCRIPT="/generators/$GENERATOR_NAME.sh" if [ ! -f "$GENERATOR_SCRIPT" ]; then echo "unknown generator type, please enter a valid generator ($(ls /generators | cut -d "." -f1 | tr "\n" " "))" >&2 exit 1 fi shift 1 ;; *) echo "unknown option $1" >&2 exit 1 ;; esac shift done if [ ! "$GENERATOR_SCRIPT" ] || [ ! "$DOC_DIR" ] || echo "$DEST" | grep -E -q "^[\/].*"; then echo "$0: bad usage" >&2 help fi . "$GENERATOR_SCRIPT" generate "$DOC_DIR" # generates doc using the wanted generator SERVER_TARGET="/usr/share/nginx/html/$DRONE_REPO_OWNER/$DRONE_REPO_NAME/$DEST" # launches rsync in archive, verbose and compression mode # creates target directory ($SERVER_TARGET) on server # then sends generated files int the server directory rsync -avz \ --rsync-path="mkdir -p \"$SERVER_TARGET\" && rsync" \ -e "ssh -o StrictHostKeyChecking=no" \ --delete "$GEN_PATH"/* root@nginx:"$SERVER_TARGET"