github.com/fibonacci-chain/fbc@v0.0.0-20231124064014-c7636198c1e9/libs/rocksdb/install.sh (about)

     1  #!/bin/sh
     2  #set -e
     3  #set -x
     4  VERSION_NUM=6.27.3
     5  VERSION=v$VERSION_NUM
     6  while [ $# -gt 0 ]; do
     7  	case "$1" in
     8  		--version)
     9  			VERSION="$2"
    10  			shift
    11  			;;
    12  		--*)
    13  			echo "Illegal option $1"
    14  			;;
    15  	esac
    16  	shift $(( $# > 0 ? 1 : 0 ))
    17  done
    18  
    19  command_exists() {
    20  	command -v "$@" > /dev/null 2>&1
    21  }
    22  
    23  is_wsl() {
    24  	case "$(uname -r)" in
    25  	*microsoft* ) true ;; # WSL 2
    26  	*Microsoft* ) true ;; # WSL 1
    27  	* ) false;;
    28  	esac
    29  }
    30  
    31  is_darwin() {
    32  	case "$(uname -s)" in
    33  	*darwin* ) true ;;
    34  	*Darwin* ) true ;;
    35  	* ) false;;
    36  	esac
    37  }
    38  
    39  get_distribution() {
    40  	lsb_dist=""
    41  	# Every system that we officially support has /etc/os-release
    42  	if [ -r /etc/os-release ]; then
    43  		lsb_dist="$(. /etc/os-release && echo "$ID")"
    44  	fi
    45  	# Returning an empty string here should be alright since the
    46  	# case statements don't act unless you provide an actual value
    47  	echo "$lsb_dist"
    48  }
    49  
    50  install_linux() {
    51    $sh_c "git clone https://github.com/facebook/rocksdb.git"
    52    $sh_c "cd rocksdb && git checkout ${VERSION}"
    53    $sh_c "cd rocksdb && make clean"
    54    $sh_c "cd rocksdb && make uninstall"
    55    $sh_c "cd rocksdb && make clean PREFIX=/usr LIBDIR=/usr/lib"
    56    $sh_c "cd rocksdb && make uninstall PREFIX=/usr LIBDIR=/usr/lib"
    57    $sh_c "cd rocksdb && make -j${num_proc} DISABLE_JEMALLOC=1 shared_lib PREFIX=/usr LIBDIR=/usr/lib"
    58    $sh_c "cd rocksdb && make install-shared PREFIX=/usr LIBDIR=/usr/lib"
    59    $sh_c "ldconfig"
    60  }
    61  
    62  install_macos(){
    63    $sh_c "git clone https://github.com/facebook/rocksdb.git"
    64    $sh_c "cd rocksdb && git checkout ${VERSION}"
    65    $sh_c "cd rocksdb && make clean"
    66    $sh_c "cd rocksdb && make uninstall DEBUG_LEVEL=0"
    67    $sh_c "cd rocksdb && make -j${num_proc} shared_lib EXTRA_CXXFLAGS='-Wno-deprecated-copy -Wno-unused-but-set-variable'"
    68    $sh_c "cd rocksdb && make install-shared"
    69  }
    70  
    71  do_install() {
    72  	echo "# Executing rocksdb install script, version: $VERSION"
    73  
    74  	user="$(id -un 2>/dev/null || true)"
    75  
    76  	sh_c='sh -c'
    77  	if [ "$user" != 'root' ]; then
    78  		if command_exists sudo; then
    79  			sh_c='sudo -E sh -c'
    80  		elif command_exists su; then
    81  			sh_c='su -c'
    82  		else
    83  			cat >&2 <<-'EOF'
    84  			Error: this installer needs the ability to run commands as root.
    85  			We are unable to find either "sudo" or "su" available to make this happen.
    86  			EOF
    87  			exit 1
    88  		fi
    89  	fi
    90  
    91  	# perform some very rudimentary platform detection
    92  	lsb_dist=$( get_distribution )
    93  	lsb_dist="$(echo "$lsb_dist" | tr '[:upper:]' '[:lower:]')"
    94  
    95    num_proc=32
    96  	# Run setup for each distro accordingly
    97  	case "$lsb_dist" in
    98  		ubuntu)
    99  			pre_reqs="git make libsnappy-dev liblz4-dev"
   100        $sh_c 'apt-get update -qq >/dev/null'
   101        $sh_c "apt-get install -y -qq $pre_reqs >/dev/null"
   102        num_proc=$( grep -c ^processor /proc/cpuinfo )
   103        install_linux
   104  			exit 0
   105  			;;
   106  		centos)
   107  		  pre_reqs="git make snappy snappy-devel lz4-devel yum-utils"
   108        $sh_c "yum install -y -q $pre_reqs"
   109        num_proc=$( grep -c ^processor /proc/cpuinfo )
   110        install_linux
   111  			exit 0
   112  			;;
   113  		*)
   114  			if [ -z "$lsb_dist" ]; then
   115  				if is_darwin; then
   116  				  pre_reqs="git make"
   117            $sh_c "xcode-select --install"
   118            $sh_c "brew install $pre_reqs"
   119            num_proc=$( sysctl -n hw.ncpu )
   120            install_macos
   121            exit 0
   122  				fi
   123  				if is_wsl; then
   124            echo
   125            echo "ERROR: Unsupported OS 'Windows'"
   126            echo "Please install RocksDB from https://github.com/facebook/rocksdb/blob/main/INSTALL.md"
   127            echo
   128            exit 1
   129          fi
   130  			fi
   131        echo
   132        echo "ERROR: Unsupported distribution '$lsb_dist'"
   133        echo
   134        exit 1
   135  			;;
   136  	esac
   137  	exit 1
   138  }
   139  
   140  # wrapped up in a function so that we have some protection against only getting
   141  # half the file during "curl | sh"
   142  do_install