-
Notifications
You must be signed in to change notification settings - Fork 7
/
cli.sh
executable file
·110 lines (102 loc) · 3.66 KB
/
cli.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
#!/bin/sh -e
## Tested with https://www.shellcheck.net/
# Usage: (install latest)
# $ curl -fsSL https://raw.githubusercontent.com/pact-foundation/pact-ruby-standalone/master/install.sh | sh
# or
# $ wget -q https://raw.githubusercontent.com/pact-foundation/pact-ruby-standalone/master/install.sh -O- | sh
#
# Usage: (install fixed version) - pass PACT_CLI_VERSION=v<PACT_CLI_VERSION> eg PACT_CLI_VERSION=v1.92.0 or set as an env var
# $ curl -fsSL https://raw.githubusercontent.com/pact-foundation/pact-ruby-standalone/master/install.sh | PACT_CLI_VERSION=v1.92.0 sh
# or
# $ wget -q https://raw.githubusercontent.com/pact-foundation/pact-ruby-standalone/master/install.sh -O- | PACT_CLI_VERSION=v1.92.0 sh
#
if [ "$tag" ]; then
echo "setting $tag as PACT_CLI_VERSION for legacy reasons"
PACT_CLI_VERSION="$tag"
fi
if [ -z "$PACT_CLI_VERSION"]; then
PACT_CLI_VERSION=$(basename "$(curl -fs -o/dev/null -w "%{redirect_url}" https://github.com/pact-foundation/pact-ruby-standalone/releases/latest)")
echo "Thanks for downloading the latest release of pact-ruby-standalone $PACT_CLI_VERSION."
echo "-----"
echo "Note:"
echo "-----"
echo "You can download a fixed version by setting the PACT_CLI_VERSION environment variable eg PACT_CLI_VERSION=v1.92.0"
echo "example:"
echo "curl -fsSL https://raw.githubusercontent.com/pact-foundation/pact-ruby-standalone/master/install.sh | PACT_CLI_VERSION=v1.92.0 sh"
else
echo "Thanks for downloading pact-ruby-standalone $PACT_CLI_VERSION."
fi
PACT_CLI_VERSION_WITHOUT_V=${PACT_CLI_VERSION#v}
MAJOR_PACT_CLI_VERSION=$(echo "$PACT_CLI_VERSION_WITHOUT_V" | cut -d '.' -f 1)
case $(uname -sm) in
'Linux x86_64')
os='linux-x86_64'
;;
'Linux aarch64')
if [ "$MAJOR_PACT_CLI_VERSION" -lt 2 ]; then
echo "Sorry, you'll need to install the pact-ruby-standalone manually."
exit 1
else
os='linux-arm64'
fi
;;
'Darwin arm64')
if [ "$MAJOR_PACT_CLI_VERSION" -lt 2 ]; then
os='osx'
else
os='osx-arm64'
fi
;;
'Darwin x86' | 'Darwin x86_64')
if [ "$MAJOR_PACT_CLI_VERSION" -lt 2 ]; then
os='osx'
else
os='osx-x86_64'
fi
;;
"Windows"* | "MINGW64"*)
if [ "$MAJOR_PACT_CLI_VERSION" -lt 2 ]; then
os='win32'
else
os='windows-x86_64'
fi
;;
*)
echo "Sorry, you'll need to install the pact-ruby-standalone manually."
exit 1
;;
esac
case $os in
'windows'* | 'win32')
filename="pact-${PACT_CLI_VERSION#v}-${os}.zip"
ext=.bat
;;
'osx'* | 'linux'*)
filename="pact-${PACT_CLI_VERSION#v}-${os}.tar.gz"
;;
esac
echo "-------------"
echo "Downloading:"
echo "-------------"
(curl -sLO https://github.com/pact-foundation/pact-ruby-standalone/releases/download/"${PACT_CLI_VERSION}"/"${filename}" && echo downloaded "${filename}") || (echo "Sorry, you'll need to install the pact-ruby-standalone manually." && exit 1)
case $os in
'windows'* | 'win32')
(unzip "${filename}" && echo unarchived "${filename}") || (echo "Sorry, you'll need to unarchived the pact-ruby-standalone manually." && exit 1)
;;
'osx'* | 'linux'*)
(tar xzf "${filename}" && echo unarchived "${filename}") || (echo "Sorry, you'll need to unarchived the pact-ruby-standalone manually." && exit 1)
;;
esac
(rm "${filename}" && echo removed "${filename}") || (echo "Sorry, you'll need to remove the pact-ruby-standalone archive manually." && exit 1)
echo "pact-ruby-standalone ${PACT_CLI_VERSION} installed to $(pwd)/pact"
echo "-------------------"
echo "available commands:"
echo "-------------------"
ls -1 "$(pwd)"/pact/bin
if [ $GITHUB_ENV ]; then
echo "PATH=${PATH}:${PWD}/pact/bin/" >>$GITHUB_ENV
else
echo "Add the following to your path"
echo "--- Linux/MacOS/Windows Bash Users --------"
echo "PATH=${PATH}:${PWD}/pact/bin/"
fi