|
| 1 | +#/usr/bin/env bash |
| 2 | + |
| 3 | +set -e |
| 4 | + |
| 5 | +function log() { |
| 6 | + echo "[+] $1" |
| 7 | +} |
| 8 | + |
| 9 | +function fatal() { |
| 10 | + echo "[!] $1" |
| 11 | + exit 1 |
| 12 | +} |
| 13 | + |
| 14 | +function platform() { |
| 15 | + local __resultvar=$1 |
| 16 | + if [[ -f "/etc/yum.conf" ]]; then |
| 17 | + eval $__resultvar="centos" |
| 18 | + elif [[ -f "/etc/dpkg/dpkg.cfg" ]]; then |
| 19 | + eval $__resultvar="ubuntu" |
| 20 | + else |
| 21 | + fatal "Unknwon operating system" |
| 22 | + fi |
| 23 | +} |
| 24 | +platform OS |
| 25 | + |
| 26 | +function package() { |
| 27 | + if [[ $OS = "ubuntu" ]]; then |
| 28 | + if dpkg --get-selections | grep --quiet $1; then |
| 29 | + log "$1 is already installed. skipping." |
| 30 | + else |
| 31 | + apt-get install $@ -y |
| 32 | + fi |
| 33 | + elif [[ $OS = "centos" ]]; then |
| 34 | + if rpm -qa | grep --quiet $1; then |
| 35 | + log "$1 is already installed. skipping." |
| 36 | + else |
| 37 | + yum install $@ -y |
| 38 | + fi |
| 39 | + fi |
| 40 | +} |
| 41 | + |
| 42 | +function detect_fpm_output() { |
| 43 | + if [[ $OS = "ubuntu" ]]; then |
| 44 | + export FPM_OUTPUT=deb |
| 45 | + elif [[ $OS = "centos" ]]; then |
| 46 | + export FPM_OUTPUT=rpm |
| 47 | + fi |
| 48 | +} |
| 49 | +detect_fpm_output |
| 50 | + |
| 51 | +function gem_install() { |
| 52 | + if gem list | grep --quiet $1; then |
| 53 | + log "$1 is already installed. skipping." |
| 54 | + else |
| 55 | + gem install $@ |
| 56 | + fi |
| 57 | +} |
| 58 | + |
| 59 | +function main() { |
| 60 | + if [[ $# -ne 1 ]]; then |
| 61 | + fatal "Usage: $0 <rocksdb_version>" |
| 62 | + else |
| 63 | + log "using rocksdb version: $1" |
| 64 | + fi |
| 65 | + |
| 66 | + if [[ -d /vagrant ]]; then |
| 67 | + if [[ $OS = "ubuntu" ]]; then |
| 68 | + package g++-4.7 |
| 69 | + export CXX=g++-4.7 |
| 70 | + |
| 71 | + # the deb would depend on libgflags2, but the static lib is the only thing |
| 72 | + # installed by make install |
| 73 | + package libgflags-dev |
| 74 | + |
| 75 | + package ruby-all-dev |
| 76 | + elif [[ $OS = "centos" ]]; then |
| 77 | + pushd /etc/yum.repos.d |
| 78 | + if [[ ! -f /etc/yum.repos.d/devtools-1.1.repo ]]; then |
| 79 | + wget http://people.centos.org/tru/devtools-1.1/devtools-1.1.repo |
| 80 | + fi |
| 81 | + package devtoolset-1.1-gcc --enablerepo=testing-1.1-devtools-6 |
| 82 | + package devtoolset-1.1-gcc-c++ --enablerepo=testing-1.1-devtools-6 |
| 83 | + export CC=/opt/centos/devtoolset-1.1/root/usr/bin/gcc |
| 84 | + export CPP=/opt/centos/devtoolset-1.1/root/usr/bin/cpp |
| 85 | + export CXX=/opt/centos/devtoolset-1.1/root/usr/bin/c++ |
| 86 | + export PATH=$PATH:/opt/centos/devtoolset-1.1/root/usr/bin |
| 87 | + popd |
| 88 | + if ! rpm -qa | grep --quiet gflags; then |
| 89 | + rpm -i https://github.com/schuhschuh/gflags/releases/download/v2.1.0/gflags-devel-2.1.0-1.amd64.rpm |
| 90 | + fi |
| 91 | + |
| 92 | + package ruby |
| 93 | + package ruby-devel |
| 94 | + package rubygems |
| 95 | + package rpm-build |
| 96 | + fi |
| 97 | + fi |
| 98 | + gem_install fpm |
| 99 | + |
| 100 | + make static_lib |
| 101 | + make install INSTALL_PATH=package |
| 102 | + fpm \ |
| 103 | + -s dir \ |
| 104 | + -t $FPM_OUTPUT \ |
| 105 | + -n rocksdb \ |
| 106 | + -v $1 \ |
| 107 | + --prefix /usr \ |
| 108 | + --url http://rocksdb.org/ \ |
| 109 | + -m rocksdb@fb.com \ |
| 110 | + --license BSD \ |
| 111 | + --vendor Facebook \ |
| 112 | + --description "RocksDB is an embeddable persistent key-value store for fast storage." \ |
| 113 | + package |
| 114 | +} |
| 115 | + |
| 116 | +main $@ |
0 commit comments