github.com/x-oss-byte/git-lfs@v2.5.2+incompatible/rpm/build_rpms.bsh (about)

     1  #!/usr/bin/env bash
     2  
     3  set -eu
     4  
     5  CURDIR=$(cd $(dirname ${BASH_SOURCE[0]}); pwd)
     6  if [ -e /etc/os-release ]; then
     7    VERSION_ID=$(source /etc/os-release; echo ${VERSION_ID})
     8    OS_NAME=$(source /etc/os-release; echo ${NAME})
     9    OS_NAME=${OS_NAME,,}
    10  else #Basically Centos 5/6
    11    VERSION_ID=($(head -n 1 /etc/redhat-release | \grep -Eo '[0-9]+'))
    12    OS_NAME=$(awk '{print tolower($1)}' /etc/redhat-release)
    13    #Stupid ancient bash 3...
    14  fi
    15  
    16  case "${OS_NAME}" in
    17    centos*|red*)
    18      RPM_DIST=".el${VERSION_ID}"
    19      ;;
    20    fedora)
    21      RPM_DIST=".fc${VERSION_ID}"
    22      ;;
    23    sles)
    24      RPM_DIST=".sles${VERSION_ID}"
    25      ;;
    26    opensuse)
    27      RPM_DIST=".opensuse${VERSION_ID}"
    28      ;;
    29    *)
    30      RPM_DIST="%{nil}"
    31      ;;
    32  esac
    33  
    34  RPMBUILD=(rpmbuild --define "_topdir ${CURDIR}" --define "dist ${RPM_DIST}")
    35  if [[ ${NODEPS:-0} != 0 ]]; then
    36    RPMBUILD=("${RPMBUILD[@]}" --nodeps)
    37  fi
    38  
    39  SUDO=${SUDO=`if which sudo > /dev/null 2>&1; then echo sudo; fi`}
    40  export PATH=${PATH}:/usr/local/bin
    41  
    42  set -vx
    43  
    44  echo "Downloading/checking for some essentials..."
    45  if which git > /dev/null 2>&1; then
    46    GIT_VERSION=($(git --version))
    47    IFS_OLD=${IFS}
    48    IFS=.
    49    GIT_VERSION=(${GIT_VERSION[2]})
    50    IFS=${IFS_OLD}
    51  else
    52    GIT_VERSION=(0 0 0)
    53  fi
    54  
    55  SPEC=${CURDIR}/SPECS/git-lfs.spec
    56  
    57  if [[ ${VERSION_ID[0]} == 5 ]]; then
    58    if ! rpm -q epel-release > /dev/null 2>&1; then
    59      $SUDO yum install -y epel-release
    60    fi
    61  fi
    62  $SUDO yum install -y make curl which rpm-build tar bison perl-Digest-SHA
    63  
    64  mkdir -p ${CURDIR}/{BUILD,BUILDROOT,SOURCES,RPMS,SRPMS}
    65  
    66  if ( [[ ${GIT_VERSION[0]} == 1 ]] && [[ ${GIT_VERSION[1]} < 8 ]] ) || [[ ${GIT_VERSION[0]} < 1 ]]; then
    67    if [[ ${VERSION_ID[0]} != 6 ]]; then
    68      $SUDO yum install -y git
    69    else
    70      curl https://setup.ius.io/ | $SUDO bash
    71      yum install -y "git >= 1.8.2"
    72    fi
    73  fi
    74  
    75  if ! which go; then
    76    echo "Installing go... one way or another"
    77    if [[ ${VERSION_ID[0]} == 5 ]]; then
    78      $SUDO yum install -y curl.x86_64 glibc gcc
    79      ${CURDIR}/golang_patch.bsh
    80      "${RPMBUILD[@]}" -ba ${CURDIR}/SPECS/golang.spec
    81      $SUDO yum install -y --nogpgcheck ${CURDIR}/RPMS/noarch/golang-1*.rpm \
    82      ${CURDIR}/RPMS/noarch/golang-pkg-bin-linux-amd64-1*.rpm \
    83      ${CURDIR}/RPMS/noarch/golang-src-1*.noarch.rpm \
    84      ${CURDIR}/RPMS/noarch/golang-pkg-linux-amd64-1*.noarch.rpm \
    85      ${CURDIR}/RPMS/noarch/golang-pkg-linux-386-1*.noarch.rpm
    86    else
    87      $SUDO yum install -y epel-release
    88      $SUDO yum install -y golang
    89    fi
    90  fi
    91  
    92  if which ruby > /dev/null 2>&1; then
    93    IFS_OLD=${IFS}
    94    IFS=.
    95    RUBY_VERSION=($(ruby -e "print RUBY_VERSION"))
    96    IFS=${IFS_OLD}
    97  else
    98    RUBY_VERSION=(0 0 0)
    99  fi
   100  
   101  if [[ ${RUBY_VERSION[0]} < 2 ]]; then
   102    if [[ ${VERSION_ID[0]} < 7 ]]; then
   103      echo "Downloading ruby..."
   104  
   105      if ! rpm -q epel-release; then
   106        $SUDO yum install -y epel-release #Optional part of centos
   107      fi
   108  
   109      $SUDO yum install -y patch libyaml-devel glibc-headers autoconf gcc-c++ glibc-devel readline-devel zlib-devel libffi-devel openssl-devel automake libtool sqlite-devel
   110      pushd ${CURDIR}/SOURCES
   111        curl -L -O http://cache.ruby-lang.org/pub/ruby/2.2/ruby-2.2.2.tar.gz
   112      popd
   113      echo "Building ruby..."
   114      "${RPMBUILD[@]}" -ba ${CURDIR}/SPECS/ruby.spec
   115      echo "Installing ruby..."
   116      $SUDO yum install -y --nogpgcheck ${CURDIR}/RPMS/x86_64/ruby*.rpm
   117    else
   118      $SUDO yum install -y ruby ruby-devel
   119    fi
   120  fi
   121  
   122  if ! which ronn; then
   123    echo "Downloading some ruby gems..."
   124    pushd ${CURDIR}/SOURCES
   125      curl -L -O https://rubygems.org/downloads/rdiscount-2.1.8.gem
   126      curl -L -O https://rubygems.org/downloads/hpricot-0.8.6.gem
   127      curl -L -O https://rubygems.org/downloads/mustache-1.0.1.gem
   128      curl -L -O https://rubygems.org/downloads/ronn-0.7.3.gem
   129    popd
   130  
   131    echo "Building ruby gems..."
   132    "${RPMBUILD[@]}" -ba ${CURDIR}/SPECS/rubygem-rdiscount.spec
   133    "${RPMBUILD[@]}" -ba ${CURDIR}/SPECS/rubygem-mustache.spec
   134    "${RPMBUILD[@]}" -ba ${CURDIR}/SPECS/rubygem-hpricot.spec
   135    "${RPMBUILD[@]}" -ba ${CURDIR}/SPECS/rubygem-ronn.spec
   136  
   137    echo "Installing ruby gems..."
   138    $SUDO yum install -y --nogpgcheck $(ls ${CURDIR}/RPMS/noarch/rubygem-*.rpm ${CURDIR}/RPMS/x86_64/rubygem-*.rpm | grep -v debuginfo)
   139  fi
   140  
   141  pushd ${CURDIR}/..
   142    #Yes, compile lfs before compiling lfs...
   143    make
   144    #Use the version output to grab the version number and short sha
   145    #(that yes, I could have gotten from git myself)
   146    LFS_VERSION=$(./bin/git-lfs version | sed -r 's|.*/([0-9.]*).*|\1|')
   147    sed -i 's|\(^Version:\s*\).*|\1'"${LFS_VERSION}"'|' ${CURDIR}/SPECS/git-lfs.spec
   148  popd
   149  
   150  #Prep the SOURCES dir for git-lfs
   151  echo "Zipping up current checkout of git-lfs..."
   152  
   153  echo "Cleaning ${CURDIR}/tmptar"
   154  rm -rf ${CURDIR}/tmptar
   155  
   156  mkdir -p ${CURDIR}/tmptar/git-lfs-${LFS_VERSION}
   157  pushd ${CURDIR}/..
   158    #I started running out of space in the docker, so I needed to copy a little less waste
   159    tar -c . --exclude tmptar --exclude repos | tar -x -C ${CURDIR}/tmptar/git-lfs-${LFS_VERSION}/
   160  popd
   161  pushd ${CURDIR}/tmptar
   162    tar -zcf ${CURDIR}/SOURCES/git-lfs-${LFS_VERSION}.tar.gz git-lfs-${LFS_VERSION}
   163  popd
   164  
   165  echo "Cleaning ${CURDIR}/tmptar again"
   166  rm -rf ${CURDIR}/tmptar
   167  
   168  #TODO TASK 2
   169  #cp ${CURDIR}/../docker/public.key ${CURDIR}/SOURCES/RPM-GPG-KEY-GITLFS
   170  touch ${CURDIR}/SOURCES/RPM-GPG-KEY-GITLFS
   171  
   172  echo "Build git-lfs rpm..."
   173  
   174  #--no-deps added for now so you can compile without offical rpms installed
   175  "${RPMBUILD[@]}" --nodeps -ba ${CURDIR}/SPECS/git-lfs.spec
   176  
   177  echo "All Done!"