118 lines
3.9 KiB
Bash
118 lines
3.9 KiB
Bash
|
#!/bin/sh
|
||
|
# -*- mode: sh; tab-width: 8; coding: utf-8-unix -*-
|
||
|
|
||
|
DBUG() { echo DEBUG $* >&2 ; }
|
||
|
INFO() { echo INFO $* >&2 ; }
|
||
|
WARN() { echo WARN $* >&2 ; }
|
||
|
ERROR() { echo ERROR $* >&2 ; }
|
||
|
|
||
|
prog=`basename $0 .bash`
|
||
|
PREFIX=/usr/local
|
||
|
ROLE=base
|
||
|
|
||
|
[ -z "$PYVER" ] && PYVER=3 # echo ERROR define PYVER >&2 && exit 1
|
||
|
[ -z "$USER" ] && USER=$( id -un )
|
||
|
|
||
|
ini_file=/usr/local/etc/testforge/testforge.bash
|
||
|
if [ ! -f $ini_file ] ; then
|
||
|
# bootstrap
|
||
|
[ -d /usr/local/etc/testforge ] || mkdir -p /usr/local/etc/testforge
|
||
|
[ -x /usr/bin/python$PYVER ] && \
|
||
|
echo export BASE_PYTHON${PYVER}_MINOR=`/usr/bin/python$PYVER --version|sed -e 's/.* //' -e 's/\.[0-9]*$//'` >> $ini_file
|
||
|
else
|
||
|
. $ini_file >/dev/null
|
||
|
fi
|
||
|
|
||
|
set -- -x
|
||
|
P="BASE_PYTHON${PYVER}_MINOR"
|
||
|
PYTHON_MINOR="$(eval echo \$$P)"
|
||
|
[ -n "$PYTHON_MINOR" ] || \
|
||
|
PYTHON_MINOR=$( python$PYVER --version 2>&1| sed -e 's@^.* @@' -e 's@\.[0-9]*$@@' )
|
||
|
|
||
|
if [ -z "$LIB" -a -d /usr/lib/python$PYTHON_MINOR ] ; then
|
||
|
LIB=lib
|
||
|
elif [ -z "$LIB" -a -d /usr/lib64/python$PYTHON_MINOR ] ; then
|
||
|
LIB=lib64
|
||
|
elif [ -n "$LIB" -a ! -d /usr/$LIB/python$PYTHON_MINOR ] ; then
|
||
|
ERROR LIB=$LIB but no /usr/$LIB/python$PYTHON_MINOR
|
||
|
exit 1
|
||
|
fi
|
||
|
|
||
|
if [ "$USER" = root ] ; then
|
||
|
[ -f /usr/$LIB/python$PYTHON_MINOR/sitecustomize.py ] && \
|
||
|
mv /usr/$LIB/python$PYTHON_MINOR/sitecustomize.py /usr/$LIB/python$PYTHON_MINOR/sitecustomize.py.bak && \
|
||
|
rm -f /usr/$LIB/python$PYTHON_MINOR/sitecustomize.pyc
|
||
|
fi
|
||
|
|
||
|
if [ ! -d /usr/local/$LIB/python$PYTHON_MINOR/site-packages/ ] ; then
|
||
|
if [ "$USER" = root ] ; then
|
||
|
mkdir -p /usr/local/$LIB/python$PYTHON_MINOR/site-packages/
|
||
|
chgrp adm /usr/local/$LIB/python$PYTHON_MINOR/site-packages/
|
||
|
chmod 775 /usr/local/$LIB/python$PYTHON_MINOR/site-packages/
|
||
|
else
|
||
|
ERROR Install error missing /usr/local/$LIB/python$PYTHON_MINOR/site-packages/
|
||
|
exit 2
|
||
|
fi
|
||
|
fi
|
||
|
|
||
|
[ -d /usr/local/$LIB/python$PYTHON_MINOR/site-packages/ ] || \
|
||
|
mkdir -p /usr/local/$LIB/python$PYTHON_MINOR/site-packages/
|
||
|
[ -f /usr/local/$LIB/python$PYTHON_MINOR/site-packages/sitecustomize.py ] || \
|
||
|
cat > /usr/local/$LIB/python$PYTHON_MINOR/site-packages/sitecustomize.py << EOF
|
||
|
# -*- mode: python; indent-tabs-mode: nil; py-indent-offset: 4; coding: utf-8 -*-
|
||
|
|
||
|
from __future__ import print_function
|
||
|
|
||
|
import codecs
|
||
|
codecs._codecs_lookup = codecs.lookup
|
||
|
def lookup(s):
|
||
|
if s.endswith('-unix'):
|
||
|
s = s[:-5]
|
||
|
elif s.endswith('-dos'):
|
||
|
s = s[:-4]
|
||
|
return codecs._codecs_lookup(s)
|
||
|
codecs.lookup = lookup
|
||
|
|
||
|
import os,sys
|
||
|
pyver = sys.version[:3]
|
||
|
notver = "3" if sys.version[:1] == '2' else '2'
|
||
|
|
||
|
for elt in sys.path:
|
||
|
if elt.find('python' + notver) < 0: continue
|
||
|
p = os.environ.get('PYTHONPATH', '')
|
||
|
sys.stderr.write('WARN: sitecustomize.py PYTHONPATH=' +p +' sys.path=' +repr(sys.path) +'\n')
|
||
|
sys.stderr.write('"python' + notver +' in sys.path for ' +sys.executable +"\n")
|
||
|
raise RuntimeError('"python' + notver +' in sys.path for ' +sys.executable)
|
||
|
|
||
|
dir=None
|
||
|
for elt in ['var', 'usr']:
|
||
|
if 'LD_LIBRARY_PATH' not in os.environ or 'PYTHONPATH' not in os.environ:
|
||
|
continue
|
||
|
dir = '/' + elt + '/local/bin'
|
||
|
if dir not in os.environ['PATH'].split(os.pathsep):
|
||
|
continue
|
||
|
dir = '/' + elt + "/local/$LIB"
|
||
|
if dir not in os.environ['LD_LIBRARY_PATH'].split(os.pathsep):
|
||
|
continue
|
||
|
dir = '/' + elt + "/local/$LIB/python" + pyver + '/site-packages'
|
||
|
# the bash wrapper will have put this on
|
||
|
if dir in os.environ['PYTHONPATH'].split(os.pathsep):
|
||
|
# print(repr(sys.path))
|
||
|
if dir not in sys.path:
|
||
|
sys.path.insert(0, dir)
|
||
|
bin = '/' + elt + '/local/bin/python' + pyver[0]
|
||
|
if elt == 'var':
|
||
|
bin += '.bash'
|
||
|
else:
|
||
|
bin += '.sh'
|
||
|
if os.path.isfile(bin):
|
||
|
# print(sys.executable + '=' + bin)
|
||
|
sys.executable = bin
|
||
|
# var takes precedence
|
||
|
break
|
||
|
|
||
|
if __name__ == '__main__':
|
||
|
print(sys.executable)
|
||
|
del os, sys, dir, elt, pyver
|
||
|
EOF
|