-
Notifications
You must be signed in to change notification settings - Fork 308
/
setup_linux.sh
executable file
·257 lines (226 loc) · 7.1 KB
/
setup_linux.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
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
#!/usr/bin/env bash
# This script installs garage on Linux distributions.
#
# NOTICE: To keep consistency across this script, scripts/setup_osx.sh and
# docker/Dockerfile.ci, if there's any changes applied to this file, specially
# regarding the installation of dependencies, apply those same changes to the
# mentioned files.
# Exit if any error occurs
set -e
### START OF CODE GENERATED BY Argbash v2.6.1 one line above ###
die()
{
local _ret=$2
test -n "$_ret" || _ret=1
test "$_PRINT_HELP" = yes && print_help >&2
echo "$1" >&2
exit ${_ret}
}
begins_with_short_option()
{
local first_option all_short_options
all_short_options='h'
first_option="${1:0:1}"
test "$all_short_options" = "${all_short_options/$first_option/}" && \
return 1 || return 0
}
# THE DEFAULTS INITIALIZATION - POSITIONALS
_positionals=()
# THE DEFAULTS INITIALIZATION - OPTIONALS
_arg_mjkey=
_arg_modify_bashrc="off"
_arg_tf_gpu="off"
print_help ()
{
printf '%s\n' "Installer of garage for Linux."
printf 'Usage: %s [--mjkey <arg>] [--(no-)modify-bashrc] ' "$0"
printf '[--(no-)tf-gpu] [-h|--help]\n'
printf '\t%s\n' "--mjkey: Path of the MuJoCo key (no default)"
printf '\t%s' "--tf-gpu,--no-tf-gpu: Install TensorFlow GPU instead of the "
printf '%s\n' "regular version (off by default)"
printf '\t%s' "--modify-bashrc,--no-modify-bashrc: Set environment variables "
printf '%s\n' "required by garage in .bashrc (off by default)"
printf '\t%s\n' "-h,--help: Prints help"
}
parse_commandline ()
{
while test $# -gt 0
do
_key="$1"
case "$_key" in
--mjkey)
test $# -lt 2 && \
die "Missing value for the optional argument '$_key'." 1
_arg_mjkey="$2"
shift
;;
--mjkey=*)
_arg_mjkey="${_key##--mjkey=}"
;;
--no-modify-bashrc|--modify-bashrc)
_arg_modify_bashrc="on"
test "${1:0:5}" = "--no-" && _arg_modify_bashrc="off"
;;
--no-tf-gpu|--tf-gpu)
_arg_tf_gpu="on"
test "${1:0:5}" = "--no-" && _arg_tf_gpu="off"
;;
-h|--help)
print_help
exit 0
;;
-h*)
print_help
exit 0
;;
*)
_PRINT_HELP=yes die "FATAL ERROR: Got an unexpected argument '$1'" 1
;;
esac
shift
done
}
parse_commandline "$@"
### END OF CODE GENERATED BY Argbash (sortof) ### ])
# Utility functions
print_error() {
printf "\e[0;31m%s\e[0m" "${1}"
}
print_warning() {
printf "\e[0;33m%s\e[0m" "${1}"
}
# Verify there's a file in the mjkey path
test -f "${_arg_mjkey}" || _PRINT_HELP=yes die \
"The path ${_arg_mjkey} of the MuJoCo key is not valid." 1
# Make sure that we're under the garage directory
GARAGE_DIR="$(readlink -f $(dirname $0)/..)"
cd "${GARAGE_DIR}"
# File where environment variables are stored
BASH_RC="${HOME}/.bashrc"
# Install dependencies
# For installing garage: wget, bzip2, unzip, git
# For building glfw: cmake, xorg-dev
# Required for mujoco_py: libglew-dev, patchelf, libosmesa6-dev
# Required for OpenAI gym: libpq-dev, ffmpeg, libjpeg-dev, swig, libsdl2-dev
# Required for OpenAI baselines: libopenmpi-dev, openmpi-bin
echo "Installing garage dependencies"
echo "You will probably be asked for your sudo password"
sudo apt -y -q update
sudo apt install -y \
wget \
bzip2 \
unzip \
git \
cmake \
xorg-dev \
libglew-dev \
patchelf \
libosmesa6-dev \
libpq-dev \
ffmpeg \
libjpeg-dev \
swig \
libsdl2-dev \
libopenmpi-dev \
openmpi-bin
# Build GLFW because the Ubuntu 16.04 version is too old
# See https://github.com/glfw/glfw/issues/1004
sudo apt purge -y libglfw*
GLFW_DIR="$(mktemp -d)/glfw"
git clone https://github.com/glfw/glfw.git "${GLFW_DIR}"
cd "${GLFW_DIR}"
git checkout 0be4f3f75aebd9d24583ee86590a38e741db0904
mkdir glfw-build
cd glfw-build
sudo cmake -DBUILD_SHARED_LIBS=ON -DGLFW_BUILD_EXAMPLES=OFF \
-DGLFW_BUILD_TESTS=OFF -DGLFW_BUILD_DOCS=OFF ..
sudo make -j"$(nproc)"
sudo make install
cd "${GARAGE_DIR}"
# Leave a note in ~/.bashrc for the added environment variables
if [[ "${_arg_modify_bashrc}" = on ]]; then
echo -e "\n# Added by the garage installer" >> "${BASH_RC}"
fi
# Set up MuJoCo
if [[ ! -d "${HOME}/.mujoco/mjpro150" ]]; then
mkdir "${HOME}"/.mujoco
MUJOCO_ZIP="$(mktemp -d)/mujoco.zip"
wget https://www.roboti.us/download/mjpro150_linux.zip -O "${MUJOCO_ZIP}"
unzip -u "${MUJOCO_ZIP}" -d "${HOME}"/.mujoco
else
print_warning "MuJoCo is already installed"
fi
# Configure MuJoCo as a shared library
export LD_LIBRARY_PATH="$LD_LIBRARY_PATH:${HOME}/.mujoco/mjpro150/bin"
LD_LIB_ENV_VAR="LD_LIBRARY_PATH=\"\$LD_LIBRARY_PATH:${HOME}/.mujoco/mjpro150"
LD_LIB_ENV_VAR="${LD_LIB_ENV_VAR}/bin\""
if [[ "${_arg_modify_bashrc}" = on ]]; then
echo "export ${LD_LIB_ENV_VAR}" >> "${BASH_RC}"
fi
# Set up conda
if [[ ! -d "${HOME}/miniconda2" ]]; then
CONDA_INSTALLER="$(mktemp -d)/miniconda.sh"
wget https://repo.continuum.io/miniconda/Miniconda2-latest-Linux-x86_64.sh \
-O "${CONDA_INSTALLER}"
chmod u+x "${CONDA_INSTALLER}"
bash "${CONDA_INSTALLER}" -b -u
# Add conda to executable programs
CONDA_SH="${HOME}/miniconda2/etc/profile.d/conda.sh"
. "${CONDA_SH}"
if [[ "${_arg_modify_bashrc}" = on ]]; then
echo ". ${CONDA_SH}" >> "${BASH_RC}"
fi
fi
# Export conda in this script
. "${CONDA_SH}"
conda update -q -y conda
# Create conda environment
conda env create -f environment.yml
if [[ "${?}" -ne 0 ]]; then
print_error "Error: conda environment could not be created"
fi
# Extras
conda activate garage
{
# Prevent pip from complaining about available upgrades
pip install --upgrade pip
# Remove any TensorFlow installations before installing the GPU flavor
pip uninstall -y tensorflow
if [[ "${_arg_tf_gpu}" = on ]]; then
pip install "tensorflow-gpu<1.10,>=1.9.0"
fi
# Fix Box2D install
# See https://github.com/openai/gym/issues/100
# See https://github.com/pybox2d/pybox2d/issues/82
pip uninstall -y Box2D Box2D-kengz box2d-py
pip install Box2D
# We need a MuJoCo key to import mujoco_py
cp ${_arg_mjkey} "${HOME}"/.mujoco/mjkey.txt
# Build mujoco-py and check it's correctly installed
python -c 'import mujoco_py'
# Install git hooks
pre-commit install -t pre-commit
pre-commit install -t pre-push
pre-commit install -t commit-msg
# Install a virtualenv for the hooks
pre-commit
}
conda deactivate
# Copy template of personal configurations so users can set them later
cp garage/config_personal_template.py garage/config_personal.py
# Add garage to python modules
export PYTHONPATH="$PYTHONPATH:${GARAGE_DIR}"
PYTHON_ENV_VAR="PYTHONPATH=\"\$PYTHONPATH:${GARAGE_DIR}\""
if [[ "${_arg_modify_bashrc}" = on ]]; then
echo "export ${PYTHON_ENV_VAR}" >> "${BASH_RC}"
else
echo -e "\nRemember to execute the following commands before running garage:"
echo "export ${LD_LIB_ENV_VAR}"
echo ". ${CONDA_SH}"
echo "export ${PYTHON_ENV_VAR}"
echo "You may wish to edit your .bashrc to prepend these commands."
fi
echo -e "\ngarage is installed! To make the changes take effect, work under" \
"a new terminal. Also, make sure to run \`conda activate garage\`" \
"whenever you open a new terminal and want to run programs under garage." \
| fold -s