-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgithub-release-install.sh
More file actions
executable file
·66 lines (57 loc) · 2.1 KB
/
github-release-install.sh
File metadata and controls
executable file
·66 lines (57 loc) · 2.1 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
#!/bin/bash
#
# A script to install an RPM from the latest Github release for a project.
#
# ORG_PROJ is the pair of URL components for organization/projectName in Github URL
# example: https://github.com/wez/wezterm/releases
# ORG_PROJ would be "wez/wezterm"
#
# ARCH_FILTER is used to select the specific RPM. Typically this can just be the arch
# such as 'x86_64' but sometimes a specific filter is required when multiple match.
# example: wezterm builds RPMs for different distros so we must be more specific.
# ARCH_FILTER of "fedora37.x86_64" gets the x86_64 RPM build for fedora37
ORG_PROJ=${1}
ARCH_FILTER=${2}
LATEST=${3}
usage() {
echo "$0 ORG_PROJ ARCH_FILTER"
echo " ORG_PROJ - organization/projectname"
echo " ARCH_FILTER - optional extra filter to further limit rpm selection"
echo " LATEST - optional tag override for latest release (eg, nightly-dev)"
}
if [ -z "${ORG_PROJ}" ]; then
usage
exit 1
fi
if [ -z "${ARCH_FILTER}" ]; then
usage
exit 2
fi
if [ -z "${LATEST}" ]; then
RELTAG="latest"
else
RELTAG="tags/${LATEST}"
fi
set ${SET_X:+-x} -eou pipefail
API_JSON=$(mktemp /tmp/api-XXXXXXXX.json)
API="https://api.github.com/repos/${ORG_PROJ}/releases/${RELTAG}"
# Read GitHub token from secret mount if available (authenticates API to avoid rate limits)
CURL_AUTH_ARGS=()
if [[ -r /run/secrets/GITHUB_TOKEN ]]; then
GITHUB_TOKEN=$(</run/secrets/GITHUB_TOKEN)
CURL_AUTH_ARGS=("-H" "Authorization: Bearer ${GITHUB_TOKEN}")
fi
# retry up to 5 times with 5 second delays for any error included HTTP 404 etc
curl --fail --retry 5 --retry-delay 5 --retry-all-errors -sL \
"${CURL_AUTH_ARGS[@]}" "${API}" -o "${API_JSON}"
RPM_URLS=$(jq \
-r \
--arg arch_filter "${ARCH_FILTER}" \
'.assets | sort_by(.created_at) | reverse | .[] | select(.name|test($arch_filter)) | select (.name|test("rpm$")) | .browser_download_url' \
"${API_JSON}")
for URL in ${RPM_URLS}; do
# WARNING: in case of multiple matches, this only installs the first matched release
echo "execute: $DNF install -y \"${URL}\""
$DNF install -y "${URL}"
break
done