-
Notifications
You must be signed in to change notification settings - Fork 0
/
setup.sh
executable file
·329 lines (312 loc) · 9.66 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
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
#!/bin/bash
#
# Enable eval with..
# %s/#eval \$cmd/eval \$cmd/g
#
# Disable eval with..
# %s/eval \$cmd/#eval \$cmd/g
echo "Run like this..."
echo "echo \"Start Over\" > /tmp/progress.log"
echo "export HXEADMPW=\"Plak8484\" ; export HANADBPW=\"Plak8484\" ; export HXEINST=\"00\" ; export XSAORG=\"LCFX\" ; export XSASPACE=\"DEV\" ; ./setup.sh"
echo "Starting..."
hxeadmpw=$HXEADMPW
hanadbpw=$HANADBPW
if [ "$HXEINST" = "" ]
then
echo "Defaulting to instance 90"
hxeinst="90"
else
echo "Using instance $HXEINST"
hxeinst=$HXEINST
fi
if [ "$XSAORG" = "" ]
then
echo "Defaulting to org named HANAExpress"
xsaorg="HANAExpress"
else
echo "Using org $XSAORG"
xsaorg=$XSAORG
fi
if [ "$XSASPACE" = "" ]
then
echo "Defaulting to space named ml"
xsaspace="ml"
else
echo "Using space $XSASPACE"
xsaspace=$XSASPACE
fi
PROGRESS_FILE=/tmp/progress.log
export PROGRESS_FILE=$PROGRESS_FILE
last_step="start_progress"
function write_progress ()
{
local step_name=$1
echo "$(date '+%F %H:%M:%S') $step_name" >> "$PROGRESS_FILE"
if [ $? -ne 0 ]; then
error_out "failed to update progress"
fi
}
function read_progress
{
echo "Reading Progress..."
local step_name
step_name=$(tail -1 "$PROGRESS_FILE" | cut -d' ' -f 3)
if [ $? -ne 0 ]; then
error_out "failed to read progress"
fi
if [ -z $step_name ]; then
step_name="start_progress"
fi
last_step=$step_name
}
read_progress
echo "Last Progress: $last_step"
#echo "hxeadmpw: $hxeadmpw"
if [ -z $hxeadmpw ]; then
read -s -p "Enter hxeadm password: " hxeadmpw
cmd="echo The passwd is: $hxeadmpw"
echo $cmd
#eval $cmd
write_progress "got_hxeadmpw"
fi
if [ -z $hanadbpw ]; then
read -s -p "Enter HANA DB SYSTEM user password: " hanadbpw
cmd="echo The passwd is: $hanadbpw"
echo $cmd
#eval $cmd
write_progress "got_hanadbpw"
fi
read_progress
case $last_step in
start_progress)
echo "starting progress"
echo ""
echo "Be sure that you can run the 'xs a' command to list running applications before continuing."
read -s -p "Continue? (Enter=Yes, Ctrl-C to exit)" contyn
echo ""
write_progress "stop_non_crit_xsa"
;&
stop_non_crit_xsa)
echo ""
echo "Stopping non-critical XS apps."
read -s -p "Continue? (Enter=Yes, Ctrl-C to exit)" contyn
echo ""
echo ""
cmd="xs target -o "$xsaorg" -s SAP ; xs a | grep STARTED | grep -v hrtt-service | grep -v di-runner | grep -v di-core | grep -v deploy-service | cut -d ' ' -f 1 | while read -r line ; do echo \"Stopping \$line\"; xs stop \$line ; done"
echo $cmd
#eval $cmd
write_progress "setup_repos"
;&
setup_repos)
echo ""
echo "Setting up Package Repositories."
read -s -p "Continue? (Enter=Yes, Ctrl-C to exit)" contyn
echo ""
echo ""
cmd="sudo zypper -n --gpg-auto-import-keys refresh"
echo $cmd
#eval $cmd
cmd="sudo zypper -n --gpg-auto-import-keys install --no-recommends --auto-agree-with-licenses --force-resolution --type pattern devel_basis"
echo $cmd
#eval $cmd
cmd="sudo zypper -n --gpg-auto-import-keys install --no-recommends --auto-agree-with-licenses --force-resolution tk-devel tcl-devel libffi-devel openssl-devel readline-devel sqlite3-devel ncurses-devel xz-devel zlib-devel wget git-core nodejs npm lynx jq libzip2 libzip inotify-tools"
echo $cmd
#eval $cmd
echo ""
read -s -p "Continue? (Enter=Yes, Ctrl-C to exit)" contyn
echo ""
echo ""
write_progress "clone_project"
;&
clone_project)
echo ""
echo "Git Clone the Python ML Project."
read -s -p "Continue? (Enter=Yes, Ctrl-C to exit)" contyn
echo ""
echo ""
cmd="git clone https://github.com/alundesap/mta_python_ml.git"
echo $cmd
#eval $cmd
write_progress "build_python_runtime"
;&
build_python_runtime)
echo ""
echo "Build and install the pyton runtime."
read -s -p "Continue? (Enter=Yes, Ctrl-C to exit)" contyn
echo ""
echo ""
cmd="wget -c https://www.python.org/ftp/python/3.6.5/Python-3.6.5.tgz"
echo $cmd
#eval $cmd
cmd="wget -c http://thedrop.sap-a-team.com/files/hana_ml-1.0.3.tar.gz"
echo $cmd
#eval $cmd
cmd="wget -c http://thedrop.sap-a-team.com/files/XS_PYTHON00_1-70003433.ZIP"
echo $cmd
#eval $cmd
cmd="tar xzvf Python-3.6.5.tgz ; md python_3_6_5 ; cd Python-3.6.5 ; ./configure --prefix=/usr/sap/HXE/HDB"$hxeinst"/hxe_python_ml/python_3_6_5/ --exec-prefix=/usr/sap/HXE/HDB"$hxeinst"/hxe_python_ml/python_3_6_5/ ; make -j4 ; make altinstall"
echo $cmd
#eval $cmd
cmd="cd ../python_3_6_5/bin ; cp easy_install-3.6 easy_install ; cp pip3.6 pip ; cp pydoc3.6 pydoc ; cp python3.6 python ; cp pyvenv-3.6 pyvenv"
echo $cmd
#eval $cmd
echo ""
echo ""
echo "Note: When setting up python on your own server: "
echo " If you find that the pip command below fails with an inablility to import the _socket library, "
echo " it’s because the configure/build process under some variations of linux leaves some important libraries in an unexpected location."
echo " Change into the directory where the target python was installed."
echo "cd python_3_6_5"
echo " Copy the files in the lib64 folder into the lib folder"
echo "cp -avp lib64/* lib"
echo " Uninstall the runtime. By first finding it’s ID and then deleting it."
echo ""
echo ""
cmd="xs create-runtime -p /usr/sap/HXE/HDB"$hxeinst"/hxe_python_ml/python_3_6_5/"
echo $cmd
#eval $cmd
cmd="cd ../.."
echo $cmd
#eval $cmd
cmd="unzip XS_PYTHON00_1-70003433.ZIP -d sap_dependencies"
echo $cmd
#eval $cmd
cmd=". set_python_env.sh"
echo $cmd
#eval $cmd
cmd="mkdir -p vendor ; pip download -d vendor -r requirements.txt --find-links ../../sap_dependencies --find-links ../../hana_ml-1.0.3.tar.gz hana_ml ; cd .."
echo $cmd
#eval $cmd
write_progress "prep_hxe_tenant"
;&
prep_hxe_tenant)
echo ""
echo "Prepare HANA HXE Tenant for deploys."
read -s -p "Continue? (Enter=Yes, Ctrl-C to exit)" contyn
echo ""
echo ""
cmd="hdbsql -i "$hxeinst" -n localhost:3"$hxeinst"13 -u SYSTEM -p "$hanadbpw" -d SYSTEMDB \"ALTER DATABASE HXE ADD 'scriptserver'\""
echo $cmd
#eval $cmd
cmd="xs create-space "$xsaspace" -o "$xsaorg""
echo $cmd
#eval $cmd
cmd="xs set-space-role XSA_ADMIN "$xsaorg" "$xsaspace" SpaceManager"
echo $cmd
#eval $cmd
cmd="xs set-space-role XSA_ADMIN "$xsaorg" "$xsaspace" SpaceDeveloper"
echo $cmd
#eval $cmd
cmd="xs set-space-role XSA_DEV "$xsaorg" "$xsaspace" SpaceManager"
echo $cmd
#eval $cmd
cmd="xs set-space-role XSA_DEV "$xsaorg" "$xsaspace" SpaceDeveloper"
echo $cmd
#eval $cmd
cmd="xs enable-tenant-database HXE -u SYSTEM -p $hanadbpw -t $hxeadmpw"
echo $cmd
#eval $cmd
cmd="xs map-tenant-database HXE -o "$xsaorg" -s "$xsaspace""
echo $cmd
#eval $cmd
write_progress "build_ml_demo_app"
;&
build_ml_demo_app)
echo ""
echo "Build the DB and Python application modules."
read -s -p "Continue? (Enter=Yes, Ctrl-C to exit)" contyn
echo ""
echo ""
cmd="xs t -s "$xsaspace""
echo $cmd
#eval $cmd
cmd="cd /usr/sap/HXE/HDB"$hxeinst"/hxe_python_ml/mta_python_ml"
echo $cmd
#eval $cmd
cmd="xs create-service hana hdi-shared python-ml-hdi"
echo $cmd
#eval $cmd
cmd="xs create-service xsuaa default python-ml-uaa"
echo $cmd
#eval $cmd
cmd="cd db ; npm install ; cd .."
echo $cmd
#eval $cmd
cmd="xs push python-ml.db -k 1024M -m 256M -p db --no-start --no-route"
echo $cmd
#eval $cmd
cmd="xs bind-service python-ml.db python-ml-hdi"
echo $cmd
#eval $cmd
cmd="xs restart python-ml.db --wait-indefinitely ; sleep 15 ; xs stop python-ml.db"
echo $cmd
#eval $cmd
cmd="xs push python-ml.python -k 1024M -m 256M -n python -p python --no-start"
echo $cmd
#eval $cmd
cmd="xs bind-service python-ml.python python-ml-hdi"
echo $cmd
#eval $cmd
cmd="xs bind-service python-ml.python python-ml-uaa"
echo $cmd
#eval $cmd
cmd="xs start python-ml.python"
echo $cmd
#eval $cmd
cmd="pymodurl=\$(xs app python-ml.python --urls) ; echo \$pymodurl"
echo $cmd
#eval $cmd
write_progress "build_web_module"
;&
build_web_module)
echo ""
echo "Build the web module and adjust the target route."
echo ""
cmd="cd web ; npm install ; cd .."
echo $cmd
#eval $cmd
cmd="xs push python-ml.web -k 1024M -m 256M -n web -p web --no-start"
echo $cmd
#eval $cmd
cmd="xs bind-service python-ml.web python-ml-uaa"
echo $cmd
#eval $cmd
cmd="xs set-env python-ml.web destinations '[{\"forwardAuthToken\":true, \"name\":\"python_be\", \"url\":\""$pymodurl"\"}]'"
echo $cmd
#eval $cmd
cmd="xs start python-ml.web"
echo $cmd
#eval $cmd
cmd="pyweburl=\$(xs app python-ml.web --urls) ; echo \$pyweburl"
echo $cmd
#eval $cmd
write_progress "get_user_add_role"
;&
get_user_add_role)
echo "Get the HDI user and add the AFLPAL role."
cmd="hdiusr=\$(xs env python-ml.python | grep '\"user\"' | cut -d \":\" -f 2 | cut -d '\"' -f 2) ; echo \$hdiusr"
echo $cmd
#eval $cmd
cmd="hdbsql -i "$hxeinst" -n localhost:3"$hxeinst"15 -u SYSTEM -p "$hanadbpw" -d HXE \"grant AFL__SYS_AFL_AFLPAL_EXECUTE to "$hdiusr"\""
echo $cmd
#eval $cmd
cmd="echo \"Python Demo App can be found at: \"\$pyweburl"
echo $cmd
#eval $cmd
write_progress "do_stepX"
;&
do_stepX)
echo ""
echo "stepX_thing"
read -s -p "Continue? (Enter=Yes, Ctrl-C to exit)" contyn
echo ""
echo ""
cmd=""
echo $cmd
#eval $cmd
write_progress "scrpt_completed"
;;
esac
#write_progress "script_completed"
echo "Ending..."
echo 'Reset with: echo "Start Over" > /tmp/progress.log'