Skip to content

Commit

Permalink
Merge pull request #3 from HewlettPackard/macos-install
Browse files Browse the repository at this point in the history
Install script for MacOS/M1 and README update
  • Loading branch information
J0HNB0Y authored Jul 7, 2021
2 parents 4dba74a + 9eb96ca commit fa283b9
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 0 deletions.
19 changes: 19 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,22 @@ The above will install the latest available release. To install a specific relea
```shell
VERSION=v0.0.5 bash <(curl -sL https://raw.githubusercontent.com/HewlettPackard/terraform-provider-hpegl/main/tools/install-hpegl-provider.sh)
```

### MacOS

Before using the install script, install GNU grep via homebrew with `brew install grep`

**Please note: Running a terminal on Apple Silicon through Rosetta will return the wrong architecture for the machine, installing amd64 rather than arm64**

Use the script `tools/install-hpegl-provider-macos.sh` to automatically download and install hpegl provider:


```shell
bash <(curl -sL https://raw.githubusercontent.com/HewlettPackard/terraform-provider-hpegl/main/tools/install-hpegl-provider-macos.sh)
```

The above will install the latest available release. To install a specific release:

```shell
VERSION=v0.0.5 bash <(curl -sL https://raw.githubusercontent.com/HewlettPackard/terraform-provider-hpegl/main/tools/install-hpegl-provider-macos.sh)
```
38 changes: 38 additions & 0 deletions tools/install-hpegl-provider-macos.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
#!/usr/bin/env bash

set -e

os="darwin"

if [[ `uname -m` == 'x86_64' ]]
then
echo 'Intel Architecture detected'
arch="amd64"
elif [[ `uname -m` == 'arm64' ]]
then
echo 'Apple Silicon Architecture detected'
arch="arm64"
fi

repo="HewlettPackard/terraform-provider-hpegl"
macos_hpegl_dir="${HOME}/.terraform.d/plugins/registry.terraform.io/hewlettpackard/hpegl"

get_latest_release () {
local release_url="https://api.github.com/repos/${repo}/releases/latest"
curl -sL "$release_url" | ggrep -Po '"tag_name": "\K.*?(?=")'
}

download_and_extract () {
local dest_dir="${macos_hpegl_dir}/${version_number}/${os}_${arch}/"
local hpegl_zip="terraform-provider-hpegl_${version_number}_${os}_${arch}.zip"
local hpegl_dl_url="https://github.com/${repo}/releases/download/${VERSION}/${hpegl_zip}"

mkdir -p "$dest_dir" && cd "$dest_dir"
curl -sL "$hpegl_dl_url" -o "$hpegl_zip" && \
unzip -u "$hpegl_zip" && \
rm -f "$hpegl_zip"
}

VERSION=${VERSION:=$(get_latest_release)}
version_number=${VERSION//v}
download_and_extract

0 comments on commit fa283b9

Please sign in to comment.