From b17c1e6b82309105ea6dad8973d8c05120affd07 Mon Sep 17 00:00:00 2001 From: Ahmet Alp Balkan Date: Wed, 19 Apr 2017 14:35:10 -0700 Subject: [PATCH] update-imported-docs.sh script improvements (#3446) - avoiding cloning the full history of k8s repo, there doesn't seem to be any difference (--depth=1 gives the same result and fetched branches are not used in this script) - quoting around variables and add '--' to some commands to separate positional arguments - using subshells instead of pushd/popd stuff, easier to read IMO - added 'set -o errexit', couldn't add 'set -o pipefail'. For some reason when I enable pipefail, it produces a vastly different output but I don't see any errors in the output. Signed-off-by: Ahmet Alp Balkan --- update-imported-docs.sh | 108 ++++++++++++++++++++-------------------- 1 file changed, 53 insertions(+), 55 deletions(-) diff --git a/update-imported-docs.sh b/update-imported-docs.sh index 93491543d3..5187559085 100755 --- a/update-imported-docs.sh +++ b/update-imported-docs.sh @@ -1,4 +1,6 @@ #!/bin/bash +set -o errexit + # Uncomment this to see the commands as they are run # set -x @@ -36,30 +38,29 @@ function process_api_ref_docs { APIREFPATH=docs/api-reference KUBECTLPATH=docs/user-guide/kubectl TMPDIR=/tmp/update_docs -TMPAPIREFDIR=${TMPDIR}'/api_ref' -TMPKUBECTLDIR=${TMPDIR}'/kubectl' +TMPAPIREFDIR="${TMPDIR}/api_ref" +TMPKUBECTLDIR="${TMPDIR}/kubectl" -rm -rf ${TMPDIR} -mkdir ${TMPDIR} -mkdir ${TMPAPIREFDIR} -mkdir ${TMPKUBECTLDIR} +rm -rf -- "${TMPDIR}" +mkdir -p -- "${TMPAPIREFDIR}" "${TMPKUBECTLDIR}" -APIREFSRCDIR=${APIREFPATH}'/v'${OLDVERSION} -APIREFDESDIR=${TMPAPIREFDIR}'/v'${OLDVERSION} -mv ${APIREFSRCDIR} ${APIREFDESDIR} -KUBECTLSRCDIR=${KUBECTLPATH}'/v'${OLDVERSION} -KUBECTLDESDIR=${TMPKUBECTLDIR}'/v'${OLDVERSION} -mv ${KUBECTLSRCDIR} ${KUBECTLDESDIR} +APIREFSRCDIR="${APIREFPATH}/v${OLDVERSION}" +APIREFDESDIR="${TMPAPIREFDIR}/v${OLDVERSION}" +mv -- "${APIREFSRCDIR}" "${APIREFDESDIR}" +KUBECTLSRCDIR="${KUBECTLPATH}/v${OLDVERSION}" +KUBECTLDESDIR="${TMPKUBECTLDIR}/v${OLDVERSION}" +mv -- "${KUBECTLSRCDIR}" "${KUBECTLDESDIR}" -git clone --depth=1 -b release-$VERSION https://github.com/kubernetes/kubernetes.git k8s -cd k8s -git remote add upstream https://github.com/kubernetes/kubernetes.git -git fetch upstream -hack/generate-docs.sh -cd .. +K8SREPO=k8s +( + git clone --depth=1 -b release-$VERSION https://github.com/kubernetes/kubernetes.git "${K8SREPO}" + cd "${K8SREPO}" + hack/generate-docs.sh +) -rm -rf _includes/v$VERSION -mkdir _includes/v$VERSION + +rm -rf "_includes/v$VERSION" +mkdir "_includes/v$VERSION" # batch fetches while read line || [[ -n ${line} ]]; do @@ -67,46 +68,46 @@ while read line || [[ -n ${line} ]]; do if [ "${myarray[1]}" = "path" ]; then TARGET="${myarray[2]}" CLEARPATH="${TARGET}" - K8SSOURCE='k8s/'${TARGET} + K8SSOURCE="${K8SREPO}/${TARGET}" DESTINATION=${TARGET%/*} - rm -rf "${CLEARPATH}" - yes | cp -rf "${K8SSOURCE}" "${DESTINATION}" + rm -rf -- "${CLEARPATH}" + yes | cp -rf -- "${K8SSOURCE}" "${DESTINATION}" fi if [ "${myarray[1]}" = "changedpath" ]; then SRC="${myarray[2]}" DESTINATION="${myarray[3]}" - echo "mv -f ${SRC} ${DESTINATION}" - yes | cp -rf "${SRC}" "${DESTINATION}" + echo "cp -rf -- ${SRC} ${DESTINATION}" + yes | cp -rf -- "${SRC}" "${DESTINATION}" fi if [ "${myarray[1]}" = "copypath" ]; then K8SSOURCE="${myarray[2]}" DESTINATION="${myarray[3]}" - echo "yes | cp -rf ${K8SSOURCE} ${DESTINATION}" - yes | cp -rf "${K8SSOURCE}" "${DESTINATION}" + echo "yes | cp -rf -- ${K8SSOURCE} ${DESTINATION}" + yes | cp -rf -- "${K8SSOURCE}" "${DESTINATION}" fi done <_data/overrides.yml # refdoc munging -pushd . -cd _includes/v$VERSION +( + cd _includes/v$VERSION # These are included in other files, so strip the DOCTYPE find . -name '*.html' -type f -exec sed -i -e "s///g" {} \; # Format html find . -name '*.html' -type f -exec sed -i -e '/