2 ################################################################################
3 # Copyright (c) 2019 AT&T Intellectual Property. #
4 # Copyright (c) 2019 Nokia. #
6 # Licensed under the Apache License, Version 2.0 (the "License"); #
7 # you may not use this file except in compliance with the License. #
8 # You may obtain a copy of the License at #
10 # http://www.apache.org/licenses/LICENSE-2.0 #
12 # Unless required by applicable law or agreed to in writing, software #
13 # distributed under the License is distributed on an "AS IS" BASIS, #
14 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. #
15 # See the License for the specific language governing permissions and #
16 # limitations under the License. #
17 ################################################################################
22 DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null && pwd )"
23 source $DIR/../etc/nexus.conf
25 if [ -z "$RICINFRA_RELEASE_NAME" ];then
26 RELEASE_NAME=$helm_release_name
28 RELEASE_NAME=$RICINFRA_RELEASE_NAME
30 if [ -z "$RICINFRA_NAMESPACE" ];then
33 NAMESPACE=$RICINFRA_NAMESPACE
35 if [ -z "$INGRESS_PORT" ];then
36 INGRESS_PORT_NEXUS=$ingress_port
38 INGRESS_PORT_NEXUS=$INGRESS_PORT
41 if [ -z "$DEFAULT_NEXUS_ADMIN_PASSWORD" ];then
42 NEXUS_ADMIN_PASSWORD=$default_admin_password
44 NEXUS_ADMIN_PASSWORD=$DEFAULT_NEXUS_ADMIN_PASSWORD
49 HOSTPOSTFIX=$(cat $DIR/../helm/values.yaml | grep hostpostfix | awk '{print $2}')
59 NEXUS_URL="http://nexus.$HOSTPOSTFIX:$INGRESS_PORT_NEXUS"
66 if [ -z $OVERRIDEYAML ]; then
68 DOCKERPASSWORD=$(cat $DIR/../../20-Credential/helm/values.yaml | awk '/^.*repositoryCredential:.*/{getline; getline; print substr($2, 2, length($2)-2);}')
69 HELMPASSWORD=$(cat $DIR/../../20-Credential/helm/values.yaml | awk '/^.*helmrepoCredential:.*/{getline; getline; print substr($2, 2, length($2)-2);}')
70 ADMINPASSWORD=$(cat $DIR/../helm/values.yaml | awk '/^.*adminPassword:.*/{print $2}')
76 DOCKERPASSWORD=$(cat $OVERRIDEYAML | awk '/^.*repositoryCredential:.*/{getline; getline; print substr($2, 2, length($2)-2);}')
80 if [ -z $DOCKERPASSWORD ]; then
81 DOCKERPASSWORD=$(cat $DIR/../../20-Credential/helm/values.yaml | awk '/^.*repositoryCredential:.*/{getline; getline; print substr($2, 2, length($2)-2);}')
84 HELMPASSWORD=$(cat $OVERRIDEYAML | awk '/^.*helmrepoCredential:.*/{getline; getline; print substr($2, 2, length($2)-2);}')
86 if [ -z $HELMPASSWORD ]; then
87 HELMPASSWORD=$(cat $DIR/../../20-Credential/helm/values.yaml | awk '/^.*helmrepoCredential:.*/{getline; getline; print substr($2, 2, length($2)-2);}')
90 ADMINPASSWORD=$(cat $OVERRIDEYAML | awk '/^.*adminPassword:.*/{print $2;}')
91 if [ -z $ADMINPASSWORD ]; then
92 ADMINPASSWORD=$(cat $DIR/../helm/values.yaml | awk '/^.*adminPassword:.*/{print $2;}')
100 #echo $DOCKERPASSWORD, $HELMPASSWORD, $ADMINPASSWORD
105 DOCKERPORT=$(cat $DIR/../helm/templates/deployment.yaml | awk '/.*- name: docker.*/{getline; print $2}')
108 DOCKERREPOSCRIPT="{\"name\":\"docker_changepassword\",\
109 \"type\":\"groovy\",\
110 \"content\":\"security.securitySystem.changePassword('docker', '$DOCKERPASSWORD')\"}"
115 # This line uses the default admin password
116 STATUS=$(curl -s -o /dev/null -w "%{http_code}" -u admin:$NEXUS_ADMIN_PASSWORD -X POST -H "Content-Type: application/json" --data "$DOCKERREPOSCRIPT" http://nexus.$HOSTPOSTFIX:$INGRESS_PORT_NEXUS/service/rest/v1/script)
119 if [ "${STATUS}" != "204" ];then
120 echo "> script upload failed!"
123 STATUS=$(curl -s -o /dev/null -w "%{http_code}" -u admin:$NEXUS_ADMIN_PASSWORD -X POST -H 'Content-Type: text/plain' -H 'Accept: application/json' http://nexus.$HOSTPOSTFIX:$INGRESS_PORT_NEXUS/service/rest/v1/script/docker_changepassword/run)
126 if [ "${STATUS}" == "200" ];then
127 echo "> docker password change succeeded!"
129 echo "> docker password change failed!"
133 STATUS=$(curl -s -o /dev/null -w "%{http_code}" -X DELETE -u admin:$NEXUS_ADMIN_PASSWORD http://nexus.$HOSTPOSTFIX:$INGRESS_PORT_NEXUS/service/rest/v1/script/docker_changepassword)
136 if [ "${STATUS}" != "204" ];then
137 echo "> script deletion failed!"
152 HELMREPOSCRIPT="{\"name\":\"helm_changepassword\",\
153 \"type\":\"groovy\",\
154 \"content\":\"security.securitySystem.changePassword('helm', '$HELMPASSWORD')\"}"
158 # This line uses the default admin password
159 STATUS=$(curl -s -o /dev/null -w "%{http_code}" -u admin:$NEXUS_ADMIN_PASSWORD -X POST -H "Content-Type: application/json" --data "$HELMREPOSCRIPT" http://nexus.$HOSTPOSTFIX:$INGRESS_PORT_NEXUS/service/rest/v1/script)
162 if [ "${STATUS}" != "204" ];then
163 echo "> script upload failed!"
166 STATUS=$(curl -s -o /dev/null -w "%{http_code}" -u admin:$NEXUS_ADMIN_PASSWORD -X POST -H 'Content-Type: text/plain' -H 'Accept: application/json' http://nexus.$HOSTPOSTFIX:$INGRESS_PORT_NEXUS/service/rest/v1/script/helm_changepassword/run)
169 if [ "${STATUS}" == "200" ];then
170 echo "> helm password change succeeded!"
172 echo "> helm password change failed!"
176 STATUS=$(curl -s -o /dev/null -w "%{http_code}" -X DELETE -u admin:$NEXUS_ADMIN_PASSWORD http://nexus.$HOSTPOSTFIX:$INGRESS_PORT_NEXUS/service/rest/v1/script/helm_changepassword)
179 if [ "${STATUS}" != "204" ];then
180 echo "> script deletion failed!"
195 ADMINSCRIPT="{\"name\":\"admin_changepassword\",\
196 \"type\":\"groovy\",\
197 \"content\":\"security.securitySystem.changePassword('admin', '$ADMINPASSWORD')\"}"
201 # This line uses the default admin password
202 STATUS=$(curl -s -o /dev/null -w "%{http_code}" -u admin:$NEXUS_ADMIN_PASSWORD -X POST -H "Content-Type: application/json" --data "$ADMINSCRIPT" http://nexus.$HOSTPOSTFIX:$INGRESS_PORT_NEXUS/service/rest/v1/script)
205 if [ "${STATUS}" != "204" ];then
206 echo "> script upload failed!"
209 STATUS=$(curl -s -o /dev/null -w "%{http_code}" -u admin:$NEXUS_ADMIN_PASSWORD -X POST -H 'Content-Type: text/plain' -H 'Accept: application/json' http://nexus.$HOSTPOSTFIX:$INGRESS_PORT_NEXUS/service/rest/v1/script/admin_changepassword/run)
212 if [ "${STATUS}" == "200" ];then
213 echo "> admin password change succeeded!"
215 echo "> admin password change failed!"
218 NEXUS_ADMIN_PASSWORD=$ADMINPASSWORD
219 STATUS=$(curl -s -o /dev/null -w "%{http_code}" -X DELETE -u admin:$NEXUS_ADMIN_PASSWORD http://nexus.$HOSTPOSTFIX:$INGRESS_PORT_NEXUS/service/rest/v1/script/admin_changepassword)
222 if [ "${STATUS}" != "204" ];then
223 echo "> script deletion failed!"