-
Notifications
You must be signed in to change notification settings - Fork 0
/
install.sh
122 lines (99 loc) · 3.52 KB
/
install.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
#! /bin/bash
# PyOP2 quick installation script. Installs PyOP2 and dependencies.
#
# Usage: install.sh [user name]
#
# When run with superuser privileges, user name is used for commands to be
# run unprivileged if given. Otherwise $USERNAME is queried, which works
# when calling this script with sudo but not when calling from a root shell.
BASE_DIR=`pwd`
PYOP2_DIR=$BASE_DIR/PyOP2
TEMP_DIR=/tmp
if [ -d $PYOP2_DIR ]; then
LOGFILE=$PYOP2_DIR/pyop2_install.log
else
LOGFILE=$BASE_DIR/pyop2_install.log
fi
if [ -f $LOGFILE ]; then
mv $LOGFILE $LOGFILE.old
fi
echo "PyOP2 installation started at `date`" | tee -a $LOGFILE
echo " on `uname -a`" | tee -a $LOGFILE
echo | tee -a $LOGFILE
if (( EUID != 0 )); then
echo "*** Unprivileged installation ***" | tee -a $LOGFILE
echo | tee -a $LOGFILE
PIP="pip install --user"
PREFIX=$HOME/.local
PATH=$PREFIX/bin:$PATH
ASUSER=""
else
echo "*** Privileged installation ***" | tee -a $LOGFILE
echo " Running unprivileged commands as ${SUDO_USER}" | tee -a $LOGFILE
echo | tee -a $LOGFILE
PIP="pip install"
PREFIX=/usr/local
HOME=$(getent passwd $SUDO_USER | cut -d: -f6)
ASUSER="sudo -u ${SUDO_USER} -E HOME=${HOME} "
fi
echo "*** Preparing system ***" | tee -a $LOGFILE
echo | tee -a $LOGFILE
if (( EUID != 0 )); then
echo "PyOP2 requires the following packages to be installed:
build-essential python-dev git-core mercurial cmake cmake-curses-gui libmed1
gmsh python-pip libhdf5-openmpi-dev libopenmpi-dev openmpi-bin libblas-dev
liblapack-dev gfortran libbost-dev"
else
apt-get update >> $LOGFILE 2>&1
apt-get install -y python-software-properties >> $LOGFILE 2>&1
apt-get install -y build-essential python-dev git-core mercurial cmake \
cmake-curses-gui libmed1 gmsh python-pip libhdf5-openmpi-dev \
libopenmpi-dev openmpi-bin libblas-dev liblapack-dev gfortran \
>> $LOGFILE 2>&1
fi
echo "*** Installing dependencies ***" | tee -a $LOGFILE
echo | tee -a $LOGFILE
# Install Cython so we can build PyOP2 from source
${PIP} Cython decorator numpy networkx >> $LOGFILE 2>&1
echo "*** Installing PETSc ***" | tee -a $LOGFILE
echo | tee -a $LOGFILE
PETSC_CONFIGURE_OPTIONS="--download-ctetgen --download-triangle --download-chaco"
${PIP} git+https://bitbucket.org/petsc/petsc.git#egg=petsc >> $LOGFILE 2>&1
${PIP} git+https://bitbucket.org/petsc/petsc4py.git#egg=petsc4py >> $LOGFILE 2>&1
echo "*** Installing PyOP2 ***" | tee -a $LOGFILE
echo | tee -a $LOGFILE
if [ ! -d PyOP2/.git ]; then
${ASUSER}git clone git://github.com/OP2/PyOP2.git >> $LOGFILE 2>&1
fi
cd $PYOP2_DIR
${ASUSER}python setup.py develop --user >> $LOGFILE 2>&1
python -c 'from pyop2 import op2'
if [ $? != 0 ]; then
echo "PyOP2 installation failed" 1>&2
echo " See ${LOGFILE} for details" 1>&2
exit 1
fi
echo "
Congratulations! PyOP2 installed successfully!
"
echo "*** Installing PyOP2 testing dependencies ***" | tee -a $LOGFILE
echo | tee -a $LOGFILE
${PIP} pytest flake8 >> $LOGFILE 2>&1
if (( EUID != 0 )); then
echo "PyOP2 tests require the following packages to be installed:"
echo " gmsh triangle-bin unzip"
else
apt-get install -y gmsh triangle-bin unzip >> $LOGFILE 2>&1
fi
echo "*** Testing PyOP2 ***" | tee -a $LOGFILE
echo | tee -a $LOGFILE
cd $PYOP2_DIR
${ASUSER}make test BACKENDS="sequential openmp" >> $LOGFILE 2>&1
if [ $? -ne 0 ]; then
echo "PyOP2 testing failed" 1>&2
echo " See ${LOGFILE} for details" 1>&2
exit 1
fi
echo "Congratulations! PyOP2 tests finished successfully!"
echo | tee -a $LOGFILE
echo "PyOP2 installation finished at `date`" | tee -a $LOGFILE