#!/bin/bash # Converts the README to the README in the signalfx-agent directory of the # integrations repo, using the special structure that signalview parses to # display in the integration tile. set -euo pipefail SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" AGENT_REPO_BASE="$SCRIPT_DIR/../.." INTEGRATIONS_REPO_PATH=${INTEGRATIONS_REPO_PATH:-$SCRIPT_DIR/../../../integrations} . $SCRIPT_DIR/common.sh to_upper_case() { tr '[:lower:]' '[:upper:]' } [ -d $INTEGRATIONS_REPO_PATH ] || \ (echo "integrations repo dir cannot be found at $INTEGRATIONS_REPO_PATH; please set \$INTEGRATIONS_REPO_PATH" && exit 1) # Convert all relative links to be absolute to the Github repo url. convert_relative_links() { sed -E -e 's@\]\(\./([a-zA-Z].*)\)@](https://github.com/signalfx/signalfx-agent/tree/master/\1)@' } uppercase_l2_headers() { perl -p -e 's/^## (.*)$/## \U$1/' } increase_all_header_level() { perl -p -e 's/^(#+) /$1# /' } strip_toc() { sed -Ee '/^ - \[.*\](.*)$/d' } convert_link_target() { perl -00p -e 's/\[(.+?)\]\((http.+?)\)/\1<\/a>/gsm' } write_doc() { printf "# ![](https://github.com/signalfx/integrations/blob/master/signalfx-agent/img/integration_smartagent.png) SignalFx Smart Agent\n\n" printf "\n\n" cat <the Github repo for the source code along with more extensive documentation. EOH cat $AGENT_REPO_BASE/README.md | \ strip_toc | \ use_marketing_name | \ sed -e '/# SignalFx SmartAgent/d' | \ sed -e '/GoDoc/d' | \ sed -e '/CircleCI/d' | \ sed -e '/## Concepts/d' | \ uppercase_l2_headers | \ increase_all_header_level | \ convert_relative_links | \ convert_link_target } write_doc | tee $INTEGRATIONS_REPO_PATH/signalfx-agent/README.md