##// END OF EJS Templates
release 6.2.0
release 6.2.0

File last commit:

r1752:af0aa7a3
r23941:80cec70f
Show More
pkginstall
119 lines | 3.2 KiB | text/plain | TextLexer
#!/bin/bash
#
# Simple installation shell script for Python packages.
#
# Usage:
# pkginstall PAKPREFIX [PYPACKAGE]
#
# PAKPREFIX: prefix of the package as distributed in the tarball.
#
# PYPACKAGE: name of the Python package as it will end up installed. If not
# given, it defaults to PAKPREFIX.
#
#-----------------------------------------------------------------------------
# Process command-line args
#
PAKPREFIX=$1
PYPACKAGE=${2:-$PAKPREFIX}
#-----------------------------------------------------------------------------
# Configure main variables
#
# Defaults for variables that the .cfg file may override.
PYTHON_DEFAULT=python
PREFIX_DEFAULT=$HOME/usr/local
# Read config file which may declare user values for these variables.
source ./pkginstall.cfg
# Set the variables we'll actually use, either from the config file or from our
# defaults.
PYTHON=${PYTHON-${PYTHON_DEFAULT}}
PREFIX=${PREFIX-${PREFIX_DEFAULT}}
#-----------------------------------------------------------------------------
# 'Main' code begins
#
# Find the actual python executable path
PYTHONX=$(which $PYTHON)
if [[ ! -x $PYTHONX ]]; then
echo "ERROR: no python executable found at given path: $PYTHON"
echo "Aborting."
exit 1
fi
# Python version information. PYTHONV holds a versioned string used to build
# the site-packages path for the actual Python version we'll use.
PYVER=$($PYTHONX -ESV 2>&1)
PYVER_MINOR=${PYVER#Python }
PYVER_MAJOR=${PYVER_MINOR:0:3}
PYTHONV=python${PYVER_MAJOR}
# Set prefixes and other variables for the installation path.
SITEPKG=${PREFIX}/lib/${PYTHONV}/site-packages
SITEPKG64=${PREFIX}/lib64/${PYTHONV}/site-packages
# User diagnostics of current config
echo "Configuration:"
echo " PYTHON : $PYTHON"
echo " PYTHONX : $PYTHONX"
echo " PREFIX : $PREFIX"
echo " SITEPKG : $SITEPKG"
echo " SITEPKG64: $SITEPKG64"
# Find tarball
tarball=$(ls *$PAKPREFIX*.tar.*)
if [[ -z $tarball ]]; then
echo "ERROR: tarball not found for $PYPACKAGE"
exit 1
fi
# Figure out the name of the directory and compression format to use to unpack
pakdir=$(echo $tarball | awk -F '.tar.' '{print $1}')
tarfmt=$(echo $tarball | awk -F '.tar.' '{print $2}')
if [[ $tarfmt == "gz" ]]; then
tarflag="z"
else
tarflag="j"
fi
# Unpack the tarball if needed
if [[ ! -d $pakdir ]]; then
echo "Unpacking tarball: $tarball"
tar -x -${tarflag} -f $tarball
if [[ ! -d $pakdir ]]; then
echo "Tarball $tarball unpacked to unexpected path, aborting"
exit 1
fi
fi
# Remove existing ${PYPACKAGE} to make sure the build doesn't pick up spurious
# things. We don't touch the bin/ dir or anything else because it's hard to
# know what goes there in advance. But this should prevent most serious
# problems.
rm -rf $SITEPKG/${PYPACKAGE}
rm -rf $SITEPKG/${PYPACKAGE}*.egg
rm -rf $SITEPKG/${PYPACKAGE}*.egg-info
rm -rf $SITEPKG64/${PYPACKAGE}
rm -rf $SITEPKG64/${PYPACKAGE}*.egg
rm -rf $SITEPKG64/${PYPACKAGE}*.egg-info
# Make/install phase
# Set python search path correctly
export PYTHONPATH=$SITEPKG:$SITEPKG64:$PYTHONPATH
# Ensure install dirs exist
mkdir -p $SITEPKG
mkdir -p $SITEPKG64
cd ${pakdir}
rm -rf build dist
$PYTHONX setup.py clean
time $PYTHONX setup.py install --prefix=$PREFIX