Guest User

Untitled

a guest
Dec 11th, 2018
134
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 6.07 KB | None | 0 0
  1. #!/bin/bash
  2.  
  3.  
  4. function extract() {
  5.     case "$1" in
  6.         *.tar.xz )
  7.             tar Jxf "$1"
  8.             DECOMP=`echo "$1" | sed 's/.tar.xz//'`
  9.             ;;
  10.         *.tar.gz )
  11.             tar zxf "$1"
  12.             DECOMP=`echo "$1" | sed 's/.tar.gz//'`
  13.             ;;
  14.         *.tar.bz2 )
  15.             tar jxf "$1"
  16.             DECOMP=`echo "$1" | sed 's/.tar.bz2//'`
  17.             ;;
  18.         *.tar )
  19.             tar xf "$1"
  20.             DECOMP=`echo "$1" | sed 's/.tar//'`
  21.             ;;
  22.         *.zip )
  23.             local destdir=`unzip -t "$1" | grep testing | head -n 1 | awk '{print $2}' | sed 's/\/$//'`
  24.             unzip -qo "$1"
  25.             if [ -d ${destdir} ]
  26.             then
  27.                 unzip -qo "$1"
  28.                 DECOMP=$destdir
  29.             else
  30.                 echo "Failed to decompress $1 . Unrecognized directory structure ${destdir}."
  31.                 unset DECOMP
  32.             fi
  33.             ;;
  34.     esac
  35. }
  36. function fetch_file() {
  37.     if [ -f "$1" ]
  38.     then
  39.         echo "Found local copy $1"
  40.     else
  41.         echo -n "Fetching $1 ..."
  42.         wget -nv -O $1 $2 2> /dev/null
  43.         echo " DONE"
  44.     fi
  45. }
  46.  
  47. function fetch_latest_fb_lib() {
  48.     local lpath="$1.tar.gz"
  49.     echo "Fetching $1 => $lpath"
  50.     local relurl="https://github.com/facebook/$1/releases"
  51.     local url=`wget -nv -O- $relurl 2> /dev/null | sed -n -r '/facebook\/.*archive\/.*tar.gz/ s/^.*(\/facebook\/.*\/archive\/)(.*\.tar\.gz).*/https:\/\/github.com\1\2/p' | head -n 1`
  52.     fetch_file $lpath $url
  53. }
  54.  
  55.  
  56. function fetch_deps() {
  57.     local libev=`wget -nv -O- https://github.com/libevent/libevent/releases 2> /dev/null | sed -n -r '/release-1.*\.tar\.gz/ s/^.*(\/libevent\/libevent\/archive\/release.*.tar.gz).*/https:\/\/github.com\1/p' | head -n 1`
  58.     fetch_file libevent.tar.gz $libev
  59.     local glogurl=`wget -nv -O- https://github.com/google/glog/releases 2> /dev/null | sed -n -r '/google\/glog\/archive\/.*\.tar\.gz/ s/^.*(\/google\/glog\/archive\/.*.tar.gz).*/https:\/\/github.com\1/p' | head -n 1`
  60.     fetch_file libglog.tar.gz $glogurl
  61.     local gflagsurl=`wget -nv -O- https://github.com/gflags/gflags/releases 2> /dev/null | sed -n -r '/gflags\/gflags\/archive\/.*\.tar\.gz/ s/^.*(\/gflags\/gflags\/archive\/.*.tar.gz).*/https:\/\/github.com\1/p' | head -n 1`
  62.     fetch_file libgflags.tar.gz $gflagsurl
  63.  
  64.     git clone https://github.com/google/double-conversion double-conversion
  65.     rm -rf double-conversion/.git
  66. }
  67.  
  68. function fetch() {
  69.     fetch_latest_fb_lib proxygen
  70.     fetch_latest_fb_lib folly
  71.     fetch_latest_fb_lib wangle
  72.  
  73.     fetch_deps
  74. }
  75.  
  76. function recompress() {
  77.     for f in *tar.gz;
  78.     do
  79.         gunzip $f
  80.     done
  81.     tar cf double-conversion.tar double-conversion
  82.     echo -n "Recompressing into mega.tar ..."
  83.     rm -f mega.tar
  84.     tar cf mega *.tar
  85.     mv mega mega.tar
  86.     echo -n " compressing .. "
  87.     xz -9 mega.tar
  88.     echo " DONE"
  89. }
  90.  
  91. function build() {
  92.     # Libevent
  93.     echo "========================== LIBEVENT ==========================="
  94.     extract libevent.tar
  95.     cd libevent-release-*
  96.     sed --in-place -r '1s/python$/python2/' event_rpcgen.py
  97.     ./autogen.sh
  98.     ./configure --with-gnu-ld
  99.     echo ">>>>>>>> Install LIBEVENT to /usr/local"
  100.     sudo make install
  101.     cd ..
  102.  
  103.     echo "========================== DOUBLE-CONVERSION ==========================="
  104.     # Double conversion
  105.     extract double-conversion.tar
  106.     cd double-conversion
  107.     sed --in-place -r '/CCFLAGS.append/ s/-O3/-O2 -march=westmere -mtune=westmere/' SConstruct
  108.     echo ">>>>>>>> Compile and install double-conversion to /usr/local"
  109.     sudo scons optimize=1 install
  110.     cd ..
  111.  
  112.     echo "========================== GFLAGS ==========================="
  113.     extract libgflags.tar
  114.     cd gflags*
  115.     cmake -D CMAKE_BUILD_TYPE=Release -D BUILD_SHARED_LIBS=ON -D BUILD_STATIC_LIBS=ON -D SITE=custom -D CMAKE_CXX_FLAGS="-O2 -march=westmere -mtune=westmere" -D CMAKE_C_FLAGS="-O2 -march=westmere -mtune=westmere"  .
  116.     make -j2
  117.     echo ">>>>>>>> Install GFLAGS to /usr/local"
  118.     sudo make install
  119.     cd ..
  120.  
  121.     echo "========================== GLOG ==========================="
  122.     extract libglog.tar
  123.     cd glog*
  124.     cmake -D CMAKE_BUILD_TYPE=Release -D BUILD_SHARED_LIBS=ON -D BUILD_STATIC_LIBS=ON -D CMAKE_RANLIB=/usr/bin/gcc-ranlib -D CMAKE_AR=/usr/bin/gcc-ar  -D SITE=custom -D CMAKE_CXX_FLAGS="-O2 -march=westmere -mtune=westmere" -D CMAKE_C_FLAGS="-O2 -march=westmere -mtune=westmere" .
  125.     ./configure --enable-static
  126.     make -j2
  127.     echo ">>>>>>>> Install GLOG to /usr/local"
  128.     sudo make install
  129.     sudo mkdir -p /usr/local/lib/cmake/glog; cp -a glog*cmake /usr/local/lib/cmake/glog
  130.     echo "======================================================================================== "
  131.     echo "WARN: Edit /usr/local/lib/cmake/glog/glog-targets.cmake to fix library/include locations"
  132.     echo "======================================================================================== "
  133.     cd ..
  134.  
  135.     echo "========================== FOLLY ==========================="
  136.     export LD_LIBRARY_PATH=/usr/local/lib
  137.     extract folly.tar
  138.     cd folly*/folly
  139.     mkdir _build; cd _build
  140.     cmake -D CMAKE_BUILD_TYPE=Release -D FOLLY_USE_JEMALLOC=0 ..
  141.     make -j2
  142.     echo ">>>>>>>> Install FOLLY to /usr/local"
  143.     sudo make install
  144.     cd ../..
  145.  
  146.     echo "========================== WANGLE ==========================="
  147.     extract wangle.tar
  148.     cd wangle*/wangle
  149.     cmake -D CMAKE_BUILD_TYPE=Release -D Boost_LIBRARY_DIR_RELEASE=/usr/lib -D BUILD_TESTS=OFF .
  150.     make
  151.     echo ">>>>>>>> Install WANGLE to /usr/local"
  152.     sudo make install
  153.     cd ../..
  154.  
  155.     echo "========================== PROXYGEN ==========================="
  156.     extract proxygen.tar
  157.     cd proxygen*/proxygen
  158.     autoreconf -ivf
  159.     ./configure
  160.     make
  161.     echo ">>>>>>>> Install PROXYGEN to /usr/local"
  162.     sudo make install
  163.  
  164.    
  165. }
  166.  
  167. function fetch_and_compress() {
  168.     # Run remotely, if needed
  169.     fetch
  170.     recompress
  171. }
  172.  
  173. function compile_locally() {
  174.     # Local compile
  175.     tar Jxf mega.tar.xz
  176.     build
  177. }
  178.  
  179.  
  180. fetch_and_compress
  181. compile_locally
Add Comment
Please, Sign In to add comment