Skip to content

Instantly share code, notes, and snippets.

@eru
Last active April 4, 2016 07:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save eru/2a8a342e499809cd12b4 to your computer and use it in GitHub Desktop.
Save eru/2a8a342e499809cd12b4 to your computer and use it in GitHub Desktop.
#!/bin/sh
# check root and set MY_YUM
MY_YUM="sudo yum"
if [ ${EUID:-${UID}} = 0 ]; then
MY_YUM="yum"
fi
# remove exists git package
eval ${MY_YUM} erase -y git
# install requied packages
eval ${MY_YUM} install -y tar gcc-c++ curl-devel expat-devel gettext-devel openssl-devel zlib-devel perl-ExtUtils-MakeMaker rpmdevtools rpm-build xmlto asciidoc perl-Error
# create rpmbuild tree
rpmdev-setuptree
cd ~/rpmbuild/SOURCES
# detect newest git version
GIT_VERSION=$(curl -sL https://www.kernel.org/pub/software/scm/git/ | sed -nre 's/<a href="git-([0-9\.]+)\.tar\.gz">.*/\1/p' | sort -t . -n -k 1,1 -k 2,2 -k 3,3 -r | head -n 1)
# download source archive
curl -OL https://www.kernel.org/pub/software/scm/git/git-${GIT_VERSION}.tar.gz
# extract spec
cd ../SPECS
tar xvf ../SOURCES/git-${GIT_VERSION}.tar.gz git-${GIT_VERSION}/git.spec
mv git-${GIT_VERSION}/git.spec .
# build rpm
rpmbuild -bb git.spec
# install git rpm
eval ${MY_YUM} localinstall -y ~/rpmbuild/RPMS/x86_64/git-${GIT_VERSION}-1.el6.x86_64.rpm ~/rpmbuild/RPMS/x86_64/perl-Git-${GIT_VERSION}-1.el6.x86_64.rpm
# unset env
unset MY_YUM
unset GIT_VERSION
# show message
echo "Complete\!\nYou can delete build files 'rm -rf ~/rpmbuild'"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment