#! /bin/sh set -e # Print our lovely banner image echo "                                                                                                                                                                                                                                                            " echo "❊ Installing the Garden CLI ❊" echo "" if [[ -n $1 ]] then GARDEN_VERSION=$1 else echo "→ Finding the latest version..." # Find version to run through GitHub release API function jsonValue() { # see https://gist.github.com/cjus/1047794 KEY=$1 num=$2 awk -F"[,:}]" '{for(i=1;i<=NF;i++){if($i~/'$KEY'\042/){print $(i+1)}}}' | tr -d '"' | sed -n ${num}p } GARDEN_VERSION=$(curl -sL https://github.com/garden-io/garden/releases/latest -H "Accept: application/json" | jsonValue tag_name 1) fi # Detect OS if [ "$(uname -s)" = "Darwin" ]; then OS=macos else OS=`ldd 2>&1|grep musl >/dev/null && echo "alpine" || echo "linux"` fi # Detect architecture ARCH=$(uname -m) case $ARCH in x86_64) ARCH=amd64 ;; arm64 | aarch64) ARCH=arm64 ;; *) echo "Unsupported architecture: $ARCH" exit 1 ;; esac PLATFORM="${OS}-${ARCH}" filename="garden-${GARDEN_VERSION}-${PLATFORM}.tar.gz" url="https://download.garden.io/core/${GARDEN_VERSION}/${filename}" tmp=$(mktemp -d /tmp/garden-install.XXXXXX) ( cd "$tmp" echo "→ Downloading ${url}..." curl -sLO "${url}" SHA=$(curl -sL "${url}.sha256") echo "" echo "Download complete!, validating checksum..." checksum=$(openssl dgst -sha256 "${filename}" | awk '{ print $2 }') if [ "$checksum" != "$SHA" ]; then echo "Checksum validation failed." >&2 exit 1 fi echo "Checksum valid." echo "" ) ( GARDEN_DIR=${HOME}/.garden TARGET_PATH=${GARDEN_DIR}/bin echo "→ Extracting to ${TARGET_PATH}..." rm -rf "${TARGET_PATH}" mkdir -p "${GARDEN_DIR}" cd "$tmp" tar -xzf "${filename}" mv "${PLATFORM}" "${TARGET_PATH}" ) rm -rf "$tmp" echo "" echo "🌺🌻 Garden has been successfully installed 🌷💐" echo "" echo "Add the Garden CLI to your path by adding the following to your .bashrc/.zshrc:" echo "" echo " export PATH=\$PATH:\$HOME/.garden/bin" echo "" echo "Head over to our documentation for next steps: https://docs.garden.io" echo ""