diff --git a/tasks/download-boshio-stemcells/task.sh b/tasks/download-boshio-stemcells/task.sh index 3ebf40fd3..94fc214f3 100755 --- a/tasks/download-boshio-stemcells/task.sh +++ b/tasks/download-boshio-stemcells/task.sh @@ -17,31 +17,43 @@ set -eu # limitations under the License. function main() { - if [ -z "$API_TOKEN" ]; then abort "The required env var API_TOKEN was not set for pivnet"; fi - local cwd=$PWD local download_dir="${cwd}/stemcells" local diag_report="${cwd}/diagnostic-report/exported-diagnostic-report.json" - cp ${cwd}/pivnet-stemcells/* ${download_dir} + cp -a "${cwd}/pivnet-stemcells/." "${download_dir}" # get the deduplicated stemcell filename for each deployed release (skipping p-bosh) local bosh_io_stemcells=($( (jq --raw-output '.added_products.deployed[] | select (.name | contains("p-bosh") | not) | select (.stemcell | contains("ubuntu") | not) |.stemcell' | \ sort -u) < "$diag_report")) if [ ${#bosh_io_stemcells[@]} -eq 0 ]; then - echo "No installed products found that require a ubuntu stemcell" + echo "No installed products found that require a non-ubuntu stemcell" exit 0 fi mkdir -p "${download_dir}" - # extract the stemcell version from the filename, e.g. 3312.21, and download the file from pivnet + # extract the stemcell version and type from the filename and download the stemcell from bosh.io for stemcell in "${bosh_io_stemcells[@]}"; do - local version=$(echo "$stemcell" | grep -Eo "[0-9]+\.[0-9]+") - local stemcell_type=bosh-$(ruby -e "puts '$stemcell'.split('$version-')[1].split('.')[0]") + echo "${stemcell}" + + if [[ $stemcell =~ ([0-9]+\.[0-9]+) ]]; then + local version="${BASH_REMATCH[1]}" + else + abort "Couldn't find a stemcell version" + fi + + if [[ $stemcell =~ $version-(.+).tgz ]]; then + local stemcell_type="bosh-${BASH_REMATCH[1]}" + else + abort "Couldn't find a stemcell type" + fi + + echo "${stemcell_type}" + echo "${version}" - curl -L -J -o ${download_dir}/${stemcell} https://bosh.io/d/stemcells/${stemcell_type}?v=${version} + wget -O "${download_dir}/${stemcell}" "https://bosh.io/d/stemcells/${stemcell_type}?v=${version}" done } diff --git a/tasks/download-boshio-stemcells/task.yml b/tasks/download-boshio-stemcells/task.yml index a8064c8ee..b5eeac390 100644 --- a/tasks/download-boshio-stemcells/task.yml +++ b/tasks/download-boshio-stemcells/task.yml @@ -27,8 +27,5 @@ inputs: outputs: - name: stemcells -params: - API_TOKEN: - run: path: pcf-pipelines/tasks/download-boshio-stemcells/task.sh