Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
branch: master
Fetching contributors…

Cannot retrieve contributors at this time

executable file 125 lines (100 sloc) 3.203 kb
#!/usr/bin/env bash
shopt -s extglob
PYTHONS="/usr/bin/python /usr/bin/python2 `command -v python`"
CURL=`command -v curl`
trim()
{
trimmed=$1
trimmed="${trimmed#"${trimmed%%[![:space:]]*}"}" # remove leading whitespace characters
trimmed="${trimmed%"${trimmed##*[![:space:]]}"}" # remove trailing whitespace characters
echo $trimmed
}
usage()
{
printf "
Usage:
${0} [options]
options:
--python : Python interpreter.
"
}
parse_arguments()
{
for arg do
val=`echo "$arg" | sed -e "s;--[^=]*=;;"`
case "$arg" in
--python=*) PYTHONS="$val $PYTHONS" ;;
--help) usage ;;
*) echo "Can't find the option. :$arg";;
esac
done
}
parse_arguments $@
if [[ ! -x $CURL ]] ; then
echo "pythonbrew required curl. curl was not found in your path."
exit
fi
for PYTHON in $PYTHONS ; do
if [[ ! -x $PYTHON ]] ; then
continue
fi
PYTHON_VERSION=`$PYTHON -V 2>&1`
PYTHON_VERSION=${PYTHON_VERSION/"Python "/""}
PYTHON_VERSION_S=`echo $PYTHON_VERSION | sed -e "s/\(^[[:digit:]]\{1,\}.[[:digit:]]\{1,\}\).*/\1/"`
if [[ $PYTHON_VERSION_S = "2.4" ]] || [[ $PYTHON_VERSION_S = "2.5" ]] || [[ $PYTHON_VERSION_S = "2.6" ]] || [[ $PYTHON_VERSION_S = "2.7" ]] || [[ ${PYTHON_VERSION_S:0:1} = "3" ]] ; then
PYTHON_FOUND='1'
break
fi
done
if [[ $PYTHON_FOUND != '1' ]] ; then
echo "pythonbrew required Python (2.4, 2.5, 2.6 or 2.7)."
#TODO Installing python.
exit
fi
systemwide_install=0
if [[ -n "$PYTHONBREW_ROOT" ]] ; then
ROOT="$PYTHONBREW_ROOT"
else
if (( UID == 0 )) ; then
systemwide_install=1
ROOT="/usr/local/pythonbrew"
else
ROOT="$HOME/.pythonbrew"
fi
fi
PATH_DISTS="$ROOT/dists"
CURL_VERSION=`$CURL --version | head -n 1 | awk '{ print $2 }'`
VERSION_ARRAY=(`echo $CURL_VERSION | tr "." "\n"`)
CURL_MAJOR=${VERSION_ARRAY[0]}
CURL_MINOR=${VERSION_ARRAY[1]}
echo "Curl version is ${CURL_MAJOR}.${CURL_MINOR}"
CURL_ADDITIONAL_PARAMETERS=""
if (( $CURL_MAJOR >= 7 )) && (( $CURL_MINOR >= 10 )) ; then
CURL_PARAMETERS=k
fi
STABLE_VERSION=`$CURL -sL${CURL_ADDITIONAL_PARAMETERS} https://github.com/utahta/pythonbrew/raw/master/stable-version.txt`
STABLE_VERSION=`trim $STABLE_VERSION`
if [[ -z "$STABLE_VERSION" ]] ; then
echo 'Can not get stable-version of pythonbrew.'
exit 1
fi
TEMP_FILE="pythonbrew-$STABLE_VERSION"
TEMP_TARBALL="$TEMP_FILE.tar.gz"
DOWNLOAD_URL="http://pypi.python.org/packages/source/p/pythonbrew/$TEMP_TARBALL"
mkdir -p "$PATH_DISTS"
rm -rf "$PATH_DISTS/$TEMP_TARBALL"
rm -rf "$PATH_DISTS/$TEMP_FILE"
echo "Downloading $DOWNLOAD_URL"
builtin cd $PATH_DISTS ; $CURL --progress-bar -L${CURL_ADDITIONAL_PARAMETERS} $DOWNLOAD_URL -o "$TEMP_TARBALL"
echo "Extracting $PATH_DISTS/$TEMP_TARBALL"
builtin cd $PATH_DISTS ; tar zxf $TEMP_TARBALL
echo "Installing pythonbrew into $ROOT"
if (( systemwide_install == 1 )) ; then
PYTHONBREW_ROOT="$ROOT" $PYTHON $PATH_DISTS/$TEMP_FILE/pythonbrew_install.py --systemwide
else
$PYTHON $PATH_DISTS/$TEMP_FILE/pythonbrew_install.py
fi
if [[ $? == 1 ]] ; then
echo "Failed to install pythonbrew."
exit
fi
Jump to Line
Something went wrong with that request. Please try again.