File size: 1,793 Bytes
b37e887
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
#!/usr/bin/env bash

set -e

PYTHON=${1:-"python"}
USERNAME=${2-"automatic"}

# Make sure we run the command as non-root user
sudoUserIf() {
  if [ "$(id -u)" -eq 0 ] && [ "${USERNAME}" != "root" ]; then
    sudo -u ${USERNAME} "$@"
  else
    "$@"
  fi
}

installPythonPackage() {
  PACKAGE=${1:-""}
  VERSION=${2:-"latest"}

  # pip skips installation if the package is already installed
  echo "Installing $PACKAGE..."
  if [ "${VERSION}" = "latest" ]; then
    sudoUserIf ${PYTHON} -m pip install ${PACKAGE} --no-cache-dir
  else
    sudoUserIf ${PYTHON} -m pip install ${PACKAGE}=="${VERSION}" --no-cache-dir
  fi
}

# If in automatic mode, determine if a user already exists, if not use vscode
if [ "${USERNAME}" = "auto" ] || [ "${USERNAME}" = "automatic" ]; then
    USERNAME=""
    POSSIBLE_USERS=("vscode" "node" "codespace" "$(awk -v val=1000 -F ":" '$3==val{print $1}' /etc/passwd)")
    for CURRENT_USER in ${POSSIBLE_USERS[@]}; do
        if id -u ${CURRENT_USER} > /dev/null 2>&1; then
            USERNAME=${CURRENT_USER}
            break
        fi
    done
    if [ "${USERNAME}" = "" ]; then
        USERNAME=vscode
    fi
elif [ "${USERNAME}" = "none" ]; then
    USERNAME=root
    USER_UID=0
    USER_GID=0
fi

# Make sure that Python is available
if ! ${PYTHON} --version > /dev/null ; then
  echo "You need to install Python before installing packages"
  exit 1
fi

installPythonPackage "numpy" "latest"
installPythonPackage "pandas" "latest"
installPythonPackage "scipy" "latest"
installPythonPackage "matplotlib" "latest"
installPythonPackage "seaborn" "latest"
installPythonPackage "scikit-learn" "latest"
installPythonPackage "tensorflow" "latest"
installPythonPackage "keras" "latest"
installPythonPackage "torch" "latest"
installPythonPackage "requests" "latest"