#!/bin/bash # -*- mode: sh; tab-width: 8; coding: utf-8-unix -*- shopt -s nullglob || { ERROR use bash ; exit 1 ; } . /usr/local/bin/usr_local_tput.bash || exit 2 . /usr/local/bin/usr_local_base.bash || exit 3 ROLE=base PREFIX=/usr/local [ -z "$PYVER" ] && PYVER=3 declare -a TARGET if [ -f /usr/local/etc/testforge/testforge.bash ] ; then . /usr/local/etc/testforge/testforge.bash >/dev/null || exit 1 P="BASE_PYTHON${PYVER}_MINOR" PYTHON_MINOR="$(eval echo \$$P)" fi [ -n "$PYTHON_MINOR" ] || \ PYTHON_MINOR=$( python$PYVER --version 2>&1| sed -e 's@^.* @@' -e 's@\.[0-9]*$@@' ) [ -z "$LIB" -a -d $PREFIX/lib/python$PYTHON_MINOR/site-packages ] && LIB=lib [ -z "$LIB" -a -d $PREFIX/lib64/python$PYTHON_MINOR/site-packages ] && LIB=lib64 if [ "$#" -eq 0 ] || [[ "$*" =~ "--version" ]] || [[ "$*" =~ "--help" ]] ; then $PREFIX/bin/python$PYVER.sh -m pip "$@" exit $? elif [ "$1" = 'html' ] ; then wget -c -O - https://pypi.org/project/$2 2>/dev/null exit $? elif [ "$1" = 'lynx' ] ; then lynx https://pypi.org/project/$2 exit $? elif [ "$1" = 'elinks' ] ; then elinks https://pypi.org/project/$2 exit $? fi if [ -x $PREFIX/bin/base_check_site_py.bash ] ; then $PREFIX/bin/base_check_site_py.bash $PYTHON_MINOR >/dev/null || exit $? fi if [ -n "$PYTHONPATH" ] && [ -x $PREFIX/bin/base_clean_pythonpath.bash ] ; then PYTHONPATH="$( $PREFIX/bin/base_clean_pythonpath.bash $PYTHON_MINOR $PYTHONPATH )" fi # could from pip import download;print(download.__file__) file=$PREFIX/$LIB/python$PYTHON_MINOR/site-packages/pip/download.py if [ -f $file ] && grep -q 'if not check_path_owner' $file ; then mv $file $file.dst sed -e 's/if not check_path_owner/if False and not check_path_owner/' \ > $file $file.dst fi #DBUG $prog PYTHON_MINOR=$PYTHON_MINOR PYTHONPATH=$PYTHONPATH LARGS="$BASE_PIP_GLOBAL_ARGS" # --no-python-version-warning if [ -f /usr/local/etc/ssl/cacert-testforge.pem ] ; then [[ "$*" =~ "--cert" ]] || [[ $LARGS =~ "--cert" ]] || LARGS="--cert $PREFIX/etc/ssl/cacert-testforge.pem $LARGS" fi if [ -e $PREFIX/net/Cache/Pip ] ; then [[ "$*" =~ "--cache-dir" ]] || [[ $LARGS =~ "--cache-dir" ]] || LARGS="--cache-dir $PREFIX/net/Cache/Pip $LARGS" fi [[ "$*" =~ "--timeout" ]] || [[ $LARGS =~ "--timeout" ]] || LARGS="--timeout=30 $LARGS" [[ "$*" =~ '--disable-pip-version-check' ]] || LARGS="--disable-pip-version-check $LARGS" [[ "$*" =~ '--proxy' ]] || LARGS="$LARGS --proxy http://localhost:3128" MYID=$( id -u ) if [ "$1" = 'uninstall' ] ; then [ $MYID -eq 0 ] && ERROR $prog should not be run as root $MYID && exit 2 elif [ "$1" = 'install' ] ; then [ $MYID -eq 0 ] && ERROR $prog should not be run as root $MYID && exit 2 shift RARGS="$RARGS --progress-bar=off" # LARGS="$LARGS --python=/usr/local/bin/python$PYTHON_MINOR.sh" /usr/local/bin/proxy_ping_test.bash wifi # || exit 3$? # Can not combine '--user' and '--prefix' if true ; then # >9.0.1 if [[ $RARGS =~ "--prefix=$PREFIX" ]] ; then : else [ $MYID -eq 0 ] && ERROR $prog should not be run as root $MYID && exit 2 RARGS=" --prefix=$PREFIX $RARGS" fi else # this is required, with the ~/.local symlinks, or it tries to uninstall from the system [[ $RARGS =~ " --user" ]] || RARGS=" --user $RARGS" # no quotes around the --install-option arg [[ $RARGS =~ "--install-scripts" ]] || RARGS=" --install-option=--install-scripts=/usr/local/bin $RARGS" [[ $RARGS =~ "--install-lib" ]] || RARGS=" --install-option=--install-lib=/usr/local/$LIB/python$PYTHON_MINOR/site-packages $RARGS" fi # if [ -d /etc/apt ] ; then # ! uname -a | grep Debian || # [[ $RARGS =~ "--install-layout" ]] || RARGS=" --install-option=--install-layout=unix $RARGS" # fi #? [[ $RARGS =~ "--no-binary" ]] || RARGS="--no-binary :all: $RARGS" # this prohibits installing .egg dirs but maybe that means no multi-version [[ $RARGS =~ "--only-binary" ]] || RARGS="--only-binary :none: $RARGS" ! $PREFIX/bin/python$PYVER.sh -m pip --help | grep -q upgrade-strategy || \ [[ $RARGS =~ "--upgrade-strategy" ]] || RARGS="--upgrade-strategy only-if-needed $RARGS" # require explicit package-by package installing - ? maybe only from ansible? RARGS="install $RARGS" export PYTHONPATH=/usr/local/$LIB/python$PYTHON_MINOR/site-packages fi TARGET=("$@") echo DBUG $prog $LARGS $RARGS "$@" exec $PREFIX/bin/python$PYVER.sh -W ignore::UserWarning -m pip $LARGS $RARGS "$@" 2>&1