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