Skip to content

Instantly share code, notes, and snippets.

@ycombinator
Created June 5, 2014 00:58
Show Gist options
  • Save ycombinator/edf193a5f5cb4fff8b95 to your computer and use it in GitHub Desktop.
Save ycombinator/edf193a5f5cb4fff8b95 to your computer and use it in GitHub Desktop.
#!/bin/bash
#
# This script builds the various parts of the site (Getting Started guides,
# blog, etc.) and combines them into a single directory, `site_html`.
#
PROJECT_ROOT="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
BUILD_DIR=/tmp/developer.rackspace.com
WORK_DIR=$BUILD_DIR/_work
TARGET_DIR=$PROJECT_ROOT/_site
ALL_PIDS=$(pgrep build_site.sh)
NUM_ALL_PIDS=$(echo "$ALL_PIDS" | wc -l)
if (( $NUM_ALL_PIDS == 2 )); then
# If I have exactly one twin running, delay my run
# so my twin might complete.
while [ $NUM_ALL_PIDS -gt 1 ]; do
echo "Its me and my twin... sleeping for 30 seconds"
sleep 30
ALL_PIDS=$(pgrep build_site.sh)
NUM_ALL_PIDS=$(echo "$ALL_PIDS" | wc -l)
done
elif (( $NUM_ALL_PIDS > 2 )); then
# Else if there more than just the two of us,
# commit suicide.
echo "There are more than 2 of us; committing suicide"
exit
fi
echo "I'm the only one running... continuing!"
# Create temporary work directory
rm -rf $WORK_DIR
mkdir -p $WORK_DIR
# Copy the site source into the work directory
rsync -Ca $PROJECT_ROOT/src/site_source/ $WORK_DIR/
# Build the Getting Started guides in the `docs/` directory using Sphinx
cd $PROJECT_ROOT/src/docs
/usr/local/bin/sphinx-build . $WORK_DIR/docs
# Build the web site HTML
export LANG=en_US.UTF-8
export LC_ALL=en_US.UTF-8
cd $WORK_DIR
/usr/local/bin/jekyll build --source . --destination $BUILD_DIR/_site
# Copy to target dir
rsync -Ca $BUILD_DIR/_site/ $TARGET_DIR/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment