Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/bash
- #python-venv-prepare.sh
- _BASE_DIR="${PWD##*/}"
- if [ $# -eq 0 ]; then
- echo "Usage: ./python-venv-prepare.sh [2.7|3.7]"
- exit 1
- fi
- while [ $# -ne 0 ]
- do
- arg="$1"
- case "$arg" in
- 2.7)
- _PYTHON_VER=2.7
- ;;
- 3.7)
- _PYTHON_VER=3.7
- ;;
- *)
- echo "Wrong param provided"
- echo "Usage: ./duplicati.sh [start|stop]"
- exit 1
- ;;
- esac
- shift
- done
- echo "--------------------------------------------------------------------------------------"
- _VENV_DIR="${_BASE_DIR}_venv-${_PYTHON_VER}"
- chmod 755 create-${_PYTHON_VER}.sh>create-${_PYTHON_VER}.sh && echo "virtualenv -p /usr/bin/python${_PYTHON_VER} '${_VENV_DIR}'" >create-${_PYTHON_VER}.sh
- chmod 755 activate-${_PYTHON_VER}.sh>activate-${_PYTHON_VER}.sh
- _PYTHON_INSTALLED=false
- dpkg -s "python${_PYTHON_VER}" &> /dev/null
- if [ $? -eq 0 ]; then
- _PYTHON_INSTALLED=true
- echo "[$(date +%Y%m%d_%H-%M-%S)] python${_PYTHON_VER} already installed. Skipping"
- fi
- if [ "${_PYTHON_VER}" == "2.7" ]; then
- if ! "${_PYTHON_INSTALLED}"; then
- sudo apt-get install -y python${_PYTHON_VER}
- sudo pip2 install virtualenv
- echo "[$(date +%Y%m%d_%H-%M-%S)] python/pip/venv Installation Completed"
- fi
- echo "source '${_VENV_DIR}'/bin/activate" >activate-${_PYTHON_VER}.sh
- elif [ "${_PYTHON_VER}" == "3.7" ]; then
- if ! "${_PYTHON_INSTALLED}"; then
- #sudo apt-get install -y python3.7-pip
- sudo apt install -y "python${_PYTHON_VER}" "python${_PYTHON_VER}-venv"
- sudo pip3 install virtualenv
- echo "[$(date +%Y%m%d_%H-%M-%S)] Python/pip/venv Installation Completed"
- fi
- echo "source '${_VENV_DIR}'/bin/activate" >activate-${_PYTHON_VER}.sh
- else
- echo "[$(date +%Y%m%d_%H-%M-%S)] ERROR"
- exit 997
- fi
- echo "[$(date +%Y%m%d_%H-%M-%S)] create-${_PYTHON_VER}.sh script created and ready to use. Launching"
- ./create-${_PYTHON_VER}.sh
- echo "[$(date +%Y%m%d_%H-%M-%S)] Please run the following command to activate your new venv:"
- echo "source '${_VENV_DIR}'/bin/activate"
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement