Skip to content

Instantly share code, notes, and snippets.

@danpalmer
Created December 30, 2012 17:07
Show Gist options
  • Save danpalmer/4413883 to your computer and use it in GitHub Desktop.
Save danpalmer/4413883 to your computer and use it in GitHub Desktop.
#!/usr/bin/env bash
# bin/compile <build-dir> <cache-dir>
set -e
BUILD_DIR=$1
CACHE_DIR=$2
BUILDPACK_DIR=`cd $(dirname $0); cd ..; pwd`
SUPPORT_DIR="$BUILDPACK_DIR/support"
NGINX_DIR="nginx-1.2.6"
NGINX_FILENAME="$NGINX_DIR.tar.gz"
NGINX_URL="http://nginx.org/download/$NGINX_FILENAME"
mkdir -p $BUILD_DIR $CACHE_DIR
function progress() {
echo "-----> $1"
}
function indent() {
c='s/^/ /'
case $(uname) in
Darwin) sed -l "$c";;
*) sed -u "$c";;
esac
}
# Download and compile Nginx
cd $CACHE_DIR
progress "Downloading Nginx Sources"
curl $NGINX_URL -o $NGINX_FILENAME
progress "Extracting Nginx Sources"
tar -xzf $NGINX_FILENAME
rm $NGINX_FILENAME
cd $NGINX_DIR
progress "Configuring"
./configure --prefix=${BUILD_DIR}/nginx --without-http_rewrite_module 2>&1 | indent
progress "Compiling"
make 2>&1 | indent
progress "Installing"
make install 2>&1 | indent
progress "Creating Boot Script"
cp "$SUPPORT_DIR/nginx.conf.erb" "$BUILD_DIR/nginx/conf/nginx.conf.erb"
cd $BUILD_DIR
cat >>boot.sh <<EOF
#!/usr/bin/env bash
set -e
set -x
erb ~/nginx/conf/nginx.conf.erb > ~/nginx/conf/nginx.conf
touch ~/nginx/logs/access.log ~/nginx/logs/error.log
echo "Launching Nginx"
nginx -p ~/nginx
EOF
chmod +x boot.sh
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment