|
| 1 | +#!/bin/sh |
| 2 | +# |
| 3 | +# Usage: |
| 4 | +# $ curl -fsSL https://raw.githubusercontent.com/pact-foundation/pact-plugins/master/install-cli.sh | bash |
| 5 | +# or |
| 6 | +# $ wget -q https://raw.githubusercontent.com/pact-foundation/pact-plugins/master/install-cli.sh -O- | bash |
| 7 | + |
| 8 | +# While most shells support `local`, it technically isn't POSIX. This will check |
| 9 | +# for `local` and alias it to `typeset` if it doesn't exist. |
| 10 | +# shellcheck disable=SC3043 |
| 11 | +# If a shell does not support `local`, it will be aliased to |
| 12 | +# `typeset`, so this check is not needed. |
| 13 | +has_local() { |
| 14 | + local _has_local |
| 15 | +} |
| 16 | +has_local 2>/dev/null || alias local=typeset |
| 17 | + |
| 18 | +set -o errexit # Exit on error |
| 19 | +set -o nounset # Treat unset variables as an error |
| 20 | + |
| 21 | +# Colours |
| 22 | +WHITE_BOLD='\033[1;37m' |
| 23 | +RESET='\033[0m' |
| 24 | + |
| 25 | +detect_osarch() { |
| 26 | + case $(uname -sm) in |
| 27 | + 'Linux x86_64') |
| 28 | + os='linux' |
| 29 | + arch='x86_64' |
| 30 | + ext='' |
| 31 | + ;; |
| 32 | + 'Linux aarch64') |
| 33 | + os='linux' |
| 34 | + arch='aarch64' |
| 35 | + ext='' |
| 36 | + ;; |
| 37 | + 'Darwin x86' | 'Darwin x86_64') |
| 38 | + os='osx' |
| 39 | + arch='x86_64' |
| 40 | + ext='' |
| 41 | + ;; |
| 42 | + 'Darwin arm64') |
| 43 | + os='osx' |
| 44 | + arch='aarch64' |
| 45 | + ext='' |
| 46 | + ;; |
| 47 | + CYGWIN* | MINGW32* | MSYS* | MINGW*) |
| 48 | + os="windows" |
| 49 | + arch='x86_64' |
| 50 | + ext='.exe' |
| 51 | + ;; |
| 52 | + *) |
| 53 | + echo "Sorry, you'll need to install the plugin CLI manually." |
| 54 | + exit 1 |
| 55 | + ;; |
| 56 | + esac |
| 57 | +} |
| 58 | + |
| 59 | +install_pact_plugin_cli() { |
| 60 | + [ -f ~/.pact/bin/pact-plugin-cli ] && \ |
| 61 | + echo "${WHITE_BOLD}=> Plugin CLI already installed${RESET}" && \ |
| 62 | + return |
| 63 | + |
| 64 | + local version="0.1.2" |
| 65 | + detect_osarch |
| 66 | + local url="https://github.com/pact-foundation/pact-plugins/releases/download/pact-plugin-cli-v${version}/pact-plugin-cli-${os}-${arch}${ext}.gz" |
| 67 | + |
| 68 | + URL=https://github.com/pact-foundation/pact-plugins/releases/download/pact-plugin-cli-v${version}/pact-plugin-cli-${os}-${arch}${ext}.gz |
| 69 | + echo "${WHITE_BOLD}=> Installing plugins CLI version '${version}'${RESET}" |
| 70 | + echo " - OS: ${os}" |
| 71 | + echo " - Arch: ${arch}" |
| 72 | + echo " - Version: ${version}" |
| 73 | + echo " - URL: ${url}" |
| 74 | + echo " - Downloading into: ~/.pact/bin/" |
| 75 | + |
| 76 | + mkdir -p ~/.pact/bin |
| 77 | + curl -sSL $url | gunzip -c > ~/.pact/bin/pact-plugin-cli |
| 78 | + chmod +x ~/.pact/bin/pact-plugin-cli |
| 79 | +} |
| 80 | + |
| 81 | +install_matt_plugin() { |
| 82 | + [ -d ~/.pact/plugins/matt-0.1.1 ] && \ |
| 83 | + echo -e "${WHITE_BOLD}=> MATT plugin already installed${RESET}" && \ |
| 84 | + return |
| 85 | + |
| 86 | + local version="0.1.1" |
| 87 | + |
| 88 | + echo "${WHITE_BOLD}=> Installing MATT plugin version '${version}'${RESET}" |
| 89 | + ~/.pact/bin/pact-plugin-cli install |
| 90 | +} |
| 91 | + |
| 92 | +main() { |
| 93 | + install_pact_plugin_cli |
| 94 | + install_matt_plugin |
| 95 | +} |
| 96 | + |
| 97 | +main |
0 commit comments