Merge pull request #41 from ovh/ttyrec_multiarch

chore: install-ttyrec.sh: adapt for multiarch
This commit is contained in:
Stéphane Lesimple 2020-11-12 19:01:07 +01:00 committed by GitHub
commit 034984f6c4
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -44,19 +44,24 @@ set_download_url() {
exit 1 exit 1
fi fi
action_doing "Getting latest release..." action_doing "Getting latest release for arch $arch..."
if command -v jq >/dev/null; then if command -v jq >/dev/null; then
# If we have jq, we can do it properly # If we have jq, we can do it properly
url=$(_apicall $RELEASE_API_URL | jq -r '.[0].assets|.[]|.browser_download_url' | grep -F "$pattern") url=$(_apicall $RELEASE_API_URL | jq -r '.[0].assets|.[]|.browser_download_url' | grep -F "$pattern" | head -n1)
elif perl -MJSON -e 1 2>/dev/null; then 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 # If we don't, there's a good chance we have Perl with the JSON module, use it
url=$(_apicall $RELEASE_API_URL | perl -MJSON -e 'undef $/; $d=decode_json(<>); foreach(@{ $d->[0]{assets} || [] }) { $_=$_->{browser_download_url}; /\Q'"$pattern"'\E/ && print && exit }') url=$(_apicall $RELEASE_API_URL | perl -MJSON -e 'undef $/; $d=decode_json(<>); foreach(@{ $d->[0]{assets} || [] }) { $_=$_->{browser_download_url}; /\Q'"$pattern"'\E/ && print && exit }' | head -n1)
else else
# Otherwise, go the ugly way, don't bother the user in installing jq just for this need # Otherwise, go the ugly way, don't bother the user in installing jq just for this need
url=$(_apicall $RELEASE_API_URL | grep -Eo 'https://[a-z0-9./_-]+' | grep -F "$pattern" | head -n1) url=$(_apicall $RELEASE_API_URL | grep -Eo 'https://[a-z0-9./_-]+' | grep -F "$pattern" | head -n1)
fi fi
action_detail "$url" if [ -n "$url" ]; then
action_detail "$url"
else
action_error "Couldn't find a proper URL for your architecture ($arch), looked for pattern '$pattern'. You may have to compile ovh-ttyrec yourself!"
exit 1
fi
} }
prepare_temp_folder() { prepare_temp_folder() {
@ -67,7 +72,15 @@ prepare_temp_folder() {
} }
action_static() { action_static() {
set_download_url "linux-static-binary.tar.gz" if command -v dpkg >/dev/null; then
set_arch_from_deb
elif command -v rpm >/dev/null; then
set_arch_from_rpm
else
arch=$(uname -m)
fi
set_download_url "_$arch-linux-static-binary.tar.gz"
prepare_temp_folder prepare_temp_folder
_download "$url" _download "$url"
@ -93,8 +106,17 @@ action_static() {
cd / cd /
} }
set_arch_from_deb() {
arch=$(dpkg --print-architecture)
}
action_debian() { action_debian() {
set_download_url ".deb" if ! command -v dpkg >/dev/null; then
echo "Couldn't find dpkg, aborting" >&2
exit 1
fi
set_arch_from_deb
set_download_url "_$arch.deb"
prepare_temp_folder prepare_temp_folder
_download "$url" _download "$url"
@ -110,8 +132,24 @@ action_debian() {
cd / cd /
} }
set_arch_from_rpm() {
arch=$(rpm -E '%{_arch}')
# in some cases, %{_arch} is not defined, so the macro isn't expanded.
# In that case, find it ourselves
if [ "$arch" = "%{_arch}" ]; then
arch=$(rpm --showrc | grep "^install arch" | awk '{print $4}')
fi
}
action_rpm() { action_rpm() {
set_download_url ".rpm" if ! command -v rpm >/dev/null; then
echo "Couldn't find rpm, aborting" >&2
exit 1
fi
set_arch_from_rpm
set_download_url ".$arch.rpm"
prepare_temp_folder prepare_temp_folder
_download "$url" _download "$url"
@ -149,6 +187,11 @@ action_auto() {
esac esac
} }
if [ "$OS_FAMILY" != "Linux" ]; then
echo "Sorry, your OS ($OS_FAMILY) is not supported." >&2
exit 1
fi
while getopts :sdrah arg; do while getopts :sdrah arg; do
case "$arg" in case "$arg" in
s) action_static; exit 0;; s) action_static; exit 0;;