Skip to content

Commit

Permalink
Added install-gdb
Browse files Browse the repository at this point in the history
  • Loading branch information
dutor committed Apr 1, 2020
1 parent 327c804 commit 06d8a39
Show file tree
Hide file tree
Showing 3 changed files with 148 additions and 19 deletions.
4 changes: 2 additions & 2 deletions docker/toolset/images/debian-8.Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ RUN apt-get install -y make \
unzip \
curl \
xz-utils \
liblzma-dev ]
python-dev ]
liblzma-dev \
python-dev \
patch \
lsb-core \
libz-dev \
Expand Down
146 changes: 146 additions & 0 deletions scripts/install-gdb
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
17 changes: 0 additions & 17 deletions share/nebula-gears/gdb-tarball-info-9.1

This file was deleted.

0 comments on commit 06d8a39

Please sign in to comment.