grezzo/featlib/pip.sh

113 lines
3.8 KiB
Bash
Executable File

#! /bin/bash --
[ ! -z "${GREZZO_1577142035}" ] && return; GREZZO_1577142035=0
. "$(this_script_path)/curl.sh"
function feat_addpacks_pip_dev() {
if ! feat_missing "apt-get"; then
sudo apt-get update
sudo apt-get install -y make build-essential libssl-dev zlib1g-dev libbz2-dev \
libreadline-dev libsqlite3-dev wget curl llvm libncurses5-dev libncursesw5-dev \
xz-utils libffi-dev liblzma-dev git
sudo apt-get install -y python3-openssl || sudo apt-get install -y python-openssl
elif ! feat_missing "pacman"; then
sudo pacman -S --needed base-devel openssl zlib bzip2 readline sqlite curl \
llvm ncurses xz libffi python-pyopenssl git
elif ! feat_missing "apk"; then
sudo apk add --no-cache bzip2-dev coreutils dpkg-dev dpkg expat-dev git curl \
findutils gcc gdbm-dev libc-dev libffi-dev libnsl-dev libtirpc-dev \
linux-headers make ncurses-dev openssl-dev pax-utils readline-dev \
sqlite-dev util-linux-dev xz-dev zlib-dev bash
elif ! feat_missing "yum"; then
sudo yum install @development zlib-devel bzip2 bzip2-devel readline-devel sqlite \
sqlite-devel openssl-devel xz xz-devel libffi-devel findutils
elif ! feat_missing "zypper"; then
sudo zypper in zlib-devel bzip2 libbz2-devel libffi-devel libopenssl-devel \
readline-devel sqlite3 sqlite3-devel xz xz-devel
fi
}
function feat_add_pip() {
feat_needed curl
feat_addpacks_pip_dev
curl https://pyenv.run | bash 2>&1
[ -f "$HOME/.bashrc.before" ] || touch "$HOME/.bashrc.before"
{ echo "export PYENV_ROOT=\"\$HOME/.pyenv\"
export PATH=\"\$PYENV_ROOT/bin:\$PATH\"
eval \"\$(pyenv init -)\"" ;
cat "$HOME/.bashrc.before"; } > "$HOME/.bashrc.before.tmp"
mv "$HOME/.bashrc.before.tmp" "$HOME/.bashrc.before"
feat_bashrc_before_needed
. "$HOME/.bashrc.before"
LATESTPYTHON="$(pyenv install -l | grep '^[0-9\. ]*$' | sed -ne '$s|\s*||gp')"
pyenv install "$LATESTPYTHON"
pyenv global "$LATESTPYTHON"
pip install wheel
pip install --upgrade pip
}
function pip_feat_ensure() {
# Ricarica .bashrc.before per eventuali modifiche al PATH
if [ -f "$HOME/.bashrc.before" ]; then
source "$HOME/.bashrc.before"
fi
# Se abbiamo pyenv, assicuriamoci che il global sia valido
if ! feat_missing "pyenv"; then
local current latest installed
current="$(pyenv global 2>/dev/null)"
installed="$(pyenv versions --bare 2>/dev/null | grep -v '^system$')"
# Cambia global se: vuoto, system, o versione non più installata
if [ -z "$current" ] || [ "$current" = "system" ] || ! echo "$installed" | grep -qxF "$current"; then
latest="$(echo "$installed" | tail -1)"
if [ -n "$latest" ]; then
pyenv global "$latest"
pyenv rehash >/dev/null 2>&1 || true
fi
fi
fi
# Se pip funziona, ok
if pip --version >/dev/null 2>&1; then
return
fi
# Altrimenti installiamo tutto
feat_needed "pip"
}
function pip_feat_missing() {
if ! pip --version >/dev/null 2>&1; then
true
else
! ( pip freeze | grep -q "$1=" )
fi
}
function pip_feat_add() {
pip install "$1"
}
function pip_feat_needed() {
pip_feat_ensure
FEAT="$1"
if pip_feat_missing "$FEAT"; then
if type "pip_feat_add_$FEAT" > /dev/null 2>&1 ; then
eval "pip_feat_add_$FEAT"
else
pip_feat_add "$FEAT"
fi
fi
}
function pip_feat_add_docker-compose() {
. "$(this_script_path)/pip.sh"
. "$(this_script_path)/docker.sh"
feat_needed "docker"
# Ora docker compose è integrato dentro docker
# TODO: verificare compatibilità con comando docker-compose
#pip_feat_add "docker-compose"
}