-
Notifications
You must be signed in to change notification settings - Fork 0
/
setup.sh
313 lines (259 loc) · 7.73 KB
/
setup.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
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
#!/bin/bash
#
# Copyright 2016-2017 HLRS, University of Stuttgart
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
#
#=============================================================================
#
# FILE: setup.sh
#
# USAGE: setup.sh <parameters>
#
# DESCRIPTION: Un/Installer for vTorque layer.
#
# OPTIONS: ---
# REQUIREMENTS: Working PBS Torque installation.
# BUGS: ---
# NOTES: ---
# AUTHOR: Nico Struckmann, [email protected]
# COMPANY: HLRS, University of Stuttgart
# VERSION: 0.1
# CREATED: July 07th 2017
# REVISION:
#
# CHANGELOG
#
#=============================================================================
#============================================================================#
# #
# SCRIPT CONFIGURATION #
# DO NOT MODIFY #
# #
#============================================================================#
#
# Base dir from where the files are copied.
#
BASE_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)";
#
# Default action to carry out.
#
DEFAULT_ACTION="setup";
#
# Default prefix for the installation.
#
DEFAULT_PREFIX="/opt";
#
# User provided action to carry out.
# Default is '$DEFAULT_ACTION'.
#
ACTION="";
#
# User provided prefix for the installation.
# Default is '$DEFAULT_PREFIX'.
#
PREFIX="";
#
# Destination dir for the installation.
# Default is '$PREFIX/vTorque'
#
DEST_DIR="";
#
# vTorque's config file
#
VTORQUE_CONFIG_FILE="";
#============================================================================#
# #
# FUNCTIONS #
# #
#============================================================================#
#---------------------------------------------------------
#
# set permissions for production
#
_setPermissions() {
chown -R root:root $DEST_DIR;
chmod -R 555 $DEST_DIR;
chmod 444 $DEST_DIR/contrib/*;
chmod 444 $DEST_DIR/doc/*.md;
chmod 444 $DEST_DIR/src/common/*;
chmod 500 $DEST_DIR/src/scripts/*;
chmod 500 $DEST_DIR/src/scripts-vm/*;
chmod 444 $DEST_DIR/src/templates/*;
chmod 444 $DEST_DIR/src/templates-vm/*;
echo "Permissions applied to installed files.";
}
#
# asks user for networking settings that are applied to VMs
#
_configureVMnetworking() {
echo "Please provide network settings, applied to VMs.";
echo -n "Domain: ";
read DOMAIN;
echo -n "Search-Domain: ";
read SEARCH_DOMAIN;
echo -n "Name server IP: ";
read NAME_SERVER;
echo -n "NFS 'server:/path' for \$HOME: ";
read NFS_HOME;
echo -n "NFS 'server:/path' for '/opt': ";
read NFS_OPT;
echo -n "NFS 'server:/path' for intermediate workspace: ";
read VM_NFS_WS;
echo -n "NTP server (1/2) IP: ";
read NTP_SERVER_1;
echo -n "NTP server (2/2) IP: ";
read NTP_SERVER_2;
sed -i -e "s,NAME_SERVER=.*,NAME_SERVER=\"$NAME_SERVER\";,g" $VTORQUE_CONFIG_FILE;
sed -i -e "s,DOMAIN=.*,DOMAIN=\"$DOMAIN\";,g" $VTORQUE_CONFIG_FILE;
sed -i -e "s,SEARCH_DOMAIN=.*,SEARCH_DOMAIN=\"$SEARCH_DOMAIN\";,g" $VTORQUE_CONFIG_FILE;
sed -i -e "s,NTP_SERVER_1=.*,NTP_SERVER_1=\"$NTP_SERVER_1\";,g" $VTORQUE_CONFIG_FILE;
sed -i -e "s,NTP_SERVER_2=.*,NTP_SERVER_2=\"$NTP_SERVER_1\";,g" $VTORQUE_CONFIG_FILE;
sed -i -e "s,VM_NFS_HOME=.*,VM_NFS_HOME=\"$NFS_HOME\";,g" $VTORQUE_CONFIG_FILE;
sed -i -e "s,VM_NFS_OPT=.*,VM_NFS_OPT=\"$NFS_OPT\";,g" $VTORQUE_CONFIG_FILE;
sed -i -e "s,VM_NFS_WS=.*,VM_NFS_WS=\"$NFS_WS\";,g" $VTORQUE_CONFIG_FILE;
echo "VM networking settings applied.";
}
#---------------------------------------------------------
#
# prints out available targets
#
usage() {
echo "usage: $0 [--prefix|-p <PREFIX>] [--uninstall|-u]";
}
#---------------------------------------------------------
#
#
#
setupServer() {
cd $BASE_DIR;
# check if destination dir exists, if not create it
if [ -e $DEST_DIR ]; then
if [ ! -d $DEST_DIR ]; then
echo "Destination dir '$DEST_DIR' is not a directory.";
exit 1;
else
mkdir -p $DEST_DIR;
fi
fi
#copy files to destination
cp -r ./lib $DEST_DIR/;
cp -r ./src/* $DEST_DIR/;
cp -r ./doc $DEST_DIR/;
cp -r ./test $DEST_DIR/;
cp ./contrib/99-mikelangelo-hpc_stack.sh /etc/profile.d/;
cp ./LICENSE $DEST_DIR/;
cp ./NOTICE $DEST_DIR/;
cp ./README* $DEST_DIR/;
# fix relative paths in doc/*
sed -i 's,../src/,../,g' $DEST_DIR/doc/*;
# set PATH
sed -i -e "s,VTORQUE_DIR=.*,VTORQUE_DIR=\"$DEST_DIR\";,g" /etc/profile.d/99-mikelangelo-hpc_stack.sh;
# apply network settings
_configureVMnetworking;
# apply correct and secure permissions
_setPermissions;
echo "Setup server done.";
}
#---------------------------------------------------------
#
#
#
cleanupServer() {
rm -Rf $DEST_DIR;
rm -f /etc/profile.d/99-mikelangelo-hpc_stack.sh;
echo "Server clean up done.";
}
#---------------------------------------------------------
#
# rename current/orig scripts in place
#
setupMoms() {
pdsh -a "\
cd $BASE_DIR;\
cp ./contrib/99-mikelangelo-hpc_stack.sh /etc/profile.d/;\
sed -i -e \"s,VTORQUE_DIR=.*,VTORQUE_DIR=$DEST_DIR,g\" /etc/profile.d/99-mikelangelo-hpc_stack.sh;\
rename -v 's/(.*)\$$$\/\$$$\1.orig/' /var/spool/torque/mom_priv/{pro,epi}logue{.user,}{.parallel,.precancel,};\
ln -sf $DEST_DIR/src/scripts/{prologue{,.parallel},epilogue{,.parallel,.precancel}} /var/spool/torque/mom_priv/;";
echo "Mom setup done";
}
#---------------------------------------------------------
#
# put original scripts back in place
#
cleanupMoms() {
pdsh -a "\
rm -f /etc/profile.d/99-mikelangelo-hpc_stack.sh;\
rm -f /var/spool/torque/mom_priv/{pro,epi}logue{.user,}{.parallel,.precancel,};\
rename 's/\.orig\$$$\//' /var/spool/torque/mom_priv/{pro,epi}logue{.user,}{.parallel,.precancel,}.orig;";
echo "Mom clean up done";
}
#============================================================================#
# #
# MAIN #
# #
#============================================================================#
# check if user has the required rights
if [ $(id -u) -ne 0 ]; then
echo "Run as root.";
exit 1;
fi
#
# parse arguments
#
while [[ $# -gt 1 ]]; do
case $1 in
--prefix|-p)
PREFIX="$2";
shift;
;;
--uninstall|-u)
ACTION="cleanup";
shift;
;;
*)
usage;
;;
esac
shift;
done
# prefix provided ?
if [ -z ${PREFIX-} ]; then
# no, use default
PREFIX=$DEFAULT_PREFIX;
fi
DEST_DIR="$PREFIX/vtorque";
VTORQUE_CONFIG_FILE="$DEST_DIR/common/config.sh";
#
# what to do ?
#
case $ACTION in
setup)
# setup server
setupServer;
# setup moms
setupMoms;
;;
cleanup)
# cleanup server
cleanupServer;
# cleanup moms
cleanupNodes;
;;
*)
usage;
;;
esac
# print summary
echo "Setup done.";