Repository: etcd-io/etcd
File: scripts/genproto.sh (Shell)

Code before:
elif [ "$OS" == "darwin" ]; then
  echo "You are on Mac, running: brew install gnu-sed"
  brew install gnu-sed
  SED="/opt/homebrew/opt/gnu-sed/libexec/gnubin/sed"
else
  echo "Failed to find GNU sed as sed or gsed." >&2
  exit 1
fi

source ./scripts/test_lib.sh

if [[ $(protoc --version | cut -f2 -d' ') != "3.20.3" ]]; then
  echo "Could not find protoc 3.20.3, installing now..."

  arch=$(go env GOARCH)

  case ${arch} in
    "amd64") file="x86_64" ;;
    "arm64") file="aarch_64" ;;
    *)
      echo "Unsupported architecture: ${arch}"
      exit 255
      ;;
  esac

  download_file="protoc-3.20.3-linux-${file}.zip"
  if [ "$OS" == "darwin" ]; then
    # protoc-3.20.3 does not have pre-built binaries for darwin_arm64. Thanks to Rosetta, we could use x86_64 binary.
    download_file="protoc-3.20.3-osx-x86_64.zip"
  fi
  download_url="https://github.com/protocolbuffers/protobuf/releases/download/v3.20.3/${download_file}"
  echo "Running on ${OS} ${arch}. Downloading ${download_url}"
  mkdir -p bin
  wget ${download_url} && unzip -p ${download_file} bin/protoc > tmpFile && mv tmpFile bin/protoc
  rm ${download_file}
  chmod +x bin/protoc
  PATH=$PATH:$(pwd)/bin
  export PATH
  echo "Now running: $(protoc --version)"

fi

GOFAST_BIN=$(tool_get_bin github.com/gogo/protobuf/protoc-gen-gofast)
GRPC_GATEWAY_BIN=$(tool_get_bin github.com/grpc-ecosystem/grpc-gateway/v2/protoc-gen-grpc-gateway)
OPENAPIV2_BIN=$(tool_get_bin github.com/grpc-ecosystem/grpc-gateway/v2/protoc-gen-openapiv2)
GOGOPROTO_ROOT="$(tool_pkg_dir github.com/gogo/protobuf/proto)/.."
GRPC_GATEWAY_ROOT="$(tool_pkg_dir github.com/grpc-ecosystem/grpc-gateway/v2/protoc-gen-grpc-gateway)/.."
RAFT_ROOT="$(tool_pkg_dir go.etcd.io/raft/v3/raftpb)/.."
GOOGLEAPI_ROOT=$(mktemp -d -t 'googleapi.XXXXX')

readonly googleapi_commit=0adf469dcd7822bf5bc058a7b0217f5558a75643

Review comment (suggestion):
```suggestion
  protoc_download_file="protoc-3.20.3-linux-${file}.zip"
```

Code after:
elif [ "$OS" == "darwin" ]; then
  echo "You are on Mac, running: brew install gnu-sed"
  brew install gnu-sed
  SED="/opt/homebrew/opt/gnu-sed/libexec/gnubin/sed"
else
  echo "Failed to find GNU sed as sed or gsed." >&2
  exit 1
fi

source ./scripts/test_lib.sh

if [[ $(protoc --version | cut -f2 -d' ') != "3.20.3" ]]; then
  echo "Could not find protoc 3.20.3, installing now..."

  arch=$(go env GOARCH)

  case ${arch} in
    "amd64") file="x86_64" ;;
    "arm64") file="aarch_64" ;;
    *)
      echo "Unsupported architecture: ${arch}"
      exit 255
      ;;
  esac

  protoc_download_file="protoc-3.20.3-linux-${file}.zip"
  if [ "$OS" == "darwin" ]; then
    # protoc-3.20.3 does not have pre-built binaries for darwin_arm64. Thanks to Rosetta, we could use x86_64 binary.
    protoc_download_file="protoc-3.20.3-osx-x86_64.zip"
  fi
  download_url="https://github.com/protocolbuffers/protobuf/releases/download/v3.20.3/${protoc_download_file}"
  echo "Running on ${OS} ${arch}. Downloading ${protoc_download_file}"
  mkdir -p bin
  wget ${download_url} && unzip -p ${protoc_download_file} bin/protoc > tmpFile && mv tmpFile bin/protoc
  rm ${protoc_download_file}
  chmod +x bin/protoc
  PATH=$PATH:$(pwd)/bin
  export PATH
  echo "Now running: $(protoc --version)"

fi

GOFAST_BIN=$(tool_get_bin github.com/gogo/protobuf/protoc-gen-gofast)
GRPC_GATEWAY_BIN=$(tool_get_bin github.com/grpc-ecosystem/grpc-gateway/v2/protoc-gen-grpc-gateway)
OPENAPIV2_BIN=$(tool_get_bin github.com/grpc-ecosystem/grpc-gateway/v2/protoc-gen-openapiv2)
GOGOPROTO_ROOT="$(tool_pkg_dir github.com/gogo/protobuf/proto)/.."
GRPC_GATEWAY_ROOT="$(tool_pkg_dir github.com/grpc-ecosystem/grpc-gateway/v2/protoc-gen-grpc-gateway)/.."
RAFT_ROOT="$(tool_pkg_dir go.etcd.io/raft/v3/raftpb)/.."
GOOGLEAPI_ROOT=$(mktemp -d -t 'googleapi.XXXXX')

readonly googleapi_commit=0adf469dcd7822bf5bc058a7b0217f5558a75643