Skip to content

Instantly share code, notes, and snippets.

@eru
Created April 4, 2016 08:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save eru/84fafee9a695aa1e90b3054e02334977 to your computer and use it in GitHub Desktop.
Save eru/84fafee9a695aa1e90b3054e02334977 to your computer and use it in GitHub Desktop.
#!/bin/sh
# set PKGCMD
PKGCMD="yum"
if type dnf >/dev/null 2>&1; then
PKGCMD="dnf"
fi
# check root user
if [ ${EUID:-${UID}} != 0 ]; then
PKGCMD="sudo ${PKGCMD}"
fi
# set spec path
SPECFILE="${HOME}/rpmbuild/SPECS/nginx.spec"
# install build requirements packages
${PKGCMD} install rpm-build GeoIP-devel gd-devel libxslt-devel openssl-devel pcre-devel perl-ExtUtils-Embed perl-devel zlib-devel gcc make which
# detect newest nginx version
NGINX_VERSION=(`curl http://nginx.org/packages/mainline/rhel/7/SRPMS/ | sed -nre 's/<a href="nginx-([0-9\.]+-1)\.el7\.ngx\.src\.rpm">.*/\1/p' | sort -t . -n -k 1,1 -k 2,2 -k 3,3 -r | head -n 1`)
# install source rpm package
rpm -ivh http://nginx.org/packages/mainline/rhel/7/SRPMS/nginx-${NGINX_VERSION}.el7.ngx.src.rpm
# patch spec file
sed -i -e 's/^\(%if 0%{?rhel} == 7\)$/\1 || 0%{?fedora} >= 18/g' ${SPECFILE}
# build packages
LC_ALL=C rpmbuild -bb ${SPECFILE}
# unset env
unset PKGCMD
unset SPECFILE
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment