-
Notifications
You must be signed in to change notification settings - Fork 174
Expand file tree
/
Copy pathget-github-release.sh
More file actions
executable file
·67 lines (53 loc) · 1.37 KB
/
get-github-release.sh
File metadata and controls
executable file
·67 lines (53 loc) · 1.37 KB
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
#!/bin/bash
set -eou pipefail
SCRIPT_DIR="$(dirname "${BASH_SOURCE[0]}")"
function usage() {
echo "
Usage:
get-github-release.sh MANDATORY
MANDATORY:
--from GitHub URL to the executable file.
--to A local path where the downloaded file will be saved.
" >&2
}
function usage_exit() {
usage
exit 1
}
function get_github_release() {
local from=""
local to=""
while [[ -n "${1:-}" ]]; do
case "${1}" in
"--from")
from="${2}"
shift
;;
"--to")
to="${2}"
shift
;;
*)
echo "Error: Unknown parameter: ${1}" >&2
usage_exit
esac
if ! shift; then
echo 'Error: Missing parameter argument.' >&2
usage_exit
fi
done
[[ "${from}" = "" ]] && echo 'Error: Parameter "from" is empty.' >&2 && usage_exit
[[ "${to}" = "" ]] && echo 'Error: Parameter "to" is empty.' >&2 && usage_exit
# File is already downloaded
if [[ -f "${to}" ]]; then
exit 0
fi
local -r bin_dir=$(dirname "${to}")
mkdir -p "${bin_dir}"
echo "Downloading ${from} to ${to}."
"${SCRIPT_DIR}/retry.sh" 3 10 curl --silent --fail --location --output "${to}" "${from}"
chmod +x "${to}"
local -r kernel_name=$(uname -s) || true
[[ "${kernel_name}" != "Darwin" ]] || xattr -c "${to}"
}
get_github_release "$@"