Skip to content

Instantly share code, notes, and snippets.

@tweekmonster
Created May 6, 2015 18:27
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tweekmonster/38454b465b386a1991b2 to your computer and use it in GitHub Desktop.
Save tweekmonster/38454b465b386a1991b2 to your computer and use it in GitHub Desktop.
Script for compiling Python 2.7.9 on Ubuntu 14.04 LTS
#!/bin/sh
# Script for compiling Python 2.7.9 on Ubuntu 14.04 LTS and installing it to /usr/local
# * Source files are downloaded and left at /usr/local/src
# * Uses checkinstall to generate a deb package, so it will take a while.
# * Can be uninstalled using 'dpkg -r private-compiled-python2.7'
# * Uncomment line 57 if you *don't* want to install virtualenv and supervisor
# * Gists will be downloaded if supervisor's conf or init script doesn't exist.
# * You'll need to add /usr/local/bin to your PATH if it's not already
ohshi()
{
tput setaf 1
echo "${1}"
tput sgr0
exit 1
}
apt-get update
apt-get -y install build-essential checkinstall
apt-get -y build-dep python2.7 python3.4
prefix="/usr/local"
py_url="https://www.python.org/ftp/python/2.7.9/Python-2.7.9.tgz"
dl_file="${prefix}/src/python2.7.9.tgz"
if [ ! -e "${dl_file}" ]; then
curl -o "${dl_file}" -L "${py_url}"
fi
src_dir=$(tar -tf "${dl_file}" | grep -o '^[^/]\+' | sort -u)
src_dir="${prefix}/src/${src_dir}"
cd "${prefix}/src"
tar zxvf "${dl_file}"
cd "${src_dir}"
export arch=$(dpkg-architecture -qDEB_HOST_MULTIARCH)
export LDFLAGS="-L/usr/lib/$arch -L/lib/$arch"
export CFLAGS="-I/usr/include/$arch"
export CPPFLAGS="-I/usr/include/$arch"
./configure --prefix="${prefix}" --with-system-expat --with-system-ffi --enable-unicode="ucs4" --with-cxx-main="/usr/bin/g++" --enable-ipv6
[ $? -ne 0 ] && ohshi "configure exited with an error!"
make -j 2
[ $? -ne 0 ] && ohshi "make exited with an error!"
checkinstall -y -D --pkgname="private-compiled-python2.7"
[ $? -ne 0 ] && ohshi "checkinstall exited with an error!"
unset arch LDFLAGS CFLAGS CPPFLAGS
python="${prefix}/bin/python"
curl -sSL "https://bootstrap.pypa.io/get-pip.py" | $python
# echo "All Done!"
# exit 0
supervisor_initd="https://gist.githubusercontent.com/tweekmonster/1fbf61399ff6489daea0/raw/e13a0992dbbe55769fde5946e2b7398e74db2742/supervisord"
supervisor_conf="https://gist.githubusercontent.com/tweekmonster/5cfb5b61a36d59c6ebda/raw/b5dbb442ff1ae22c6f7aa940ba91ef7a799995bb/supervisord.conf"
pip="${prefix}/bin/pip"
$pip install supervisor virtualenv virtualenvwrapper
if [ -e "/etc/init.d/supervisord" ]; then
tput setaf 1
echo "Not downloading init.d script: /etc/init.d/supervisord already exists!"
tput sgr0
echo "You can get it here and do it yourself: ${supervisor_initd}"
else
curl -sSL "${supervisor_initd}" -o "/etc/init.d/supervisord"
chmod +x "/etc/init.d/supervisord"
update-rc.d supervisord defaults
fi
mkdir -p "/etc/supervisor/conf.d"
mkdir -p "/var/log/supervisor"
chown root:adm "/var/log/supervisor"
if [ ! -e "/etc/supervisor/supervisord.conf" ]; then
curl -sSL "${supervisor_conf}" -o "/etc/supervisor/supervisord.conf"
fi
echo "All done"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment