2016-10-30 00:37:28 +03:00
|
|
|
#!/usr/bin/env bash
|
|
|
|
|
2018-03-29 22:47:37 +03:00
|
|
|
# shellcheck disable=SC1090
|
|
|
|
# shellcheck disable=SC1091
|
|
|
|
|
2016-10-30 00:37:28 +03:00
|
|
|
set -e
|
|
|
|
set -o pipefail
|
|
|
|
|
2017-03-17 21:51:20 +03:00
|
|
|
# vars
|
2017-09-26 18:08:02 +03:00
|
|
|
PYTHON=python3
|
|
|
|
PIP=pip3
|
2017-06-27 20:12:56 +03:00
|
|
|
SUDO=sudo
|
2018-06-07 19:12:03 +03:00
|
|
|
VENV_NAME=.shipyard
|
2017-03-17 21:51:20 +03:00
|
|
|
|
|
|
|
# process options
|
2018-06-07 19:12:03 +03:00
|
|
|
while getopts "h?23ce:u" opt; do
|
2017-03-17 21:51:20 +03:00
|
|
|
case "$opt" in
|
|
|
|
h|\?)
|
|
|
|
echo "install.sh parameters"
|
|
|
|
echo ""
|
2017-06-29 18:48:05 +03:00
|
|
|
echo "-2 install for Python 2.7"
|
2017-09-26 18:08:02 +03:00
|
|
|
echo "-3 install for Python 3.4+ [default]"
|
|
|
|
echo "-c install for Cloud Shell (via Dockerfile)"
|
2017-03-17 21:51:20 +03:00
|
|
|
echo "-e [environment name] install to a virtual environment"
|
2018-06-07 19:12:03 +03:00
|
|
|
echo "-u force install into user python environment instead of a virtual enviornment"
|
2017-03-17 21:51:20 +03:00
|
|
|
echo ""
|
|
|
|
exit 1
|
|
|
|
;;
|
2017-06-29 18:48:05 +03:00
|
|
|
2)
|
|
|
|
PYTHON=python
|
|
|
|
PIP=pip
|
|
|
|
;;
|
2017-03-17 21:51:20 +03:00
|
|
|
3)
|
|
|
|
PYTHON=python3
|
|
|
|
PIP=pip3
|
|
|
|
;;
|
2017-06-27 20:12:56 +03:00
|
|
|
c)
|
|
|
|
PYTHON=python3
|
|
|
|
PIP=pip3
|
|
|
|
VENV_NAME=cloudshell
|
|
|
|
SUDO=
|
|
|
|
;;
|
2017-03-17 21:51:20 +03:00
|
|
|
e)
|
|
|
|
VENV_NAME=$OPTARG
|
|
|
|
;;
|
2018-06-07 19:12:03 +03:00
|
|
|
u)
|
|
|
|
VENV_NAME=
|
|
|
|
;;
|
2017-03-17 21:51:20 +03:00
|
|
|
esac
|
|
|
|
done
|
|
|
|
shift $((OPTIND-1))
|
|
|
|
[ "$1" = "--" ] && shift
|
|
|
|
|
2017-06-27 20:12:56 +03:00
|
|
|
# non-cloud shell environment checks
|
2018-09-18 00:47:53 +03:00
|
|
|
if [ -n "$SUDO" ]; then
|
2017-06-27 20:12:56 +03:00
|
|
|
# check to ensure this is not being run directly as root
|
2018-03-29 22:47:37 +03:00
|
|
|
if [ "$(id -u)" -eq 0 ]; then
|
2017-06-27 20:12:56 +03:00
|
|
|
echo "Installation cannot be performed as root or via sudo."
|
|
|
|
echo "Please install as a regular user."
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
# check for sudo
|
|
|
|
if hash sudo 2> /dev/null; then
|
|
|
|
echo "sudo found."
|
|
|
|
else
|
|
|
|
echo "sudo not found. Please install sudo first before proceeding."
|
|
|
|
exit 1
|
|
|
|
fi
|
2016-10-30 00:37:28 +03:00
|
|
|
fi
|
|
|
|
|
|
|
|
# check that shipyard.py is in cwd
|
2018-03-29 22:47:37 +03:00
|
|
|
if [ ! -f "${PWD}"/shipyard.py ]; then
|
2016-10-30 00:37:28 +03:00
|
|
|
echo "shipyard.py not found in $PWD."
|
|
|
|
echo "Please run install.sh from the same directory as shipyard.py."
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
2017-03-17 21:51:20 +03:00
|
|
|
# check for python
|
2016-11-28 20:47:02 +03:00
|
|
|
if hash $PYTHON 2> /dev/null; then
|
|
|
|
echo "Installing for $PYTHON."
|
|
|
|
else
|
|
|
|
echo "$PYTHON not found, please install $PYTHON first with your system software installer."
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
2017-03-29 18:56:19 +03:00
|
|
|
# check for anaconda
|
|
|
|
set +e
|
|
|
|
ANACONDA=0
|
2018-03-29 22:47:37 +03:00
|
|
|
if $PYTHON -c "from __future__ import print_function; import sys; print(sys.version)" | grep -Ei 'anaconda|continuum|conda-forge'; then
|
2017-03-29 18:56:19 +03:00
|
|
|
# check for conda
|
|
|
|
if hash conda 2> /dev/null; then
|
|
|
|
echo "Anaconda environment detected."
|
|
|
|
else
|
|
|
|
echo "Anaconda environment detected, but conda command not found."
|
|
|
|
exit 1
|
|
|
|
fi
|
2018-03-29 22:47:37 +03:00
|
|
|
if [ -z "$VENV_NAME" ]; then
|
2017-03-29 18:56:19 +03:00
|
|
|
echo "Virtual environment name must be supplied for Anaconda installations."
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
ANACONDA=1
|
|
|
|
PIP=pip
|
|
|
|
fi
|
|
|
|
set -e
|
|
|
|
|
|
|
|
# perform some virtual env parameter checks
|
|
|
|
INSTALL_VENV_BIN=0
|
2018-09-18 00:47:53 +03:00
|
|
|
if [ -n "$VENV_NAME" ]; then
|
2017-03-29 18:56:19 +03:00
|
|
|
# check if virtual env, env is not named shipyard
|
|
|
|
if [ "$VENV_NAME" == "shipyard" ]; then
|
|
|
|
echo "Virtual environment name cannot be shipyard. Please use a different virtual environment name."
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
# check for virtualenv executable
|
|
|
|
if [ $ANACONDA -eq 0 ]; then
|
|
|
|
if hash virtualenv 2> /dev/null; then
|
|
|
|
echo "virtualenv found."
|
|
|
|
else
|
|
|
|
echo "virtualenv not found."
|
|
|
|
INSTALL_VENV_BIN=1
|
|
|
|
fi
|
|
|
|
fi
|
2018-06-07 19:12:03 +03:00
|
|
|
echo "Installing into virtualenv: $VENV_NAME"
|
|
|
|
else
|
|
|
|
echo "Installing into user environment instead of virtualenv"
|
2017-03-29 18:56:19 +03:00
|
|
|
fi
|
|
|
|
|
2016-10-30 00:37:28 +03:00
|
|
|
# try to get /etc/lsb-release
|
|
|
|
if [ -e /etc/lsb-release ]; then
|
|
|
|
. /etc/lsb-release
|
|
|
|
else
|
|
|
|
if [ -e /etc/os-release ]; then
|
|
|
|
. /etc/os-release
|
|
|
|
DISTRIB_ID=$ID
|
|
|
|
DISTRIB_RELEASE=$VERSION_ID
|
|
|
|
fi
|
2017-06-29 17:33:52 +03:00
|
|
|
# check for OS X
|
2018-10-26 23:36:33 +03:00
|
|
|
if [ -z "${DISTRIB_ID+x}" ] && [ "$(uname)" == "Darwin" ]; then
|
2017-06-29 17:33:52 +03:00
|
|
|
DISTRIB_ID=$(uname)
|
|
|
|
DISTRIB_RELEASE=$(uname -a | cut -d' ' -f3)
|
|
|
|
fi
|
2016-10-30 00:37:28 +03:00
|
|
|
fi
|
|
|
|
|
2018-10-26 23:36:33 +03:00
|
|
|
if [ -z "${DISTRIB_ID+x}" ] || [ -z "${DISTRIB_RELEASE+x}" ]; then
|
2016-10-30 00:37:28 +03:00
|
|
|
echo "Unknown DISTRIB_ID or DISTRIB_RELEASE."
|
|
|
|
echo "Please refer to the Installation documentation for manual installation steps."
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
|
|
|
# lowercase vars
|
2018-03-29 22:47:37 +03:00
|
|
|
if [ "$DISTRIB_ID" != "Darwin" ]; then
|
2017-06-29 17:33:52 +03:00
|
|
|
DISTRIB_ID=${DISTRIB_ID,,}
|
|
|
|
DISTRIB_RELEASE=${DISTRIB_RELEASE,,}
|
|
|
|
fi
|
2016-10-30 00:37:28 +03:00
|
|
|
|
2018-03-01 06:50:30 +03:00
|
|
|
echo "Detected OS: $DISTRIB_ID $DISTRIB_RELEASE"
|
|
|
|
|
2016-10-30 00:37:28 +03:00
|
|
|
# install requisite packages from distro repo
|
2018-09-18 00:47:53 +03:00
|
|
|
if [ -n "$SUDO" ] || [ "$(id -u)" -eq 0 ]; then
|
2018-03-29 22:47:37 +03:00
|
|
|
if [ "$DISTRIB_ID" == "ubuntu" ] || [ "$DISTRIB_ID" == "debian" ]; then
|
2017-06-27 20:12:56 +03:00
|
|
|
$SUDO apt-get update
|
2018-03-01 06:50:30 +03:00
|
|
|
if [ $ANACONDA -eq 1 ]; then
|
|
|
|
PYTHON_PKGS=
|
2017-06-27 20:12:56 +03:00
|
|
|
else
|
2018-03-01 06:50:30 +03:00
|
|
|
if [ $PYTHON == "python" ]; then
|
|
|
|
PYTHON_PKGS="libpython-dev python-dev"
|
|
|
|
if [ $ANACONDA -eq 0 ]; then
|
|
|
|
PYTHON_PKGS="$PYTHON_PKGS python-pip"
|
|
|
|
fi
|
|
|
|
else
|
|
|
|
PYTHON_PKGS="libpython3-dev python3-dev"
|
|
|
|
if [ $ANACONDA -eq 0 ]; then
|
|
|
|
PYTHON_PKGS="$PYTHON_PKGS python3-pip"
|
|
|
|
fi
|
2017-06-27 20:12:56 +03:00
|
|
|
fi
|
2017-03-29 18:56:19 +03:00
|
|
|
fi
|
2018-03-29 22:47:37 +03:00
|
|
|
# shellcheck disable=SC2086
|
2017-06-27 20:12:56 +03:00
|
|
|
$SUDO apt-get install -y --no-install-recommends \
|
|
|
|
build-essential libssl-dev libffi-dev openssl \
|
|
|
|
openssh-client rsync $PYTHON_PKGS
|
2018-03-29 22:47:37 +03:00
|
|
|
elif [ "$DISTRIB_ID" == "centos" ] || [ "$DISTRIB_ID" == "rhel" ]; then
|
2018-03-01 06:50:30 +03:00
|
|
|
$SUDO yum makecache fast
|
|
|
|
if [ $ANACONDA -eq 1 ]; then
|
|
|
|
PYTHON_PKGS=
|
2017-06-27 20:12:56 +03:00
|
|
|
else
|
2018-03-01 06:50:30 +03:00
|
|
|
if [ $PYTHON == "python" ]; then
|
|
|
|
PYTHON_PKGS="python-devel"
|
|
|
|
else
|
2018-03-29 22:47:37 +03:00
|
|
|
if ! yum list installed epel-release; then
|
2018-03-01 06:50:30 +03:00
|
|
|
echo "epel-release package not installed."
|
|
|
|
echo "Please install the epel-release package or refer to the Installation documentation for manual installation steps".
|
|
|
|
exit 1
|
|
|
|
fi
|
2018-03-29 22:47:37 +03:00
|
|
|
if ! yum list installed python34; then
|
2018-03-01 06:50:30 +03:00
|
|
|
echo "python34 epel package not installed."
|
|
|
|
echo "Please install the python34 epel package or refer to the Installation documentation for manual installation steps."
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
PYTHON_PKGS="python34-devel"
|
2017-06-27 20:12:56 +03:00
|
|
|
fi
|
|
|
|
fi
|
2018-03-29 22:47:37 +03:00
|
|
|
# shellcheck disable=SC2086
|
2017-06-27 20:12:56 +03:00
|
|
|
$SUDO yum install -y gcc openssl-devel libffi-devel openssl \
|
|
|
|
openssh-clients rsync $PYTHON_PKGS
|
2017-03-29 18:56:19 +03:00
|
|
|
if [ $ANACONDA -eq 0 ]; then
|
2018-02-18 00:22:38 +03:00
|
|
|
curl -fSsL --tlsv1 https://bootstrap.pypa.io/get-pip.py | $SUDO $PYTHON
|
2017-03-29 18:56:19 +03:00
|
|
|
fi
|
2018-03-29 22:47:37 +03:00
|
|
|
elif [ "$DISTRIB_ID" == "opensuse" ] || [ "$DISTRIB_ID" == "sles" ]; then
|
2017-06-27 20:12:56 +03:00
|
|
|
$SUDO zypper ref
|
2018-03-01 06:50:30 +03:00
|
|
|
if [ $ANACONDA -eq 1 ]; then
|
|
|
|
PYTHON_PKGS=
|
2017-06-27 20:12:56 +03:00
|
|
|
else
|
2018-03-01 06:50:30 +03:00
|
|
|
if [ $PYTHON == "python" ]; then
|
|
|
|
PYTHON_PKGS="python-devel"
|
|
|
|
else
|
|
|
|
PYTHON_PKGS="python3-devel"
|
|
|
|
fi
|
2016-11-28 20:47:02 +03:00
|
|
|
fi
|
2018-03-29 22:47:37 +03:00
|
|
|
# shellcheck disable=SC2086
|
2017-06-27 20:12:56 +03:00
|
|
|
$SUDO zypper -n in gcc libopenssl-devel libffi48-devel openssl \
|
|
|
|
openssh rsync $PYTHON_PKGS
|
|
|
|
if [ $ANACONDA -eq 0 ]; then
|
2018-02-18 00:22:38 +03:00
|
|
|
curl -fSsL --tlsv1 https://bootstrap.pypa.io/get-pip.py | $SUDO $PYTHON
|
2016-11-28 20:47:02 +03:00
|
|
|
fi
|
2018-03-29 22:47:37 +03:00
|
|
|
elif [ "$DISTRIB_ID" == "Darwin" ]; then
|
2017-06-29 17:33:52 +03:00
|
|
|
# check for pip, otherwise install it
|
|
|
|
if hash $PIP 2> /dev/null; then
|
|
|
|
echo "$PIP detected."
|
|
|
|
else
|
|
|
|
echo "$PIP not found, installing for Python"
|
|
|
|
$SUDO $PYTHON -m ensurepip
|
|
|
|
fi
|
2016-10-30 00:37:28 +03:00
|
|
|
else
|
2017-06-27 20:12:56 +03:00
|
|
|
echo "Unsupported distribution."
|
|
|
|
echo "Please refer to the Installation documentation for manual installation steps."
|
|
|
|
exit 1
|
2017-03-29 18:56:19 +03:00
|
|
|
fi
|
2016-10-30 00:37:28 +03:00
|
|
|
fi
|
|
|
|
|
2017-03-17 21:51:20 +03:00
|
|
|
# create virtual env if required and install required python packages
|
2018-09-18 00:47:53 +03:00
|
|
|
if [ -n "$VENV_NAME" ]; then
|
2017-03-29 18:56:19 +03:00
|
|
|
# install virtual env if required
|
|
|
|
if [ $INSTALL_VENV_BIN -eq 1 ]; then
|
2018-09-18 00:47:53 +03:00
|
|
|
if [ -n "$SUDO" ] || [ "$(id -u)" -eq 0 ]; then
|
2017-06-27 20:12:56 +03:00
|
|
|
$SUDO $PIP install virtualenv
|
|
|
|
else
|
|
|
|
$PIP install --user virtualenv
|
|
|
|
fi
|
2017-03-29 18:56:19 +03:00
|
|
|
fi
|
|
|
|
if [ $ANACONDA -eq 0 ]; then
|
2017-04-01 07:57:41 +03:00
|
|
|
# create venv if it doesn't exist
|
2018-09-18 00:47:53 +03:00
|
|
|
if [ -n "$SUDO" ] || [ "$(id -u)" -eq 0 ]; then
|
2018-03-29 22:47:37 +03:00
|
|
|
virtualenv -p $PYTHON "$VENV_NAME"
|
2017-06-27 20:12:56 +03:00
|
|
|
else
|
2018-03-29 22:47:37 +03:00
|
|
|
"${HOME}"/.local/bin/virtualenv -p $PYTHON "$VENV_NAME"
|
2017-06-27 20:12:56 +03:00
|
|
|
fi
|
2018-03-29 22:47:37 +03:00
|
|
|
source "${VENV_NAME}"/bin/activate
|
2018-06-07 19:12:03 +03:00
|
|
|
$PYTHON -m pip install --upgrade pip
|
|
|
|
$PIP install --upgrade setuptools
|
2017-11-08 20:47:03 +03:00
|
|
|
set +e
|
|
|
|
$PIP uninstall -y azure-storage
|
|
|
|
set -e
|
2017-03-29 18:56:19 +03:00
|
|
|
$PIP install --upgrade -r requirements.txt
|
2018-01-30 18:55:12 +03:00
|
|
|
$PIP install --upgrade --no-deps -r req_nodeps.txt
|
2017-03-29 18:56:19 +03:00
|
|
|
deactivate
|
|
|
|
else
|
2018-03-01 06:50:30 +03:00
|
|
|
# set python version
|
|
|
|
pyver=$($PYTHON -c "import sys;a=sys.version_info;print('{}.{}'.format(a[0],a[1]));")
|
|
|
|
echo "Creating conda env for Python $pyver"
|
2017-03-29 18:56:19 +03:00
|
|
|
# create conda env
|
2017-04-01 07:57:41 +03:00
|
|
|
set +e
|
2018-03-29 22:47:37 +03:00
|
|
|
conda create --yes --name "$VENV_NAME" python="${pyver}"
|
2017-04-01 07:57:41 +03:00
|
|
|
set -e
|
2018-03-29 22:47:37 +03:00
|
|
|
source activate "$VENV_NAME"
|
2017-03-29 18:56:19 +03:00
|
|
|
conda install --yes pip
|
|
|
|
# temporary workaround with pip requirements upgrading setuptools and
|
|
|
|
# conda pip failing to reference the old setuptools version
|
|
|
|
set +e
|
|
|
|
$PIP install --upgrade setuptools
|
2017-11-08 20:47:03 +03:00
|
|
|
$PIP uninstall -y azure-storage
|
2017-03-29 18:56:19 +03:00
|
|
|
set -e
|
|
|
|
$PIP install --upgrade -r requirements.txt
|
2018-01-30 18:55:12 +03:00
|
|
|
$PIP install --upgrade --no-deps -r req_nodeps.txt
|
2018-03-29 22:47:37 +03:00
|
|
|
source deactivate "$VENV_NAME"
|
2017-03-29 18:56:19 +03:00
|
|
|
fi
|
2017-03-17 21:51:20 +03:00
|
|
|
else
|
2018-06-07 19:12:03 +03:00
|
|
|
$PYTHON -m pip install --upgrade --user pip
|
2018-01-24 01:50:36 +03:00
|
|
|
$PIP install --upgrade --user setuptools
|
2017-11-08 20:47:03 +03:00
|
|
|
set +e
|
|
|
|
$PIP uninstall -y azure-storage
|
|
|
|
set -e
|
2017-03-17 21:51:20 +03:00
|
|
|
$PIP install --upgrade --user -r requirements.txt
|
2018-01-22 19:03:27 +03:00
|
|
|
$PIP install --upgrade --no-deps --user -r req_nodeps.txt
|
2017-03-17 21:51:20 +03:00
|
|
|
fi
|
|
|
|
|
2016-10-30 00:37:28 +03:00
|
|
|
# create shipyard script
|
|
|
|
cat > shipyard << EOF
|
|
|
|
#!/usr/bin/env bash
|
|
|
|
|
|
|
|
set -e
|
|
|
|
set -f
|
|
|
|
|
|
|
|
BATCH_SHIPYARD_ROOT_DIR=$PWD
|
2017-03-17 21:51:20 +03:00
|
|
|
VENV_NAME=$VENV_NAME
|
2016-10-30 00:37:28 +03:00
|
|
|
|
|
|
|
EOF
|
|
|
|
cat >> shipyard << 'EOF'
|
|
|
|
if [ -z $BATCH_SHIPYARD_ROOT_DIR ]; then
|
|
|
|
echo Batch Shipyard root directory not set.
|
|
|
|
echo Please rerun the install.sh script.
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
2016-11-02 21:20:37 +03:00
|
|
|
EOF
|
|
|
|
|
2018-09-18 00:47:53 +03:00
|
|
|
if [ -n "$VENV_NAME" ]; then
|
2017-03-29 18:56:19 +03:00
|
|
|
if [ $ANACONDA -eq 0 ]; then
|
2017-03-17 21:51:20 +03:00
|
|
|
cat >> shipyard << 'EOF'
|
|
|
|
source $BATCH_SHIPYARD_ROOT_DIR/$VENV_NAME/bin/activate
|
|
|
|
EOF
|
2017-03-29 18:56:19 +03:00
|
|
|
else
|
|
|
|
cat >> shipyard << 'EOF'
|
|
|
|
source activate $VENV_NAME
|
|
|
|
EOF
|
|
|
|
fi
|
2017-03-17 21:51:20 +03:00
|
|
|
fi
|
|
|
|
|
2016-11-28 20:47:02 +03:00
|
|
|
if [ $PYTHON == "python" ]; then
|
2016-11-02 21:20:37 +03:00
|
|
|
cat >> shipyard << 'EOF'
|
2016-10-31 20:27:39 +03:00
|
|
|
python $BATCH_SHIPYARD_ROOT_DIR/shipyard.py $*
|
2016-10-30 00:37:28 +03:00
|
|
|
EOF
|
|
|
|
else
|
2016-10-31 20:27:39 +03:00
|
|
|
cat >> shipyard << 'EOF'
|
|
|
|
python3 $BATCH_SHIPYARD_ROOT_DIR/shipyard.py $*
|
|
|
|
EOF
|
2016-10-30 00:37:28 +03:00
|
|
|
fi
|
2016-11-28 20:47:02 +03:00
|
|
|
|
2018-09-18 00:47:53 +03:00
|
|
|
if [ -n "$VENV_NAME" ]; then
|
2017-03-29 18:56:19 +03:00
|
|
|
if [ $ANACONDA -eq 0 ]; then
|
2017-03-17 21:51:20 +03:00
|
|
|
cat >> shipyard << 'EOF'
|
|
|
|
deactivate
|
|
|
|
EOF
|
2017-03-29 18:56:19 +03:00
|
|
|
else
|
|
|
|
cat >> shipyard << 'EOF'
|
|
|
|
source deactivate $VENV_NAME
|
|
|
|
EOF
|
|
|
|
fi
|
2017-03-17 21:51:20 +03:00
|
|
|
fi
|
|
|
|
|
2016-11-28 20:47:02 +03:00
|
|
|
chmod 755 shipyard
|
|
|
|
|
|
|
|
echo ""
|
2018-03-29 22:47:37 +03:00
|
|
|
if [ -z "$VENV_NAME" ]; then
|
|
|
|
# shellcheck disable=SC2016
|
2017-03-17 21:51:20 +03:00
|
|
|
echo '>> Please add $HOME/.local/bin to your $PATH. You can do this '
|
|
|
|
echo '>> permanently in your shell rc script, e.g., .bashrc for bash shells.'
|
|
|
|
echo ""
|
|
|
|
fi
|
2017-04-01 07:57:41 +03:00
|
|
|
echo ">> Install complete for $PYTHON. Please run Batch Shipyard as: $PWD/shipyard"
|