Skip to content

Commit

Permalink
Adds support to install on M1 Macbooks (#297)
Browse files Browse the repository at this point in the history
Signed-off-by: Rich Ehrhardt <[email protected]>

Signed-off-by: Rich Ehrhardt <[email protected]>
  • Loading branch information
rich-ehrhardt authored Jan 18, 2023
1 parent 20642fa commit 2ed721c
Show file tree
Hide file tree
Showing 2 changed files with 66 additions and 4 deletions.
25 changes: 23 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ Library and CLI used to generate Infrastructure as Code installable components c

## CLI Usage

### Installation
### Installation (non-M1 Macbook)

To install the latest version of iascable into `/usr/local/bin`, run the following:

Expand All @@ -18,7 +18,28 @@ If you would like to install a different version of the CLI and/or put it in a d
curl -sL https://iascable.cloudnativetoolkit.dev/install.sh | RELEASE=2.15.1 DEST_DIR=~/bin sh
```

#### Install beta version
### Installation on M1 Macbook
The M1 Macbook version will install the AMD64 binary and requires Rosetta to be installed. If you do not have Rosetta installed, see [this](https://support.apple.com/en-us/HT211861) link.

To install the latest version of iascable into `/usr/local/bin`, as above for non-M1 Macbooks, however add a sudo to write to /usr/local/bin as follows:

```shell
curl -sL https://iascable.cloudnativetoolkit.dev/install.sh | sudo sh
```

If you would like to install a different version of the CLI and/or put it in a different directory, use the following:

```shell
curl -sL https://iascable.cloudnativetoolkit.dev/install.sh | RELEASE=2.15.1 DEST_DIR=~/bin sh
```

Note that the install script creates a new binary for the downloaded version and creates a symbolic link to it. Over time, you may build up multiple versions in your destination directory which may need to be manually removed if not required. This also allows for using a prior version by updating the symbolic link to point to a different version as follows:

```shell
sudo ln -s /usr/local/bin/iascable-2.25.5 /usr/local/bin/iascable
```

### Install beta version

If you would like to install the latest beta release of the cli, use the following:

Expand Down
45 changes: 43 additions & 2 deletions install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

DEST_DIR="${1:-$DEST_DIR}"
RELEASE="${2:-$RELEASE}"
TMP_DIR="/tmp"

if [ -z "${DEST_DIR}" ]; then
DEST_DIR="/usr/local/bin"
Expand Down Expand Up @@ -52,5 +53,45 @@ case $(uname -m) in
*) echo "Unable to determine system architecture" >&2; exit 1 ;;
esac

echo "Installing version ${RELEASE} of iascable for ${TYPE}${ARCH} into ${DEST_DIR}"
curl --progress-bar -Lo "${DEST_DIR}/iascable" "https://github.com/cloud-native-toolkit/iascable/releases/download/${RELEASE}/iascable-${TYPE}${ARCH}" && chmod +x "${DEST_DIR}/iascable"
# If an Apple M1 Mac, use AMD64 architecture with Rosetta
if [[ "${TYPE}" == "macos" ]] && [[ "${ARCH}" == "-arm64" ]]; then
# Check that Rosetta is installed before continuing (Rosetta is known as oah by macos)
if [[ ! $(/usr/bin/pgrep oahd) ]]; then
echo "Rosetta must be installed. Please install and try again."
exit 2;
fi

# Create temporary directory if it does nto exist
if [[ ! -d "${TMP_DIR}" ]]; then
mkdir -p "${TMP_DIR}"
fi

# Download the binary to a temporary directory (/tmp by default)
echo "Downloading ${RELEASE} of iascable for ${TYPE} into ${TMP_DIR}"
curl --progress-bar -Lo "${TMP_DIR}/iascable-${RELEASE}" "https://github.com/cloud-native-toolkit/iascable/releases/download/${RELEASE}/iascable-${TYPE}"
chmod +x "${TMP_DIR}/iascable-${RELEASE}"

# Check if there is an existing version of iascable installed.
if [[ -h "${DEST_DIR}/iascable" ]]; then # Link file
# Remove link file
echo "Detected existing linked file ${DEST_DIR}/iascable"
rm "${DEST_DIR}/iascable"
elif [[ -x "${DEST_DIR}/iascable" ]]; then
# Get current version number
VERSION=$($DEST_DIR/iascable --version)
echo "Detected existing executable with version ${VERSION}"

# Copy existing binary to copy with current release
mv "${DEST_DIR}/iascable" "${DEST_DIR}/iascable-${VERSION}"
fi

# Move binary to destination directory and create link
echo "Moving ${TMP_DIR}/iascable-${RELEASE} to ${DEST_DIR} and creating symbolic link"
mv "${TMP_DIR}/iascable-${RELEASE}" "${DEST_DIR}/iascable-${RELEASE}"
ln -s "${DEST_DIR}/iascable-${RELEASE}" "${DEST_DIR}/iascable"

else # Non-Mac M1
echo "Installing version ${RELEASE} of iascable for ${TYPE}${ARCH} into ${DEST_DIR}"
curl --progress-bar -Lo "${DEST_DIR}/iascable" "https://github.com/cloud-native-toolkit/iascable/releases/download/${RELEASE}/iascable-${TYPE}${ARCH}" && chmod +x "${DEST_DIR}/iascable"
fi

0 comments on commit 2ed721c

Please sign in to comment.