forked from DataIntellectTech/TorQ
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinstalltorqapp.sh
287 lines (247 loc) · 7.73 KB
/
installtorqapp.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
#!/bin/bash
#Example usage:
#bash installtorqapp.sh --torq TorQ-3.7.0.tar.gz --releasedir deploy --data datatemp --installfile TorQ-Finance-Starter-Pack-1.9.0.tar.gz
#or
#bash installtorqapp.sh -t TorQ-3.7.0.tar.gz -r deploy -d datatemp -i TorQ-Finance-Starter-Pack-1.9.0.tar.gz
#Creating variables from the definitions
POSITIONAL=()
while [[ $# -gt 0 ]]
do
key="$1"
case $key in
-t|--torq)
torq=`realpath "$2"`
shift # past argument
shift # past value
;;
-r|--releasedir)
releasedir=`realpath "$2"`
shift # past argument
shift # past value
;;
-i|--installfile)
installfile=`realpath "$2"`
shift # past argument
shift # past value
;;
-d|--data)
data=`realpath "$2"`
shift # past argument
shift # past value
;;
-e|--env)
env=`realpath "$2"`
shift # past argument
shift # past value
;;
--default)
DEFAULT=YES
shift # past argument
;;
*) # unknown option
POSITIONAL+=("$1") # save it in an array for later
shift # past argument
;;
esac
done
set -- "${POSITIONAL[@]}" # restore positional parameters
echo ""
echo "============================================================="
echo "VARIABLES DEFINED FOR THE INSTALLATION SCRIPT:"
echo "============================================================="
echo "torq = $torq"
echo "releasedir = $releasedir"
echo "env = $env"
echo "installfile = $installfile"
echo "data = $data "
echo ""
echo "============================================================="
echo "CHECKING VARIABLES AND CREATING RELEASE DIRECTORIES"
echo "============================================================="
if [ -z "$torq" ]
then
echo "\$torq var empty"
echo "example usage can be seen first line of script"
echo "exiting script"
exit 1
elif [ ! -f "$torq" ]
then
echo "\$torq directory given doesn't exist"
echo "exiting"
exit 1
fi
if [ -z "$installfile" ]
then
echo "\$installfile var empty"
echo "example usage can be seen first line of script"
echo "exiting script"
exit 1
elif [ ! -f "$installfile" ]
then
echo "\$installfile path given doesn't exist"
echo "exiting"
exit 1
fi
if [ -z "$releasedir" ]
then
echo "\$releasedir var empty"
echo "example usage can be seen first line of script"
echo "exiting script"
exit 1
fi
if [ ! -d "$releasedir" ]
then
echo "$releasedir directory doesn't exists"
echo "making the releasedir"
mkdir $releasedir
fi
#Making necessary structure for the deploy folder.
if [ ! -d "$releasedir/bin" ]
then
echo "$releasedir/bin directory doesn't exists"
echo "making the bin directory"
mkdir $releasedir/bin
fi
if [ ! -d "$releasedir/TorQ" ]
then
echo "$releasedir/TorQ directory doesn't exists"
echo "making the TorQ directory"
mkdir $releasedir/TorQ
fi
if [ ! -d "$releasedir/TorQApp" ]
then
echo "$releasedir/TorQApp directory doesn't exists"
echo "making the TorQApp directory"
mkdir $releasedir/TorQApp
fi
echo "============================================================="
echo "MOVING TORQ INSTALLATION TO CORRECT FOLDER:"
echo "============================================================="
if ! { tar ztf "$torq" || tar tf "$torq"; } >/dev/null 2>&1
then
echo "$torq is not a tar file"
if [ ! -d "$torq" ]
then
echo "$torq directory doesn't exists"
exit 1
fi
echo "moving the TorQ installation to the deploy folder"
version_number=`echo $torq | sed 's:.*-::'`
echo "Creating a latest softlink for TorQ"
ln -sfn $torq $releasedir/TorQ/latest
ln -sfn $torq $releasedir/TorQ/$version_number
cp $releasedir/TorQ/latest/torq.sh $releasedir/bin/.
echo ""
else
echo "$torq is a tar file"
version_number=`echo $torq | sed 's:.*-::' | sed 's:.tar.gz*.::'`
torq_unzip_dir=$releasedir/TorQ/$version_number/
torq_dir_name=`echo ${torq%???????} | sed 's:.*/::'`
if [ ! -d "$torq_unzip_dir" ]
then
echo "unzip directory:"
echo $torq_unzip_dir
echo "directory doesn't exists"
echo "making the TorQ directory with the latest version"
mkdir $torq_unzip_dir
fi
echo $version_number
echo $torq_unzip_dir
echo $torq_dir_name
echo ""
echo $releasedir/TorQ/$version_number/$torq_dir_name
echo $releasedir/TorQ/latest
echo ""
tar -xf $torq -C $torq_unzip_dir
ln -sfn $releasedir/TorQ/$version_number/$torq_dir_name $releasedir/TorQ/latest
cp $releasedir/TorQ/latest/torq.sh $releasedir/bin/.
echo ""
fi
echo ""
echo "============================================================="
echo "UNZIPPING TORQAPP TO CORRECT PLACES"
echo "============================================================="
echo "Unzipping the TorQ addition package:"
echo $installfile
echo "TorQ-APP version name/number:"
app_version=`echo $installfile | sed 's:.*-::' | sed 's:.tar.gz*.::'`
echo $app_version
unzip_dir=$releasedir/TorQApp/$app_version/
if [ ! -d "$unzip_dir" ]
then
echo "unzip directory:"
echo $unzip_dir
echo "directory doesn't exists"
echo "making the TorQApp directory with the latest version"
mkdir $unzip_dir
fi
app_dir_name=`echo ${installfile%???????} | sed 's:.*/::'`
tar -xf $installfile -C $unzip_dir
echo ""
echo "Unzipping complete!"
echo "New folder in TorQApp directory:"
echo $app_dir_name
echo "Creating a latest softlink"
ln -sfn $unzip_dir/$app_dir_name $releasedir/TorQApp/latest
cp $releasedir/TorQApp/latest/setenv.sh $releasedir/bin/.
echo ""
echo "============================================================="
echo "CHECKING IF HDB EXISTS IF NOT COPY IT FROM THE APP:"
echo "============================================================="
#creating the HDB directory if it doesn't exist in data folder.
if [ -z "$data" ]
then
echo "\$data var empty pointing the variable to release directory"
data="$releasedir/data"
echo "$data"
else
echo "this softlink has executed"
ln -sfn $data $releasedir/data
fi
if [ ! -d "$data" ]
then
echo "data folder doesn't exist"
echo "making the data directory"
mkdir $data
for i in logs tplogs wdb wdbhdb
do
mkdir $data/$i
done
fi
if [ ! -d "$data/hdb" ]
then
echo "$data/hdb directory doesn't exists"
echo "making the data/hdb directory"
cp -r $releasedir/TorQApp/latest/hdb $data/hdb
fi
if [ ! -d "$data/dqe" ]
then
echo "$data/dqe directory doesn't exists"
echo "making the data/hdb directory"
cp -r $releasedir/TorQApp/latest/dqe $data/dqe
fi
echo ""
echo "============================================================="
echo "doing necessary repalcements in torq.sh setenv.sh and processes"
echo "============================================================="
sed -i "/^hostnames=/a cd $releasedir/TorQ/latest" $releasedir/bin/torq.sh
sed -i "s|export TORQHOME=.*|export TORQHOME=$releasedir/TorQ/latest|" $releasedir/bin/setenv.sh
sed -i "s|export TORQAPPHOME=.*|export TORQAPPHOME=$releasedir/TorQApp/latest|" $releasedir/bin/setenv.sh
sed -i "s|export TORQDATAHOME=.*|export TORQDATAHOME=$releasedir/data|" $releasedir/bin/setenv.sh
echo ""
echo "============================================================="
echo "CHECKING ENVIRONMENT SPECIFIC FILE CHANGES"
echo "============================================================="
if [ -f "$env" ]
then
echo $releasedir/TorQApp/latest/
echo $releasedir/bin/
echo "Env file exists appying the appropriate replacements"
sh $env $releasedir/TorQApp/latest/
sh $env $releasedir/bin/
fi
echo ""
echo "============================================================="
echo "INSTALLATION COMPLETE"
echo "============================================================="
echo "Installation is finished. For a regular installation, run it as follows in the working directory: ./deploy/bin/torq.sh start all"