Last active
January 16, 2026 14:33
-
-
Save adamruzicka/9873d57588bfc84a2afd39df6a828971 to your computer and use it in GitHub Desktop.
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 | |
| # Example use: | |
| # ./doc-check.sh https://docs.redhat.com/en/documentation/red_hat_satellite/6.18 html-single | |
| DOC_URL="$1" | |
| VARIANT="$2" | |
| # Example URL: https://docs.redhat.com/en/documentation/red_hat_satellite/6.18/\$VARIANT/administering_red_hat_satellite/index#Using_the_Project_Content_Dashboard_admin | |
| # Guide: administering_red_hat_satellite | |
| # Section: index | |
| # Anchor: Using_the_Project_Content_Dashboard_admin | |
| # Assumptions: | |
| # - if VARIANT is html-single, the section does not matter | |
| # - if the guide is wrong, docs site will return 404 which will count as a a failure | |
| # - if the anchor is wrong, there won't be any element on the page which would have it as it as an id attribute | |
| # DOC_BASE=https://docs.redhat.com/en/documentation/red_hat_satellite/6.18/$VARIANT | |
| DOC_BASE=${DOC_URL}/$VARIANT | |
| report_failure() { | |
| kind="$1" | |
| element="$2" | |
| path="$3" | |
| echo | |
| echo "Failed to locate $kind '$element' in $path" | |
| } | |
| TOTAL=0 | |
| SUCCESS=0 | |
| FAILURE=0 | |
| while read DOC_PATH; do | |
| TMPFILE="$(mktemp)" | |
| if curl -L "${DOC_BASE}${DOC_PATH}" -q --fail -s >"$TMPFILE"; then | |
| if echo "$DOC_PATH" | grep -q '#' ; then | |
| ANCHOR="$(echo "$DOC_PATH" | cut -d '#' -f 2)" | |
| if grep -q "id=\"$ANCHOR\"" "$TMPFILE"; then | |
| echo -n '.' | |
| SUCCESS=$((SUCCESS + 1)) | |
| else | |
| report_failure anchor "$ANCHOR" "${DOC_BASE}${DOC_PATH}" | |
| FAILURE=$((FAILURE + 1)) | |
| fi | |
| else | |
| echo -n '.' | |
| SUCCESS=$((SUCCESS + 1)) | |
| fi | |
| else | |
| report_failure guide "$(echo "$DOC_PATH" | awk -F / '{ print $2 "/" $3 }')" "${DOC_BASE}${DOC_PATH}" | |
| FAILURE=$((FAILURE + 1)) | |
| fi | |
| TOTAL=$((TOTAL + 1)) | |
| rm "$TMPFILE" | |
| done < <(grep -Po '#{ForemanThemeSatellite.documentation_root}[^"]+' lib/foreman_theme_satellite/documentation.rb | sed 's|#{ForemanThemeSatellite.documentation_root}||') | |
| echo | |
| echo "Checked $TOTAL links, $SUCCESS ok, $FAILURE broken" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment