diff --git a/hack/lib/util.sh b/hack/lib/util.sh index 980f77dda5f..60a9fac0471 100644 --- a/hack/lib/util.sh +++ b/hack/lib/util.sh @@ -96,6 +96,18 @@ kube::util::host_platform() { echo "${host_os}/${host_arch}" } +kube::util::find-binary() { + local lookfor="${1}" + local host_platform="$(kube::util::host_platform)" + local locations=( + "${KUBE_ROOT}/_output/dockerized/bin/${host_platform}/${lookfor}" + "${KUBE_ROOT}/_output/local/bin/${host_platform}/${lookfor}" + "${KUBE_ROOT}/platforms/${host_platform}/${lookfor}" + ) + local bin=$( (ls -t "${locations[@]}" 2>/dev/null || true) | head -1 ) + echo -n "${bin}" +} + # Wait for background jobs to finish. Return with # an error status if any of the jobs failed. kube::util::wait-for-jobs() { diff --git a/hack/run-gendocs.sh b/hack/run-gendocs.sh index 2676714eaa7..3c922788a0e 100755 --- a/hack/run-gendocs.sh +++ b/hack/run-gendocs.sh @@ -30,61 +30,10 @@ get_absolute_dirname() { echo "$(cd "$(dirname "$1")" && pwd)" } -# Detect the OS name/arch so that we can find our binary -case "$(uname -s)" in - Darwin) - host_os=darwin - ;; - Linux) - host_os=linux - ;; - *) - echo "Unsupported host OS. Must be Linux or Mac OS X." >&2 - exit 1 - ;; -esac - -case "$(uname -m)" in - x86_64*) - host_arch=amd64 - ;; - i?86_64*) - host_arch=amd64 - ;; - amd64*) - host_arch=amd64 - ;; - arm*) - host_arch=arm - ;; - i?86*) - host_arch=x86 - ;; - *) - echo "Unsupported host arch. Must be x86_64, 386 or arm." >&2 - exit 1 - ;; -esac - # Find binary -locations=( - "${KUBE_ROOT}/_output/dockerized/bin/${host_os}/${host_arch}/gendocs" - "${KUBE_ROOT}/_output/local/bin/${host_os}/${host_arch}/gendocs" - "${KUBE_ROOT}/platforms/${host_os}/${host_arch}/gendocs" -) -gendocs=$( (ls -t "${locations[@]}" 2>/dev/null || true) | head -1 ) -locations=( - "${KUBE_ROOT}/_output/dockerized/bin/${host_os}/${host_arch}/genman" - "${KUBE_ROOT}/_output/local/bin/${host_os}/${host_arch}/genman" - "${KUBE_ROOT}/platforms/${host_os}/${host_arch}/genman" -) -genman=$( (ls -t "${locations[@]}" 2>/dev/null || true) | head -1 ) -locations=( - "${KUBE_ROOT}/_output/dockerized/bin/${host_os}/${host_arch}/genbashcomp" - "${KUBE_ROOT}/_output/local/bin/${host_os}/${host_arch}/genbashcomp" - "${KUBE_ROOT}/platforms/${host_os}/${host_arch}/genbashcomp" -) -genbashcomp=$( (ls -t "${locations[@]}" 2>/dev/null || true) | head -1 ) +gendocs=$(kube::util::find-binary "gendocs") +genman=$(kube::util::find-binary "genman") +genbashcomp=$(kube::util::find-binary "genbashcomp") if [[ ! -x "$gendocs" || ! -x "$genman" || ! -x "$genbashcomp" ]]; then { diff --git a/hack/verify-gendocs.sh b/hack/verify-gendocs.sh index a663a2ceafc..77c1a79c471 100755 --- a/hack/verify-gendocs.sh +++ b/hack/verify-gendocs.sh @@ -30,63 +30,9 @@ get_absolute_dirname() { echo "$(cd "$(dirname "$1")" && pwd)" } -# Detect the OS name/arch so that we can find our binary -case "$(uname -s)" in - Darwin) - host_os=darwin - ;; - Linux) - host_os=linux - ;; - *) - echo "Unsupported host OS. Must be Linux or Mac OS X." >&2 - exit 1 - ;; -esac - -case "$(uname -m)" in - x86_64*) - host_arch=amd64 - ;; - i?86_64*) - host_arch=amd64 - ;; - amd64*) - host_arch=amd64 - ;; - arm*) - host_arch=arm - ;; - i?86*) - host_arch=x86 - ;; - *) - echo "Unsupported host arch. Must be x86_64, 386 or arm." >&2 - exit 1 - ;; -esac - -# Find binary -locations=( - "${KUBE_ROOT}/_output/dockerized/bin/${host_os}/${host_arch}/gendocs" - "${KUBE_ROOT}/_output/local/bin/${host_os}/${host_arch}/gendocs" - "${KUBE_ROOT}/platforms/${host_os}/${host_arch}/gendocs" -) -gendocs=$( (ls -t "${locations[@]}" 2>/dev/null || true) | head -1 ) - -locations=( - "${KUBE_ROOT}/_output/dockerized/bin/${host_os}/${host_arch}/genman" - "${KUBE_ROOT}/_output/local/bin/${host_os}/${host_arch}/genman" - "${KUBE_ROOT}/platforms/${host_os}/${host_arch}/genman" -) -genman=$( (ls -t "${locations[@]}" 2>/dev/null || true) | head -1 ) - -locations=( - "${KUBE_ROOT}/_output/dockerized/bin/${host_os}/${host_arch}/genbashcomp" - "${KUBE_ROOT}/_output/local/bin/${host_os}/${host_arch}/genbashcomp" - "${KUBE_ROOT}/platforms/${host_os}/${host_arch}/genbashcomp" -) -genbashcomp=$( (ls -t "${locations[@]}" 2>/dev/null || true) | head -1 ) +gendocs=$(kube::util::find-binary "gendocs") +genman=$(kube::util::find-binary "genman") +genbashcomp=$(kube::util::find-binary "genbashcomp") if [[ ! -x "$gendocs" || ! -x "$genman" || ! -x "$genbashcomp" ]]; then {