-
-
Save 2xyo/2628491 to your computer and use it in GitHub Desktop.
Setup virtual env for appengine
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# | |
# Build a virtual environment suitable for running appengine. | |
# This uses virtualenvwrapper to make the virtual environment | |
# and modifies the postactivate/postdeactivate scripts to make | |
# the appengine code happy. | |
# | |
# Usage: | |
# $ curl -s https://raw.github.com/gist/2628491 | bash | |
# | |
# | |
# Install steps: | |
# 1) Checks for virtualenvwrapper and install if needed. | |
# 2) Activates virtualenvwrapper and creates $WORKON_HOME | |
# 3) Makes 'appengine' virtual environment | |
# 4) Modifies postactivate scripts | |
# 5) Downloads and extracts google appengine source | |
# 6) pip installs a few extra packages | |
# | |
# Ubuntu Install Help | |
# 1) First Install python2.5, python-setuptools and curl | |
# 2) sudo add-apt-repository ppa:fkrull/deadsnakes | |
# 3) sudo apt-get update | |
# 4) sudo apt-get install curl python-setuptools python2.5 | |
PLATFORM=`uname -s` | |
if [[ $PLATFORM -eq "Linux" ]] | |
then | |
# Check if python2.5 installed and install other prereqs | |
# Ubuntu no longer has python2.5 in a main repository. | |
which python2.5 | |
if [ ! $? == 0 ] | |
then | |
sudo add-apt-repository ppa:fkrull/deadsnakes | |
sudo apt-get update | |
sudo apt-get install curl python-setuptools python2.5-dev libssl-dev libbluetooth-dev | |
fi | |
which python2.7 | |
if [ ! $? == 0 ] | |
then | |
sudo add-apt-repository ppa:fkrull/deadsnakes | |
sudo apt-get update | |
sudo apt-get install python2.7 python2.7-dev | |
fi | |
# check for individual packages in case they already had python2.5 | |
# just in case | |
if [ ! -e /usr/bin/curl ] | |
then | |
sudo apt-get install curl | |
fi | |
if [ ! -e /usr/bin/easy_install ] | |
then | |
sudo apt-get install python-setuptools | |
fi | |
# check for ssl | |
if [ ! -e /usr/include/openssl/ssl.h ] | |
then | |
sudo apt-get install libssl-dev | |
fi | |
# check for libbluetooth-dev | |
if [ ! -e /usr/include/bluetooth/bluetooth.h ] | |
then | |
sudo apt-get install libbluetooth-dev | |
fi | |
fi | |
LATEST_VERSION=`curl -s http://appengine.google.com/api/updatecheck | awk '$1 ~/release/ {print $2};' | sed s/\"//g` | |
# Modify me as new versions are released. | |
APPENGINE_VERSION=google_appengine_$LATEST_VERSION.zip | |
which virtualenvwrapper.sh | |
VWNOTFOUND=$? | |
if (( $VWNOTFOUND == 1 )) | |
then | |
echo 'Installing virtualenvwrapper...' | |
sudo easy_install virtualenvwrapper | |
fi | |
if [[ ! $WORKON_HOME ]] | |
then | |
export WORKON_HOME=$HOME/envs | |
fi | |
# make sure we are not dealing with a customize path | |
unset PYTHONPATH | |
mkdir -p $WORKON_HOME | |
source `which virtualenvwrapper.sh` | |
cd $WORKON_HOME | |
if [[ -e appengine ]] | |
then | |
echo "Deleting existing appengine ENV" | |
rm -rf appengine | |
fi | |
mkvirtualenv --no-site-packages --distribute --python=python2.7 appengine | |
if [[ ! $VIRTUAL_ENV ]] | |
then | |
echo "Problem running mkvirtualenv!" | |
exit 1 | |
fi | |
# Don't download the file over again. | |
if [ ! -e $APPENGINE_VERSION ] | |
then | |
curl -O http://googleappengine.googlecode.com/files/$APPENGINE_VERSION | |
fi | |
echo "Extracting Google App Engine source..." | |
unzip -q $APPENGINE_VERSION -d $VIRTUAL_ENV | |
if [ ! $? == 0 ] | |
then | |
echo "Problem unzipping file $APPENGINE_VERISON" | |
echo "Please delete it and try again!" | |
exit $? | |
fi | |
# Create a pth file for App Engine source | |
echo "$VIRTUAL_ENV/google_appengine" > $VIRTUAL_ENV/lib/python2.7/site-packages/gae.pth | |
# Link scripts | |
cd $VIRTUAL_ENV/bin | |
ln -s $VIRTUAL_ENV/google_appengine/*.py . | |
# link os.pyc to make appengine happy | |
REALPREFIX=`python2.7 -c "import sys;print sys.prefix"` | |
cd $VIRTUAL_ENV/lib/python2.7 | |
echo "Linking os.pyc to $REALPREFIX/lib/python2.7/os.pyc" | |
rm -rf os.pyc | |
ln -s $REALPREFIX/lib/python2.7/os.pyc | |
# SSL needs to be installed with sudo!! lame! | |
echo "Installing ssl with sudo:" | |
sudo $VIRTUAL_ENV/bin/pip install -q ssl | |
echo "Fixing perms" | |
sudo chown -R `whoami` $VIRTUAL_ENV | |
# uninstall webob as it conflicts with the bundled one in app engine. | |
echo "Uninstalling webob ..." | |
pip uninstall -q -y webob | |
echo "You are ready to roll. Edit .bashrc as needed and run 'workon appengine'" | |
if (( $VWNOTFOUND == 1 )) | |
then | |
echo "Virtualenvwrapper has been installed." | |
echo "Please add the following to your .bashrc file:" | |
echo ' export WORKON_HOME=$HOME/envs' | |
echo ' source `which virtualenvwrapper.sh`' | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment