Merge "update drools container configuration"
[oom.git] / kubernetes / policy / charts / drools / resources / config / opt / policy / config / drools / apps-install.sh
1 #!/bin/bash
2 #
3 # ============LICENSE_START=======================================================
4 # ONAP
5 # ================================================================================
6 # Copyright (C) 2018 AT&T Intellectual Property. All rights reserved.
7 # ================================================================================
8 # Licensed under the Apache License, Version 2.0 (the "License");
9 # you may not use this file except in compliance with the License.
10 # You may obtain a copy of the License at
11 #
12 #      http://www.apache.org/licenses/LICENSE-2.0
13 #
14 # Unless required by applicable law or agreed to in writing, software
15 # distributed under the License is distributed on an "AS IS" BASIS,
16 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17 # See the License for the specific language governing permissions and
18 # limitations under the License.
19 # ============LICENSE_END=========================================================
20 #
21
22 # #################################
23 # Usage
24 # #################################
25
26 function usage {
27     echo
28     echo "Usage: $(basename $0) <application-name> <zipped-application-version> <download-directory>"
29     echo "Example: $(basename $0) controlloop 1.2.0 /opt/policy/config/drools"
30     echo
31 }
32
33 # #################################
34 # snapshot url computation
35 # #################################
36
37 function url_snapshot {
38     if [[ $DEBUG == y ]]; then
39         echo "-- ${FUNCNAME[0]} --"
40         set -x
41     fi
42
43     APP_URL="${APP_URL}/snapshots/org/onap/policy/drools-applications/${APP_NAME}/packages/apps-${APP_NAME}/${APP_VERSION}"
44
45     local APP_METADATA_URL="${APP_URL}/maven-metadata.xml"
46     local APP_SNAPSHOT_VERSION=$(curl --silent "${APP_METADATA_URL}" | grep -Po "(?<=<value>).*(?=</value>)" | sort -V | tail -1)
47
48     if [[ -z ${APP_SNAPSHOT_VERSION} ]]; then
49         echo "ERROR: cannot compute SNAPSHOT version"
50         usage
51         exit 1
52     fi
53
54     APP_URL="${APP_URL}/apps-${APP_NAME}-${APP_SNAPSHOT_VERSION}.zip"
55 }
56
57 # #################################
58 # release url computation
59 # #################################
60
61 function url_release {
62     if [[ $DEBUG == y ]]; then
63         echo "-- ${FUNCNAME[0]} --"
64         set -x
65     fi
66
67     APP_URL="${APP_URL}/releases/org/onap/policy/drools-applications/${APP_NAME}/packages/apps-${APP_NAME}/${APP_VERSION}/apps-${APP_NAME}-${APP_VERSION}.zip"
68 }
69
70 # #################################
71 # Main
72 # #################################
73
74 if [[ $DEBUG == y ]]; then
75     set -x
76 fi
77
78 APP_NAME=$1
79 if [[ -z ${APP_NAME} ]]; then
80     echo "ERROR: no APPLICATION NAME provided (ie. controlloop)"
81     usage
82     exit 1
83 fi
84
85 APP_VERSION=$2
86 if [[ -z ${APP_VERSION} ]]; then
87     echo "ERROR: no APPLICATION VERSION provided"
88     usage
89     exit 1
90 fi
91
92 DOWNLOAD_DIR=$3
93 if [[ -z ${DOWNLOAD_DIR} ]]; then
94     echo "ERROR: no DOWNLOAD DIRECTORY provided"
95     usage
96     exit 1
97 fi
98
99 if [[ ! -d ${DOWNLOAD_DIR} ]]; then
100     echo "ERROR: ${DOWNLOAD_DIR} is not a directory"
101     usage
102     exit 1
103 fi
104
105 APP_GROUP_ID="org.onap.policy.drools-applications.${APP_NAME}.packages"
106 APP_ARTIFACT_ID="apps-${APP_NAME}"
107 APP_BASE_URL="https://nexus.onap.org/content/repositories"
108
109 APP_URL="${APP_BASE_URL}"
110
111 if [[ ${APP_VERSION} =~ \-SNAPSHOT$ ]]; then
112     url_snapshot
113 else
114     url_release
115 fi
116
117 wget "${APP_URL}" -O "${DOWNLOAD_DIR}"/apps-"${APP_NAME}".zip
118 if [[ $? != 0 ]]; then
119     echo "ERROR: cannot download ${DOWNLOAD_DIR}/apps-${APP_NAME}.zip"
120     exit 1
121 fi
122
123 echo "APP ${APP_NAME} stored at ${DOWNLOAD_DIR}/apps-${APP_NAME}.zip"
124 ls -l "${DOWNLOAD_DIR}"/apps-"${APP_NAME}".zip