Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save Geekfish/7433322 to your computer and use it in GitHub Desktop.
Save Geekfish/7433322 to your computer and use it in GitHub Desktop.
#!/bin/bash
echo "This script will rebuild a Debian style package (deb) of latest stable"
echo "Nginx. The original deb is from nginx.org apt repository."
echo
echo "This will prompt you yes or no on a few changes to the build as well as"
echo "it will compile and package the latest Google NGX Pagespeed module."
echo
echo "This is built and tested on Ubuntu 12.04 LTS, fresh OS install."
echo "There are no guarantees, and I take no liability if it breaks, but it"
echo "worked perfect on my machine."
echo
echo "Would you like to continue?"
select yn in "Yes" "No"; do
case $yn in
Yes ) break;;
No ) exit;;
esac
done
CHANGE_USER=yes
REMOVE_DAV=no
PAGESPEED_VER="1.7.30.1"
apt-get update && apt-get upgrade -y
apt-get install build-essential -y
apt-get build-dep nginx -y
apt-get install dpkg-dev build-essential zlib1g-dev libpcre3 libpcre3-dev git unzip -y
wget http://nginx.org/keys/nginx_signing.key
apt-key add nginx_signing.key
echo "deb http://nginx.org/packages/debian/ squeeze nginx" > /etc/apt/sources.list.d/nginx.list
echo "deb-src http://nginx.org/packages/debian/ squeeze nginx" >> /etc/apt/sources.list.d/nginx.list
apt-get update
cd /tmp
apt-get source nginx
NGINX_VER=$(find ./nginx* -maxdepth 0 -type d | sed "s|^\./||")
NGINX_BUILD_DIR=/tmp/$NGINX_VER
if [ "$CHANGE_USER" = "yes" ]; then
sed -ie s/--user=nginx/--user=www-data/g $NGINX_BUILD_DIR/debian/rules
sed -ie s/--group=nginx/--group=www-data/g $NGINX_BUILD_DIR/debian/rules
fi
if [ "$REMOVE_DAV" = "yes" ]; then
sed -i '/--with-http_dav_module \\/d' $NGINX_BUILD_DIR/debian/rules
fi
sed -i '/--with-http_flv_module \\/d' $NGINX_BUILD_DIR/debian/rules
sed -i '/--with-http_mp4_module \\/d' $NGINX_BUILD_DIR/debian/rules
sed -i '/--with-mail \\/d' $NGINX_BUILD_DIR/debian/rules
sed -i '/--with-mail_ssl_module \\/d' $NGINX_BUILD_DIR/debian/rules
sed -i '/--with-http_sub_module \\/i--with-http_geoip_module \\' $NGINX_BUILD_DIR/debian/rules
mkdir $NGINX_BUILD_DIR/modules
wget https://github.com/pagespeed/ngx_pagespeed/archive/release-$PAGESPEED_VER-beta.zip -O $NGINX_BUILD_DIR/modules/release-$PAGESPEED_VER-beta.zip
unzip $NGINX_BUILD_DIR/modules/release-$PAGESPEED_VER-beta.zip -d $NGINX_BUILD_DIR/modules
rm -f $NGINX_BUILD_DIR/modules/release-$PAGESPEED_VER-beta.zip
wget https://dl.google.com/dl/page-speed/psol/$PAGESPEED_VER.tar.gz -O $NGINX_BUILD_DIR/modules/ngx_pagespeed-release-$PAGESPEED_VER-beta/$PAGESPEED_VER.tar.gz
tar -C $NGINX_BUILD_DIR/modules/ngx_pagespeed-release-$PAGESPEED_VER-beta -xzf $NGINX_BUILD_DIR/modules/ngx_pagespeed-release-$PAGESPEED_VER-beta/$PAGESPEED_VER.tar.gz
rm -f $NGINX_BUILD_DIR/modules/ngx_pagespeed-release-$PAGESPEED_VER-beta/$PAGESPEED_VER.tar.gz
sed -i '/--with-file-aio \\/i--add-module=modules/ngx_pagespeed-release-'"$PAGESPEED_VER"'-beta \\' $NGINX_BUILD_DIR/debian/rules
cd $NGINX_BUILD_DIR
dpkg-buildpackage -b
echo
echo
echo
echo "***************************************************************"
echo "* install package from /tmp like so: *"
echo "* dpkg -i /tmp/nginx_$NGINX_VER~squeeze_amd64.deb *"
echo "* or if you want the debug version *"
echo "* dpkg -i /tmp/nginx-debug_$NGINX_VER~squeeze_amd64.deb *"
echo "* *"
if [ "$CHANGE_USER" = "yes" ]; then
echo "* REMEMBER TO CHANGE /etc/nginx/nginx.conf user to www-data *"
echo "* *"
fi
echo "* To test pagespeed: *"
echo "* in the file /etc/nginx/nginx.conf *"
echo "* add the following in the http { ... } block *"
echo "* pagespeed on; *"
echo "* pagespeed FileCachePath /var/ngx_pagespeed_cache; *"
echo "* *"
echo "* then: *"
echo "* mkdir /var/ngx_pagespeed_cache *"
if [ "$CHANGE_USER" = "yes" ]; then
echo "* chown www-data:www-data /var/ngx_pagespeed_cache *"
else
echo "* chown nginx:nginx /var/ngx_pagespeed_cache *"
fi
echo "* then: *"
echo "* /etc/init.d/nginx reload *"
echo "* curl -I -p http://localhost|grep X-Page-Speed *"
echo "* *"
if [ "$PATCH_SYSLOG" = "yes" ]; then
echo "* for logging to syslog: *"
echo "* see https://github.com/yaoweibin/nginx_syslog_patch *"
fi
echo "* *"
echo "***************************************************************"
echo
exit 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment