-#!/bin/bash
-################################################################################
-# Copyright (c) 2019 AT&T Intellectual Property. #
-# Copyright (c) 2019 Nokia. #
-# #
-# Licensed under the Apache License, Version 2.0 (the "License"); #
-# you may not use this file except in compliance with the License. #
-# You may obtain a copy of the License at #
-# #
-# http://www.apache.org/licenses/LICENSE-2.0 #
-# #
-# Unless required by applicable law or agreed to in writing, software #
-# distributed under the License is distributed on an "AS IS" BASIS, #
-# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. #
-# See the License for the specific language governing permissions and #
-# limitations under the License. #
-################################################################################
-
-OVERRIDEYAML=$1
-
-
-DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null && pwd )"
-source $DIR/../etc/nexus.conf
-
-if [ -z "$RICINFRA_RELEASE_NAME" ];then
- RELEASE_NAME=$helm_release_name
-else
- RELEASE_NAME=$RICINFRA_RELEASE_NAME
-fi
-if [ -z "$RICINFRA_NAMESPACE" ];then
- NAMESPACE=$namespace
-else
- NAMESPACE=$RICINFRA_NAMESPACE
-fi
-if [ -z "$INGRESS_PORT" ];then
- INGRESS_PORT_NEXUS=$ingress_port
-else
- INGRESS_PORT_NEXUS=$INGRESS_PORT
-fi
-
-if [ -z "$DEFAULT_NEXUS_ADMIN_PASSWORD" ];then
- NEXUS_ADMIN_PASSWORD=$default_admin_password
-else
- NEXUS_ADMIN_PASSWORD=$DEFAULT_NEXUS_ADMIN_PASSWORD
-fi
-
-
-
-HOSTPOSTFIX=$(cat $DIR/../helm/values.yaml | grep hostpostfix | awk '{print $2}')
-
-
-
-
-
-
-
-
-
-NEXUS_URL="http://nexus.$HOSTPOSTFIX:$INGRESS_PORT_NEXUS"
-
-
-
-
-
-
-if [ -z $OVERRIDEYAML ]; then
-
- DOCKERPASSWORD=$(cat $DIR/../../20-Credential/helm/values.yaml | awk '/^.*repositoryCredential:.*/{getline; getline; print substr($2, 2, length($2)-2);}')
- HELMPASSWORD=$(cat $DIR/../../20-Credential/helm/values.yaml | awk '/^.*helmrepoCredential:.*/{getline; getline; print substr($2, 2, length($2)-2);}')
- ADMINPASSWORD=$(cat $DIR/../helm/values.yaml | awk '/^.*adminPassword:.*/{print $2}')
-
-else
-
-
-
- DOCKERPASSWORD=$(cat $OVERRIDEYAML | awk '/^.*repositoryCredential:.*/{getline; getline; print substr($2, 2, length($2)-2);}')
-
-
-
- if [ -z $DOCKERPASSWORD ]; then
- DOCKERPASSWORD=$(cat $DIR/../../20-Credential/helm/values.yaml | awk '/^.*repositoryCredential:.*/{getline; getline; print substr($2, 2, length($2)-2);}')
- fi
-
- HELMPASSWORD=$(cat $OVERRIDEYAML | awk '/^.*helmrepoCredential:.*/{getline; getline; print substr($2, 2, length($2)-2);}')
-
- if [ -z $HELMPASSWORD ]; then
- HELMPASSWORD=$(cat $DIR/../../20-Credential/helm/values.yaml | awk '/^.*helmrepoCredential:.*/{getline; getline; print substr($2, 2, length($2)-2);}')
- fi
-
- ADMINPASSWORD=$(cat $OVERRIDEYAML | awk '/^.*adminPassword:.*/{print $2;}')
- if [ -z $ADMINPASSWORD ]; then
- ADMINPASSWORD=$(cat $DIR/../helm/values.yaml | awk '/^.*adminPassword:.*/{print $2;}')
- fi
-
-fi
-
-
-
-
-#echo $DOCKERPASSWORD, $HELMPASSWORD, $ADMINPASSWORD
-
-
-
-
-DOCKERPORT=$(cat $DIR/../helm/templates/deployment.yaml | awk '/.*- name: docker.*/{getline; print $2}')
-
-
-DOCKERREPOSCRIPT="{\"name\":\"docker_changepassword\",\
- \"type\":\"groovy\",\
- \"content\":\"security.securitySystem.changePassword('docker', '$DOCKERPASSWORD')\"}"
-
-
-
-
-# This line uses the default admin password
-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)
-
-
-if [ "${STATUS}" != "204" ];then
- echo "> script upload failed!"
-fi
-
-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)
-
-
-if [ "${STATUS}" == "200" ];then
- echo "> docker password change succeeded!"
-else
- echo "> docker password change failed!"
-fi
-
-
-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)
-
-
-if [ "${STATUS}" != "204" ];then
- echo "> script deletion failed!"
-fi
-
-
-
-
-
-
-
-
-
-
-
-
-
-HELMREPOSCRIPT="{\"name\":\"helm_changepassword\",\
- \"type\":\"groovy\",\
- \"content\":\"security.securitySystem.changePassword('helm', '$HELMPASSWORD')\"}"
-
-
-
-# This line uses the default admin password
-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)
-
-
-if [ "${STATUS}" != "204" ];then
- echo "> script upload failed!"
-fi
-
-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)
-
-
-if [ "${STATUS}" == "200" ];then
- echo "> helm password change succeeded!"
-else
- echo "> helm password change failed!"
-fi
-
-
-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)
-
-
-if [ "${STATUS}" != "204" ];then
- echo "> script deletion failed!"
-fi
-
-
-
-
-
-
-
-
-
-
-
-
-
-ADMINSCRIPT="{\"name\":\"admin_changepassword\",\
- \"type\":\"groovy\",\
- \"content\":\"security.securitySystem.changePassword('admin', '$ADMINPASSWORD')\"}"
-
-
-
-# This line uses the default admin password
-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)
-
-
-if [ "${STATUS}" != "204" ];then
- echo "> script upload failed!"
-fi
-
-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)
-
-
-if [ "${STATUS}" == "200" ];then
- echo "> admin password change succeeded!"
-else
- echo "> admin password change failed!"
-fi
-
-NEXUS_ADMIN_PASSWORD=$ADMINPASSWORD
-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)
-
-
-if [ "${STATUS}" != "204" ];then
- echo "> script deletion failed!"
-fi
-