parameters:
  - name: enableDownload
    type: boolean
    default: true
  - name: packages
    type: object
    default:
      - name: name
        default: ""  
      - name: download_location
        default: ""
      - name: unpack_location
        default: "$(Build.BinariesDirectory)"    
      - name: url
        default: ""
      - name: archive
        default: "zip"   
      - name: clean
        type: boolean
        default: true


jobs:
  - job: DownloadBinaries
    displayName: Download Build Binaries
    steps:
      - checkout: none
      - ${{ each package in parameters.packages }}:
        - bash: |    
            curl -Lk -o ${{package.download_location}} \
                  ${{package.url}}
          displayName: 'Download ${{package.name}}'
        - ${{ if eq(package.archive,'zip') }}:
          - bash: |    
              echo Unzipping to ${{package.unpack_location}}
              unzip   -qq -d ${{package.unpack_location}} ${{package.download_location}}
              chmod -R u+x ${{package.unpack_location}}
            displayName: 'Unzip ${{package.name}}'

        - ${{ if coalesce(package.clean,true) }}:
          - bash: |    
              rm -rf ${{package.download_location}}

              ls -ltr $(Build.BinariesDirectory)
            displayName: 'Clean ${{package.name}}'             

parameters:
  - name: enableDownload
    type: boolean
    default: true
  - name: packages
    type: object
    default:
      - name: name
        default: ""  
      - name: download_location
        default: ""
      - name: unpack_location
        default: "$(Build.BinariesDirectory)"    
      - name: url
        default: ""
      - name: archive
        default: "zip"   
      - name: clean
        type: boolean
        default: true


jobs:
  - job: DownloadBinaries
    displayName: Download Build Binaries
    steps:
      - checkout: none
      - ${{ each package in parameters.packages }}:
        - bash: |    
            curl -Lk -o ${{package.download_location}} \
                  ${{package.url}}
          displayName: 'Download ${{package.name}}'
        - ${{ if eq(package.archive,'zip') }}:
          - bash: |    
              echo Unzipping to ${{package.unpack_location}}
              unzip   -qq -d ${{package.unpack_location}} ${{package.download_location}}
              chmod -R u+x ${{package.unpack_location}}

              ls -ltr ${{package.download_location}}

            displayName: 'Unzip ${{package.name}}'

        - ${{ if coalesce(package.clean,true) }}:
          - bash: |    
              rm -rf ${{package.download_location}}
            displayName: 'Clean ${{package.name}}'             

Rearrange to allow binaries been kept
Rearrange to allow binaries been kept
