[OOF] Use common secret template for mariadb credentials
[oom.git] / kubernetes / common / dgbuilder / resources / scripts / createReleaseDir.sh
1 # Copyright © 2018 AT&T, Amdocs, Bell Canada
2 #
3 # Licensed under the Apache License, Version 2.0 (the "License");
4 # you may not use this file except in compliance with the License.
5 # You may obtain a copy of the License at
6 #
7 #       http://www.apache.org/licenses/LICENSE-2.0
8 #
9 # Unless required by applicable law or agreed to in writing, software
10 # distributed under the License is distributed on an "AS IS" BASIS,
11 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 # See the License for the specific language governing permissions and
13 # limitations under the License.
14
15 #!/bin/bash
16 export PATH=$PATH:.
17 appDir=$(pwd)
18 if [ "$#" != 3 -a "$#" != 4 ]
19 then
20         echo "Usage $0 releaseDir  loginId emailAddress [gitLocalRepository]"
21         echo "Note: Specify the gitLocalRepository path if you would want to be able to import flows from your local git repository"
22         exit
23 fi
24 if [ ! -e "releases" ]
25 then
26         mkdir releases
27 fi
28 releaseDir="$1"
29 name="Release $releaseDir"
30 loginId="$2"
31 emailid="$3"
32 dbHost="{{.Values.config.dbServiceName}}.{{.Release.Namespace}}"
33 dbPort="3306"
34 dbName="sdnctl"
35 dbUser="sdnctl"
36 dbPassword="{{.Values.config.dbSdnctlPassword}}"
37 gitLocalRepository="$4"
38
39 lastPort=$(find "releases/" -name "customSettings.js" |xargs grep uiPort|cut -d: -f2|sed -e s/,//|sort|tail -1)
40 echo $lastPort|grep uiPort >/dev/null 2>&1
41 if [ "$?" == "0" ]
42 then
43 lastPort=$(find "releases/" -name "customSettings.js" |xargs grep uiPort|cut -d: -f3|sed -e s/,//|sort|tail -1)
44 fi
45 #echo $lastPort
46 if [ "${lastPort}" == "" ]
47 then
48         lastPort="3099"
49 fi
50 let nextPort=$(expr $lastPort+1)
51 #echo $nextPort
52 if [ ! -e "releases/$releaseDir" ]
53 then
54 mkdir releases/$releaseDir
55 cd releases/$releaseDir
56 mkdir flows
57 mkdir flows/shared
58 mkdir flows/shared/backups
59 mkdir html
60 mkdir xml
61 mkdir lib
62 mkdir lib/flows
63 mkdir logs
64 mkdir conf
65 mkdir codecloud
66 customSettingsFile="customSettings.js"
67 if [ ! -e "./$customSettingsFile" ]
68 then
69         echo "module.exports = {" >$customSettingsFile
70         echo "          'name' : '$name'," >>$customSettingsFile
71         echo "          'emailAddress' :'$emailid'," >>$customSettingsFile
72         echo "          'uiPort' :$nextPort," >>$customSettingsFile
73         echo "          'mqttReconnectTime': 15000," >>$customSettingsFile
74         echo "          'serialReconnectTime' : 15000,"  >>$customSettingsFile
75         echo "          'debugMaxLength': 1000," >>$customSettingsFile
76         echo "          'htmlPath': 'releases/$releaseDir/html/'," >>$customSettingsFile
77         echo "          'xmlPath': 'releases/$releaseDir/xml/'," >>$customSettingsFile
78         echo "          'flowFile' : 'releases/$releaseDir/flows/flows.json'," >>$customSettingsFile
79         echo "          'sharedDir': 'releases/$releaseDir/flows/shared'," >>$customSettingsFile
80         echo "          'userDir' : 'releases/$releaseDir'," >>$customSettingsFile
81         echo "          'httpAuth': {user:'$loginId',pass:'cc03e747a6afbbcbf8be7668acfebee5'}," >>$customSettingsFile
82         echo "          'dbHost': '$dbHost'," >>$customSettingsFile
83         echo "          'dbPort': '$dbPort'," >>$customSettingsFile
84         echo "          'dbName': '$dbName'," >>$customSettingsFile
85         echo "          'dbUser': '$dbUser'," >>$customSettingsFile
86         echo "          'dbPassword': '$dbPassword'," >>$customSettingsFile
87         echo "          'gitLocalRepository': '$gitLocalRepository'" >>$customSettingsFile
88         echo "          'restConfUrl': '$restConfUrl'," >>$customSettingsFile
89         echo "          'restConfUser': '$restConfUser'," >>$customSettingsFile
90         echo "          'restConfPassword': '$restConfPassword'," >>$customSettingsFile
91         echo "          'formatXML': '$formatXML'," >>$customSettingsFile
92         echo "          'formatJSON': '$formatJSON'," >>$customSettingsFile
93         echo "          'enableHttps': true" >>$customSettingsFile
94         echo "          }" >>$customSettingsFile
95 fi
96         #echo "Created custom settings  file $customSettingsFile"
97         echo "Done ....."
98 else
99         echo "ERROR:customSettings file $customSettingsFile already exists for $releaseDir"
100         exit
101 fi
102 #echo "Content of custom settings file"
103 #echo "============================================================================"
104 #       cat $customSettingsFile
105 #echo "============================================================================"
106 svclogicPropFile="./conf/svclogic.properties"
107 if [ ! -d "${appDir}/yangFiles" ]
108 then
109         mkdir -p "${appDir}/yangFiles"
110 fi
111 if [ ! -d "${appDir}/generatedJS" ]
112 then
113         mkdir -p "${appDir}/generatedJS"
114 fi
115
116 if [ ! -e "./$svclogicPropFile" ]
117 then
118         echo "org.onap.ccsdk.sli.dbtype=jdbc" >$svclogicPropFile
119         echo "org.onap.ccsdk.sli.jdbc.url=jdbc:mysql://{{.Values.config.dbServiceName}}.{{.Release.Namespace}}:3306/sdnctl" >>$svclogicPropFile
120         echo "org.onap.ccsdk.sli.jdbc.database=sdnctl" >>$svclogicPropFile
121         echo "org.onap.ccsdk.sli.jdbc.user=sdnctl" >>$svclogicPropFile
122         echo "org.onap.ccsdk.sli.jdbc.password={{.Values.config.dbSdnctlPassword}}" >>$svclogicPropFile
123 fi
124 if [ ! -e "${appDir}/flowShareUsers.js" ]
125 then
126         echo "module.exports = {\"flowShareUsers\":" >${appDir}/flowShareUsers.js
127         echo "  [" >>${appDir}/flowShareUsers.js
128         echo "  ]" >>${appDir}/flowShareUsers.js
129         echo "}" >>${appDir}/flowShareUsers.js
130 fi
131 grep "$releaseDir" ${appDir}/flowShareUsers.js >/dev/null 2>&1
132 if [ "$?" != "0" ]
133 then
134         num_of_lines=$(cat ${appDir}/flowShareUsers.js|wc -l)
135         if [ $num_of_lines -gt 4 ]
136         then
137                 content=$(head -n -2 ${appDir}/flowShareUsers.js)
138                 echo "${content}," > ${appDir}/flowShareUsers.js
139         else
140                 content=$(head -n -2 ${appDir}/flowShareUsers.js)
141                 echo "$content" > ${appDir}/flowShareUsers.js
142         fi
143         echo "  {" >> ${appDir}/flowShareUsers.js
144         echo "          \"name\" : \"$name\"," >> ${appDir}/flowShareUsers.js
145         echo "          \"rootDir\" : \"$releaseDir\"" >> ${appDir}/flowShareUsers.js
146         echo "  }" >> ${appDir}/flowShareUsers.js
147         echo "  ]" >> ${appDir}/flowShareUsers.js
148         echo "}" >> ${appDir}/flowShareUsers.js
149 fi