mirror of
https://github.com/ovh/the-bastion.git
synced 2025-09-06 13:04:22 +08:00
enh: ttyrec & yubico installs: hardcode URLs for when API is down
This commit is contained in:
parent
415bc9b903
commit
e847a19857
3 changed files with 114 additions and 22 deletions
|
@ -52,4 +52,40 @@ action_static() {
|
|||
cd /
|
||||
}
|
||||
|
||||
# only used when/if the API is down and we're in CI mode
|
||||
default_urls() {
|
||||
local ver="1.1.6.7"
|
||||
local rpmver="${ver}-1"
|
||||
local list="
|
||||
-${rpmver}.aarch64.rpm
|
||||
-${rpmver}.armv7hnl.rpm
|
||||
-${rpmver}.armv7l.rpm
|
||||
-${rpmver}.i386.rpm
|
||||
-${rpmver}.mips64el.rpm
|
||||
-${rpmver}.ppc64le.rpm
|
||||
-${rpmver}.s390x.rpm
|
||||
-${rpmver}.x86_64.rpm
|
||||
-${ver}_amd64-freebsd-static-binary.tar.gz
|
||||
-${ver}_amd64-linux-static-binary.tar.gz
|
||||
-${ver}_arm64-linux-static-binary.tar.gz
|
||||
-${ver}_armel-linux-static-binary.tar.gz
|
||||
-${ver}_armhf-linux-static-binary.tar.gz
|
||||
-${ver}_i386-linux-static-binary.tar.gz
|
||||
-${ver}_mips64el-linux-static-binary.tar.gz
|
||||
-${ver}_ppc64el-linux-static-binary.tar.gz
|
||||
-${ver}_s390x-linux-static-binary.tar.gz
|
||||
_${ver}_amd64.deb
|
||||
_${ver}_arm64.deb
|
||||
_${ver}_armel.deb
|
||||
_${ver}_armhf.deb
|
||||
_${ver}_i386.deb
|
||||
_${ver}_mips64el.deb
|
||||
_${ver}_ppc64el.deb
|
||||
_${ver}_s390x.deb"
|
||||
for suffix in $list
|
||||
do
|
||||
echo "https://github.com/ovh/ovh-ttyrec/releases/download/v${ver}/ovh-ttyrec${suffix}"
|
||||
done
|
||||
}
|
||||
|
||||
install_main "$@"
|
||||
|
|
|
@ -41,4 +41,54 @@ action_static() {
|
|||
cd /
|
||||
}
|
||||
|
||||
# only used when/if the API is down and we're in CI mode
|
||||
default_urls() {
|
||||
local ver="1.0.0"
|
||||
local list="
|
||||
-${ver}.aarch64.rpm
|
||||
-${ver}.armv7hnl.rpm
|
||||
-${ver}.armv6l.rpm
|
||||
-${ver}.i386.rpm
|
||||
-${ver}.mips64el.rpm
|
||||
-${ver}.ppc64le.rpm
|
||||
-${ver}.s390x.rpm
|
||||
-${ver}.x86_64.rpm
|
||||
_${ver}_amd64.deb
|
||||
_${ver}_arm64.deb
|
||||
_${ver}_armel.deb
|
||||
_${ver}_armhf.deb
|
||||
_${ver}_darwin_amd64.tar.gz
|
||||
_${ver}_freebsd_386.tar.gz
|
||||
_${ver}_freebsd_amd64.tar.gz
|
||||
_${ver}_freebsd_arm64.tar.gz
|
||||
_${ver}_freebsd_armv5.tar.gz
|
||||
_${ver}_freebsd_armv7.tar.gz
|
||||
_${ver}_i386.deb
|
||||
_${ver}_linux_386.tar.gz
|
||||
_${ver}_linux_amd64.tar.gz
|
||||
_${ver}_linux_arm64.tar.gz
|
||||
_${ver}_linux_armv5.tar.gz
|
||||
_${ver}_linux_armv7.tar.gz
|
||||
_${ver}_linux_mips64le_hardfloat.tar.gz
|
||||
_${ver}_linux_ppc64le.tar.gz
|
||||
_${ver}_linux_s390x.tar.gz
|
||||
_${ver}_mips64el.deb
|
||||
_${ver}_netbsd_386.tar.gz
|
||||
_${ver}_netbsd_amd64.tar.gz
|
||||
_${ver}_netbsd_armv5.tar.gz
|
||||
_${ver}_netbsd_armv7.tar.gz
|
||||
_${ver}_openbsd_386.tar.gz
|
||||
_${ver}_openbsd_amd64.tar.gz
|
||||
_${ver}_openbsd_arm64.tar.gz
|
||||
_${ver}_openbsd_armv5.tar.gz
|
||||
_${ver}_openbsd_armv7.tar.gz
|
||||
_${ver}_ppc64le.deb
|
||||
_${ver}_s390x.deb
|
||||
_${ver}_windows_amd64.tar.gz"
|
||||
for suffix in $list
|
||||
do
|
||||
echo "https://github.com/ovh/yubico-piv-checker/releases/download/v${ver}/yubico-piv-checker${suffix}"
|
||||
done
|
||||
}
|
||||
|
||||
install_main "$@"
|
||||
|
|
|
@ -54,18 +54,30 @@ set_download_url() {
|
|||
# shellcheck disable=SC2064
|
||||
trap "rm -f $payload" EXIT
|
||||
|
||||
maxtries=60
|
||||
for try in $(seq 1 $maxtries); do
|
||||
_apicall "$RELEASE_API_URL" > "$payload"
|
||||
if command -v jq >/dev/null; then
|
||||
# If we have jq, we can do it properly
|
||||
urls="$(jq -r '.[0].assets|.[]|.browser_download_url' < "$payload")"
|
||||
elif perl -MJSON -e 1 2>/dev/null; then
|
||||
# If we don't, there's a good chance we have Perl with the JSON module, use it
|
||||
urls="$(perl -MJSON -e 'undef $/; $d=decode_json(<>); exit if ref $d ne "ARRAY"; foreach(@{ $d->[0]{assets} || [] }) { print $_->{browser_download_url}."\n" }' "$payload")"
|
||||
# shellcheck disable=SC2034
|
||||
for try in 1 2; do
|
||||
|
||||
if [ "$USE_DEFAULT_URLS" = 1 ]; then
|
||||
urls="$(default_urls)"
|
||||
else
|
||||
# Otherwise, go the ugly way, don't bother the user in installing jq just for this need
|
||||
urls="$(grep -Eo 'https://[a-z0-9./_-]+' "$payload")"
|
||||
_apicall "$RELEASE_API_URL" > "$payload"
|
||||
|
||||
if [ ! -s "$payload" ]; then
|
||||
action_error "API returned an empty body, did we hit the query limit? Auto-retrying with hardcoded URLs"
|
||||
USE_DEFAULT_URLS=1
|
||||
continue
|
||||
fi
|
||||
|
||||
if command -v jq >/dev/null; then
|
||||
# If we have jq, we can do it properly
|
||||
urls="$(jq -r '.[0].assets|.[]|.browser_download_url' < "$payload")"
|
||||
elif perl -MJSON -e 1 2>/dev/null; then
|
||||
# If we don't, there's a good chance we have Perl with the JSON module, use it
|
||||
urls="$(perl -MJSON -e 'undef $/; $d=decode_json(<>); exit if ref $d ne "ARRAY"; foreach(@{ $d->[0]{assets} || [] }) { print $_->{browser_download_url}."\n" }' "$payload")"
|
||||
else
|
||||
# Otherwise, go the ugly way, don't bother the user in installing jq just for this need
|
||||
urls="$(grep -Eo 'https://[a-z0-9./_-]+' "$payload")"
|
||||
fi
|
||||
fi
|
||||
|
||||
url="$(echo "$urls" | grep -E "$pattern" | head -n1)"
|
||||
|
@ -74,18 +86,12 @@ set_download_url() {
|
|||
# success
|
||||
action_detail "$url"
|
||||
return 0
|
||||
elif [ ! -s "$payload" ]; then
|
||||
action_error "API returned an empty body, did we hit the query limit?"
|
||||
if [ "$CI" = "true" ]; then
|
||||
action_detail "... CI environment detected, try $try out of $maxtries, sleeping and retrying..."
|
||||
sleep 63
|
||||
continue
|
||||
fi
|
||||
exit 1
|
||||
elif [ -z "$urls" ]; then
|
||||
action_error "Couldn't find any URL in the returned body, did we hit the query limit? Body follows:"
|
||||
cat "$payload"
|
||||
exit 1
|
||||
action_error "Auto-retrying with hardcoded URLs"
|
||||
USE_DEFAULT_URLS=1
|
||||
continue
|
||||
else
|
||||
action_error "Couldn't find a proper URL for your architecture ($arch), looked for pattern '$pattern'. You may have to compile $PROGRAM_NAME yourself!"
|
||||
action_detail "Maybe the release asset naming pattern has changed and we're not aware, if you think one of the packages below match your OS & arch, you may download & install them manually:"
|
||||
|
@ -95,8 +101,8 @@ set_download_url() {
|
|||
exit 1
|
||||
fi
|
||||
done
|
||||
# if we're here, we've reached maxtries
|
||||
action_error "Reached max tries, aborting"
|
||||
|
||||
# unreachable code, but fail just in case
|
||||
exit 1
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue