Created
December 24, 2012 20:42
-
-
Save gedex/4370623 to your computer and use it in GitHub Desktop.
Build multiple Python versions.
This file contains hidden or 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 multiple Python versions. | |
# | |
# Author: Akeda Bagus <[email protected]> | |
# Licensed under MIT license. | |
BASE_URL=http://python.org/ftp/python/ | |
CURRENT_DIR=$(pwd) | |
# This is where all python version will be built | |
TARGET_DIR="/home/lang/python/" | |
PYTHON_VERSION=$1 | |
DOWNLOAD_FILENAME="Python-${PYTHON_VERSION}.tar.bz2" | |
DOWNLOAD_URL="${BASE_URL}${PYTHON_VERSION}/${DOWNLOAD_FILENAME}" | |
CHECK_DOWNLOAD="curl -o /dev/null --silent --head --write-out '%{http_code}' ${DOWNLOAD_URL}" | |
DOWNLOAD_CMD="curl -C - -O ${DOWNLOAD_URL}" | |
EXTRACT_CMD="tar -xjf ${DOWNLOAD_FILENAME}" | |
# Adjust to your needs | |
BUILD_OPTIONS= | |
usage() { | |
echo -e "Build multiple Python version." | |
echo -e "Usage: $0 [arguments] [PYTHON_VERSION]\n" | |
echo -e "Examples:" | |
echo -e "Build Python 2.7.3" | |
echo -e "\t $0 2.7.3\n" | |
echo -e "List of available PYTHON_VERSION" | |
echo -e "\t $0 list\n" | |
echo -e "[arguments]" | |
echo -e " help\t Display this help" | |
echo -e " list\t List of available PYTHON_VERSION" | |
} | |
python_version_list() { | |
echo -e "See http://python.org/ftp/python/" | |
} | |
python_switch_to() { | |
echo -e "Not Implemented yet" | |
exit 1 | |
} | |
mismatch_version() { | |
echo -e "Unrecognized version $PYTHON_VERSION." | |
python_version_list | |
exit 1 | |
} | |
python_build() { | |
# Set the prefix or target build dir | |
TARGET_VERSION_DIR=${TARGET_DIR}${PYTHON_VERSION} | |
if [ -d "$TARGET_VERSION_DIR" ] | |
then | |
# TODO: Rebuild or switch to | |
echo -e "$PYTHON_VERSION already exists" | |
exit 1 | |
fi | |
# Download the source | |
HTTP_CODE=$($CHECK_DOWNLOAD) | |
if [[ $HTTP_CODE != "'200'" ]] | |
then | |
mismatch_version | |
fi | |
$DOWNLOAD_CMD | |
$EXTRACT_CMD | |
rm $DOWNLOAD_FILENAME | |
mv Python-${PYTHON_VERSION} $TARGET_VERSION_DIR | |
cd ${TARGET_VERSION_DIR} | |
# Build | |
make clean | |
./configure --prefix=${TARGET_VERSION_DIR} ${BUILD_OPTIONS} | |
make | |
make install | |
cd $CURRENT_DIR | |
exit 0 | |
} | |
# If no args supplied | |
if [ $# -lt 1 ] | |
then | |
usage | |
exit 1 | |
fi | |
if [[ $1 == "help" ]] | |
then | |
usage | |
exit 0 | |
fi | |
if [[ $1 == "list" ]] | |
then | |
python_version_list | |
exit 0 | |
fi | |
# Otherwise arg is Python version to install or switch into | |
python_build | |
exit 0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment