update sdnc-web image
[sdnc/oam.git] / installation / sdnc-web / src / main / scripts / configure.sh
1 #!/bin/bash
2
3 ###
4 # ============LICENSE_START=======================================================
5 # ONAP : ccsdk distribution web
6 # ================================================================================
7 # Copyright (C) 2020 highstreet technologies GmbH Intellectual Property.
8 # All rights reserved.
9 # ================================================================================
10 # Licensed under the Apache License, Version 2.0 (the "License");
11 # you may not use this file except in compliance with the License.
12 # You may obtain a copy of the License at
13 #
14 #      http://www.apache.org/licenses/LICENSE-2.0
15 #
16 # Unless required by applicable law or agreed to in writing, software
17 # distributed under the License is distributed on an "AS IS" BASIS,
18 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
19 # See the License for the specific language governing permissions and
20 # limitations under the License.
21 # ============LICENSE_END=========================================================
22 ###
23
24 # Comment listening on 8080 in nginx.conf as we don't want nginx to listen on any port other than SDNR
25 sed -i 's/listen/\#listen/g' /opt/bitnami/nginx/conf/nginx.conf
26
27 update_index_html() {
28  
29     # Backup the index.html file
30     cp /opt/bitnami/nginx/html/odlux/index.html /opt/bitnami/nginx/html/odlux/index.html.backup
31     #default values
32     ODLUX_AUTH_METHOD="basic"
33     ENABLE_ODLUX_RBAC=${ENABLE_ODLUX_RBAC:-false}
34     
35     if [ "$ENABLE_OAUTH" == "true" ]; then
36         ODLUX_AUTH_METHOD="oauth"
37     fi
38     echo "authentication is $ODLUX_AUTH_METHOD"
39     echo "rbac access is enabled: $ENABLE_ODLUX_RBAC"
40     ODLUX_CONFIG='{"authentication":"'$ODLUX_AUTH_METHOD'","enablePolicy":'$ENABLE_ODLUX_RBAC'}'
41 #    sed -z 's/<script>[^<]*<\/script>/<script>\n    \/\/ run the application \n  require\(\[\"connectApp\",\"faultApp\",\"maintenanceApp\",\"configurationApp\",\"performanceHistoryApp\",\"inventoryApp\",\"eventLogApp\",\"mediatorApp\",\"networkMapApp\",\"linkCalculationApp\",\"helpApp\",\"run\"\], function \(connectApp,faultApp,maintenanceApp,configurationApp,performanceHistoryApp,inventoryApp,eventLogApp,mediatorApp,networkMapApp,linkCalculationApp,helpApp,run\) \{ \n run.configure('$ODLUX_CONFIG'); \n    connectApp.register\(\); \n  faultApp.register\(\);\n    maintenanceApp.register\(\); \n     configurationApp.register\(\);\n    performanceHistoryApp.register\(\); \n    inventoryApp.register\(\);\n    eventLogApp.register\(\);\n   mediatorApp.register\(\);\n   networkMapApp.register\(\);\n   linkCalculationApp.register\(\);\n     helpApp.register\(\);\n      run.runApplication();\n    \}\);\n  <\/script>/' -i /opt/bitnami/nginx/html/odlux/index.html 
42
43     #replace require expression
44     sed -z 's/require(\["run"\],\ function\ (run)/require\(\[\"connectApp\",\"faultApp\",\"maintenanceApp\",\"configurationApp\",\"performanceHistoryApp\",\"inventoryApp\",\"eventLogApp\",\"mediatorApp\",\"networkMapApp\",\"linkCalculationApp\",\"helpApp\",\"run\"\], function \(connectApp,faultApp,maintenanceApp,configurationApp,performanceHistoryApp,inventoryApp,eventLogApp,mediatorApp,networkMapApp,linkCalculationApp,helpApp,run\)/' -i /opt/bitnami/nginx/html/odlux/index.html 
45     #replace run.runApplication expression
46     sed -z 's/run.runApplication();/connectApp.register\(\); \n  faultApp.register\(\);\n    maintenanceApp.register\(\); \n     configurationApp.register\(\);\n    performanceHistoryApp.register\(\); \n    inventoryApp.register\(\);\n    eventLogApp.register\(\);\n   mediatorApp.register\(\);\n   networkMapApp.register\(\);\n   linkCalculationApp.register\(\);\n     helpApp.register\(\);\n      run.runApplication();/' -i /opt/bitnami/nginx/html/odlux/index.html 
47     #replace run.configure expression if exists
48     sed -z 's/run.configureApplication([^)]\+)/run.configureApplication('$ODLUX_CONFIG');/' -i /opt/bitnami/nginx/html/odlux/index.html 
49
50 }
51
52 update_nginx_site_conf() {
53
54     if [ "$WEBPROTOCOL" == "HTTPS" ]
55     then
56         FN=/opt/bitnami/nginx/conf/server_blocks/https_site.conf
57         rm /opt/bitnami/nginx/conf/server_blocks/http_site.conf
58         
59         sed -i 's|SSL_CERT_DIR|'$SSL_CERT_DIR'|g' $FN
60         sed -i 's|\bSSL_CERTIFICATE\b|'$SSL_CERTIFICATE'|g' $FN
61         sed -i 's|\bSSL_CERTIFICATE_KEY\b|'$SSL_CERTIFICATE_KEY'|g' $FN
62
63     elif [ "$WEBPROTOCOL" == "HTTP" ]
64     then
65         FN=/opt/bitnami/nginx/conf/server_blocks/http_site.conf
66         rm /opt/bitnami/nginx/conf/server_blocks/https_site.conf
67         fi
68
69     if [ -z "$FN" ]; then
70         echo "unknown env WEBPROTOCOL: $WEBPROTOCOL"
71         exit 1
72     fi
73
74     # replace needed parameters
75     sed -i 's|WEBPORT|'$WEBPORT'|g' $FN
76     sed -i 's|SDNRPROTOCOL|'$SDNRPROTOCOL'|g' $FN
77     sed -i 's|SDNRHOST|'$SDNRHOST'|g' $FN
78     sed -i 's|SDNRPORT|'$SDNRPORT'|g' $FN
79     sed -i 's|DNS_RESOLVER|'$DNS_RESOLVER'|g' $FN
80
81     # handle optional parameters
82     if [ -z "$TRPCEURL" ]; then
83         echo "transportPCE forwarding disabled"
84         sed -i 's|proxy_pass TRPCEURL/$1;|return 404;|g' $FN
85     
86     else
87         sed -i 's|TRPCEURL|'$TRPCEURL'|g' $FN
88     fi
89     if [ -z "$TOPOURL" ]; then
90         echo "topology api forwarding disabled"
91         sed -i 's|proxy_pass TOPOURL;|return 404;|g' $FN
92     else
93         sed -i 's|TOPOURL|'$TOPOURL'|g' $FN
94     fi
95     if [ -z "$TILEURL" ]; then
96         echo "tile server forwarding disabled"
97         sed -i 's|proxy_pass TILEURL/$1;|return 404;|g' $FN
98     else
99         sed -i 's|TILEURL|'$TILEURL'|g' $FN
100     fi
101
102 }
103
104 update_index_html
105
106 update_nginx_site_conf