Last active
September 8, 2022 07:56
-
-
Save xram64/999a0a42e01ef9d91f1b9f620795d859 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/usr/bin/env bash | |
| set -e | |
| cd "$(dirname "${0}")" | |
| BASE_DIR="$(pwd)" | |
| PACKAGES=(aria2 git unzip wget) | |
| # Tensorflow states 3.4.0 as the minimum version. | |
| # This is also the minimum version with venv support. | |
| # 3.8.0 and up only includes tensorflow 2.0 and not 1.15 | |
| MIN_PYTHON_VERS="3.4.0" | |
| MAX_PYTHON_VERS="3.7.13" # PATCH: Bump allowed max version up from 3.7.9 | |
| version_check () { | |
| MAX_VERS=$(echo -e "$(python3 --version | cut -d' ' -f2)\n$MAX_PYTHON_VERS\n$MIN_PYTHON_VERS"\ | |
| | sort -V | tail -n1) | |
| MIN_VERS=$(echo -e "$(python3 --version | cut -d' ' -f2)\n$MAX_PYTHON_VERS\n$MIN_PYTHON_VERS"\ | |
| | sort -V | head -n1) | |
| if [ "$MIN_VERS" != "$MIN_PYTHON_VERS" ]; then | |
| echo "Your installed python version, $(python3 --version), is too old." | |
| echo "Please update to at least $MIN_PYTHON_VERS." | |
| exit 1 | |
| elif [ "$MAX_VERS" != "$MAX_PYTHON_VERS" ]; then | |
| echo "Your installed python version, $(python3 --version), is too new." | |
| echo "Please install $MAX_PYTHON_VERS." | |
| exit 1 | |
| fi | |
| } | |
| pip_install () { | |
| if [ ! -d "./venv" ]; then | |
| # Some distros have venv built into python so this isn't always needed. | |
| if is_command 'apt-get'; then | |
| apt-get install python3.7-dev python3.7-venv | |
| fi | |
| # PATCH: Create a venv without pip, then install pip | |
| # (Ref: https://askubuntu.com/questions/488529/pyvenv-3-4-error-returned-non-zero-exit-status-1) | |
| python -m venv --without-pip ./venv | |
| chmod u+x "${BASE_DIR}/venv/bin/activate" | |
| source "${BASE_DIR}/venv/bin/activate" | |
| wget https://bootstrap.pypa.io/get-pip.py # get installation script for pip | |
| chmod u+x get-pip.py | |
| "${BASE_DIR}/venv/bin/python" get-pip.py | |
| deactivate | |
| fi | |
| source "${BASE_DIR}/venv/bin/activate" | |
| pip install --upgrade pip setuptools | |
| pip install -r "${BASE_DIR}/requirements.txt" | |
| } | |
| is_command() { | |
| command -v "${@}" > /dev/null | |
| } | |
| system_package_install() { | |
| SUDO='' | |
| if (( $EUID != 0 )); then | |
| SUDO='sudo' | |
| fi | |
| PACKAGES=(aria2 git unzip wget) | |
| if is_command 'apt-get'; then | |
| $SUDO apt-get install ${PACKAGES[@]} | |
| elif is_command 'brew'; then | |
| brew install ${PACKAGES[@]} | |
| elif is_command 'yum'; then | |
| $SUDO yum install ${PACKAGES[@]} | |
| elif is_command 'dnf'; then | |
| $SUDO dnf install ${PACKAGES[@]} | |
| elif is_command 'pacman'; then | |
| $SUDO pacman -S ${PACKAGES[@]} | |
| elif is_command 'apk'; then | |
| $SUDO apk --update add ${PACKAGES[@]} | |
| else | |
| echo "You do not seem to be using a supported package manager." | |
| echo "Please make sure ${PACKAGES[@]} are installed then press [ENTER]" | |
| read NOT_USED | |
| fi | |
| } | |
| install_aid () { | |
| version_check | |
| pip_install | |
| system_package_install | |
| } | |
| install_aid |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment