-
Notifications
You must be signed in to change notification settings - Fork 5
/
quick_setup_1.5.sh
executable file
·147 lines (123 loc) · 4.99 KB
/
quick_setup_1.5.sh
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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
#!/usr/bin/env bash
#::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
# ScalaTion Kernel Quick Setup Script for ScalaTion 1.5
#::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
# @author Michael Cotterell
# @version 1.1.x
# @see LICENSE.md (MIT style license file).
#::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
# usage: bash quick_setup_1.5.sh venv-dir [--pypi]
#
# arguments:
# venve-dir directory to use for virtual environment (create if needed)
#::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
# This script uses the Python 3 virtual environment in `venv-dir` to start
# Jupyter with support for the ScalaTion 1.5 big data framework. It quickly
# sets up Jupyter, ScalaTion, and ScalaTion Kernel so that users can rapidly
# get started with ScalaTion in Jupyter notebooks.
#
# ## Initial Run
# The first time the script is run, it may need to create some directories and
# download some dependencies. For example, if `venv-dir` does not exist, then
# the script attempts to create it using Python's `venv` module. Additional
# dependencies that are downloaded by this script are saved and or installed
# into the virtual environment provided by `venv-dir` and do not alter the
# script's initial Python environment. This script downloads the latest
# ScalaTion 1.5 distribution and adds paths to its JAR files to the
# `SCALATION_JARS` environment variable. Lastly, the script starts Jupyter
# with support for the ScalaTion 1.5 big data framework.
#
# ## Subsequent Runs
# If `venv-dir` already exists and contains the needed dependencies, then this
# script simply starts Jupyter with support for the ScalaTion 1.5 big data
# framework.
#::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
# @see http://jupyter.readthedocs.io/en/latest/
# @see http://cobweb.cs.uga.edu/~jam/scalation.html
# @see https://github.com/scalation/scalation_kernel
# @see https://docs.python.org/3/library/venv.html
#::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
# NO USER MODIFICATIONS NEEDED AFTER THIS POINT;
# However, we encourage interested users to inspect the script to see what it
# is doing.
function display_title {
echo "ScalaTion Kernel Quick Setup Script"
}
function display_usage {
display_title
echo "usage: $0 venv-dir [--pypi]"
echo "See script contents for more information."
}
function download_dep {
DEP_ID=$1 # short name / id
DEP_NAME=$2 # descriptive name
DEP_TAR=$3 # url for tar.gz file
DEP_DIR=$4 # directory
DEP_TMP="${DEP_ID}.tar.gz"
echo "Downloading ${DEP_NAME}..."
wget "${DEP_TAR}" --progress=bar -O "${DEP_TMP}"
mkdir -p "${DEP_DIR}"
tar zxf "${DEP_TMP}" -C "${DEP_DIR}" --strip-components=1
rm -rf "${DEP_TMP}"
}
function check_scalation {
DEP_ID="scalation"
DEP_NAME="ScalaTion 1.5"
DEP_TAR="http://cobweb.cs.uga.edu/~jam/scalation_${SCALATION_VER}.tar.gz"
DEP_DIR="${DEP_ID}"
echo "Checking for ${DEP_NAME}..."
[[ ! -d "${DEP_DIR}" ]] && download_dep "$DEP_ID" "$DEP_NAME" "$DEP_TAR" "$DEP_DIR"
}
function check_deps_quick {
echo "Checking for Python (need >= 3.3) ..."
! [[ -x `command -v python3` ]] && echo "Not found! Cannot continue." && exit 1
echo $(which python3)
echo $(python3 --version)
echo "Checking for Java (need >= 8) ..."
! [[ -x `command -v java` ]] && echo "Not found! Cannot continue." && exit 1
echo $(which java)
echo $(java -version)
echo "Checking for Scala (need >= 2.12.4) ..."
! [[ -x `command -v scala` ]] && echo "Not found! Cannot continue." && exit 1
echo $(which scala)
echo $(scala -version)
# echo "Checking for SBT ..."
# ! [[ -x `command -v sbt` ]] && echo "Not found! Cannot continue." && exit 1
# echo $(which sbt)
read -p "Are you sure you want to continue? [y/n] " -n 1 -r
echo # (optional) move to a new line
if [[ ! $REPLY =~ ^[Yy]$ ]]
then
[[ "$0" = "$BASH_SOURCE" ]] && exit 1 || return 1
fi
}
# display usage?
[[ ($# -ne 1) || ($# == "--help") || ($# == "-h") ]] && display_usage && exit 1
check_deps_quick
SCALATION_VER="1.5"
SCALATION_TAR="http://cobweb.cs.uga.edu/~jam/scalation_${SCALATION_VER}.tar.gz"
SCALATION_DIR="scalation"
VIRTUALENV="$1"
# setup virtualenv if needed
if [ ! -d "$VIRTUALENV" ]; then
echo "Creating a Python 3 virtual environment in ${VIRTUALENV}..."
python3 -m venv "$VIRTUALENV"
fi
# activate virtualenv
echo "Activating the Python 3 virtual environment in ${VIRTUALENV}..."
cd "${VIRTUALENV}"
source "bin/activate"
check_scalation
# setup environment variables
JARS="."
for JARFILE in $(find scalation*/scalation_models/lib | grep .jar); do
JARS=$(readlink -f $JARFILE):$JARS
done
export SCALATION_JARS=$JARS
# install python packages if needed
python3 -m pip install --upgrade pip
# install kernel
python3 -m pip install -e ..
python3 -m scalation_kernel.install
# run jupyter
python3 -m jupyter notebook