make_package.sh 3.1 KB

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