Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix Python version in Ubuntu18 #979

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
130 changes: 101 additions & 29 deletions installer/install_dependencies.sh
Original file line number Diff line number Diff line change
@@ -1,42 +1,114 @@
#!/bin/bash

#SetupTool version to be installed
amanr032 marked this conversation as resolved.
Show resolved Hide resolved
SETUPTOOL_VERSION="65.0.0"
PY_VERSION_RE='^3(\.[0-9]+)(\.[0-9])?$'

# Install dependencies
echo Installing dependencies
sudo apt-get install -y make curl wget libltdl7 libseccomp2 libffi-dev gawk apt-transport-https ca-certificates curl gnupg gnupg-agent lsb-release software-properties-common sshpass pv

echo Enabling docker repository
sudo mkdir -p /etc/apt/keyrings
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /etc/apt/keyrings/docker.gpg --yes

echo \
"deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.gpg] https://download.docker.com/linux/ubuntu \
$(lsb_release -cs) stable" | sudo tee /etc/apt/sources.list.d/docker.list > /dev/null

# Update local repositories
echo Updating local repositories
sudo apt-get update

# Install python dependencies
echo Installing Python dependencies
sudo apt-get install -y python3-distutils
sudo apt-get install -y python3-pip
python3 -m pip install -U pip setuptools

# Install ansible if not present
if [ "`which ansible`" != "" ]; then
function install_common_dependencies() {
amanr032 marked this conversation as resolved.
Show resolved Hide resolved
echo Installing common dependencies
sudo apt-get install -y make curl wget libltdl7 libseccomp2 libffi-dev gawk apt-transport-https ca-certificates \
curl gnupg gnupg-agent lsb-release software-properties-common sshpass pv

echo Enabling docker repository
sudo mkdir -p /etc/apt/keyrings
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /etc/apt/keyrings/docker.gpg --yes

echo \
"deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.gpg] https://download.docker.com/linux/ubuntu \
$(lsb_release -cs) stable" | sudo tee /etc/apt/sources.list.d/docker.list > /dev/null

# Update local repositories
echo Updating local repositories
sudo apt-get update
amanr032 marked this conversation as resolved.
Show resolved Hide resolved
}

# Install Pyenv
function install_pyenv() {
if command -v pyenv 1; then
echo pyenv available
amanr032 marked this conversation as resolved.
Show resolved Hide resolved
else
echo Installing Pyenv Dependencies
amanr032 marked this conversation as resolved.
Show resolved Hide resolved
sudo apt-get install -y make build-essential libssl-dev zlib1g-dev \
libbz2-dev libreadline-dev libsqlite3-dev llvm \
libncursesw5-dev xz-utils tk-dev libxml2-dev libxmlsec1-dev libffi-dev liblzma-dev
echo Downloading pyenv
curl https://pyenv.run | bash
export PATH="$HOME/.pyenv/bin:$PATH" && eval "$(pyenv init --path)" \
&& echo -e 'export PATH="$HOME/.pyenv/bin:$PATH"\nif command -v pyenv 1>/dev/null 2>&1; then\n eval "$(pyenv init -)"\nfi' >> ~/.bashrc
echo Restarting shell
amanr032 marked this conversation as resolved.
Show resolved Hide resolved
fi
}

# Install Python
function install_python() {
echo Start Python $PYTHON_VERSION Installtion
amanr032 marked this conversation as resolved.
Show resolved Hide resolved
pyenv install $PYTHON_VERSION
pyenv global $PYTHON_VERSION
echo Finish Python Installtion
}

#Upgrade Python if version is below than $PYTHON_VERSION
amanr032 marked this conversation as resolved.
Show resolved Hide resolved
function upgrade_python {
PYTHON_VERSION=${1}
if [ -z $PYTHON_VERSION ] || ! [[ $PYTHON_VERSION =~ $re ]]; then
return
fi
if $(dpkg --compare-versions $(python3 -c 'import sys; print(".".join(map(str, sys.version_info[:3])))') "lt" $PYTHON_VERSION); then
install_pyenv
install_python
fi
}

# Install setuptools
function install_setuptools {
IFS=' '
v=`python3 -m pip list | grep -i setuptools | { read _ v; echo $v; }`
if $(dpkg --compare-versions $v "gt" $SETUPTOOL_VERSION); then
python3 -m pip install setuptools==65.0.0
fi
unset IFS v
}


# Install Python Dependencies
function install_python_dependencies() {
echo Installing Python dependencies
sudo apt-get install -y python3-distutils
sudo apt-get install -y python3-pip
python3 -m pip install -U pip
install_setuptools
# Install ansible if not present
amanr032 marked this conversation as resolved.
Show resolved Hide resolved
if [ "`which ansible`" != "" ]; then
echo ansible already installed, skipping.
amanr032 marked this conversation as resolved.
Show resolved Hide resolved
else
else
echo Installing ansible
python3 -m pip install --user ansible
fi
fi
}


# Install docker if not present
if [ "`which docker`" != "" ]; then
function install_docker() {
if [ "`which docker`" != "" ]; then
echo Docker already installed, skipping.
else
else
echo Installing docker
sudo apt-get install -y docker-ce docker-ce-cli containerd.io docker-compose-plugin
fi
amanr032 marked this conversation as resolved.
Show resolved Hide resolved
}


function main() {
install_common_dependencies
upgrade_python ${1}
install_python_dependencies
install_docker
Ensure /usr/local/bin is in path
amanr032 marked this conversation as resolved.
Show resolved Hide resolved
export PATH=$PATH:/usr/local/bin
}


# Ensure /usr/local/bin is in path
export PATH=$PATH:/usr/local/bin
# Entry point. START
main ${1}
exec $SHELL