/
pkginstall
executable file
·119 lines (98 loc) · 3.17 KB
/
pkginstall
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
#!/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