# Copyright (c) HashiCorp, Inc.
# SPDX-License-Identifier: BUSL-1.1

name: install-vault
inputs:
  version:
    required: false
    default: 1.2.4
runs:
  using: composite
  steps:
  - name: Install Vault
    run: |-
      set -x

      case "${OSTYPE}" in
        linux*)  os="linux" ;;
        darwin*) os="darwin" ;;
        msys*)   os="windows" ;;
        *)       echo "unknown os: ${OSTYPE}"; exit 1 ;;
      esac

      curl -SL --fail -o /tmp/vault.zip https://releases.hashicorp.com/vault/"${{ inputs.version }}"/vault_"${{ inputs.version }}"_"${os}"_amd64.zip

      if [[ "${os}" != "windows" ]]; then
        sudo unzip -d /usr/local/bin /tmp/vault.zip
        rm -rf /tmp/vault*
      else
        rm -rf c:\Windows\vault.exe
        unzip /tmp/vault.zip -d "/c/Windows"
        rm -rf /tmp/vault*
      fi
    shell: bash
