From c5c1ad4fb8d16b3e8fe5f4f8b99b2824072abe71 Mon Sep 17 00:00:00 2001 From: evitalis Date: Tue, 10 Dec 2019 09:34:03 -0600 Subject: [PATCH] Make docs testing_formatter script more portable (#65112) * Make script more portable sha1sum is a Linux only command. Test for the command and if not found use sha1 instead for portability. Avoid patches on BSD and Mac systems. --- docs/bin/testing_formatter.sh | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/docs/bin/testing_formatter.sh b/docs/bin/testing_formatter.sh index 8db81bf030d..5e3781b4945 100755 --- a/docs/bin/testing_formatter.sh +++ b/docs/bin/testing_formatter.sh @@ -1,4 +1,4 @@ -#!/bin/bash -eu +#!/bin/sh FILENAME=../docsite/rst/dev_guide/testing/sanity/index.rst @@ -20,7 +20,21 @@ $(for test in $(../../bin/ansible-test sanity --list-tests --allow-disabled); do EOF +# By default use sha1sum which exists on Linux, if not present select the correct binary +# based on platform defaults +SHA_CMD="sha1sum" +if ! which ${SHA_CMD} > /dev/null 2>&1; then + if which sha1 > /dev/null 2>&1; then + SHA_CMD="sha1" + elif which shasum > /dev/null 2>&1; then + SHA_CMD="shasum" + else + # exit early with an error if no hashing binary can be found since it is required later + exit 1 + fi +fi + # Put file into place if it has changed -if [ "$(sha1sum <$FILENAME)" != "$(sha1sum <$FILENAME.new)" ]; then +if [ "$(${SHA_CMD} <$FILENAME)" != "$(${SHA_CMD} <$FILENAME.new)" ]; then mv -f $FILENAME.new $FILENAME fi