Skip to content

Instantly share code, notes, and snippets.

@chixq
Created February 13, 2014 10:48
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save chixq/8973080 to your computer and use it in GitHub Desktop.
#!/bin/bash
#####
# Builds a custom nginx
#
# RELEASE_TAGS="+your+tags+here"
# RELEASE_MAINTAINER="Your Name Here"
# RELEASE_MAINTAINER_EMAIL="hi@example.com"
# RELEASE_MESSAGE="Some message"
#
#####
NGINX_VERSION="1.5.2"
NGINX_URL="http://www.nginx.org/download/nginx-$NGINX_VERSION.tar.gz"
who=`whoami`
sudo=
if [ "$who" != "root" ];then
$sudo='sudo'
fi
PACKAGE_MGM_TOOL=
PACKAGE_INSTALL_TOOL=
PACKAGE_QUERY_TOOL=
PACKAGE_BUILD_TOOL=
echo "[CMD] checking distrobution"
if [ -f /usr/bin/lsb_release ]; then
distro=`/usr/bin/lsb_release -d | awk '{ print $2 }'`
else
if [ -f /etc/redhat-release ]; then
distro=$(cat /etc/redhat-release | awk '{ print $1}')
elif [ -f /etc/debian_version ]; then
distro=$(cat /etc/debian_version | awk '{ print $1}')
fi
fi
echo "[CMD] verifying dependencies"
DEPS="git debhelper libgd2-xpm-dev libgeoip-dev liblua5.1-0-dev libmhash-dev libpam0g-dev libperl-dev libxslt1-dev po-debconf"
for i in $DEPS ; do
dpkg-query -W -f='${Package}\n' | grep ^$i$ > /dev/null
if [ $? != 0 ] ; then
echo "[Error] You need to install $i"
$sudo $PACKAGE_INSTALL_TOOL -y install $i
# missing_package=1
fi
done
# if [ $missing_package == 1 ] ; then
# exit 1
# fi
echo "[CMD] get the source from repo"
curl -L $NGINX_URL | tar zxvf
cd nginx-$NGINX_VERSION
# echo "[CMD] get the nginx version"
# nginx_version=`ls -lahF .|grep nginx|grep '^d[rwx-]\{9\} '| grep '\/$'|rev|cut -d' ' -f1 | rev|sed 's/nginx-//'|sed 's/\///'`
echo "[CMD] retrieve all the nginx modules you want"
if [[ "$distro" = "Ubuntu" ]]; then
cd "nginx-${nginx_version}/debian/modules"
else
cd "nginx-${nginx_version}/centos/modules"
echo "[CMD] clone all the nginx modules from github"
git clone -q git://github.com/zebrafishlabs/nginx-statsd.git
git clone -q git://github.com/FRiCKLE/ngx_coolkit.git
cd ..
echo "[CMD] ensure the proper dependencies are in place"
cat control | sed 's/libgd2-noxpm-dev/libgd2-xpm-dev/' >> tmp ; rm control ; mv tmp control
echo "[CMD] remove unneeded and broken modules"
cat rules |sed '/with-http_image_filter_module/ d' >> tmp ; rm rules ; mv tmp rules
echo "[CMD] split up the rules file so we can rewrite it"
awk '/\$\(CONFIGURE_OPTS\)/{n++}{filename = "rule-" n ; print > filename }' rules
echo "[CMD] adding modules to the nginx-full package"
echo -e "\t --add-module=\$(MODULESDIR)/headers-more-nginx-module \\" >> rule-
echo -e "\t --add-module=\$(MODULESDIR)/nginx-development-kit \\" >> rule-
echo -e "\t --add-module=\$(MODULESDIR)/nginx-lua \\" >> rule-
echo -e "\t --add-module=\$(MODULESDIR)/nginx-statsd \\" >> rule-
echo -e "\t --add-module=\$(MODULESDIR)/ngx_coolkit \\" >> rule-
echo "[CMD] combine all the rule files"
ls |grep rule-|while read file; do cat $file >> tmp; done; rm rules ; mv tmp rules
echo "[CMD] get the current nginx minor nginx_version"
minor_version=$(head -n 1 changelog | sed 's/ *ubuntu.*//' | sed 's/nginx (//'|cut -d '-' -f 2);
minor_version=$(($minor_version + 1));
echo "[CMD] get the current ubuntu release"
ubuntu_release=$(head -n 1 changelog| sed 's/ *\;.*//'|cut -d ' ' -f 3)
echo "[CMD] get the current time for this release"
release_time=$(LC_TIME=en_US.UTF-8 date +"%a, %d %b %Y %I:%M:%S %z")
echo "[CMD] update the changelog"
echo "nginx (${nginx_version}-${minor_version}${RELEASE_TAGS}) ${ubuntu_release}; urgency=low
[ ${RELEASE_MAINTAINER} ]
* New release: ${RELEASE_MESSAGE}
-- ${RELEASE_MAINTAINER} <${RELEASE_MAINTAINER_EMAIL}> ${release_time}
"|cat - changelog > tmp && mv tmp changelog
echo "[CMD] Create a build"
cd ..
dpkg-buildpackage
echo "[CMD] DONE!"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment