-
Notifications
You must be signed in to change notification settings - Fork 0
/
INSTALL
executable file
·215 lines (165 loc) · 7.85 KB
/
INSTALL
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
#!/usr/bin/env bash
# Main installation script for the BenchPRO site package.
# System parameters are read from ./site.sh
trap ctrl_c INT
MYID=""
function ctrl_c() {
printf "\nQuitting.\n"
if [[ ! -z $MYID ]]; then
kill -9 $MYID > /dev/null
fi
exit 1
}
progress() {
while true; do
printf "."
sleep 1
done
}
# Print error and exit
quit() {
printf "$1"
ctrl_c
}
patch_wrapper() {
WRAPPER="$BPS_HOME/python/bin/benchpro"
sed -i '3 i try:' $WRAPPER
sed -i '4s;^;\t;' $WRAPPER
sed -i '5s;^;\t;' $WRAPPER
printf "except Exception as e:\n" >> $WRAPPER
printf "\traise Exception(\"BenchPRO module not loaded\") from e\n" >> $WRAPPER
}
# Install Python package and set group permissions
install() {
export CC=gcc
export CXX=g++
export FC=gfortran
python3 -m pip uninstall -y benchpro &>> $BPS_LOG
python3 setup.py install --prefix=${BPS_HOME}/python/ &>> $BPS_LOG
[[ ${PIPESTATUS[0]} -ne 0 ]] && quit "\nPackage installation failed\n"
# Change group permissions
#chmod a+rX ${BPS_HOME}
chmod -R a+rX ${BPS_HOME}/python
chmod a+x ${BPS_HOME}/python/bin/benchpro
#chmod a+rwx ${BPS_HOME}/collection
# Update symlink
ln -s python/lib/python${PY_VERSION}/site-packages/benchpro-latest/ ${BPS_HOME}/package
ln -s benchpro-${BPS_VERSION}-py${PY_VERSION}.egg/ ${BPS_HOME}/python/lib/python${PY_VERSION}/site-packages/benchpro-latest
patch_wrapper
}
SRC_PATH=`pwd`
# Source site variables
SOURCE_FILE="$SRC_PATH/site.sh"
printf "Reading ${SOURCE_FILE}...\n"
source $SOURCE_FILE
[[ ${PIPESTATUS[0]} -ne 0 ]] && quit "\nCan't source ${SOURCE_FILE}\n"
# Test that BPS_HOME is writable
mkdir -p $BPS_HOME && printf "\nWe have write permission to ${BPS_HOME}\n" || quit "\nCan't write to ${BPS_HOME}\n"
# Quick install
if [[ "$1" = "-d" ]]; then
printf "Debug mode"
install
exit 0
fi
# Check if SSH key exists
[[ ! -f "$SSH_KEY" ]] && quit "\nProvided SSH key not found.\n"
printf "\nCleaning up old files...\n"
# Clean up env & build/install directories
${SRC_PATH}/clean
rm -rf ${BPS_HOME}/python/lib/python${PY_VERSION}/site-packages/benchpro-${BPS_VERSION}*
rm -f ${BPS_MODULES}/benchpro/*.lua
rm -f ${BPS_HOME}/package
rm -f ${BPS_HOME}/python/lib/python${PY_VERSION}/site-packages/benchpro-latest
printf "Done.\n"
#--------------------CREATE SITE PATHS---------------------------
printf "\nCreating BPS_HOME...\n"
# Setup
mkdir -p ${BPS_HOME}/logs
mkdir -p ${BPS_COLLECT}
setfacl -d -m group::rwX,other::rwX ${BPS_COLLECT}
chmod a+w ${BPS_COLLECT}
mkdir -p ${BPS_HOME}/python/lib/python${PY_VERSION}/site-packages
mkdir -p ${BPS_MODULES}/benchpro
chmod a+w ${BPS_MODULES}
setfacl -d -m group::rX,other::rX ${BPS_MODULES}
printf "Done.\n"
#--------------------MODULE FILE---------------------------------
printf "\nGenerating site module...\n"
# Copy and contextualize module file
cp ${SRC_PATH}/modulefiles/benchpro.lua ${BPS_MODULES}/benchpro/${BPS_VERSION}.lua
function update_mod() {
# Check val is set
[[ -z $2 ]] && printf "$1 not set" && exit 1
sed -i "3 i setenv(\"$1\", \"$2\")" ${BPS_MODULES}/benchpro/${BPS_VERSION}.lua
}
# Copy current 'BP_' EVs to modulefile
while IFS='=' read -r -d '' n v; do
if [[ "$n" == "BP"* ]]; then
update_mod $n $v
fi
done < <(env -0)
# Contextualize generic module file after install
sed -i "/Version:/c\Version: ${BPS_VERSION} " ${BPS_MODULES}/benchpro/${BPS_VERSION}.lua
sed -i "/local bp_home/c\local bp_home = \"${BP_HOME}\"" ${BPS_MODULES}/benchpro/${BPS_VERSION}.lua
sed -i "/local bp_repo/c\local bp_repo = \"${BP_REPO}\"" ${BPS_MODULES}/benchpro/${BPS_VERSION}.lua
sed -i "/local bp_apps/c\local bp_apps = \"${BP_APPS}\"" ${BPS_MODULES}/benchpro/${BPS_VERSION}.lua
sed -i "/local bp_results/c\local bp_results = \"${BP_RESULTS}\"" ${BPS_MODULES}/benchpro/${BPS_VERSION}.lua
sed -i "/local py_version/c\local py_version = \"${PY_VERSION}\"" ${BPS_MODULES}/benchpro/${BPS_VERSION}.lua
sed -i "/local py_mod/c\local py_mod = \"${PY_MODULE}\"" ${BPS_MODULES}/benchpro/${BPS_VERSION}.lua
sed -i "/local bps_site/c\local bps_site = \"${BPS_HOME}\"" ${BPS_MODULES}/benchpro/${BPS_VERSION}.lua
sed -i "/local py_lib/c\local py_lib = \"${PY_LIB}\"" ${BPS_MODULES}/benchpro/${BPS_VERSION}.lua
# Python module or Python env
if [[ -z $PY_ENV ]]; then
sed -i "/source_sh/s/^/--/ " ${BPS_MODULES}/benchpro/${BPS_VERSION}.lua
fi
if [[ $PY_MOD_LOAD == 0 ]]; then
sed -i "/depends_on/s/^/--/ " ${BPS_MODULES}/benchpro/${BPS_VERSION}.lua
fi
printf "Done.\n"
chmod -R a+rX ${BPS_MODULES}
#-----------------------CREATE VIRTENV------------------------------
if [[ $PY_ENV ]]; then
deactivate
printf "Creating virtual env...\n"
printf "`type python3`\n"
python3 -m virtualenv --system-site-packages $BPS_HOME/bp_env
[[ $? ]] && exit 1
printf "Sourcing $BPS_HOME/bp_env/bin/activate..."
source $BPS_HOME/bp_env/bin/activate
chmod -R a+rX $BPS_HOME/bp_env
printf "`type python3`\n"
printf "Done.\n"
fi
#----------------------INSTALL PYTHON PACKAGE-----------------------
#printf "\nLoading module...\n"
#ml unload benchpro
#ml use ${BPS_MODULES}
#ml benchpro || quit "\nCan't load module\n"
#progress &
#MYID=$!
printf "\nInstalling Package...\n"
install
# Kill progress
#kill -9 $MYID > /dev/null
printf "\nDone.\n"
#----------------------CLEAN BUILD FILES------------------------------
# Clean build files
${SRC_PATH}/clean >/dev/null
#----------------------TEST DB CONNECTION------------------------------
# Check SSH connection
printf "\nTesting Connection to DB...\n"
ssh -i ${SSH_KEY} ${DB_USER}@${DB_HOST} -t "printf 'Connection test\n'" > /dev/null 2>&1
[[ ${PIPESTATUS[0]} -ne 0 ]] && quit "\nSSH connection failed\n"
printf "\n"
printf -- "------------------------------------------------\n"
printf "BenchPRO successfully installed into ${BPS_HOME}\n"
printf "User files installed into ${BP_HOME} for testing\n"
printf "To use, load site module with:\n"
printf "ml use ${BPS_MODULES}\n"
printf "ml benchpro\n"
printf "\n"
printf -- "------------------------------------------------\n"
printf "Add the following lines to your crontab:\n"
echo "5 * * * * /bin/rsync --remove-source-files -av -e \"ssh -i $SSH_KEY\" $BPS_HOME/collection/* $DB_USER@$DB_HOST:$REMOTE_PATH/ >> $BPS_HOME/logs/collect_\`date +\\%Y\\-%m-%d\`.log 2>&1\n"
echo "0 0 * * * /bin/rsync -av /home1/06280/mcawood/work2/repo_backup/ $BP_REPO/ | tee -a $BPS_HOME/logs/repo_\`date +\\%Y\\-%m-%d\`.log\n"
printf "\nDone.\n"