-
Notifications
You must be signed in to change notification settings - Fork 1
/
install.sh
executable file
·156 lines (132 loc) · 4.31 KB
/
install.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
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
#!/usr/bin/env bash
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# https://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
set -o errexit
set -o nounset
set -o pipefail
DEFAULT_VERSION=latest
show_help() {
cat << EOF
Usage: $(basename "$0") <options>
-h, --help Display help
-v, --version The YAKS version to use (default: $DEFAULT_VERSION)
--github-token Optional token used when fetching the latest YAKS release to avoid hitting rate limits
EOF
}
main() {
local version="$DEFAULT_VERSION"
local github_token=
parse_command_line "$@"
install_yaks
cleanup_workspace
}
parse_command_line() {
while :; do
case "${1:-}" in
-h|--help)
show_help
exit
;;
-v|--version)
if [[ -n "${2:-}" ]]; then
version="$2"
shift
else
echo "ERROR: '-v|--version' cannot be empty." >&2
show_help
exit 1
fi
;;
--github-token)
if [[ -n "${2:-}" ]]; then
github_token="$2"
shift
else
echo "ERROR: '--github-token' cannot be empty." >&2
show_help
exit 1
fi
;;
*)
break
;;
esac
shift
done
}
install_yaks() {
install_version=$version
info=
if [[ "$version" = "latest" ]]
then
if [[ -z "$github_token" ]]
then
install_version=$(curl --silent "https://api.github.com/repos/citrusframework/yaks/releases/latest" | grep '"tag_name":' | sed -E 's/.*"([^"]+)".*/\1/')
else
install_version=$(curl -H "Authorization: $github_token" --silent "https://api.github.com/repos/citrusframework/yaks/releases/latest" | grep '"tag_name":' | sed -E 's/.*"([^"]+)".*/\1/')
fi
info="=$install_version"
fi
if [[ "$version" = "nightly" ]]
then
if [[ -z "$github_token" ]]
then
install_version=$(curl --silent "https://api.github.com/repos/citrusframework/yaks/releases" | grep '"tag_name":' | head -1 | sed -E 's/.*"([^"]+)".*/\1/')
else
install_version=$(curl -H "Authorization: $github_token" --silent "https://api.github.com/repos/citrusframework/yaks/releases" | grep '"tag_name":' | head -1 | sed -E 's/.*"([^"]+)".*/\1/')
fi
info="=$install_version"
fi
if [[ "$version" == "nightly:"* ]]
then
install_version=$(echo $install_version | tr -d nightly:)
fi
os=$(get_os)
binary_version=$(echo $install_version | tr -d v)
echo "Loading citrusframework/yaks/releases/download/$install_version/yaks-$binary_version-$os-64bit.tar.gz"
echo "Installing YAKS client version $version$info on $os..."
curl -L --silent https://github.com/citrusframework/yaks/releases/download/$install_version/yaks-$binary_version-$os-64bit.tar.gz -o yaks.tar.gz
mkdir -p _yaks
tar -zxf yaks.tar.gz --directory ./_yaks
if [[ "$os" = "windows" ]]
then
mkdir /yaks
mv ./_yaks/yaks.exe /yaks/
echo "/yaks" >> $GITHUB_PATH
else
sudo mv ./_yaks/yaks /usr/local/bin/
fi
echo "YAKS client installed successfully!"
}
cleanup_workspace() {
if [[ -f "./yaks.tar.gz" ]]
then
rm yaks.tar.gz
fi
if [[ -d "./_yaks" ]]
then
rm -r _yaks
fi
}
get_os() {
osline="$(uname -s)"
case "${osline}" in
Linux*) os=linux;;
Darwin*) os=mac;;
CYGWIN*) os=windows;;
MINGW*) os=windows;;
Windows*) os=windows;;
*) os="UNKNOWN:${osline}"
esac
echo ${os}
}
main "$@"