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 all commits
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
133 changes: 104 additions & 29 deletions installer/install_dependencies.sh
Original file line number Diff line number Diff line change
@@ -1,42 +1,117 @@
#!/bin/bash

# SetupTool version to be installed
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_common_dependencies() {
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 \
"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 Pyenv
install_pyenv() {
if command -v pyenv 1; then
echo pyenv is already installed
else
echo Installing pyenv dependencies
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
fi
}

# Install Python
install_python() {
echo Start Python $PYTHON_VERSION installation
pyenv install $PYTHON_VERSION
pyenv global $PYTHON_VERSION
echo Finish Python Installtion
}

# Upgrade Python if version is below than $PYTHON_VERSION
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
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
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
if [ "`which ansible`" != "" ]; then
echo ansible already installed, skipping.
else
install_ansible() {
if [ "`which ansible`" != "" ]; then
echo Ansible already installed, skipping.
else
echo Installing ansible
python3 -m pip install --user ansible
fi
fi
}


# Install docker if not present
if [ "`which docker`" != "" ]; then
install_docker() {
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
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
fi
}


main() {
install_common_dependencies
upgrade_python ${1}
install_python_dependencies
install_ansible
install_docker
# Ensure /usr/local/bin is in path
export PATH=$PATH:/usr/local/bin
echo Restarting shell
exec $SHELL
}


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