Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save malfborger/566626b0480f2e286ba1 to your computer and use it in GitHub Desktop.
Save malfborger/566626b0480f2e286ba1 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 14.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
echo
echo "Please enter NGX Pagespeed version number which you can get from "
echo "https://github.com/pagespeed/ngx_pagespeed/releases "
echo "include the whole string, example: 1.9.32.1-beta "
echo "NGX Version: "
read NGX_PAGESPEED_VER
echo
CHANGE_USER=no
REMOVE_DAV=no
REMOVE_FLV=no
REMOVE_MP4=no
REMOVE_MAIL=no
ADD_GEOIP=no
echo "Would you like to change the user and group to www-data instead of default (nginx)?"
select yn in "Yes" "No"; do
case $yn in
Yes ) CHANGE_USER=yes; break;;
No ) break;;
esac
done
echo "Would you like to remove the http dav module?"
select yn in "Yes" "No"; do
case $yn in
Yes ) REMOVE_DAV=yes; break;;
No ) break;;
esac
done
echo "Would you like to remove the http flv module?"
select yn in "Yes" "No"; do
case $yn in
Yes ) REMOVE_FLV=yes; break;;
No ) break;;
esac
done
echo "Would you like to remove the http mp4 module?"
select yn in "Yes" "No"; do
case $yn in
Yes ) REMOVE_MP4=yes; break;;
No ) break;;
esac
done
echo "Would you like to remove the mail and mail ssl modules?"
select yn in "Yes" "No"; do
case $yn in
Yes ) REMOVE_MAIL=yes; break;;
No ) break;;
esac
done
echo "Would you like to add http-geoip module?"
select yn in "Yes" "No"; do
case $yn in
Yes ) ADD_GEOIP=yes; break;;
No ) break;;
esac
done
cd /tmp
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 && apt-get upgrade -y
apt-get install dpkg-dev build-essential zlib1g-dev libpcre3 libpcre3-dev git unzip -y
apt-get build-dep nginx -y
apt-get source nginx
PSOL_VER=$(echo $NGX_PAGESPEED_VER | cut -d \- -f 1)
NGINX_VER=$(find ./nginx* -maxdepth 0 -type d | sed "s|^\./||")
NGINX_VER_NUM=$(echo $NGINX_VER | cut -d \- -f 2)
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
if [ "$REMOVE_FLV" = "yes" ]; then
sed -i '/--with-http_flv_module \\/d' $NGINX_BUILD_DIR/debian/rules
fi
if [ "$REMOVE_MP4" = "yes" ]; then
sed -i '/--with-http_mp4_module \\/d' $NGINX_BUILD_DIR/debian/rules
fi
if [ "$REMOVE_MAIL" = "yes" ]; then
sed -i '/--with-mail \\/d' $NGINX_BUILD_DIR/debian/rules
sed -i '/--with-mail_ssl_module \\/d' $NGINX_BUILD_DIR/debian/rules
fi
if [ "$ADD_GEOIP" = "yes" ]; then
sed -i '/--with-http_sub_module \\/i--with-http_geoip_module \\' $NGINX_BUILD_DIR/debian/rules
fi
mkdir $NGINX_BUILD_DIR/modules
wget https://github.com/pagespeed/ngx_pagespeed/archive/release-$NGX_PAGESPEED_VER.zip -O $NGINX_BUILD_DIR/modules/release-$NGX_PAGESPEED_VER.zip
unzip $NGINX_BUILD_DIR/modules/release-$NGX_PAGESPEED_VER.zip -d $NGINX_BUILD_DIR/modules
rm -f $NGINX_BUILD_DIR/modules/release-$NGX_PAGESPEED_VER.zip
wget https://dl.google.com/dl/page-speed/psol/$PSOL_VER.tar.gz -O $NGINX_BUILD_DIR/modules/ngx_pagespeed-release-$NGX_PAGESPEED_VER/$PSOL_VER.tar.gz
tar -C $NGINX_BUILD_DIR/modules/ngx_pagespeed-release-$NGX_PAGESPEED_VER -xzf $NGINX_BUILD_DIR/modules/ngx_pagespeed-release-$NGX_PAGESPEED_VER/$PSOL_VER.tar.gz
rm -f $NGINX_BUILD_DIR/modules/ngx_pagespeed-release-$NGX_PAGESPEED_VER/$PSOL_VER.tar.gz
sed -i '/--with-file-aio \\/i--add-module=modules/ngx_pagespeed-release-|NGX_PAGESPEED_VER| \\' $NGINX_BUILD_DIR/debian/rules
sed -ie "s/|NGX_PAGESPEED_VER|/$NGX_PAGESPEED_VER/g" $NGINX_BUILD_DIR/debian/rules
echo "PSOL_VER: $PSOL_VER"
echo "NGINX_VER: $NGINX_VER"
echo "NGINX_VER_NUM: $NGINX_VER_NUM"
echo "NGINX_BUILD_DIR: $NGINX_BUILD_DIR"
echo "NGX_PAGESPEED_VER: $NGX_PAGESPEED_VER"
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_NUM~squeeze_amd64.deb *"
echo "* or if you want the debug version *"
echo "* dpkg -i /tmp/nginx-debug_$NGINX_VER_NUM~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 "* *"
echo "* *"
echo "***************************************************************"
echo
exit 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment