publish-docs.sh 1.0 KB

123456789101112131415161718192021222324252627282930313233343536
  1. #!/bin/bash
  2. FROM=build/site
  3. HOST="$1"
  4. HOST_PATH="$2"
  5. SSH_PRIVATE_KEY="$3"
  6. SSH_KNOWN_HOST="$4"
  7. SSH_PRIVATE_KEY_PATH="$HOME/.ssh/${GITHUB_REPOSITORY:-publish-docs}"
  8. if [ "$#" -ne 4 ]; then
  9. echo -e "not enough arguments USAGE:\n\n$0 \$HOST \$HOST_PATH \$SSH_PRIVATE_KEY \$SSH_KNOWN_HOST\n\n" >&2
  10. exit 1
  11. fi
  12. (
  13. set -e
  14. set -f
  15. install -m 600 -D /dev/null "$SSH_PRIVATE_KEY_PATH"
  16. echo "$SSH_PRIVATE_KEY" > "$SSH_PRIVATE_KEY_PATH"
  17. echo "$SSH_KNOWN_HOST" > ~/.ssh/known_hosts
  18. RSYNC_OPTS='-avz --delete'
  19. if [ -f .full-build ]; then
  20. unlink .full-build
  21. BUILD_REFNAME=
  22. fi
  23. if [ -n "$BUILD_REFNAME" ]; then
  24. RSYNC_OPTS="-c $RSYNC_OPTS$(find $FROM -mindepth 1 -maxdepth 1 \! -name 404.html \! -name '.*' -type f -printf ' --include /%P')"
  25. RSYNC_OPTS="$RSYNC_OPTS$(find $FROM -mindepth 1 -maxdepth 1 -type d \! -name _ -printf ' --include /%P --include /%P/**') --exclude **"
  26. fi
  27. rsync $RSYNC_OPTS -e "ssh -i $SSH_PRIVATE_KEY_PATH" $FROM/ "$HOST:$HOST_PATH"
  28. )
  29. exit_code=$?
  30. rm -f "$SSH_PRIVATE_KEY_PATH"
  31. exit $exit_code