-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
148 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,146 @@ | ||
#! /usr/bin/env bash | ||
|
||
# Copyright (c) 2019 vesoft inc. All rights reserved. | ||
# | ||
# This source code is licensed under Apache 2.0 License, | ||
# attached with Common Clause Condition 1.0, found in the LICENSES directory. | ||
|
||
# Usage: install-gdb | ||
|
||
# Always use bash | ||
shell=$(basename $(readlink /proc/$$/exe)) | ||
if [ ! x$shell = x"bash" ] | ||
then | ||
bash $0 $@ | ||
exit $? | ||
fi | ||
|
||
[[ $(uname) = Linux ]] || { | ||
echo "Only Linux is supported" | ||
exit 1 | ||
} | ||
|
||
[[ $# -ne 0 ]] && version=$(echo "$@" | sed 's;.*--version=(\S*).*;\1;p' -rn) | ||
|
||
url_base=https://nebula-graph.oss-accelerate.aliyuncs.com/toolset | ||
this_dir=$(dirname $(readlink -f $0)) | ||
|
||
version_files_dir=$this_dir/../share/nebula-gears | ||
|
||
mapfile -t all_versions < <( ls -1 $version_files_dir/gdb-tarball-info-* | \ | ||
awk -F'/' '{print $NF}' | \ | ||
awk -F'-' '{print $NF}') | ||
|
||
[[ -z $version ]] && { | ||
echo "Please specify the version you want to build with --version=x.y.z" 1>&2; | ||
echo "Optional versions are: ${all_versions[@]}" 1>&2; | ||
exit 1; | ||
} | ||
|
||
[[ $version = all ]] && version=(${all_versions[@]}) | ||
if [[ ${#version[@]} -eq 1 ]] | ||
then | ||
mapfile -t version < <(echo $version | tr ',' '\n') | ||
fi | ||
|
||
if [[ ${#version[@]} -gt 1 ]] | ||
then | ||
exit_status=0 | ||
for v in ${version[@]} | ||
do | ||
$0 --version=$v | ||
[[ $? -ne 0 ]] && exit_status=$? | ||
done | ||
exit $exit_status | ||
fi | ||
|
||
|
||
# We consider two derivatives: Red Hat and Debian | ||
# Place preset libc versions of each from newer to older | ||
CentOS_libc_preset=( 2.17 2.12 ) | ||
Debian_libc_preset=( 2.24 2.19 2.13 ) | ||
|
||
selected_distro= | ||
selected_libc= | ||
selected_archive= | ||
this_distro=$(lsb_release -si) | ||
this_libc=$(ldd --version | head -1 | cut -d ')' -f 2 | cut -d ' ' -f 2) | ||
|
||
hash wget &>/dev/null || { | ||
echo "'wget' not fould, please install it first" 1>&2 | ||
exit 1 | ||
} | ||
|
||
download_cmd="wget -c" | ||
wget --help | grep -q '\--show-progress' && \ | ||
download_cmd="$download_cmd -q --show-progress" || \ | ||
download_cmd="$download_cmd --progress=bar:force:noscroll" | ||
|
||
# Guess the root distro | ||
[[ "$this_distro" = CentOS ]] && selected_distro=CentOS | ||
[[ "$this_distro" = RedHat ]] && selected_distro=CentOS | ||
[[ "$this_distro" = Fedora ]] && selected_distro=CentOS | ||
[[ "$this_distro" = Debian ]] && selected_distro=Debian | ||
[[ "$this_distro" = Ubuntu ]] && selected_distro=Debian | ||
[[ "$this_distro" = LinuxMint ]] && selected_distro=Debian | ||
|
||
# backoff distro | ||
[[ -n $this_distro ]] || selected_distro=Debian | ||
|
||
function version_cmp { | ||
mapfile -t left < <( echo $1 | tr . '\n' ) | ||
mapfile -t right < <( echo $2 | tr . '\n') | ||
local i | ||
for i in ${!left[@]} | ||
do | ||
local lv=${left[$i]} | ||
local rv=${right[$i]} | ||
[[ -z $rv ]] && { echo $lv; return; } | ||
[[ $lv -ne $rv ]] && { echo $((lv - rv)); return; } | ||
done | ||
((i++)) | ||
rv=${right[$i]} | ||
[[ ${#right[@]} -gt ${#left[@]} ]] && { echo $((0-rv)); return; } | ||
} | ||
|
||
# Find the maximum version not greater than the system one | ||
function select_libc { | ||
local this_version=$1 | ||
shift 1 | ||
local candidates="$@" | ||
for v in $candidates | ||
do | ||
if [[ $(version_cmp $v $this_version) -le 0 ]] | ||
then | ||
echo $v | ||
break | ||
fi | ||
done | ||
} | ||
|
||
case $selected_distro in | ||
CentOS) | ||
selected_libc=$(select_libc $this_libc "${CentOS_libc_preset[@]}") | ||
;; | ||
Debian) | ||
selected_libc=$(select_libc $this_libc "${Debian_libc_preset[@]}") | ||
;; | ||
esac | ||
|
||
[[ -z $selected_libc ]] && { | ||
echo "No suitable GDB found to download for your environment: $this_distro, glibc-$this_libc" 1>&2 | ||
exit 1 | ||
} | ||
|
||
selected_archive=vesoft-gdb-$version-$selected_distro-x86_64-glibc-$selected_libc.sh | ||
|
||
url=$url_base/$selected_archive | ||
$download_cmd $url | ||
[[ $? -ne 0 ]] && { | ||
echo "Downloading $selected_archive failed" 1>&2 | ||
exit 1 | ||
} | ||
|
||
bash $selected_archive | ||
|
||
rm -rf $selected_archive |
This file was deleted.
Oops, something went wrong.